zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: tricky.c and i-c-w
@ 1999-07-09  8:35 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 1999-07-09  8:35 UTC (permalink / raw)
  To: zsh-workers


I wrote:

> 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.

Yes, we have to break menu-completion when someone sets [LR]BUFFER,
otherwise the command-line positions stored get invalid.

Bye
 Sven

diff -u oos/Zle/zle_params.c Src/Zle/zle_params.c
--- oos/Zle/zle_params.c	Thu Jul  8 11:11:37 1999
+++ Src/Zle/zle_params.c	Fri Jul  9 10:29:59 1999
@@ -137,6 +137,8 @@
 	    cs = ll;
     } else
 	cs = ll = 0;
+    fixsuffix();
+    menucmp = 0;
 }
 
 /**/
@@ -156,6 +158,8 @@
 	cs = ll;
     else
 	cs = x;
+    fixsuffix();
+    menucmp = 0;
 }
 
 /**/
@@ -182,6 +186,8 @@
     ll = ll - cs + len;
     cs = len;
     zsfree(x);
+    fixsuffix();
+    menucmp = 0;
 }
 
 /**/
@@ -205,6 +211,8 @@
     sizeline(ll = cs + len);
     memcpy(line + cs, y, len);
     zsfree(x);
+    fixsuffix();
+    menucmp = 0;
 }
 
 /**/

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

* PATCH: tricky.c and i-c-w
@ 1999-07-08  9:11 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 1999-07-08  9:11 UTC (permalink / raw)
  To: zsh-workers


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-07-09  8:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-09  8:35 PATCH: tricky.c and i-c-w Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1999-07-08  9:11 Sven Wischnowsky

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).