Skip to content

Commit

Permalink
Show list on complete if not yet visible
Browse files Browse the repository at this point in the history
Resolves #340.
  • Loading branch information
marlonrichert committed Sep 14, 2021
1 parent 118f8bb commit 586c60c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
30 changes: 19 additions & 11 deletions .clitest/complete-word.post.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Setup:
% autoload -Uz zmathfunc && zmathfunc
% autoload -Uz $PWD/functions/widget/.autocomplete.complete-word.post
% unset terminfo
% typeset -gA terminfo=() compstate=() _lastcomp=()
% typeset -gA terminfo=() compstate=( [old_list]=shown ) _lastcomp=()
% terminfo[kcbt]=BACKSPACE
% zstyle ':autocomplete:*' add-space 'FOO' 'TAG' 'BAR'
%
Expand All @@ -12,39 +12,47 @@ Setup:
Only `menu-select` widget sets `$MENUSELECT`:
```zsh
% WIDGET=menu-select .autocomplete.complete-word.post
% print -r - ${(q+)compstate[insert]} $+MENUSELECT
1 1
% print -r -- ${(q+)compstate[insert]} ${(q+)compstate[list]} $+MENUSELECT
1 '' 1
%
```

Only `Shift-Tab` key sets `$compstate[insert]` to `*:0`:
```zsh
% KEYS=BACKSPACE .autocomplete.complete-word.post
% print -r - ${(q+)compstate[insert]} $+MENUSELECT
0 0
% print -r -- ${(q+)compstate[insert]} ${(q+)compstate[list]} $+MENUSELECT
0 '' 0
%
```

`add-space` tag in current completion adds space:
```zsh
% _comp_tags='LOREM TAG IPSUM' _lastcomp[tags]='OTHER' .autocomplete.complete-word.post
% print -r - ${(q+)compstate[insert]} $+MENUSELECT
'1 ' 0
% print -r -- ${(q+)compstate[insert]} ${(q+)compstate[list]} $+MENUSELECT
'1 ' '' 0
%
```

`add-space` tag in previous completion adds space, if current completion is not used:
```zsh
% _comp_tags= _lastcomp[tags]='LOREM TAG IPSUM' .autocomplete.complete-word.post
% print -r - ${(q+)compstate[insert]} $+MENUSELECT
'1 ' 0
% print -r -- ${(q+)compstate[insert]} ${(q+)compstate[list]} $+MENUSELECT
'1 ' '' 0
%
```

`add-space` tag in previous completion does NOT add space, if current completion is used:
```zsh
% _comp_tags='OTHER' _lastcomp[tags]='TAG' .autocomplete.complete-word.post
% print -r - ${(q+)compstate[insert]} $+MENUSELECT
1 0
% print -r -- ${(q+)compstate[insert]} ${(q+)compstate[list]} $+MENUSELECT
1 '' 0
%
```

If list is not yet shown, then insert unambiguous and show list:
```zsh
% compstate[old_list]= _comp_tags= _lastcomp[tags]= .autocomplete.complete-word.post
% print -r -- ${(q+)compstate[insert]} ${(q+)compstate[list]} $+MENUSELECT
unambiguous 'list force packed rows' 0
%
```
10 changes: 7 additions & 3 deletions functions/widget/.autocomplete.complete-word.post
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#autoload
builtin autoload -Uz is-at-least

unset MENUSELECT
compstate[insert]=
builtin autoload -Uz is-at-least

private key_name=
case $KEYS in
Expand All @@ -11,9 +12,11 @@ esac
local key_style=
builtin zstyle -s :autocomplete:${key_name}: widget-style key_style

if ( [[ $key_name == shift-tab ]] ||
if [[ ! -v compstate[old_list] || -z $compstate[old_list] ]] ||
(
[[ -v _autocomplete__unambiguous && -n $_autocomplete__unambiguous ]] &&
builtin zstyle -t ":autocomplete:${key_name}:" insert-unambiguous
) && [[ -v _autocomplete__unambiguous && -n $_autocomplete__unambiguous ]]; then
); then

if ! is-at-least 5.8.1; then
# Work around a crashing bug in Zsh.
Expand All @@ -23,6 +26,7 @@ if ( [[ $key_name == shift-tab ]] ||
fi

compstate[insert]+=unambiguous
compstate[list]='list force packed rows'
unset _autocomplete__unambiguous
return
fi
Expand Down
7 changes: 6 additions & 1 deletion scripts/.autocomplete.key-binding
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ zmodload -F zsh/parameter p:funcstack p:functions
emulate -L zsh
setopt $_autocomplete__func_opts[@]

local -a ignored=()
builtin zstyle -g ignored ':autocomplete:shift-tab:*' insert-unambiguous ||
builtin zstyle ':autocomplete:shift-tab:*' insert-unambiguous yes

local tab_style=
builtin zstyle -s :autocomplete:tab: widget-style tab_style ||
tab_style='complete-word'

if builtin zstyle -t :autocomplete:tab: fzf || builtin zstyle -t :autocomplete:tab: fzf-completion; then
if builtin zstyle -t :autocomplete:tab: fzf ||
builtin zstyle -t :autocomplete:tab: fzf-completion; then
typeset -gH fzf_default_completion=$tab_style
functions[.autocomplete.fzf-completion]=$functions[fzf-completion]
fzf-completion() {
Expand Down

0 comments on commit 586c60c

Please sign in to comment.