zsh-workers
 help / color / mirror / code / Atom feed
* Re: [zsh 4.0.1 bug] filename completion
       [not found] <1010626051501.ZM24562@candle.brasslantern.com>
@ 2001-06-26  8:02 ` Sven Wischnowsky
  2001-06-27  6:26   ` PATCH (?) " Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Sven Wischnowsky @ 2001-06-26  8:02 UTC (permalink / raw)
  To: zsh-workers

[ moved to -workers ]

Bart Schaefer wrote:

> ...
> 
> I fooled around with _cd a bit and got something that works, but I'm not
> happy with it, so I'm going to hope that Sven has a better idea of what's
> going on.

I've now fooled around a bit, too, and first couldn't get it to fail,
because I don't have cdpath set.

So my comment is that I don't understand the code in _cd at all.  Why do
we test for cdablevars only if `$#cdpath -ne 0'?  It works without.

And then the test for when cdablevars should be used: it's obviously
wrong (that's the real reason for the bug).  We should complete
parameter names[1] if there is no slash in the word or if we are before the
first slash.  Otherwise we could check if there is no directory matching
the string before the first slash but a parameter with that name -- and
only in that case should we trick _path_files into completing a word
with the parameter name replaced by the value of the parameter.

Otherwise completing `soft/f<TAB>' might surprise users who would expect
it to complete to `software/foo'.


Bye
  Sven

[1] Or user names.  Urgh.

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


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

* PATCH (?) Re: [zsh 4.0.1 bug] filename completion
  2001-06-26  8:02 ` [zsh 4.0.1 bug] filename completion Sven Wischnowsky
@ 2001-06-27  6:26   ` Bart Schaefer
  2001-06-27 13:11     ` Sven Wischnowsky
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2001-06-27  6:26 UTC (permalink / raw)
  To: zsh-workers

On Jun 26, 10:02am, Sven Wischnowsky wrote:
}
} So my comment is that I don't understand the code in _cd at all.

I was afraid you were going to say that.

} Why do we test for cdablevars only if `$#cdpath -ne 0'?  It works without.

Venturing deep into the archives, we find ...

That test dates all the way from workers/5628, a patch by PWS, and at the
time the only code in that `if' branch was `_path_files -W cdpath -/', so
it made sense then.

Most of the rest of the code in that block crawled in at workers/6970,
also by PWS, attempting to fix (gasp) cdablevars behavior.  There's no
hint in that message about why the cdablevars code only applies inside
the cdpath branch.

} And then the test for when cdablevars should be used: it's obviously
} wrong (that's the real reason for the bug).  We should complete
} parameter names[1]

The comment, also there since 6970: "In that case we could also complete
variable names, but it hardly seems worth it."

} [1] Or user names.  Urgh.

There's code in _tilde to handle most of this.  The change to _cd that I
was not very happy with, involved invoking _tilde when we might have a
cdablevar.  I've still got that, but I've improved it a little.

} Otherwise we could check if there is no directory matching
} the string before the first slash but a parameter with that name -- and
} only in that case should we trick _path_files into completing a word
} with the parameter name replaced by the value of the parameter.
} 
} Otherwise completing `soft/f<TAB>' might surprise users who would expect
} it to complete to `software/foo'.

Shouldn't it simply do -both-, e.g. offering two possible completions if
there exists both a ~soft/f* and a software/f* ?

Anyway, here's a patch for assorted changes related to this.  Tell me if
I've gone wildly astray here.  There appeared to be a whole lot of excess
locals in _tilde (leftover from extricating _directory_stack, I think).

diff -x CVS -ru zsh-forge/current/Completion/Zsh/Command/_cd zsh-4.0/Completion/Zsh/Command/_cd
--- zsh-forge/current/Completion/Zsh/Command/_cd	Thu Jun 21 02:28:01 2001
+++ zsh-4.0/Completion/Zsh/Command/_cd	Tue Jun 26 23:12:04 2001
@@ -5,7 +5,7 @@
 #    and the string doesn't begin with ~, /, ./ or ../.
 #  - In the second argument to cd for the form `cd old new', completes
 #    possible `new' strings by examining `old' and $PWD.
-#  - After - or +, completes numbers, but the listing
+#  - After - or +, _directory_stack completes numbers, but the listing
 #    gives you the list of directories to complete.  This turns on
 #    menu-completion and lists the possibilities automatically, otherwise
 #    it's not a lot of use.  If you don't type the + or - it will
@@ -24,31 +24,45 @@
   rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}})
   (( $#rep )) && _wanted -C replacement strings expl replacement compadd -a rep
 else
-  [[ CURRENT -gt 1 ]] && _directory_stack && ret=0
-
-  if [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then
-    local tdir tdir2
-
-    # With cdablevars, we can convert foo/bar/... to ~foo/bar/... if
-    # there is no directory foo.  In that case we could also complete
-    # variable names, but it hardly seems worth it.
-    # Note we need a tilde because cdablevars also allows user home
-    # directories, hence we also need nonomatch to suppress error messages.
-    if [[ -o cdablevars && -n "$PREFIX" && ! -d ${tdir::=${PREFIX%%/*}} &&
-          -d ${~tdir2::="~$tdir"} ]]; then
-      PREFIX="~$PREFIX"
-      _wanted directories expl directory _path_files -/ && ret=0
-    else
-      local tmpcdpath
+  # Complete directory stack entries with ~ or when not in command position
+  # (the rest of this test is optimization for the _tilde call below)
+  if [[ "$PREFIX" == (#b)(\~|)[^/]# &&
+      ( -n "$match[1]" || ( CURRENT -gt 1 && ! -o cdablevars ) ) ]]; then
+    _directory_stack && ret=0
+  fi
 
-      tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
-      _alternative \
-          'local-directories:local directories:_path_files -/' \
-	  "path-directories:directories in cdpath:_path_files -W tmpcdpath -/" && ret=0
+  if [[ $PREFIX != (\~|/|./|../)* ]]; then
+    local tmpcdpath
+    tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
+
+    # With cdablevars, we can complete foo as if ~foo/
+    if [[ -o cdablevars && -n "$PREFIX" ]]; then
+      if [[ "$PREFIX" != */* ]]; then
+        _tilde && ret=0
+      else
+	# Note we need a tilde because cdablevars also allows user home
+	# directories, hence nonomatch (above) to suppress error messages.
+        PREFIX="~$PREFIX"
+        _wanted named-directories expl 'directories after cdablevar' \
+	    _path_files -/ && ret=0
+        PREFIX="$PREFIX[2,-1]"
+      fi
+    fi
+    if [[ $#tmpcdpath -ne 0 ]]; then
+      # Don't complete local directories in command position, that's
+      # already handled by _command_names (see _autocd)
+      if [[ CURRENT -eq 1 ]]; then
+	_wanted path-directories expl 'directories in cdpath' \
+	  _path_files -W tmpcdpath -/ && ret=0
+      else
+        _alternative \
+	  'local-directories:local directories:_path_files -/' \
+	  "path-directories:directories in cdpath:_path_files -W tmpcdpath -/" && ret=2
+      fi
+      return ret
     fi
-  else
-    _wanted directories expl directory _path_files -/ && ret=0
   fi
+  _wanted directories expl directory _path_files -/ && ret=0
 
   return ret
 fi
diff -x CVS -ru zsh-forge/current/Completion/Zsh/Context/_tilde zsh-4.0/Completion/Zsh/Context/_tilde
--- zsh-forge/current/Completion/Zsh/Context/_tilde	Mon Apr  2 04:24:49 2001
+++ zsh-4.0/Completion/Zsh/Context/_tilde	Tue Jun 26 22:25:59 2001
@@ -6,7 +6,7 @@
 
 [[ -n "$compstate[quote]" ]] && return 1
 
-local expl suf dirs list lines revlines i ret disp nm="$compstate[nmatches]"
+local expl suf ret
 
 if [[ "$SUFFIX" = */* ]]; then
   ISUFFIX="/${SUFFIX#*/}$ISUFFIX"

-- 
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] 6+ messages in thread

* Re: PATCH (?) Re: [zsh 4.0.1 bug] filename completion
  2001-06-27  6:26   ` PATCH (?) " Bart Schaefer
@ 2001-06-27 13:11     ` Sven Wischnowsky
  2001-06-27 16:20       ` Bart Schaefer
  2001-06-27 18:35       ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Sven Wischnowsky @ 2001-06-27 13:11 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> ...
>
> } Otherwise completing `soft/f<TAB>' might surprise users who would expect
> } it to complete to `software/foo'.
> 
> Shouldn't it simply do -both-, e.g. offering two possible completions if
> there exists both a ~soft/f* and a software/f* ?

Of course.  If possible.  I saw a problem that can be looked at in
action with your patch applied (see below).

> Anyway, here's a patch for assorted changes related to this.  Tell me if
> I've gone wildly astray here.

It looks as good as we can currently get... (after replacing the
`_alternative ... && ret=2' with `... && ret=0').

> There appeared to be a whole lot of excess
> locals in _tilde (leftover from extricating _directory_stack, I think).

Yes, my fault, I'm sure.


Now for the problem: just sticking a tilde in front of $PREFIX won't
work in a case like the one we're discussing (a named directory `soft'
and a directory `software').  Try it with `cd soft/<TAB>'.  The `soft'
vanishes.  That's because the call on line 46/47 adds matches like
`~soft/foo' and the calls on lines 59/60 add matches like `software/foo'.
Of course it can't be able to merge these into a sensible unambiguous
string to insert in the line.

We can almost get to where we want to get by changing it to what you can
see in the patch below.  It first stuffs the parameter into $IPREFIX and
then calls _path_files with a -W containing the expanded directory.  For
that to work, we also need the patch to compmatch.c, which I'm going to
commit.

But this isn't a really good solution, because with that and directories
`~soft/foo' and `software/foo' completion after `cd soft/f<TAB>' lists
the `foo's, not the ambiguous prefix, because _path_files can't know
that the ambiguity is in the prefix (which it was told to ignore in one
case anyway).

Because of that I'm not going to commit that part of the patch (nor the
_tilde part, for completeness' sake).  But it's probably the best result
we're ever going to be able to get there.  At least I don't see how to
resolve this without some serious changes to the completion system.


Bye
  Sven

Index: Completion/Zsh/Command/_cd
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_cd,v
retrieving revision 1.2
diff -u -r1.2 _cd
--- Completion/Zsh/Command/_cd	2001/06/21 09:33:16	1.2
+++ Completion/Zsh/Command/_cd	2001/06/27 13:06:35
@@ -5,7 +5,7 @@
 #    and the string doesn't begin with ~, /, ./ or ../.
 #  - In the second argument to cd for the form `cd old new', completes
 #    possible `new' strings by examining `old' and $PWD.
-#  - After - or +, completes numbers, but the listing
+#  - After - or +, _directory_stack completes numbers, but the listing
 #    gives you the list of directories to complete.  This turns on
 #    menu-completion and lists the possibilities automatically, otherwise
 #    it's not a lot of use.  If you don't type the + or - it will
@@ -24,31 +24,55 @@
   rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}})
   (( $#rep )) && _wanted -C replacement strings expl replacement compadd -a rep
 else
-  [[ CURRENT -gt 1 ]] && _directory_stack && ret=0
-
-  if [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then
-    local tdir tdir2
+  # Complete directory stack entries with ~ or when not in command position
+  # (the rest of this test is optimization for the _tilde call below)
+  if [[ "$PREFIX" == (#b)(\~|)[^/]# &&
+      ( -n "$match[1]" || ( CURRENT -gt 1 && ! -o cdablevars ) ) ]]; then
+    _directory_stack && ret=0
+  fi
 
-    # With cdablevars, we can convert foo/bar/... to ~foo/bar/... if
-    # there is no directory foo.  In that case we could also complete
-    # variable names, but it hardly seems worth it.
-    # Note we need a tilde because cdablevars also allows user home
-    # directories, hence we also need nonomatch to suppress error messages.
-    if [[ -o cdablevars && -n "$PREFIX" && ! -d ${tdir::=${PREFIX%%/*}} &&
-          -d ${~tdir2::="~$tdir"} ]]; then
-      PREFIX="~$PREFIX"
-      _wanted directories expl directory _path_files -/ && ret=0
-    else
-      local tmpcdpath
-
-      tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
-      _alternative \
-          'local-directories:local directories:_path_files -/' \
+  if [[ $PREFIX != (\~|/|./|../)* ]]; then
+    local tmpcdpath
+    tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
+
+    # With cdablevars, we can complete foo as if ~foo/
+    if [[ -o cdablevars && -n "$PREFIX" ]]; then
+      if [[ "$PREFIX" != */* ]]; then
+        _tilde && ret=0
+      else
+        local oipre="$IPREFIX" opre="$PREFIX" dirpre dir
+
+	# Note we need a tilde because cdablevars also allows user home
+	# directories, hence nonomatch (above) to suppress error messages.
+
+        dirpre="${PREFIX%%/*}/"
+        IPREFIX="$IPREFIX$dirpre"
+        eval "dir=( ~$dirpre )"
+        PREFIX="${PREFIX#*/}"
+
+        [[ $#dir -eq 1 && "$dir[1]" != "~$dirpre" ]] &&
+          _wanted named-directories expl 'directories after cdablevar' \
+	      _path_files -W dir -/ && ret=0
+
+        PREFIX="$opre"
+        IPREFIX="$oipre"
+      fi
+    fi
+    if [[ $#tmpcdpath -ne 0 ]]; then
+      # Don't complete local directories in command position, that's
+      # already handled by _command_names (see _autocd)
+      if [[ CURRENT -eq 1 ]]; then
+	_wanted path-directories expl 'directories in cdpath' \
+	  _path_files -W tmpcdpath -/ && ret=0
+      else
+        _alternative \
+	  'local-directories:local directories:_path_files -/' \
 	  "path-directories:directories in cdpath:_path_files -W tmpcdpath -/" && ret=0
+      fi
+      return ret
     fi
-  else
-    _wanted directories expl directory _path_files -/ && ret=0
   fi
+  _wanted directories expl directory _path_files -/ && ret=0
 
   return ret
 fi
Index: Completion/Zsh/Context/_tilde
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Context/_tilde,v
retrieving revision 1.1
diff -u -r1.1 _tilde
--- Completion/Zsh/Context/_tilde	2001/04/02 11:24:49	1.1
+++ Completion/Zsh/Context/_tilde	2001/06/27 13:06:35
@@ -6,7 +6,7 @@
 
 [[ -n "$compstate[quote]" ]] && return 1
 
-local expl suf dirs list lines revlines i ret disp nm="$compstate[nmatches]"
+local expl suf ret
 
 if [[ "$SUFFIX" = */* ]]; then
   ISUFFIX="/${SUFFIX#*/}$ISUFFIX"
Index: Src/Zle/compmatch.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compmatch.c,v
retrieving revision 1.35
diff -u -r1.35 compmatch.c
--- Src/Zle/compmatch.c	2001/04/03 11:25:13	1.35
+++ Src/Zle/compmatch.c	2001/06/27 13:06:35
@@ -1178,14 +1178,18 @@
     }
     /* This is the cline struct for the remaining string at the end. */
 
-    *q = n = get_cline(NULL, 0, NULL, 0, NULL, 0, (plen <= 0 ? CLF_NEW : 0));
     if (p != str) {
 	int olen = str - p, llen = (op < 0 ? 0 : op);
 
+        *q = n = get_cline(NULL, 0, NULL, 0, NULL, 0, (plen <= 0 ? CLF_NEW : 0));
+
 	if (llen > olen)
 	    llen = olen;
 	n->prefix = get_cline(NULL, llen, p, olen, NULL, 0, 0);
     }
+    else if (!ret)
+        *q = n = get_cline(NULL, 0, NULL, 0, NULL, 0, (plen <= 0 ? CLF_NEW : 0));
+
     n->next = NULL;
 
     if (lp)

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


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

* Re: PATCH (?) Re: [zsh 4.0.1 bug] filename completion
  2001-06-27 13:11     ` Sven Wischnowsky
@ 2001-06-27 16:20       ` Bart Schaefer
  2001-06-28  7:32         ` Sven Wischnowsky
  2001-06-27 18:35       ` Bart Schaefer
  1 sibling, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2001-06-27 16:20 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

On Jun 27,  3:11pm, Sven Wischnowsky wrote:
} Subject: Re: PATCH (?) Re: [zsh 4.0.1 bug] filename completion
}
} It looks as good as we can currently get... (after replacing the
} `_alternative ... && ret=2' with `... && ret=0').

Where in the world did that come from?  I don't have ret=2 in my copy
here from which I generated that diff ... I just checked and even re-
generated the diff and there's no ret=2 ...

} Now for the problem: just sticking a tilde in front of $PREFIX won't
} work in a case like the one we're discussing (a named directory `soft'
} and a directory `software').  Try it with `cd soft/<TAB>'.  The `soft'
} vanishes.

Yes, I did notice that.  Actually, in my case, it doesn't vanish, but it
is replaced by ~soft/xx where xx is the unambiguous prefix of subdirs
within ~soft/.  Oh, that's because there are no subdirectories of the
software/ directory -- if I make one, then soft/ vanishes.

} That's because the call on line 46/47 adds matches like
} `~soft/foo' and the calls on lines 59/60 add matches like `software/foo'.
} 
} We can almost get to where we want to get by changing it to what you can
} see in the patch below.  It first stuffs the parameter into $IPREFIX and
} then calls _path_files with a -W containing the expanded directory.

I played with and discarded that approach in the course of coming up with
what I posted (although I used `compset -P' to manipulate the prefixes,
rather than munging the parameters directly).  But perhaps the reason I
discarded it was because of (the symptoms of) the compatch.c problem.

} But this isn't a really good solution, because with that and directories
} `~soft/foo' and `software/foo' completion after `cd soft/f<TAB>' lists
} the `foo's, not the ambiguous prefix

Hrm.  That's a pretty minor problem by comparison.  Particularly since it
will (appear to) do the right thing if there are at least two directories
starting with `f' that don't share a whole name in common.

} Because of that I'm not going to commit that part of the patch

I think you should commit it.  Anybody else have an opinion?

-- 
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] 6+ messages in thread

* Re: PATCH (?) Re: [zsh 4.0.1 bug] filename completion
  2001-06-27 13:11     ` Sven Wischnowsky
  2001-06-27 16:20       ` Bart Schaefer
@ 2001-06-27 18:35       ` Bart Schaefer
  1 sibling, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2001-06-27 18:35 UTC (permalink / raw)
  To: zsh-workers

I wrote:
} } But this isn't a really good solution, because with that and directories
} } `~soft/foo' and `software/foo' completion after `cd soft/f<TAB>' lists
} } the `foo's, not the ambiguous prefix
} 
} Hrm.  That's a pretty minor problem by comparison.  Particularly since it
} will (appear to) do the right thing if there are at least two directories
} starting with `f' that don't share a whole name in common.

One complication of this is:

schaefer<509> cd soft/<TAB>
Completing directories after cdablevar
software/       src/            sparc-solaris/  share/          scripts/      
Completing local directories
subdir/

The "local directory" listed above is really ./software/subdir/.  Cycling
through the menu completions inserts it properly -- it's just the display
that is wrong.

-- 
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] 6+ messages in thread

* Re: PATCH (?) Re: [zsh 4.0.1 bug] filename completion
  2001-06-27 16:20       ` Bart Schaefer
@ 2001-06-28  7:32         ` Sven Wischnowsky
  0 siblings, 0 replies; 6+ messages in thread
From: Sven Wischnowsky @ 2001-06-28  7:32 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> ...
> 
> } But this isn't a really good solution, because with that and directories
> } `~soft/foo' and `software/foo' completion after `cd soft/f<TAB>' lists
> } the `foo's, not the ambiguous prefix
> 
> Hrm.  That's a pretty minor problem by comparison.  Particularly since it
> will (appear to) do the right thing if there are at least two directories
> starting with `f' that don't share a whole name in common.

Yes.

> } Because of that I'm not going to commit that part of the patch
> 
> I think you should commit it.  Anybody else have an opinion?

Thinking again yesterday evening, I came to the conclusion that's it's
at least better than what we have now and to commit it.


In another mail:

> One complication of this is:
> 
> schaefer<509> cd soft/<TAB>
> Completing directories after cdablevar
> software/       src/            sparc-solaris/  share/          scripts/      
> Completing local directories
> subdir/
> 
> The "local directory" listed above is really ./software/subdir/.  Cycling
> through the menu completions inserts it properly -- it's just the display
> that is wrong.

Yes, that's what I meant.  A result of calling _path_files twice with
different prefixes.

May main problem is probably that I fail to see the `larger problem
behind this' so that I could try to tackle that.  Modifying _path_files
just to improve this one case doesn't look like the right thing.


Bye
  Sven

Index: Completion/Zsh/Command/_cd
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_cd,v
retrieving revision 1.2
diff -u -r1.2 _cd
--- Completion/Zsh/Command/_cd	2001/06/21 09:33:16	1.2
+++ Completion/Zsh/Command/_cd	2001/06/28 07:34:03
@@ -5,7 +5,7 @@
 #    and the string doesn't begin with ~, /, ./ or ../.
 #  - In the second argument to cd for the form `cd old new', completes
 #    possible `new' strings by examining `old' and $PWD.
-#  - After - or +, completes numbers, but the listing
+#  - After - or +, _directory_stack completes numbers, but the listing
 #    gives you the list of directories to complete.  This turns on
 #    menu-completion and lists the possibilities automatically, otherwise
 #    it's not a lot of use.  If you don't type the + or - it will
@@ -24,31 +24,55 @@
   rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}})
   (( $#rep )) && _wanted -C replacement strings expl replacement compadd -a rep
 else
-  [[ CURRENT -gt 1 ]] && _directory_stack && ret=0
-
-  if [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then
-    local tdir tdir2
+  # Complete directory stack entries with ~ or when not in command position
+  # (the rest of this test is optimization for the _tilde call below)
+  if [[ "$PREFIX" == (#b)(\~|)[^/]# &&
+      ( -n "$match[1]" || ( CURRENT -gt 1 && ! -o cdablevars ) ) ]]; then
+    _directory_stack && ret=0
+  fi
 
-    # With cdablevars, we can convert foo/bar/... to ~foo/bar/... if
-    # there is no directory foo.  In that case we could also complete
-    # variable names, but it hardly seems worth it.
-    # Note we need a tilde because cdablevars also allows user home
-    # directories, hence we also need nonomatch to suppress error messages.
-    if [[ -o cdablevars && -n "$PREFIX" && ! -d ${tdir::=${PREFIX%%/*}} &&
-          -d ${~tdir2::="~$tdir"} ]]; then
-      PREFIX="~$PREFIX"
-      _wanted directories expl directory _path_files -/ && ret=0
-    else
-      local tmpcdpath
-
-      tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
-      _alternative \
-          'local-directories:local directories:_path_files -/' \
+  if [[ $PREFIX != (\~|/|./|../)* ]]; then
+    local tmpcdpath
+    tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
+
+    # With cdablevars, we can complete foo as if ~foo/
+    if [[ -o cdablevars && -n "$PREFIX" ]]; then
+      if [[ "$PREFIX" != */* ]]; then
+        _tilde && ret=0
+      else
+        local oipre="$IPREFIX" opre="$PREFIX" dirpre dir
+
+	# Note we need a tilde because cdablevars also allows user home
+	# directories, hence nonomatch (above) to suppress error messages.
+
+        dirpre="${PREFIX%%/*}/"
+        IPREFIX="$IPREFIX$dirpre"
+        eval "dir=( ~$dirpre )"
+        PREFIX="${PREFIX#*/}"
+
+        [[ $#dir -eq 1 && "$dir[1]" != "~$dirpre" ]] &&
+          _wanted named-directories expl 'directories after cdablevar' \
+	      _path_files -W dir -/ && ret=0
+
+        PREFIX="$opre"
+        IPREFIX="$oipre"
+      fi
+    fi
+    if [[ $#tmpcdpath -ne 0 ]]; then
+      # Don't complete local directories in command position, that's
+      # already handled by _command_names (see _autocd)
+      if [[ CURRENT -eq 1 ]]; then
+	_wanted path-directories expl 'directories in cdpath' \
+	  _path_files -W tmpcdpath -/ && ret=0
+      else
+        _alternative \
+	  'local-directories:local directories:_path_files -/' \
 	  "path-directories:directories in cdpath:_path_files -W tmpcdpath -/" && ret=0
+      fi
+      return ret
     fi
-  else
-    _wanted directories expl directory _path_files -/ && ret=0
   fi
+  _wanted directories expl directory _path_files -/ && ret=0
 
   return ret
 fi
Index: Completion/Zsh/Context/_tilde
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Context/_tilde,v
retrieving revision 1.1
diff -u -r1.1 _tilde
--- Completion/Zsh/Context/_tilde	2001/04/02 11:24:49	1.1
+++ Completion/Zsh/Context/_tilde	2001/06/28 07:34:03
@@ -6,7 +6,7 @@
 
 [[ -n "$compstate[quote]" ]] && return 1
 
-local expl suf dirs list lines revlines i ret disp nm="$compstate[nmatches]"
+local expl suf ret
 
 if [[ "$SUFFIX" = */* ]]; then
   ISUFFIX="/${SUFFIX#*/}$ISUFFIX"

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


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

end of thread, other threads:[~2001-06-28  7:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1010626051501.ZM24562@candle.brasslantern.com>
2001-06-26  8:02 ` [zsh 4.0.1 bug] filename completion Sven Wischnowsky
2001-06-27  6:26   ` PATCH (?) " Bart Schaefer
2001-06-27 13:11     ` Sven Wischnowsky
2001-06-27 16:20       ` Bart Schaefer
2001-06-28  7:32         ` Sven Wischnowsky
2001-06-27 18:35       ` Bart Schaefer

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