51860: simplify suffix handling in _prefix to remove less accurate hack

This solves the following problems in the _prefix completer:
- The old code had logic for dealing with compstate[unambiguous] that
  was unnecessary. It works fine without it.
- Because of this logic, if a widget set compstate[insert]=1 after
  calling _main_complete, an `x` was left after the completion on the
  command line.
- If the same widget also set `compstate[to_end]=`, then instead, the
  last character of the inserted completion would be treated as an
  autoremovable suffix, with the actual suffix being inserted to the
  line as a normal character.
- After inserting a completion, the cursor would move to the end of the
  entire current word on the command, not the end of word that was
  inserted. This is not what you want with _prefix, since you are trying
  to complete a word _before_ the one on the command line, after which
  you usually want to insert a separator, such as a space or slash,
  before the next word.
This commit is contained in:
Marlon Richert
2023-06-22 13:13:09 -07:00
committed by Bart Schaefer
parent 4f6a1b3717
commit 6c993144bd
3 changed files with 57 additions and 8 deletions

View File

@@ -49,13 +49,8 @@ for tmp in "$comp[@]"; do
fi
if [[ "$tmp" != _prefix ]] && "$tmp"; then
[[ compstate[nmatches] -gt 1 ]] && return 0
compadd -U -i "$IPREFIX" -I "$ISUFFIX" - "${compstate[unambiguous]%$suf}x"
compstate[list]=
if [[ -n $compstate[unambiguous] ]]; then
compstate[insert]=unambiguous
else
compstate[insert]=0
if [[ -n $compstate[old_list] || ${compstate[unambiguous]%$suf} == $PREFIX ]]; then
compstate[to_end]=match
fi
return 0
fi

View File

@@ -35,6 +35,54 @@
>line: {: dir1/}{}
>line: {: dir2/}{}
comptest $': d\t\t\t\t\t \t'
0:unambiguous prefix and autoremovable suffix
>line: {: dir}{}
>line: {: dir}{}
>DESCRIPTION:{file}
>DI:{dir1}
>DI:{dir2}
>line: {: dir1/}{}
>line: {: dir2/}{}
>line: {: dir1/}{}
>line: {: dir1 }{}
>DESCRIPTION:{file}
>DI:{dir1}
>DI:{dir2}
>FI:{file1}
>FI:{file2}
comptest $': suf\ebd\t\t\t\t\t \t'
0:unambiguous prefix and autoremovable suffix with _prefix completer
>line: {: dir}{suf}
>line: {: dir}{suf}
>DESCRIPTION:{file}
>DI:{dir1}
>DI:{dir2}
>line: {: dir1/}{suf}
>line: {: dir2/}{suf}
>line: {: dir1/}{suf}
>line: {: dir1 }{suf}
>DESCRIPTION:{file}
>DI:{dir1}
>DI:{dir2}
>FI:{file1}
>FI:{file2}
F:regression test workers/51641
comptesteval 'comptest-postfunc() { compstate[insert]=1 compstate[list]= }'
comptest $': \t \t'
0:compstate[insert]=1 compstate[list]=
>line: {: dir1/}{}
>line: {: dir1 dir1/}{}
comptest $': suf\eb\t \t'
0:compstate[insert]=1 compstate[list]= with _prefix completer
>line: {: dir1/}{suf}
>line: {: dir1 dir1/}{suf}
F:regression test workers/51641
comptesteval 'comptest-postfunc() {}'
comptest $': *\t\t\t\t\t\t'
0:_expand shows file types
>line: {: dir1/}{}

View File

@@ -40,7 +40,7 @@ KEYTIMEOUT=1
setopt zle
autoload -U compinit
compinit -u
zstyle ":completion:*" completer _expand _complete _ignored
zstyle ":completion:*" completer _expand _complete _prefix _ignored
zstyle ":completion:*:default" list-colors "no=<NO>" "fi=<FI>" "di=<DI>" "ln=<LN>" "pi=<PI>" "so=<SO>" "bd=<BD>" "cd=<CD>" "ex=<EX>" "mi=<MI>" "tc=<TC>" "sp=<SP>" "lc=<LC>" "ec=<EC>\n" "rc=<RC>"
zstyle ":completion:*" group-name ""
zstyle ":completion:*:messages" format "<MESSAGE>%d</MESSAGE>
@@ -51,6 +51,12 @@ zstyle ":completion:*:options" verbose yes
zstyle ":completion:*:values" verbose yes
setopt noalwayslastprompt listrowsfirst completeinword
zmodload zsh/complist
zle -C complete-word complete-word complete-word-with-postfunc
complete-word-with-postfunc() {
local +h -a comppostfuncs=( comptest-postfunc )
_main_complete "$@"
}
comptest-postfunc() {}
complete-word-with-report () {
print -lr "<WIDGET><complete-word>"
zle complete-word