Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: Questions/comments on completion code that arise from PWS's zsh guide
- X-seq: zsh-workers 9870
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: Re: Questions/comments on completion code that arise from PWS's zsh guide
- Date: Fri, 25 Feb 2000 09:32:33 +0100 (MET)
- In-reply-to: "Bart Schaefer"'s message of Thu, 24 Feb 2000 17:45:32 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
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@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author