zsh-workers
 help / color / mirror / code / Atom feed
* Bug in _approximate with ~/
@ 2001-08-16 15:54 martin.ebourne
  2001-08-16 17:45 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: martin.ebourne @ 2001-08-16 15:54 UTC (permalink / raw)
  To: zsh-workers


Hi,

I think I've found a weird bug in _approximate. This reproduces it:

% zsh -f                                                                                                                            Thu 16 Aug 2001
16:51:12
% echo $ZSH_VERSION
4.0.2
% autoload -U compinit
% compinit
% zstyle ":completion:*" completer _complete _approximate
% mkdir -p ~/test/test{1,2}
% ~/test/f

Press tab immediately after the 'f', and I get:

% \!
\!      *       -       .       0       1       :       @       X       \[      e       r       test1/  test2/  w       \{      \}
~/test/f

Which wasn't quite what I expected! ;)

Cheers,

Martin.




This e-mail message is CONFIDENTIAL and may contain legally privileged
information.  If you are not the intended recipient you should not  read,
copy, distribute, disclose or otherwise use the information in this e-mail.
Please also telephone or fax us immediately and delete the message from
your system.  E-mail may be susceptible to data corruption, interception
and unauthorised amendment, and we do not accept liability for any such
corruption, interception or amendment or the consequences thereof.


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

* Re: Bug in _approximate with ~/
  2001-08-16 15:54 Bug in _approximate with ~/ martin.ebourne
@ 2001-08-16 17:45 ` Bart Schaefer
  2001-08-17  9:16   ` Sven Wischnowsky
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2001-08-16 17:45 UTC (permalink / raw)
  To: martin.ebourne, zsh-workers

On Aug 16,  4:54pm, martin.ebourne@arcordia.com wrote:
} Subject: Bug in _approximate with ~/
}
} % zstyle ":completion:*" completer _complete _approximate
} % mkdir -p ~/test/test{1,2}
} % ~/test/f
} 
} Press tab immediately after the 'f', and I get:
} 
} % \!
} \!      *       -       .       0       1       :       @       X       \[
} e       r       test1/  test2/  w       \{      \}
} ~/test/f
} 
} Which wasn't quite what I expected! ;)

~/test/f is in command position. Therefore it gets compared to parameter
names, reserved words, aliases, command names, file names, job specifiers
(%1, %2, etc.), and some other things I've forgotten.  It doesn't match
any of the above, so you get offered a bunch of possibilites, some from
each of those sources.  If you were to menu-complete through the list
so that you could see the suffixes that get auto-appended to each one,
you'd get some idea where they came from; for example, X e r w : - and
dot are commands.

In _approximate there's this snippet:

    ### This distinction doesn't seem to be needed anymore
    # if [[ "$PREFIX" = \~*/* ]]; then
    #   PREFIX="${PREFIX%%/*}/(#a${_comp_correct})${PREFIX#*/}"
    # else
      PREFIX="(#a${_comp_correct})$PREFIX"
    # fi

This results in a PREFIX that looks like `(#a1)~/test/f'.  _path_files
does the right thing with this -- it peels off the (#a1), expands the
tilde, and then applies (#a1) to each path element.  However, none of
the other completions that are attempted in command position are this
intelligent -- they all interpret `(#a1)~/test/f' as `(#a1)()~/test/f',
that is, allow one correction to the empty string as long as that does
not match `/test/f'.  Consequently you get all the one-letter commands,
parameters, reserved words, etc.

You're right, this is a bug.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: Bug in _approximate with ~/
  2001-08-16 17:45 ` Bart Schaefer
@ 2001-08-17  9:16   ` Sven Wischnowsky
  2001-08-17 14:36     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 2001-08-17  9:16 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> ...
> 
> This results in a PREFIX that looks like `(#a1)~/test/f'.  _path_files
> does the right thing with this -- it peels off the (#a1), expands the
> tilde, and then applies (#a1) to each path element.  However, none of
> the other completions that are attempted in command position are this
> intelligent -- they all interpret `(#a1)~/test/f' as `(#a1)()~/test/f',
> that is, allow one correction to the empty string as long as that does
> not match `/test/f'.  Consequently you get all the one-letter commands,
> parameters, reserved words, etc.
> 
> You're right, this is a bug.

Hmhm.  To be fixed in C-code where the globbing flags are moved
farther into the prefix if needed.


This also made me notice a slightly wrong test in _path_files.


Bye
  Sven

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.10
diff -u -r1.10 _path_files
--- Completion/Unix/Type/_path_files	2001/08/13 10:57:44	1.10
+++ Completion/Unix/Type/_path_files	2001/08/17 09:13:31
@@ -653,7 +653,7 @@
 
 if zstyle -t ":completion:${curcontext}:paths" expand prefix &&
    [[ nm -eq compstate[nmatches] && $#exppaths -ne 0 &&
-      "$exppaths" != "$eorig" ]]; then
+      "$linepath$exppaths" != "$eorig" ]]; then
   PREFIX="${opre}"
   SUFFIX="${osuf}"
   compadd -Q "$mopts[@]" -S '' -M "r:|/=* r:|=*" -p "$linepath" -a exppaths
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.48
diff -u -r1.48 compcore.c
--- Src/Zle/compcore.c	2001/07/25 10:45:59	1.48
+++ Src/Zle/compcore.c	2001/08/17 09:13:32
@@ -1782,21 +1782,23 @@
 	} else
 	    lsl = 0;
 	if (dat->aflags & CAF_MATCH) {
-	    int ml, gfl = 0;
+	    int ml, gfl = 0, tildepat = 0;
 	    char *globflag = NULL;
 
 	    if (comppatmatch && *comppatmatch &&
-		dat->ppre && lpre[0] == '(' && lpre[1] == '#') {
+		lpre[0] == '(' && lpre[1] == '#') {
 		char *p;
 
 		for (p = lpre + 2; *p && *p != ')'; p++);
 
-		if (*p == ')') {
+		if (*p == ')' && (dat->ppre || p[1] == '~')) {
 		    char sav = p[1];
 
 		    p[1] = '\0';
 		    globflag = dupstring(lpre);
 		    gfl = p - lpre + 1;
+                    if (!dat->ppre)
+                        tildepat = 1;
 		    p[1] = sav;
 
 		    lpre = p + 1;
@@ -1859,7 +1861,11 @@
 		int is = (*comppatmatch == '*');
 		char *tmp = (char *) zhalloc(2 + llpl + llsl + gfl);
 
-		if (gfl) {
+		if (tildepat) {
+                    tmp[0] = '~';
+                    strcpy(tmp + 1, globflag);
+                    strcat(tmp, lpre + 1);
+                } else if (gfl) {
 		    strcpy(tmp, globflag);
 		    strcat(tmp, lpre);
 		} else

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


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

* Re: Bug in _approximate with ~/
  2001-08-17  9:16   ` Sven Wischnowsky
@ 2001-08-17 14:36     ` Bart Schaefer
  2001-08-20 13:11       ` Sven Wischnowsky
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2001-08-17 14:36 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

On Aug 17, 11:16am, Sven Wischnowsky wrote:
}
} Bart Schaefer wrote:
} 
} > the other completions that are attempted in command position are this
} > intelligent -- they all interpret `(#a1)~/test/f' as `(#a1)()~/test/f',
} > that is, allow one correction to the empty string as long as that does
} > not match `/test/f'.  Consequently you get all the one-letter commands,
} 
} Hmhm.  To be fixed in C-code where the globbing flags are moved
} farther into the prefix if needed.

Is that really right?  What if I actually type `(#a1)~/test/f' before I
hit TAB?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: Bug in _approximate with ~/
  2001-08-17 14:36     ` Bart Schaefer
@ 2001-08-20 13:11       ` Sven Wischnowsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 2001-08-20 13:11 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Aug 17, 11:16am, Sven Wischnowsky wrote:
> }
> } Bart Schaefer wrote:
> } 
> } > the other completions that are attempted in command position are this
> } > intelligent -- they all interpret `(#a1)~/test/f' as `(#a1)()~/test/f',
> } > that is, allow one correction to the empty string as long as that does
> } > not match `/test/f'.  Consequently you get all the one-letter commands,
> } 
> } Hmhm.  To be fixed in C-code where the globbing flags are moved
> } farther into the prefix if needed.
> 
> Is that really right?  What if I actually type `(#a1)~/test/f' before I
> hit TAB?

Hrmpf, yes, I always forget that one might type something like that by 
hand.  Still, since _approximate works by faking a different PREFIX,
some things will never be possible, I fear.

All this will become more manageable when all of this stuff is in
shell code, I hope.


Bye
  Sven

Index: Completion/Base/Completer/_approximate
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Completer/_approximate,v
retrieving revision 1.5
diff -u -r1.5 _approximate
--- Completion/Base/Completer/_approximate	2001/08/16 08:07:42	1.5
+++ Completion/Base/Completer/_approximate	2001/08/20 13:09:25
@@ -49,15 +49,16 @@
 
 if (( ! $+functions[compadd] )); then
   compadd() {
+    local ppre="$argv[(I)-p]"
+
     [[ ${argv[(I)-[a-zA-Z]#U[a-zA-Z]#]} -eq 0 &&
        "${#:-$PREFIX$SUFFIX}" -le _comp_correct ]] && return
 
-    ### This distinction doesn't seem to be needed anymore
-    # if [[ "$PREFIX" = \~*/* ]]; then
-    #   PREFIX="${PREFIX%%/*}/(#a${_comp_correct})${PREFIX#*/}"
-    # else
+    if [[ "$PREFIX" = \~* && ( ppre -eq 0 || "$argv[ppre+1]" != \~* ) ]]; then
+      PREFIX="~(#a${_comp_correct})${PREFIX[2,-1]}"
+    else
       PREFIX="(#a${_comp_correct})$PREFIX"
-    # fi
+    fi
 
     (( $_correct_group && $argv[(I)-*[JV]] )) &&
         _correct_expl[_correct_group]=${argv[(R)-*[JV]]}
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.49
diff -u -r1.49 compcore.c
--- Src/Zle/compcore.c	2001/08/17 09:25:22	1.49
+++ Src/Zle/compcore.c	2001/08/20 13:09:26
@@ -1782,23 +1782,21 @@
 	} else
 	    lsl = 0;
 	if (dat->aflags & CAF_MATCH) {
-	    int ml, gfl = 0, tildepat = 0;
+	    int ml, gfl = 0;
 	    char *globflag = NULL;
 
 	    if (comppatmatch && *comppatmatch &&
-		lpre[0] == '(' && lpre[1] == '#') {
+		dat->ppre && lpre[0] == '(' && lpre[1] == '#') {
 		char *p;
 
 		for (p = lpre + 2; *p && *p != ')'; p++);
 
-		if (*p == ')' && (dat->ppre || p[1] == '~')) {
+		if (*p == ')') {
 		    char sav = p[1];
 
 		    p[1] = '\0';
 		    globflag = dupstring(lpre);
 		    gfl = p - lpre + 1;
-                    if (!dat->ppre)
-                        tildepat = 1;
 		    p[1] = sav;
 
 		    lpre = p + 1;
@@ -1861,11 +1859,7 @@
 		int is = (*comppatmatch == '*');
 		char *tmp = (char *) zhalloc(2 + llpl + llsl + gfl);
 
-		if (tildepat) {
-                    tmp[0] = '~';
-                    strcpy(tmp + 1, globflag);
-                    strcat(tmp, lpre + 1);
-                } else if (gfl) {
+		if (gfl) {
 		    strcpy(tmp, globflag);
 		    strcat(tmp, lpre);
 		} else

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


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

end of thread, other threads:[~2001-08-20 13:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-16 15:54 Bug in _approximate with ~/ martin.ebourne
2001-08-16 17:45 ` Bart Schaefer
2001-08-17  9:16   ` Sven Wischnowsky
2001-08-17 14:36     ` Bart Schaefer
2001-08-20 13: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).