Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: _call



Here is the helper function we were talking about some time ago.

It's called with a tag and any number of strings as arguments. It
looks up the `command' style with the tag and if it is set, evaluates
its value instead of the strings given as arguments. If the value of
the style starts with a hyphen, it is only prepended to the strings
given as arguments.

I haven't used that in too many places, yet.

Note also, that the command style makes the ugly arguments and
list-arguments styles superfluous and hence they are removed. You can
replace uses of them with something like

  zstyle '...:pids' command ps ...
  zstyle '...:pids-list' command ps ...

(that second one is the replacement for list-arguments).


Bye
 Sven

diff -ru ../z.old/Completion/Base/_arguments Completion/Base/_arguments
--- ../z.old/Completion/Base/_arguments	Mon Feb 28 10:37:07 2000
+++ Completion/Base/_arguments	Mon Feb 28 10:39:32 2000
@@ -67,7 +67,7 @@
     # those hyphens and anything from the space or comma after the
     # option up to the end. 
 
-    lopts=("--${(@)^${(@)${(@)${(@M)${(@ps:\n:j:\n:)${(@)${(@M)${(@f)$(${~words[1]} --help 2>&1)//\[--/
+    lopts=("--${(@)^${(@)${(@)${(@M)${(@ps:\n:j:\n:)${(@)${(@M)${(@f)$(_call options ${~words[1]} --help 2>&1)//\[--/
 --}:#[ 	]#-*}//,/
 }}:#[ 	]#--*}#*--}%%[], ]*}:#}")
     lopts=( "${(@)lopts:#--}" )
diff -ru ../z.old/Completion/Builtins/_pids Completion/Builtins/_pids
--- ../z.old/Completion/Builtins/_pids	Mon Feb 28 10:37:10 2000
+++ Completion/Builtins/_pids	Mon Feb 28 10:39:32 2000
@@ -12,17 +12,17 @@
   shift 2
 fi
 
-zstyle -a ":completion:${curcontext}:ps" arguments args
+zstyle -s ":completion:${curcontext}:pids" command args
 
-out="$(command ps $args 2>/dev/null)"
+out="$(_call pids ps 2>/dev/null)"
 
 if zstyle -T ":completion:${curcontext}:processes" verbose; then
-  zstyle -a ":completion:${curcontext}:ps" list-arguments listargs
+  zstyle -s ":completion:${curcontext}:pids-list" command listargs
   (( $#listargs )) || listargs=( "$args[@]" )
   if [[ "$listargs" = "$args" ]]; then
     list=("${(@Mr:COLUMNS-1:)${(f@)out}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
   else
-    list=("${(@Mr:COLUMNS-1:)${(f@)$(command ps $listargs 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
+    list=("${(@Mr:COLUMNS-1:)${(f@)$(_call pids-list ps 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
   fi
   desc=(-ld list)
 else
@@ -30,4 +30,4 @@
 fi
 
 compadd "$expl[@]" "$@" "$desc[@]" - \
-    ${${${(M)${(f)"$(command ps $args 2>/dev/null)"}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]#*${~match}}## #}%% *}
+    ${${${(M)${(f)"${out}"}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]#*${~match}}## #}%% *}
diff -ru ../z.old/Completion/Linux/_rpm Completion/Linux/_rpm
--- ../z.old/Completion/Linux/_rpm	Mon Feb 28 10:37:17 2000
+++ Completion/Linux/_rpm	Mon Feb 28 10:39:32 2000
@@ -190,7 +190,7 @@
     ;&
   package)
     _wanted packages expl 'RPM package' &&
-        compadd "$expl[@]" -M 'r:|-=* r:|=*' - $(rpm -qa) && ret=0
+        compadd "$expl[@]" -M 'r:|-=* r:|=*' - $(_call packages rpm -qa) && ret=0
     ;;
   package_file)
     if compset -P ftp://; then
@@ -205,7 +205,7 @@
     if compset -P '*\{'; then
       _wanted tags expl 'RPM tag' &&
           compadd "$expl[@]" -M 'm:{a-z}={A-Z}' -S '\}' - \
-                  "${(@)${(@f)$(rpm --querytags)}#RPMTAG_}" && ret=0
+                  "${(@)${(@f)$(_call tags rpm --querytags)}#RPMTAG_}" && ret=0
     else
       _message 'RPM format'
     fi
diff -ru ../z.old/Completion/User/_a2ps Completion/User/_a2ps
--- ../z.old/Completion/User/_a2ps	Mon Feb 28 10:37:18 2000
+++ Completion/User/_a2ps	Mon Feb 28 10:39:32 2000
@@ -7,7 +7,7 @@
 
   _a2ps_cache_cmd="$words[1]"
 
-  descr=( "${(@)${(f@)$(LC_ALL=C $words[1] --list=features)//
+  descr=( "${(@)${(f@)$(_call features LC_ALL=C $words[1] --list=features)//
  /	}:#}" )
 
   _a2ps_cache_values=(
diff -ru ../z.old/Completion/User/_archie Completion/User/_archie
--- ../z.old/Completion/User/_archie	Mon Feb 28 10:37:18 2000
+++ Completion/User/_archie	Mon Feb 28 10:39:33 2000
@@ -24,7 +24,7 @@
 
 case "$state" in
 serverhost)
-  : ${(A)archie_servers:=${(M)$(archie -L):#archie.*}}
+  : ${(A)archie_servers:=${(M)$(_call hosts archie -L):#archie.*}}
 
   _wanted hosts expl 'archie servers' && compadd "$expl[@]" -  $archie_servers
   ;;
diff -ru ../z.old/Completion/User/_diff_options Completion/User/_diff_options
--- ../z.old/Completion/User/_diff_options	Mon Feb 28 10:37:18 2000
+++ Completion/User/_diff_options	Mon Feb 28 10:39:33 2000
@@ -4,7 +4,7 @@
 
 (( $+_diff_is_gnu )) || {
 	_diff_is_gnu=0;
-        [[ $(command diff -v </dev/null 2>/dev/null) == *GNU* ]] && _diff_is_gnu=1
+        [[ $(_call version diff -v </dev/null 2>/dev/null) == *GNU* ]] && _diff_is_gnu=1
 }
 
 if (( _diff_is_gnu ))
diff -ru ../z.old/Completion/User/_finger Completion/User/_finger
--- ../z.old/Completion/User/_finger	Mon Feb 28 10:37:19 2000
+++ Completion/User/_finger	Mon Feb 28 10:39:33 2000
@@ -4,7 +4,7 @@
 typeset -A opt_args
 
 if (( ! $+_finger_args )); then
-  local help="$(finger -\? 2>&1)"
+  local help="$(_call options finger -\? 2>&1)"
   local -A optionmap
 
 ## `finger -\?':
diff -ru ../z.old/Completion/User/_groups Completion/User/_groups
--- ../z.old/Completion/User/_groups	Mon Feb 28 10:37:19 2000
+++ Completion/User/_groups	Mon Feb 28 10:39:33 2000
@@ -7,7 +7,7 @@
 if ! zstyle -a ":completion:${curcontext}:" groups groups; then
   (( $+_cache_groups )) ||
       if (( ${+commands[ypcat]} )); then
-        : ${(A)_cache_groups:=${${(s: :)$(ypcat group.byname)}%%:*}} # If you use YP
+        : ${(A)_cache_groups:=${${(s: :)$(_call groups ypcat group.byname)}%%:*}} # If you use YP
       else
         : ${(A)_cache_groups:=${${(s: :)$(</etc/group)}%%:*}}
       fi
diff -ru ../z.old/Completion/User/_gs Completion/User/_gs
--- ../z.old/Completion/User/_gs	Mon Feb 28 10:37:19 2000
+++ Completion/User/_gs	Mon Feb 28 10:39:33 2000
@@ -36,7 +36,7 @@
       case "$IPREFIX" in
       *DEVICE\=)
         _wanted devices expl 'ghostscript device' &&
-            compadd "$expl[@]" - "${(@)${=${$(gs -h)##* devices:}%%Search path:*}:#}" && ret=0
+            compadd "$expl[@]" - "${(@)${=${$(_call devices gs -h)##* devices:}%%Search path:*}:#}" && ret=0
         ;;
       *OutputFile\=)
         _description files expl 'output file'
diff -ru ../z.old/Completion/User/_killall Completion/User/_killall
--- ../z.old/Completion/User/_killall	Mon Feb 28 10:37:20 2000
+++ Completion/User/_killall	Mon Feb 28 10:39:33 2000
@@ -3,7 +3,7 @@
 if [[ "$OSTYPE" = linux* ]]; then
   _alternative \
       'signals:: _signals -p' \
-      'processes:process:{ compadd "$expl[@]" ${$(ps ho comm 2> /dev/null):#(ps|COMMAND)} }'
+      'processes:process:{ compadd "$expl[@]" ${$(_call pids ps ho comm 2> /dev/null):#(ps|COMMAND)} }'
 else
   _signals -p
 fi
diff -ru ../z.old/Completion/User/_lp Completion/User/_lp
--- ../z.old/Completion/User/_lp	Mon Feb 28 10:37:20 2000
+++ Completion/User/_lp	Mon Feb 28 10:39:34 2000
@@ -64,7 +64,7 @@
     else
       printer=()
     fi
-    list=( ${(M)"${(f@)$(lpq $printer 2> /dev/null)}":#[0-9]*} )
+    list=( ${(M)"${(f@)$(_call jobs lpq $printer 2> /dev/null)}":#[0-9]*} )
 
     if (( $#list )); then
       _tags users jobs
diff -ru ../z.old/Completion/User/_telnet Completion/User/_telnet
--- ../z.old/Completion/User/_telnet	Mon Feb 28 10:37:22 2000
+++ Completion/User/_telnet	Mon Feb 28 10:39:34 2000
@@ -9,7 +9,7 @@
 typeset -A opt_args
 
 if (( ! $+_telnet_args )); then
-  local help="$(telnet -\? < /dev/null 2>&1)"
+  local help="$(_call options telnet -\? < /dev/null 2>&1)"
   local -A optionmap
   optionmap=(
     '*\[-8\]*' '-8[allow 8-Bit data]'
diff -ru ../z.old/Completion/User/_users_on Completion/User/_users_on
--- ../z.old/Completion/User/_users_on	Mon Feb 28 10:37:23 2000
+++ Completion/User/_users_on	Mon Feb 28 10:39:34 2000
@@ -6,7 +6,7 @@
 
 if which users >/dev/null; then
   _description users expl 'users logged on'
-  compadd "$@" "$expl[@]" - $(users) && return 0
+  compadd "$@" "$expl[@]" - $(_call users users) && return 0
 else
   # Other methods of finding out users logged on should be added here
   return 1
diff -ru ../z.old/Completion/User/_yp Completion/User/_yp
--- ../z.old/Completion/User/_yp	Mon Feb 28 10:37:23 2000
+++ Completion/User/_yp	Mon Feb 28 10:39:34 2000
@@ -4,8 +4,8 @@
 typeset -A opt_args
 
 if (( ! $+_yp_cache_maps )); then
-  _yp_cache_maps=( "${(@)${(@f)$(ypwhich -m)}%% *}" )
-  _yp_cache_nicks=( "${(@)${(@)${(@f)$(ypwhich -x)}#*\"}%%\"*}" )
+  _yp_cache_maps=( "${(@)${(@f)$(_call maps ypwhich -m)}%% *}" )
+  _yp_cache_nicks=( "${(@)${(@)${(@f)$(_call names ypwhich -x)}#*\"}%%\"*}" )
   _yp_args=(
     '(-x)-d[specify domain]:domain name:' \
     '(-x)-k[display keys]' \
diff -ru ../z.old/Completion/X/_x_font Completion/X/_x_font
--- ../z.old/Completion/X/_x_font	Mon Feb 28 10:37:24 2000
+++ Completion/X/_x_font	Mon Feb 28 10:39:34 2000
@@ -9,7 +9,7 @@
 if (( ! $+_font_cache )); then
   typeset -gU _font_cache
 
- _font_cache=( "${(@)^${(@f)$(xlsfonts)}%%--*}--" )
+ _font_cache=( "${(@)^${(@f)$(_call fonts xlsfonts)}%%--*}--" )
 fi
 
 compadd -M 'r:|-=* r:|=*' "$expl[@]" "$@" -S '' - "$_font_cache[@]"
diff -ru ../z.old/Completion/X/_x_window Completion/X/_x_window
--- ../z.old/Completion/X/_x_window	Mon Feb 28 10:37:25 2000
+++ Completion/X/_x_window	Mon Feb 28 10:39:34 2000
@@ -4,7 +4,7 @@
 
 _tags windows || return 1
 
-list=( "${(@)${(M@)${(@f)$(xwininfo -root -tree)}:#[ 	]#0x[0-9a-f]# \"*}##[ 	]#}" )
+list=( "${(@)${(M@)${(@f)$(_call windows xwininfo -root -tree)}:#[ 	]#0x[0-9a-f]# \"*}##[ 	]#}" )
 
 if [[ "$1" = -n ]]; then
   shift
diff -ru ../z.old/Doc/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- ../z.old/Doc/Zsh/compsys.yo	Mon Feb 28 09:08:57 2000
+++ Doc/Zsh/compsys.yo	Mon Feb 28 10:44:33 2000
@@ -587,6 +587,13 @@
 used to look up the values of the tt(expand), tt(cursor) and
 tt(special-dirs) styles
 )
+item(tt(pids))(
+for process identifiers
+)
+item(tt(pids-list))(
+used to look up the tt(command) style when generating the list to
+display for process identifiers
+)
 item(tt(pods))(
 for perl pods
 )
@@ -602,9 +609,6 @@
 item(tt(processes))(
 for process identifiers
 )
-item(tt(ps))(
-used to look up the tt(arguments) and tt(list-arguments) styles
-)
 item(tt(sequences))(
 for sequences (e.g. tt(mh) sequences)
 )
@@ -674,10 +678,6 @@
 This style is used by the tt(_prefix) completer to decide if a space
 should be inserted before the suffix.
 )
-item(tt(arguments))(
-The value of this style is given to the tt(ps) command by functions
-that call it when generating process identifiers as matches.
-)
 item(tt(auto-description))(
 If set, this style's value will be used as the description for options which
 are not described by the completion functions, but that have exactly
@@ -693,6 +693,25 @@
 widget to stop incremental completion without the key having any
 further effect.
 )
+item(tt(command))(
+This style can be used to override the defaults in several completion
+functions for how commands are called to generate information about
+possible matches. The strings in the value are joined with spaces
+between them to build the command line to execute. If the value starts 
+with a hyphen the string built will be prepended to the default
+supplied by the completion function. This allows one to easily stick a 
+tt(builtin) or tt(command) in front of the default in case one has,
+for example, a shell function with the same name as the command
+called, but for completion purposes one needs to ensure that the real
+command is called.
+
+For example, the function generating process IDs as matches uses this
+style with the tt(pids) tag to generate the IDs to complete and iwhen
+the tt(verbose) style is `true', it uses this style with the
+tt(pids-list) tag to generate the strings to display. When using
+different values for these two tags one should ensure that the process
+IDs appear in the same order in both lists.
+)
 item(tt(completer))(
 The strings given as the value of this style give the names of the
 completer functions to use. The available completer functions are
@@ -935,10 +954,6 @@
 example, the hostname is already typed, only those ports will be
 completed for which pairs with the hostname from the line exist.
 )
-item(tt(hosts-ports-users))(
-Like tt(hosts-ports) but used for commands like tt(telnet) and
-containing strings of the form `var(host)tt(:)var(port)tt(:)var(user)'.
-)
 item(tt(ignore-parents))(
 When completing files it is possible to make names of directories
 already mentioned on the line or the current working directory be
@@ -1009,10 +1024,6 @@
 should be shown even if there is only one possible completion. This is 
 done if the value of this style is the string tt(always).
 )
-item(tt(list-arguments))(
-Like the tt(arguments) style, but used when calling the tt(ps) command 
-to generate the list to display.
-)
 item(tt(list-colors))(
 If the tt(zsh/complist) module is used, this style can be used to set
 color specifications as with the tt(ZLS_COLORS) and tt(ZLS_COLOURS)
@@ -1469,6 +1480,10 @@
 people's accounts. Finally, this may also be used by some commands with
 the tt(accounts) tag.
 )
+item(tt(users-hosts-ports))(
+Like tt(users-hosts) but used for commands like tt(telnet) and
+containing strings of the form `var(user)tt(@)var(host)tt(:)var(port)'.
+)
 item(tt(verbose))(
 This is used in several contexts to decide if only a simple or a
 verbose list of matches should be generated. For example some commands 
@@ -1908,6 +1923,19 @@
 example, the function completing inside subscripts might use
 `tt(_compalso -math-)' to include the completions generated for
 mathematical environments.
+)
+findex(_call)
+item(tt(_call) var(tag) var(string) ...)(
+This function is used in places where a command is called and the user 
+should have the possibility to override the default for calling this
+command. It looks up the tt(command) style with the supplied
+var(tag). If the style is set, its value is used as the command to
+execute.
+
+In any case, the var(strings) from the call to tt(_call) or from the
+style are concatenated with spaces between them and the resulting
+string is evaluated. The return value is the return value of the
+command called.
 )
 findex(_normal)
 item(tt(_normal))(

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author