Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh 4.x bug in completion?



Bart Schaefer wrote:

> I get very strange behavior from 4.0.2.
> 
> With
> 
> zstyle ':completion:*' completer _complete _prefix  
> 
> I get:
> 
> schaefer<503> <Ctrl-P>
> schaefer<503> echo foo<Ctrl-A>
> schaefer<503> sud<TAB>echo foo
> schaefer<503> sudoecho  foo
>                        ^
> 		       cursor here
> 
> That is, it inserts `sudo' with no trailing space, but then moves to
> the end of the word `echo' and adds a space *there*.  That is almost
> certainly wrong?
> 
> I get exactly the same thing from 4.1.0-dev-2.
> 
> If I then add
> 
> zstyle ':completion:*' add-space yes
> 
> I get `sudo echo  foo', that is, it has added a space both after `sudo'
> and after `echo'.

Hm, yes.  These were both caused by _prefix being actually a hack.  But
we can hack some more when there is a single match, to trick it into
leaving the cursor where it should be left.

And then we need that hunk in the C-code because if the user requests
that no list is shown, we should do that and not print the explanation
strings.

> And, by the way, with TAB bound to expand-or-complete-prefix, I can in
> fact reproduce the original complaint.  Auto-removing the space may make
> sense when completing in the middle of a file path, but it doesn't when
> completing in command position.

That's the hunk in zle_tricky.c.  It turns off the auto-suffix behaviour
if completion left us after a space, leaving the space if a non-space
character is typed next.  I hope this is the most sensible thing to do.


Should this and/or the _man thing go into the stable branch? (I.e., is
that to be updated until the next stable release?)


Bye
  Sven

Index: Completion/Base/Completer/_prefix
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Completer/_prefix,v
retrieving revision 1.1
diff -u -r1.1 _prefix
--- Completion/Base/Completer/_prefix	2001/04/02 11:08:54	1.1
+++ Completion/Base/Completer/_prefix	2001/07/10 09:16:04
@@ -4,7 +4,7 @@
 
 [[ _matcher_num -gt 1 || -z "$SUFFIX" ]] && return 1
 
-local comp curcontext="$curcontext" tmp \
+local comp curcontext="$curcontext" tmp suf="$SUFFIX" \
       _completer _completer_num \
       _matcher _c_matcher _matchers _matcher_num
 
@@ -44,7 +44,13 @@
       _matcher="$_c_matcher"
     fi
 
-    [[ "$tmp" != _prefix ]] && "$tmp" && return 0
+    if [[ "$tmp" != _prefix ]] && "$tmp"; then
+      [[ compstate[nmatches] -gt 1 ]] && return 0
+      compadd -U -i "$IPREFIX" -I "$ISUFFIX" - "${compstate[unambiguous]%$suf}x"
+      compstate[list]=
+      compstate[insert]=unambiguous
+      return 0
+    fi
     (( _matcher_num++ ))
   done
   (( _completer_num++ ))
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.45
diff -u -r1.45 compcore.c
--- Src/Zle/compcore.c	2001/02/28 09:12:57	1.45
+++ Src/Zle/compcore.c	2001/07/10 09:16:05
@@ -420,7 +420,7 @@
 	cs = origcs;
     }
     /* Print the explanation strings if needed. */
-    if (!showinglist && validlist && usemenu != 2 && 
+    if (!showinglist && validlist && usemenu != 2 && uselist &&
 	(nmatches != 1 || diffmatches) &&
 	useline >= 0 && useline != 2 && (!oldlist || !listshown)) {
 	onlyexpl = 3;
Index: Src/Zle/zle_tricky.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_tricky.c,v
retrieving revision 1.30
diff -u -r1.30 zle_tricky.c
--- Src/Zle/zle_tricky.c	2001/06/25 09:32:21	1.30
+++ Src/Zle/zle_tricky.c	2001/07/10 09:16:06
@@ -2363,6 +2363,8 @@
 
     comppref = 1;
     ret = expandorcomplete(args);
+    if (cs && line[cs - 1] == ' ')
+        makesuffixstr(NULL, "\\-", 0);
     comppref = 0;
     return ret;
 }

-- 
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author