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

Re: PATCH: cleanup of a few completion functions



Bart wrote:

> }  - use of pager style in _complete-debug.
> 
> That patch doesn't seem to be in here, so I can't get too upset about 
> it.

I must have missed it when I collated the patch together. It is now
below (including associated _zstyle change). With it, anyone who does
use their editor for viewing the traces will need:
  zstyle ':completion:complete-debug:*' pager $EDITOR
Note that nslookup also uses the pager style so it's not new and using
a context of '*' might not be what you'd want.

> } Anyone know what is going on with the "(${opts#-l})-L+[.... specs in
> } _zle and _pine? They don't seem to work to me. Did they before (I may
> } have blindly copied _zle when I wrote _pine)? To work, it seems to 
> need
> } to be "(${(@)^^opts#-l})-L+...
>
> That's my fault.  I never use rc_expand_param myself so I always forget
> that it's turned on everywhere in the completion code.

Actually, it needed to be \(${(j. .)opts:#-l}')-L... and unsetting
rc_expand_param wouldn't actually fix it. I've tried 3.1.9 and nothings
changed since then so it probably never worked right in _zle.

Anyway, I've fixed both _zle and _pine and cleaned up _zle. I'm not
sure that the loop over $state is necessary in _zle but I've left it.

Oliver

Index: Completion/Base/Widget/_complete_debug
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_complete_debug,v
retrieving revision 1.3
diff -u -r1.3 _complete_debug
--- Completion/Base/Widget/_complete_debug	2001/06/21 10:05:19	1.3
+++ Completion/Base/Widget/_complete_debug	2002/01/17 12:56:48
@@ -4,7 +4,7 @@
 
 (( $+_debug_count )) || integer -g _debug_count
 local tmp=${TMPPREFIX}${$}${words[1]:t}$[++_debug_count]
-local w="${(qq)words}"
+local pager w="${(qq)words}"
 
 exec 3>&-	# Too bad if somebody else is using it ...
 [[ -t 2 ]] && { exec 3>&2 2>| $tmp ; trap 'exec 2>&3 3>&-' EXIT INT }
@@ -15,7 +15,8 @@
 unsetopt xtrace
 
 [[ -t 3 ]] && {
-    print -sR "${VISUAL:-${EDITOR:-${PAGER:-more}}} ${(q)tmp} ;: $w"
+    zstyle -s ':completion:complete-debug::::' pager pager
+    print -sR "${pager:-${PAGER:-${VISUAL:-${EDITOR:-more}}}} ${(q)tmp} ;: $w"
     _message -r "Trace output left in $tmp (up-history to view)"
     [[ $compstate[nmatches] -le 1 && $compstate[list] != *force* ]] &&
         compstate[list]='list force messages'
Index: Completion/Unix/Command/_pine
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_pine,v
retrieving revision 1.3
diff -u -r1.3 _pine
--- Completion/Unix/Command/_pine	2001/05/30 11:54:53	1.3
+++ Completion/Unix/Command/_pine	2002/01/17 12:56:48
@@ -42,12 +42,12 @@
   "($opts $send)-o[open first folder read-only]" \
   "(-F -h -v)-r[restricted - can only send mail to oneself]" \
   "(-h -v)-d[set debug level]:debug:(0 1 2 3 4 5 6 7 8 9 flush timestamp imap= numfiles= verbose=)" \
-  "(${opts#-F})-k[force use of function keys]" \
-  "(${opts#-F})-z[allow use of ^Z suspension]" \
-  "(${opts#-F})-p+[use alternate .pinerc file]:alternate pinerc:_files" \
-  "(${opts#-F})-P+[use alternate pine.conf file]:alternate pine.conf:_files" \
-  "(${opts#-F})-x[use configuration exceptions file]:configuration exceptions file:_files" \
-  "(${opts#-F})-bail[exit if pinerc file doesn't already exist]" \
+  \(${(j. .)opts:#-F}')-k[force use of function keys]' \
+  \(${(j. .)opts:#-F}')-z[allow use of ^Z suspension]' \
+  \(${(j. .)opts:#-F}')-p+[use alternate .pinerc file]:alternate pinerc:_files' \
+  \(${(j. .)opts:#-F}')-P+[use alternate pine.conf file]:alternate pine.conf:_files' \
+  \(${(j. .)opts:#-F}')-x[use configuration exceptions file]:configuration exceptions file:_files' \
+  \(${(j. .)opts:#-F}")-bail[exit if pinerc file doesn't already exist]" \
   '*::recipient:->userhost' \
   ${^_cache_pine_options}':option value' && return 0
 
Index: Completion/Zsh/Command/_zle
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_zle,v
retrieving revision 1.1
diff -u -r1.1 _zle
--- Completion/Zsh/Command/_zle	2001/04/02 11:33:23	1.1
+++ Completion/Zsh/Command/_zle	2002/01/17 12:56:48
@@ -1,7 +1,7 @@
 #compdef zle
 
-local expl ret=1 st
-local -a opts compwids state
+local expl ret=1
+local -a opts compwids state line context
 
 compwids=(accept-and-menu-complete
 	  complete-word
@@ -19,59 +19,55 @@
     "($opts)-A[define widget alias]:old widget:->widget :new widget:->widget" \
     "($opts)-C[define completion widget]:new widget name:->comp-widget :completion widget:->builtin-comp-widget :widget shell function:->function" \
     "($opts)-D[delete widget]:*:widget:->widget" \
-    "(${opts#-l})-L+[with -l, list as commands]:*:-:->listing" \
-    "(${opts#-[La]})-l+[list user-defined widgets]:*:-:->listing" \
-    "(${opts#-l})-a+[with -l, list all widgets]:*:-:->listing" \
+    \(${(j. .)opts:#-l}')-L[with -l, list as commands]' \
+    \(${(j. .)opts:#-[La]}')-l+[list user-defined widgets]:*:-:->listing' \
+    \(${(j. .)opts:#-l}')-a[with -l, list all widgets]' \
     "($opts)-M[display message]:message: " \
     "($opts)-N[define new widget]:widget name:->widget-or-function ::widget shell function:->function" \
-    "(${opts#-c})-R+[redisplay]:*:-:->redisplay" \
-    "(${opts#-R})-c+[with -R, clear listing]:*:-:->redisplay" \
+    \(${(j. .)opts:#-c}')-R+[redisplay]:*:-:->redisplay' \
+    \(${(j. .)opts:#-R}')-c[with -R, clear listing]' \
     "($opts)-U[unget to input stack]:string: " \
-    '(-)::widget name:->call'
+    '(-):widget:->widget' \
+    '(-)*::widget args:->args' && ret=0
 
 [[ $state == listing ]] &&
-  _arguments -s -S \
-    "-l[list user-defined widgets]" \
+  _arguments -s -S '!-l' \
     "(-a)-L[list as commands]" \
     "(-L)-a[list all widgets]" \
-    '(-)*:widget name:->widget'
+    '*:widget name:->widget' && ret=0
 
-for st in $state; do
-  case $st in
-    (call)
-      if ((CURRENT > 2)); then
-	_arguments \
-          '(-N)-n[numeric prefix]:number: ' \
-	  '(-n)-N[reset numeric prefix]' \
-	  ':widget::' '(-)*:widget arguments: ' && ret=0
-	  # :widget:: is a placeholder so we needn't shift words
-	continue
-      fi
-      ;&
+while (( $#state )); do
+  case "$state[1]" in
+    (args)
+      _arguments \
+        '(-N)-n[numeric prefix]:number:' \
+	'(-n)-N[reset numeric prefix]' \
+	'(-)*:widget arguments: ' && ret=0
+      ;;
     (widget*)
-      _wanted widgets expl widget compadd -k widgets && ret=0
+      _wanted -C "$context[1]" widgets expl widget compadd -k widgets && ret=0
       [[ $st != *function ]] && continue
       ;&
     (function)
-      _wanted functions expl 'widget shell function' \
+      _wanted -C "$context[1]" functions expl 'widget shell function' \
 	compadd -k functions && ret=0
       ;;
     (comp-widget)
-      _wanted widgets expl 'completion widget' \
+      _wanted -C "$context[1]" widgets expl 'completion widget' \
 	compadd -k "widgets[(R)(*:|)(.|)(${(j(|))compwids})(|:*)]" && ret=0
       ;&
     (builtin-comp-widget)
-      _wanted widgets expl 'builtin completion widget' \
+      _wanted -C "$context[1]" widgets expl 'builtin completion widget' \
 	compadd -k "widgets[(I)(.|)(${(j(|))compwids})]" && ret=0
       ;;
     (redisplay)
-      _arguments -s \
-        "-R[redisplay]" \
-	"(*)-c[clear listing]" \
-	"(-)::status line: " "*:strings to list: " && ret=0
+      _arguments -s -S '!-R' \
+	"-c[clear listing]" \
+	":status line" "*:strings to list" && ret=0
       ;;
-    (*) ret=$?;;
   esac
+  shift 1 state
+  shift 1 context
 done
 
 return ret
Index: Completion/Zsh/Command/_zstyle
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_zstyle,v
retrieving revision 1.6
diff -u -r1.6 _zstyle
--- Completion/Zsh/Command/_zstyle	2002/01/10 11:00:05	1.6
+++ Completion/Zsh/Command/_zstyle	2002/01/17 12:56:49
@@ -89,6 +89,7 @@
   original		 c:bool
   packageset		 c:packageset
   path			 c:_directories
+  pager			 c:_command_names
   pine-directory         c:_directories
   ports			 c:_ports
   prefix-hidden		 c:bool
@@ -233,8 +234,8 @@
 
     functions)
       _wanted comp-widget expl 'completion widget' \
-          compadd $suf - all-matches complete-tag correct-word expand-word \
-	  expand-alias-word history-words
+          compadd $suf - all-matches complete-debug complete-tag \
+	  correct-word expand-word expand-alias-word history-words
       ;;
 
     user-host-port)

This email has been scanned for all viruses by the MessageLabs SkyScan service. For more information on a proactive anti-virus service working around the clock, around the globe, visit http://www.messagelabs.com



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