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

PATCH: new-style completion for parameters and options



As Andrej mentioned, this had some problems.

Making typeset print `local' for local parameters was simple. I've
made it be printed after the type since there may uses relying on
things like `array' to be the first on the line. Thank god I don't
have to decide if this is important/careful enough to be included in
an official version. If not, most the rest of this patch is pretty
useless.

This adds the files `Core/_{{set_,unset_}options,parameters}' to be
able to easily complete them. The ones for the options also use a `-M' 
option for this ignore-underscore-and-map-upper-to-lower-case thing.

Btw, why is `_vars' in `Base' and `_vars_eq' in `Builtins'?

Bye
 Sven

--- os/params.c	Mon Mar 22 13:44:37 1999
+++ Src/params.c	Tue Mar 23 15:31:05 1999
@@ -2709,6 +2709,8 @@
 	    printf("array ");
 	else if (p->flags & PM_HASHED)
 	    printf("association ");
+	if (p->level)
+	    printf("local ");
 	if (p->flags & PM_LEFT)
 	    printf("left justified %d ", p->ct);
 	if (p->flags & PM_RIGHT_B)
diff -u -r oc/Base/_brace_parameter Completion/Base/_brace_parameter
--- oc/Base/_brace_parameter	Tue Mar 23 11:56:54 1999
+++ Completion/Base/_brace_parameter	Tue Mar 23 15:52:08 1999
@@ -1,11 +1,9 @@
 #defcomp -brace-parameter-
 
-# Simple but without spiffy suffix handling: compgen -v -S '} '
-
 if [[ "$SUFFIX" = *\}* ]]; then
   ISUFFIX="${SUFFIX#*\}}$ISUFFIX"
   SUFFIX="${SUFFIX%%\}*}"
-  compadd -S '} ' -r '-:?#%+=[/' - "${(@)${(@)${(@f)$(set)}%%\=*}:gs/'//}"
+  _parameters -S '} ' -r '-:?#%+=[/'
 else
-  compadd -S '} ' -r '-:?#%+=[/' - "${(@)${(@)${(@f)$(set)}%%\=*}:gs/'//}"
+  _parameters -S '} ' -r '-:?#%+=[/'
 fi
diff -u -r oc/Base/_condition Completion/Base/_condition
--- oc/Base/_condition	Tue Mar 23 11:56:54 1999
+++ Completion/Base/_condition	Tue Mar 23 15:59:32 1999
@@ -3,14 +3,14 @@
 local prev="$words[CURRENT-1]"
 
 if [[ "$prev" = -o ]]; then
-  compgen -o -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}'
+  _options
 elif [[ "$prev" = -([no]t|ef) ]]; then
   _files
 else
   local ret=1
 
   _files && ret=0
-  compgen -v && ret=0
+  _parameters && ret=0
 
   return ret
 fi
diff -u -r oc/Base/_math Completion/Base/_math
--- oc/Base/_math	Tue Mar 23 11:56:55 1999
+++ Completion/Base/_math	Tue Mar 23 15:51:04 1999
@@ -9,4 +9,4 @@
   SUFFIX="${SUFFIX%%[^a-zA-Z0-9_]*}"
 fi
 
-compgen -v
+_parameters
diff -u -r oc/Base/_parameter Completion/Base/_parameter
--- oc/Base/_parameter	Tue Mar 23 11:56:54 1999
+++ Completion/Base/_parameter	Tue Mar 23 15:50:44 1999
@@ -1,3 +1,3 @@
 #defcomp -parameter-
 
-compgen -v
+_parameters
diff -u -r oc/Base/_vars Completion/Base/_vars
--- oc/Base/_vars	Tue Mar 23 11:56:54 1999
+++ Completion/Base/_vars	Tue Mar 23 15:49:30 1999
@@ -1,3 +1,3 @@
 #defcomp getopts read unset vared
 
-compgen -v
+_parameters
diff -u -r oc/Builtins/_setopt Completion/Builtins/_setopt
--- oc/Builtins/_setopt	Tue Mar 23 11:56:56 1999
+++ Completion/Builtins/_setopt	Tue Mar 23 16:01:14 1999
@@ -1,11 +1,3 @@
 #defcomp setopt
 
-local nm=$compstate[nmatches] ret=1
-
-compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \
-         -s '$({ unsetopt kshoptionprint; unsetopt } 2>/dev/null)' && ret=0
-
-[[ compstate[nmatches] -eq nm ]] &&
-    compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o && ret=0
-
-return ret
+_unset_options || _options
diff -u -r oc/Builtins/_unsetopt Completion/Builtins/_unsetopt
--- oc/Builtins/_unsetopt	Tue Mar 23 11:56:56 1999
+++ Completion/Builtins/_unsetopt	Tue Mar 23 16:02:02 1999
@@ -1,11 +1,3 @@
 #defcomp unsetopt
 
-local nm=$compstate[nmatches] ret=1
-
-compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \
-         -s '$({ unsetopt kshoptionprint; setopt } 2>/dev/null)' && ret=0
-
-[[ compstate[nmatches] -eq nm ]] &&
-    compgen -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o && ret=0
-
-return ret
+_set_options || _options
diff -u -r oc/Builtins/_vars_eq Completion/Builtins/_vars_eq
--- oc/Builtins/_vars_eq	Tue Mar 23 11:56:56 1999
+++ Completion/Builtins/_vars_eq	Tue Mar 23 15:50:04 1999
@@ -1,3 +1,3 @@
 #defcomp declare export integer local readonly typeset
 
-compgen -v -q -S '='
+_parameters -q -S '='
diff -u -r oc/Core/_main_complete Completion/Core/_main_complete
--- oc/Core/_main_complete	Tue Mar 23 11:56:57 1999
+++ Completion/Core/_main_complete	Tue Mar 23 15:55:59 1999
@@ -15,7 +15,10 @@
 #    any matches, correction is tried and if that doesn't yield
 #    anything either, correcting completion is attempted.
 
-local comp
+local comp _set_options _unset_options
+
+_set_options=("${(@f)$({ unsetopt kshoptionprint; setopt } 2>/dev/null)}")
+_unset_options=("${(@f)$({ unsetopt kshoptionprint; setopt } 2>/dev/null)}")
 
 setopt localoptions nullglob rcexpandparam
 unsetopt markdirs globsubst shwordsplit nounset ksharrays
diff -u -r Completion/Core/_options Completion/Core/_options
--- Completion/Core/_options	Tue Mar 23 16:04:24 1999
+++ Completion/Core/_options	Tue Mar 23 15:57:49 1999
@@ -0,0 +1,5 @@
+#autoload
+
+# This should be used to complete all option names.
+
+compgen "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o
diff -u -r Completion/Core/_parameters Completion/Core/_parameters
--- Completion/Core/_parameters	Tue Mar 23 16:04:24 1999
+++ Completion/Core/_parameters	Tue Mar 23 15:49:26 1999
@@ -0,0 +1,7 @@
+#autoload
+
+# This should be used to complete parameter names, it first tries to
+# complete only non-local parameters. All arguments are given to compadd.
+
+compadd "$@" - "${(@)${(@)${(@)${(@f)$(typeset)}:#*local *\=*}%%\=*}##* }" ||
+    compadd "$@" - "${(@)${(@)${(@f)$(typeset)}%%\=*}##* }"
diff -u -r Completion/Core/_set_options Completion/Core/_set_options
--- Completion/Core/_set_options	Tue Mar 23 16:04:25 1999
+++ Completion/Core/_set_options	Tue Mar 23 16:01:24 1999
@@ -0,0 +1,7 @@
+#autoload
+
+# Complete all set options. This relies on `_main_complete' to store the
+# names of the options that were set when it was called in the array
+# `_set_options'.
+
+compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - $=_set_options
diff -u -r Completion/Core/_unset_options Completion/Core/_unset_options
--- Completion/Core/_unset_options	Tue Mar 23 16:04:25 1999
+++ Completion/Core/_unset_options	Tue Mar 23 16:01:31 1999
@@ -0,0 +1,7 @@
+#autoload
+
+# Complete all unset options. This relies on `_main_complete' to store the
+# names of the options that were set when it was called in the array
+# `_set_options'.
+
+compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - $=_unset_options

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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