From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: tricky.c and i-c-w
Date: Thu, 8 Jul 1999 11:11:05 +0200 (MET DST) [thread overview]
Message-ID: <199907080911.LAA11926@beta.informatik.hu-berlin.de> (raw)
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@informatik.hu-berlin.de
next reply other threads:[~1999-07-08 9:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-07-08 9:11 Sven Wischnowsky [this message]
1999-07-09 8:35 Sven Wischnowsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199907080911.LAA11926@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).