Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: tricky.c and i-c-w
- X-seq: zsh-workers 7028
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: tricky.c and i-c-w
- Date: Thu, 8 Jul 1999 11:11:05 +0200 (MET DST)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
While playing with i-c-w I found a bug in the completion code: when it
inserted something into the line and another widget changes the line
by modifying BUFFER and friends, the cursor position the completion
code had to store internally could become invalid.
I fear that there are even more problems here: if we are in a
menu-completion and someone changes the command line directly, calling
the completion code again may have all kinds of nasty effects. At
least I think so, haven't tried it yet, but I will look into it.
Anyway, the patch patches the file Functions/Zle/incremental-complete-word.
The first change is that you can put a `%u' in the prompt which will
be replaced by the unambiguous part of the matches if there is any and
it differs from what's on the line (giving you some visual feedback
when it might be interesting to hit TAB).
The other change is that the list isn't always shown any more, only if
the config key incremental_list is set to a non-empty string.
All this is relative to the version Peter posted. Haven't added any
real comments yet.
Bye
Sven
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c Wed Jul 7 11:28:51 1999
+++ Src/Zle/zle_tricky.c Thu Jul 8 10:39:24 1999
@@ -818,7 +818,8 @@
* string inserted by the last completion. */
if (fromcomp & FC_INWORD)
- cs = lastend;
+ if ((cs = lastend) > ll)
+ cs = ll;
/* Check if we have to start a menu-completion (via automenu). */
diff -u of/Zle/incremental-complete-word Functions/Zle/incremental-complete-word
--- of/Zle/incremental-complete-word Thu Jul 8 10:04:10 1999
+++ Functions/Zle/incremental-complete-word Thu Jul 8 11:01:00 1999
@@ -10,28 +10,47 @@
# abort back to the state when you started.
#
# Completion keys:
-# incremental_prompt Prompt to show in status line during icompletion
+# incremental_prompt Prompt to show in status line during icompletion;
+# the sequence `%u' is replaced by the unambiguous
+# part of all matches if there is any and it is
+# different from the word on the line
# incremental_stop Pattern matching keys which will cause icompletion
# to stop and the key to re-executed
# incremental_break Pattern matching keys which will cause icompletion
# to stop and the key to be discarded
# incremental_completer Name of completion widget to call to get choices
+# incremental_list If set to a non-empty string, the matches will be
+# listed on every key-press
emulate -L zsh
-unsetopt menucomplete # doesn't work well
+unsetopt autolist menucomplete automenu # doesn't work well
-local key lbuf="$LBUFFER" rbuf="$RBUFFER" pmpt
+local key lbuf="$LBUFFER" rbuf="$RBUFFER" pmpt word lastl lastr wid twid
[[ -n "$compconfig[incremental_completer]" ]] &&
set ${(s.:.)compconfig[incremental_completer]}
pmpt="${compconfig[incremental_prompt]-incremental completion...}"
-zle list-choices
-zle -R "$pmpt"
+if [[ -n "$compconfig[incremental_list]" ]]; then
+ wid=list-choices
+else
+ wid=complete-word
+fi
+
+zle $wid "$@"
+LBUFFER="$lbuf"
+RBUFFER="$rbuf"
+if [[ "${LBUFFER}${RBUFFER}" = *${_lastcomp[unambiguous]}* ]]; then
+ word=''
+else
+ word="${_lastcomp[unambiguous]}"
+fi
+zle -R "${pmpt//\\%u/$word}"
read -k key
while [[ '#key' -ne '#\\r' && '#key' -ne '#\\n' &&
'#key' -ne '#\\C-g' ]]; do
+ twid=$wid
if [[ "$key" = ${~compconfig[incremental_stop]} ]]; then
zle -U "$key"
return
@@ -41,11 +60,24 @@
[[ $#LBUFFER -gt $#l ]] && LBUFFER="$LBUFFER[1,-2]"
elif [[ '#key' -eq '#\\t' ]]; then
zle complete-word "$@"
+ lbuf="$LBUFFER"
+ rbuf="$RBUFFER"
+ elif [[ '#key' -eq '#\\C-d' ]]; then
+ twid=list-choices
else
LBUFFER="$LBUFFER$key"
fi
- zle list-choices "$@"
- zle -R "$pmpt"
+ lastl="$LBUFFER"
+ lastr="$RBUFFER"
+ zle $twid "$@"
+ LBUFFER="$lastl"
+ RBUFFER="$lastr"
+ if [[ "${LBUFFER}${RBUFFER}" = *${_lastcomp[unambiguous]}* ]]; then
+ word=''
+ else
+ word="${_lastcomp[unambiguous]}"
+ fi
+ zle -R "${pmpt//\\%u/$word}"
read -k key
done
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author