From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2462 invoked from network); 8 Jul 1999 09:11:25 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 8 Jul 1999 09:11:25 -0000 Received: (qmail 19513 invoked by alias); 8 Jul 1999 09:11:10 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7028 Received: (qmail 19497 invoked from network); 8 Jul 1999 09:11:06 -0000 Date: Thu, 8 Jul 1999 11:11:05 +0200 (MET DST) Message-Id: <199907080911.LAA11926@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk Subject: PATCH: tricky.c and i-c-w 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