zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: Re: Questions/comments on completion code that arise from PWS's zsh guide
@ 2000-02-25 15:39 Sven Wischnowsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 2000-02-25 15:39 UTC (permalink / raw)
  To: zsh-workers


Alexandre Duret-Lutz wrote:

>  Sven> The patch adds _tilde_files which completes files and expands tildes
>  Sven> if there are any. And makes _dd use it. 
> 
> But this will *always* expand tildes.  Since I am using magicequalsubst, 
> I don't want tildes to be expanded 'on the line' in places where
> it would be done by magicequalsubst.
> 
> Shouldn't there be a option to _tilde_files saying that _tilde_files is
> called in a context where magicequalsubst will expand the tilde (in which
> case _tilde_files should care whether the magicequalsubst is set or not) ?
> Or it may be the default.

Yes, I think _tilde_files should do that always.

>  Sven> Does anyone know of other places where this might be useful?
> 
> What happens with _arguments's equal-ended options ?
> Should they use _tilde_files instead of _files ?
> It may be good that `--prefix=~/usr' get expanded to
> `--prefix=/myhomedir/usr' when magicequalsubst is unset, 
> but I would find strange that `--prefix ~/usr' expands 
> to `--prefix /myhomedir/usr' too...

Hm. Maybe, but not unconditionally because currently _tilde_files
always does the expansion, not only if there is a $IPREFIX.
The solution would be an option for _tilde_files that makes it do
expansion only if the is a IPREFIX (or maybe an option with an argument 
which is taken as a pattern and _tilde_files expands only if IPREFIX
matches that) and changing the actions in the calls to _arguments and
_values (unless the commands do tilde-expansion themselves).


Bye
 Sven

diff -ru ../z.old/Completion/User/_tilde_files Completion/User/_tilde_files
--- ../z.old/Completion/User/_tilde_files	Fri Feb 25 14:17:37 2000
+++ Completion/User/_tilde_files	Fri Feb 25 16:37:57 2000
@@ -2,7 +2,7 @@
 
 # Complete files and expand tilde expansions in it.
 
-if (( $argv[(I)-W*] )); then
+if [[ ( -o magicequalsubst && "$IPREFIX" = *\= ) || $argv[(I)-W*] -ne 0 ]]; then
   _files "$@"
   return
 fi

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


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

* Re: PATCH: Re: Questions/comments on completion code that arise from PWS's zsh guide
  2000-02-25  8:32 Sven Wischnowsky
@ 2000-02-25 15:23 ` Alexandre Duret-Lutz
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Duret-Lutz @ 2000-02-25 15:23 UTC (permalink / raw)
  To: zsh-workers; +Cc: Sven Wischnowsky

>>> "Sven" == Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

[please forgive this if I totaly miss the point, but I
have just read all zsh mails for the last two weeks and
may have missed some important things]

 Sven> Bart Schaefer wrote:

[...]

 >> Why don't we have _dd expand the tilde when magicequalsubst is not set,
 >> and leave _path_files alone?

 Sven> But this is, of course, better.

 Sven> The patch adds _tilde_files which completes files and expands tildes
 Sven> if there are any. And makes _dd use it. 

But this will *always* expand tildes.  Since I am using magicequalsubst, 
I don't want tildes to be expanded 'on the line' in places where
it would be done by magicequalsubst.

Shouldn't there be a option to _tilde_files saying that _tilde_files is
called in a context where magicequalsubst will expand the tilde (in which
case _tilde_files should care whether the magicequalsubst is set or not) ?
Or it may be the default.

 Sven> Does anyone know of other places where this might be useful?

What happens with _arguments's equal-ended options ?
Should they use _tilde_files instead of _files ?
It may be good that `--prefix=~/usr' get expanded to
`--prefix=/myhomedir/usr' when magicequalsubst is unset, 
but I would find strange that `--prefix ~/usr' expands 
to `--prefix /myhomedir/usr' too...

-- 
Alexandre Duret-Lutz


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

* PATCH: Re: Questions/comments on completion code that arise from PWS's zsh guide
@ 2000-02-25  8:32 Sven Wischnowsky
  2000-02-25 15:23 ` Alexandre Duret-Lutz
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Wischnowsky @ 2000-02-25  8:32 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Feb 24,  9:51am, Sven Wischnowsky wrote:
> } Subject: Re: Questions/comments on completion code that arise from PWS's z
> }
> } Bart Schaefer wrote:
> } 
> } > Completing files after `=' is enabled for `dd' even if `magicequalsubst'
> } > is not set -- but of course tilde-expansion doesn't happen when the
> } > command is finally executed unless `magicequalsubst' IS set.
> } 
> } Hm, right. One solution would be to add a new option to _path_files
> } [...] But a better solution might to just make _path_files check [...]
> } Hrm, just make _path_files add a warning to the list?
> 
> This isn't really a _path_files problem, is it?  It's the caller that
> has put the `=' into IPREFIX.  I suppose it could produce a warning as
> a courtesy, but it's really not _path_files job to figure out what that
> equal sign means.  For all it knows, the command to which the x=y arg
> is being passed is one that is able to expand the tilde internally.

I was vaguely thinking about something like `avoid to duplicate...'.

> Why don't we have _dd expand the tilde when magicequalsubst is not set,
> and leave _path_files alone?

But this is, of course, better.

The patch adds _tilde_files which completes files and expands tildes
if there are any. And makes _dd use it. Does anyone know of other
places where this might be useful?


The hunk in compresult.c changes the test when to restore the original 
word instead of using the unambiguous string. It was a bit to strict,
giving different behaviour for completion after ~/ and ~root/ in this
case. That may be too irritating.


Bye
 Sven

diff -ru ../z.old/Completion/Core/_path_files Completion/Core/_path_files
--- ../z.old/Completion/Core/_path_files	Thu Feb 24 13:58:29 2000
+++ Completion/Core/_path_files	Fri Feb 25 09:10:25 2000
@@ -36,7 +36,7 @@
   if [[ "$tmp1[1]" = '(' ]]; then
     prepaths=( ${^=tmp1[2,-2]%/}/ )
   elif [[ "$tmp1[1]" = '/' ]]; then
-    prepaths=( "$tmp1/" )
+    prepaths=( "${tmp1%/}/" )
   else
     prepaths=( ${(P)^tmp1%/}/ )
     (( ! $#prepaths )) && prepaths=( ${tmp1%/}/ )
diff -ru ../z.old/Completion/User/.distfiles Completion/User/.distfiles
--- ../z.old/Completion/User/.distfiles	Thu Feb 24 13:58:33 2000
+++ Completion/User/.distfiles	Fri Feb 25 09:29:07 2000
@@ -9,7 +9,7 @@
     _perl_basepods _perl_builtin_funcs _perl_modules _perldoc
     _ports _prcs _prompt _ps _pspdf _psutils _rcs _rlogin _sh _socket
     _ssh _strip _stty _su _sudo _tar _tar_archive _telnet _tex _texi
-    _tiff _uncompress _unpack _urls _use_lo _user_at_host _users
-    _users_on _webbrowser _wget _whereis _whois _xargs _yodl _yp
+    _tiff _tilde_files _uncompress _unpack _urls _use_lo _user_at_host
+    _users _users_on _webbrowser _wget _whereis _whois _xargs _yodl _yp
     _zdump
 '
diff -ru ../z.old/Completion/User/_dd Completion/User/_dd
--- ../z.old/Completion/User/_dd	Thu Feb 24 13:58:33 2000
+++ Completion/User/_dd	Fri Feb 25 09:12:20 2000
@@ -11,10 +11,10 @@
               ascii ebcdic ibm block unblock lcase ucase swab noerror sync
 elif compset -P 1 'if='; then
   _description files expl 'input file'
-  _files "$expl[@]"
+  _tilde_files "$expl[@]"
 elif compset -P 1 'of='; then
   _description files expl 'output file'
-  _files "$expl[@]"
+  _tilde_files "$expl[@]"
 else
   _wanted values expl option &&
       compadd "$expl[@]" -S '=' if of ibs obs bs cbs skip files seek count conv
diff -ru ../z.old/Completion/User/_tilde_files Completion/User/_tilde_files
--- ../z.old/Completion/User/_tilde_files	Fri Feb 25 09:25:34 2000
+++ Completion/User/_tilde_files	Fri Feb 25 09:27:29 2000
@@ -0,0 +1,38 @@
+#autoload
+
+# Complete files and expand tilde expansions in it.
+
+if (( $argv[(I)-W*] )); then
+  _files "$@"
+  return
+fi
+
+case "$PREFIX" in
+\~/*)
+  IPREFIX="${IPREFIX}${HOME}/"
+  PREFIX="${PREFIX[3,-1]}"
+  _files "$@" -W "${HOME}"
+  ;;
+\~*/*)
+  local user="${PREFIX[2,-1]%%/*}"
+
+  if (( $+userdirs[$user] )); then
+    user="$userdirs[$user]"
+  elif (( $+nameddirs[$user] )); then
+    user="$nameddirs[$user]"
+  else
+    _message "unknown user \`$user'"
+    return 1
+  fi
+  IPREFIX="${IPREFIX}${user%/}/"
+  PREFIX="${PREFIX#*/}"
+  _files "$@" -W "$user"
+  ;;
+\~*)
+  compset -P '?'
+  _users "$@"
+  ;;
+*)
+  _files "$@"
+  ;;
+esac
diff -ru ../z.old/Src/Zle/compresult.c Src/Zle/compresult.c
--- ../z.old/Src/Zle/compresult.c	Thu Feb 24 13:58:11 2000
+++ Src/Zle/compresult.c	Fri Feb 25 09:24:03 2000
@@ -627,10 +627,9 @@
 	cline_str(ainfo->line, 1, NULL);
 
 	/* Sometimes the different match specs used may result in a cline
-	 * that is shorter than the original string. If that happened, we
-	 * re-insert the old string. Unless there were matches added with
-	 * -U, that is. */
-	if (lastend - wb < we - wb && !hasunmatched) {
+	 * that gives an empty string. If that happened, we re-insert the
+         * old string. Unless there were matches added with -U, that is. */
+	if (!(lastend - wb) && !hasunmatched) {
 	    cs = wb;
 	    foredel(lastend - wb);
 	    inststrlen(old, 0, we - wb);

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


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

end of thread, other threads:[~2000-02-25 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-25 15:39 PATCH: Re: Questions/comments on completion code that arise from PWS's zsh guide Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
2000-02-25  8:32 Sven Wischnowsky
2000-02-25 15:23 ` Alexandre Duret-Lutz

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