Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 1/3] Fix _prefix insertion logic
- X-seq: zsh-workers 51716
- From: Marlon Richert <marlon.richert@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Cc: Marlon Richert <marlon.richert@xxxxxxxxx>
- Subject: [PATCH 1/3] Fix _prefix insertion logic
- Date: Fri, 5 May 2023 14:41:55 +0300
- Archived-at: <https://zsh.org/workers/51716>
- In-reply-to: <CAH+w=7aWEesO_hN+eUCj9VCJ+soUvXqSSNRAAPSY-JoCZvcWcQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7aWEesO_hN+eUCj9VCJ+soUvXqSSNRAAPSY-JoCZvcWcQ@mail.gmail.com>
From: Marlon Richert <marlon.richert@xxxxxxxxx>
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.
Discussed in workers/51641.
---
Completion/Base/Completer/_prefix | 9 +--------
Test/Y01completion.ztst | 18 ++++++++++++++++++
Test/comptest | 2 +-
3 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/Completion/Base/Completer/_prefix b/Completion/Base/Completer/_prefix
index 74be5f47d..01739166e 100644
--- a/Completion/Base/Completer/_prefix
+++ b/Completion/Base/Completer/_prefix
@@ -49,14 +49,7 @@ 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
- fi
+ compstate[to_end]=''
return 0
fi
(( _matcher_num++ ))
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index f976f9f91..51e246307 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -63,6 +63,24 @@
>NO:{file1}
>NO:{file2}
+ comptesteval 'tst-insert() { compstate[insert]=1; compstate[list]= }'
+ comptesteval 'comppostfuncs=( tst-insert )'
+ comptest $': dir1\ebf\t'
+0:_prefix with compstate[insert]=1 does not move to end
+>line: {: file1}{dir1}
+
+ comptesteval 'unfunction tst-insert'
+ comptesteval 'comppostfuncs=()'
+ comptest $': dir1\ebf\t\t\t\t'
+0:_prefix inserts unambiguous and does not move to end
+>line: {: file}{dir1}
+>line: {: file}{dir1}
+>DESCRIPTION:{file}
+>FI:{file1}
+>FI:{file2}
+>line: {: file1}{dir1}
+>line: {: file2}{dir1}
+
comptesteval $'zstyle -d \'*\' glob'
comptesteval '_users () { compadd user1 user2 }'
comptest $': ~\t\t\t\t\t'
diff --git a/Test/comptest b/Test/comptest
index 79c69979a..a57f4bcc4 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -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>
--
2.39.2 (Apple Git-143)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author