zsh-workers
 help / color / mirror / code / Atom feed
* Automatic hash -d
@ 2001-04-13  2:08 Wayne Davison
  2001-04-13  2:30 ` "keep-prefix true" feature request Wayne Davison
  0 siblings, 1 reply; 10+ messages in thread
From: Wayne Davison @ 2001-04-13  2:08 UTC (permalink / raw)
  To: Zsh Workers

In the old completion system, I can complete a path that includes a
variable prefixed with a ~ without having to first use an explicit
hash -d.  In the new completion system, this only works if I complete
just the ~VAR name first.  In other words:

  # (Assume that there are files in /var/www/html/subdir)

  zsh -f
  % export w=/var/www/html
  % ls ~w/subdir/<TAB>           # Completes as expected
  % hash -dv
  w=/var/www/html
  % exit

  zsh -f
  % export w=/var/www/html
  % autoload -U compinit
  % compinit
  % zstyle ':completion:*' completer _expand _complete
  % bindkey '\t' complete-word
  % ls ~w/subdir/<TAB>           # Beeps.  Nothing added to hash -d.
  % ls ~w<TAB>                   # Expands w.  w added to hash -d.
  % ls ~w/subdir/<TAB>           # Now this works (as expected).

I can work around this, but it would be nice to have the auto hash -d
code work the same in each completion system.

..wayne..


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

* "keep-prefix true" feature request
@ 2001-04-13  2:30 ` Wayne Davison
  2001-04-13  4:50   ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Wayne Davison @ 2001-04-13  2:30 UTC (permalink / raw)
  To: Zsh Workers

I'd like the "keep-prefix true" setting to work a little differently.
It keeps a variable from expanding only if it is the first item in the
filename, and I'd like it to avoid expanding any variable that has
text after it (like the old completion system does).  In other words:

  % # ... Normal compinit setup ...
  % zstyle ':completion:*:expand:*' keep-prefix true
  % export xpkg=/var/spool/pkg/solaris_x86
  % export htd=/usr/local/etc/http/htdocs
  % cd ~xpkg/apache$htd/<TAB>

This expands $htd, but I want to complete dirs without expansion.
...At least, it used to...  Now it's just beeping at me unless I
change the '~' into a '$'.  I'll investigate further, but my requested
feature is the same:  leave the prefixed characters unchanged if there
are suffix characters present (between the cursor and the variable).

..wayne..


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

* Re: "keep-prefix true" feature request
  2001-04-13  2:30 ` "keep-prefix true" feature request Wayne Davison
@ 2001-04-13  4:50   ` Bart Schaefer
  2001-04-13  5:09     ` Automatic hash -d Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2001-04-13  4:50 UTC (permalink / raw)
  To: Zsh Workers

On Apr 12,  7:30pm, Wayne Davison wrote:
} Subject: "keep-prefix true" feature request
}
}   % cd ~xpkg/apache$htd/<TAB>
}
} Now it's just beeping at me unless I change the '~' into a '$'.  

This comes from the test at line 193 of _path_files.  If there's a
leading tilde, it expands the tilde-expression but never expands the
stuff to the right of the first slash.  If there's no leading tilde,
the branch at line 244 is taken and everything gets expanded.

(This is also why your "automatic hash -d" doesn't work:  it expands
the tilde-expression by checking whether there is already a dirstack
entry, not by actually evaluating the expression.)

It *seems* to work just to swap those two branches (test for $ first,
then leading tilde), and in fact that *also* seems to handle this:

} I'd like the "keep-prefix true" setting to work a little differently.
} It keeps a variable from expanding only if it is the first item in the
} filename, and I'd like it to avoid expanding any variable that has
} text after it (like the old completion system does).

I'm sure somebody can explain to me why the following is wrong.

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.1
diff -u -r1.1 _path_files
--- Completion/Unix/Type/_path_files	2001/04/02 11:36:27	1.1
+++ Completion/Unix/Type/_path_files	2001/04/13 04:44:16
@@ -190,7 +190,23 @@
 
 # Now let's have a closer look at the string to complete.
 
-if [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
+if [[ "$pre" = *\$*/* && "$compstate[quote]" != \" ]]; then
+
+  # If there is a parameter expansion in the word from the line, we try
+  # to complete the beast by expanding the prefix and completing anything
+  # after the first slash after the parameter expansion.
+  # This fails for things like `f/$foo/b/<TAB>' where the first `f' is
+  # meant as a partial path.
+
+  linepath="${(M)pre##*\$[^/]##/}"
+  eval 'realpath=${(e)~linepath}' 2>/dev/null
+  [[ -z "$realpath" || "$realpath" = "$linepath" ]] && return 1
+  pre="${pre#${linepath}}"
+  i="${#linepath//[^\\/]}"
+  orig="${orig[1,(in:i:)/][1,-2]}"
+  donepath=
+  prepaths=( '' )
+elif [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
   # It begins with `~', so remember anything before the first slash to be able
   # to report it to the completion code. Also get an expanded version of it
   # (in `realpath'), so that we can generate the matches. Then remove that
@@ -239,22 +255,6 @@
   [[ "$realpath" = "$linepath" ]] && return 1
   pre="${pre#*/}"
   orig="${orig#*/}"
-  donepath=
-  prepaths=( '' )
-elif [[ "$pre" = *\$*/* && "$compstate[quote]" != \" ]]; then
-
-  # If there is a parameter expansion in the word from the line, we try
-  # to complete the beast by expanding the prefix and completing anything
-  # after the first slash after the parameter expansion.
-  # This fails for things like `f/$foo/b/<TAB>' where the first `f' is
-  # meant as a partial path.
-
-  linepath="${(M)pre##*\$[^/]##/}"
-  eval 'realpath=${(e)~linepath}' 2>/dev/null
-  [[ -z "$realpath" || "$realpath" = "$linepath" ]] && return 1
-  pre="${pre#${linepath}}"
-  i="${#linepath//[^\\/]}"
-  orig="${orig[1,(in:i:)/][1,-2]}"
   donepath=
   prepaths=( '' )
 else

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

* Re: Automatic hash -d
  2001-04-13  4:50   ` Bart Schaefer
@ 2001-04-13  5:09     ` Bart Schaefer
  2001-04-13  8:01       ` Wayne Davison
  2001-04-13 16:47       ` Bart Schaefer
  0 siblings, 2 replies; 10+ messages in thread
From: Bart Schaefer @ 2001-04-13  5:09 UTC (permalink / raw)
  To: Zsh Workers

On Apr 12,  7:08pm, Wayne Davison wrote:
} Subject: Automatic hash -d
}
} In the old completion system, I can complete a path that includes a
} variable prefixed with a ~ without having to first use an explicit
} hash -d.  In the new completion system, this only works if I complete
} just the ~VAR name first.

On Apr 13,  9:50pm, Bart Schaefer wrote:
}
} [Writing about _path-files] ... it expands
} the tilde-expression by checking whether there is already a dirstack
} entry, not by actually evaluating the expression.

This provides the automatic naming of the directory, but I wonder if it
ought to have some kind of style test for performance reasons?

(Line numbers relative to my patch in 13973.)

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.1
diff -u -r1.1 _path_files
--- Completion/Unix/Type/_path_files	2001/04/02 11:36:27	1.1
+++ Completion/Unix/Type/_path_files	2001/04/13 05:00:59
@@ -199,6 +215,7 @@
   # prefix path by setting `prepaths'.
 
   linepath="${pre[2,-1]%%/*}"
+  eval : "~$linepath" 2>/dev/null	# Create nameddir if necessary
   if [[ -z "$linepath" ]]; then
     realpath="${HOME%/}/"
   elif (( $+userdirs[$linepath] )); then

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

* Re: Automatic hash -d
  2001-04-13  5:09     ` Automatic hash -d Bart Schaefer
@ 2001-04-13  8:01       ` Wayne Davison
  2001-04-13 15:38         ` Bart Schaefer
  2001-04-13 16:47       ` Bart Schaefer
  1 sibling, 1 reply; 10+ messages in thread
From: Wayne Davison @ 2001-04-13  8:01 UTC (permalink / raw)
  To: Zsh Workers

On Fri, 13 Apr 2001, Bart Schaefer wrote:
> Index: Completion/Unix/Type/_path_files

I applied both of your changes to _path_files, and things are working
very nicely now.  I'll let you know if I encounter any problems.

..wayne..


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

* Re: Automatic hash -d
  2001-04-13  8:01       ` Wayne Davison
@ 2001-04-13 15:38         ` Bart Schaefer
  0 siblings, 0 replies; 10+ messages in thread
From: Bart Schaefer @ 2001-04-13 15:38 UTC (permalink / raw)
  To: Zsh Workers

On Apr 13,  1:01am, Wayne Davison wrote:
} Subject: Re: Automatic hash -d
}
} I applied both of your changes to _path_files, and things are working
} very nicely now.  I'll let you know if I encounter any problems.

Here's one potential oddity:

% z=/usr/local/share/zsh
% ls ~`echo z`/<TAB>
Completing unknown user `echo z`

And yet ~z has now been made into a nameddir.

Perhaps backticks should be treated like $(...) and therefore passed
through the parameter expansion branch in _path_files?  The expression
would be something like:

    if [[ "$pre" = *(\`[^\`]#\`|\$)*/* && ...

Of course one must be careful when completing command substitutions in
general.

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

* Re: Automatic hash -d
  2001-04-13  5:09     ` Automatic hash -d Bart Schaefer
  2001-04-13  8:01       ` Wayne Davison
@ 2001-04-13 16:47       ` Bart Schaefer
  2001-04-17  9:04         ` Sven Wischnowsky
  1 sibling, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2001-04-13 16:47 UTC (permalink / raw)
  To: Zsh Workers

On Apr 13,  5:09am, Bart Schaefer wrote:
}
} +  eval : "~$linepath" 2>/dev/null	# Create nameddir if necessary

I have not committed this, because the code immediately following seems
to go to great lengths to *avoid* creating the nameddir ... the entire
cascade testing $userdirs and $nameddirs could otherwise be replaced by
an eval like the one in the *\$*/* branch, I think.  In fact, that's
probably what's wrong with testing *\$*/* first: It does an eval and may
thereby create a nameddir.

So I'm going to wait for Sven to get back and give his opinions.

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

* Re: Automatic hash -d
  2001-04-13 16:47       ` Bart Schaefer
@ 2001-04-17  9:04         ` Sven Wischnowsky
  2001-04-18  5:56           ` PATCH (?): " Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Sven Wischnowsky @ 2001-04-17  9:04 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> On Apr 13,  5:09am, Bart Schaefer wrote:
> }
> } +  eval : "~$linepath" 2>/dev/null	# Create nameddir if necessary
> 
> I have not committed this, because the code immediately following seems
> to go to great lengths to *avoid* creating the nameddir ... the entire
> cascade testing $userdirs and $nameddirs could otherwise be replaced by
> an eval like the one in the *\$*/* branch, I think.  In fact, that's
> probably what's wrong with testing *\$*/* first: It does an eval and may
> thereby create a nameddir.
> 
> So I'm going to wait for Sven to get back and give his opinions.

It's probably ok to use eval there, ensuring that it doesn't print error
messages, because that seems to have been the reason for all that code
(added in 9880).

Bye
  Sven


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


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

* PATCH (?): Re: Automatic hash -d
  2001-04-17  9:04         ` Sven Wischnowsky
@ 2001-04-18  5:56           ` Bart Schaefer
  2001-04-18  8:29             ` Sven Wischnowsky
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2001-04-18  5:56 UTC (permalink / raw)
  To: Zsh Workers

On Apr 13,  3:38pm, Bart Schaefer wrote:
}
} Perhaps backticks should be treated like $(...) and therefore passed
} through the parameter expansion branch in _path_files?  The expression
} would be something like:
} 
}     if [[ "$pre" = *(\`[^\`]#\`|\$)*/* && ...

On Apr 17, 11:04am, Sven Wischnowsky wrote:
} 
} It's probably ok to use eval there, ensuring that it doesn't print error
} messages, because that seems to have been the reason for all that code
} (added in 9880).

So how's this look?  I'm a little worried about "$compstate[quote]" != \"
but that's what was there before, and I don't really understand why I'm
worried (nor why it's there, for that matter; the -z "$compstate[quote]"
test in the next branch makes more sense to me).

One further note about this:  If you complete

	% ls ~notauser/<TAB>
	Completing unknown user `notauser'

If instead you complete

	% var=notadir
	% ls ~notauser/$var/<TAB>
	No matches for `files', `file', or `corrections'

But if you then immediately hit RET, you see

	zsh: no such user or named directory: notauser

Ideally, the code in _path_files would first peel off the ~notauser and
check that for errors, and then discover that the prefix still contains
an expansion and try to shift more of it into linepath and realpath and
check *that* for errors; but I wasn't prepared to do that much violence
to _path_files.

I'll wait for Sven to either commit something or to tell me to go ahead
and commit the following patch (which, BTW, is *instead* of the patch in
13974).

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.2
diff -u -r1.2 _path_files
--- Completion/Unix/Type/_path_files	2001/04/13 16:31:39	1.2
+++ Completion/Unix/Type/_path_files	2001/04/18 05:40:46
@@ -190,7 +190,7 @@
 
 # Now let's have a closer look at the string to complete.
 
-if [[ "$pre" = *\$*/* && "$compstate[quote]" != \" ]]; then
+if [[ "$pre" = *(\`[^\`]#\`|\$)*/* && "$compstate[quote]" != \" ]]; then
 
   # If there is a parameter expansion in the word from the line, we try
   # to complete the beast by expanding the prefix and completing anything
@@ -207,6 +207,7 @@
   donepath=
   prepaths=( '' )
 elif [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
+
   # It begins with `~', so remember anything before the first slash to be able
   # to report it to the completion code. Also get an expanded version of it
   # (in `realpath'), so that we can generate the matches. Then remove that
@@ -217,10 +218,6 @@
   linepath="${pre[2,-1]%%/*}"
   if [[ -z "$linepath" ]]; then
     realpath="${HOME%/}/"
-  elif (( $+userdirs[$linepath] )); then
-    realpath="${userdirs[$linepath]%/}/"
-  elif (( $+nameddirs[$linepath] )); then
-    realpath="${nameddirs[$linepath]%/}/"
   elif [[ "$linepath" = ([-+]|)[0-9]## ]]; then
     if [[ "$linepath" != [-+]* ]]; then
       if [[ -o pushdminus ]]; then
@@ -248,8 +245,11 @@
   elif [[ "$linepath" = [-+] ]]; then
     realpath=${~:-\~$linepath}/
   else
-    _message "unknown user \`$linepath'"
-    return 1
+    eval "realpath=~${linepath}/" 2>/dev/null
+    if [[ -z "$realpath" ]]; then
+      _message "unknown user \`$linepath'"
+      return 1
+    fi
   fi
   linepath="~${linepath}/"
   [[ "$realpath" = "$linepath" ]] && return 1

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

* Re: PATCH (?): Re: Automatic hash -d
  2001-04-18  5:56           ` PATCH (?): " Bart Schaefer
@ 2001-04-18  8:29             ` Sven Wischnowsky
  0 siblings, 0 replies; 10+ messages in thread
From: Sven Wischnowsky @ 2001-04-18  8:29 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> ...
> 
> So how's this look? 

Good, I think you can commit it.

> I'm a little worried about "$compstate[quote]" != \"
> but that's what was there before, and I don't really understand why I'm
> worried (nor why it's there, for that matter; the -z "$compstate[quote]"
> test in the next branch makes more sense to me).

I think it's a typo.  And I couldn't find the message that added it in
the archive, searching for `compstate\[quote\]'.  That test once was
`-z $compstate[quote]', too, which wasn't right either.

It should test $compstate[quote] != \', because $s aren't expanded
inside single quotes (try it with completion after

  foo=bar
  echo '$foo/<TAB>

where there exists a directory named `$foo').

> ...
> 
> Ideally, the code in _path_files would first peel off the ~notauser and
> check that for errors, and then discover that the prefix still contains
> an expansion and try to shift more of it into linepath and realpath and
> check *that* for errors; but I wasn't prepared to do that much violence
> to _path_files.

Yes, that would be better.  I might have a look once your patch is
committed, don't have the time now.

Bye
  Sven


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


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

end of thread, other threads:[~2001-04-18  8:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-13  2:08 Automatic hash -d Wayne Davison
2001-04-13  2:30 ` "keep-prefix true" feature request Wayne Davison
2001-04-13  4:50   ` Bart Schaefer
2001-04-13  5:09     ` Automatic hash -d Bart Schaefer
2001-04-13  8:01       ` Wayne Davison
2001-04-13 15:38         ` Bart Schaefer
2001-04-13 16:47       ` Bart Schaefer
2001-04-17  9:04         ` Sven Wischnowsky
2001-04-18  5:56           ` PATCH (?): " Bart Schaefer
2001-04-18  8:29             ` 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).