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

RE: PATCH: new-style completion for parameters and options



Andrej Borsenkow wrote:

> What is the reason for compgen (and compctl) to complete non-local variables
> at all? compctl never did it before (it simply could not be called in such a
> context) - so there is no compatibility change related to completion.

Err, right, hadn't thought about that.

Not being able to see a reason to complete local parameters, I changed 
this (in tricky.c). 

So this patch is (partly) the reverse of 5904. It makes `compgen -v'
be used in many places again. The `_parameters' functions has to be
kept, though, since it is still used by `_brace_parameters'.

This also changes the option handling. The functions now call
`_options' instead of `_(un|)set_options'. Again, I think these
functions should still be kept, especially since I only commented out
the stuff in `_main_complete' and `_(un|)setopt'.

I've also (finally) documented them in the `README' file.

Better now? ;-)

Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Wed Mar 24 13:41:56 1999
+++ Src/Zle/zle_tricky.c	Thu Mar 25 09:08:22 1999
@@ -3654,8 +3654,8 @@
     } else if (addwhat == CC_QUOTEFLAG || addwhat == -2  ||
 	      (addwhat == -3 && !(hn->flags & DISABLED)) ||
 	      (addwhat == -4 && (PM_TYPE(pm->flags) == PM_SCALAR) &&
-	       (tt = pm->gets.cfn(pm)) && *tt == '/')    ||
-	      (addwhat == -9 && !(hn->flags & PM_UNSET)) ||
+	       !pm->level && (tt = pm->gets.cfn(pm)) && *tt == '/')    ||
+	      (addwhat == -9 && !(hn->flags & PM_UNSET) && !pm->level) ||
 	      (addwhat > 0 &&
 	       ((!(hn->flags & PM_UNSET) &&
 		 (((addwhat & CC_ARRAYS)    &&  (hn->flags & PM_ARRAY))    ||
@@ -3664,7 +3664,8 @@
 		  ((addwhat & CC_SCALARS)   &&  (hn->flags & PM_SCALAR))   ||
 		  ((addwhat & CC_READONLYS) &&  (hn->flags & PM_READONLY)) ||
 		  ((addwhat & CC_SPECIALS)  &&  (hn->flags & PM_SPECIAL))  ||
-		  ((addwhat & CC_PARAMS)    && !(hn->flags & PM_EXPORTED)))) ||
+		  ((addwhat & CC_PARAMS)    && !(hn->flags & PM_EXPORTED))) &&
+		 !pm->level) ||
 		((( addwhat & CC_SHFUNCS)				  ||
 		  ( addwhat & CC_BUILTINS)				  ||
 		  ( addwhat & CC_EXTCMDS)				  ||
diff -u -r oc/Base/_condition Completion/Base/_condition
--- oc/Base/_condition	Thu Mar 25 09:11:35 1999
+++ Completion/Base/_condition	Thu Mar 25 09:12:30 1999
@@ -10,7 +10,7 @@
   local ret=1
 
   _files && ret=0
-  _parameters && ret=0
+  compgen -v && ret=0
 
   return ret
 fi
diff -u -r oc/Base/_math Completion/Base/_math
--- oc/Base/_math	Thu Mar 25 09:11:36 1999
+++ Completion/Base/_math	Thu Mar 25 09:12:39 1999
@@ -9,4 +9,4 @@
   SUFFIX="${SUFFIX%%[^a-zA-Z0-9_]*}"
 fi
 
-_parameters
+compgen -v
diff -u -r oc/Base/_parameter Completion/Base/_parameter
--- oc/Base/_parameter	Thu Mar 25 09:11:36 1999
+++ Completion/Base/_parameter	Thu Mar 25 09:12:54 1999
@@ -1,3 +1,3 @@
 #defcomp -parameter-
 
-_parameters
+compgen -v
diff -u -r oc/Base/_vars Completion/Base/_vars
--- oc/Base/_vars	Thu Mar 25 09:11:35 1999
+++ Completion/Base/_vars	Thu Mar 25 09:13:06 1999
@@ -1,3 +1,3 @@
 #defcomp getopts read unset vared
 
-_parameters
+compgen -v
diff -u -r oc/Builtins/_setopt Completion/Builtins/_setopt
--- oc/Builtins/_setopt	Thu Mar 25 09:11:38 1999
+++ Completion/Builtins/_setopt	Thu Mar 25 09:17:16 1999
@@ -1,3 +1,10 @@
 #defcomp setopt
 
-_unset_options || _options
+# If you first want to complete only unset options, un-comment the lines
+# setting the _unset_options  array and then use:
+#
+#   _unset_options || _options
+#
+# here.
+
+_options
diff -u -r oc/Builtins/_unsetopt Completion/Builtins/_unsetopt
--- oc/Builtins/_unsetopt	Thu Mar 25 09:11:37 1999
+++ Completion/Builtins/_unsetopt	Thu Mar 25 09:15:41 1999
@@ -1,3 +1,10 @@
 #defcomp unsetopt
 
-_set_options || _options
+# If you first want to complete only unset options, uncomment the lines
+# setting the _set_options  array and then use:
+#
+#   _set_options || _options
+#
+# here.
+
+_options
diff -u -r oc/Builtins/_vars_eq Completion/Builtins/_vars_eq
--- oc/Builtins/_vars_eq	Thu Mar 25 09:11:38 1999
+++ Completion/Builtins/_vars_eq	Thu Mar 25 09:16:20 1999
@@ -1,3 +1,3 @@
 #defcomp declare export integer local readonly typeset
 
-_parameters -q -S '='
+compgen -v -q -S '='
diff -u -r oc/Core/_main_complete Completion/Core/_main_complete
--- oc/Core/_main_complete	Thu Mar 25 09:11:40 1999
+++ Completion/Core/_main_complete	Thu Mar 25 09:31:05 1999
@@ -19,10 +19,21 @@
 # without arguments. If arguments are given, they should be names of
 # completer functions which will then be called.
 
-local comp _set_options _unset_options
 
-_set_options=("${(@f)$({ unsetopt kshoptionprint; setopt } 2>/dev/null)}")
-_unset_options=("${(@f)$({ unsetopt kshoptionprint; setopt } 2>/dev/null)}")
+# If you want to complete only set or unset options for the unsetopt
+# and setopt builtin, un-comment these lines:
+#
+#   local _set_options _unset_options
+#
+#   _set_options=("${(@f)$({ unsetopt kshoptionprint; setopt } 2>/dev/null)}")
+#   _unset_options=("${(@f)$({ unsetopt kshoptionprint; setopt } 2>/dev/null)}")
+#
+# This is needed because completion function may set options locally
+# which makes the output of setopt and unsetopt reflect a different
+# state than the global one for which you are completing.
+
+
+local comp
 
 setopt localoptions nullglob rcexpandparam
 unsetopt markdirs globsubst shwordsplit nounset ksharrays
diff -u -r oc/Core/_parameters Completion/Core/_parameters
--- oc/Core/_parameters	Thu Mar 25 09:11:40 1999
+++ Completion/Core/_parameters	Thu Mar 25 09:20:08 1999
@@ -1,7 +1,8 @@
 #autoload
 
-# This should be used to complete parameter names, it first tries to
-# complete only non-local parameters. All arguments are given to compadd.
+# This should be used to complete parameter names if you need some of the
+# extra options of compadd. 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 oc/README Completion/README
--- oc/README	Thu Mar 25 09:11:41 1999
+++ Completion/README	Thu Mar 25 09:31:00 1999
@@ -67,6 +67,12 @@
     function dispatches to the various other functions for individual
     commands.  (Actually, the system is fairly context-sensitive, so
     it is wider than just command+argument.)
+  _options
+    Utility to complete option names, allowing the optional `no' prefix
+    and correctly handling upper case letters and underscores.
+  _parameters
+    This can be used to complete parameter names if you need some of the
+    options of compadd not supported by compgen.
   _path_files
     The function usually called to complete filenames and directories.  It
     replaces the standard -f, -g and -/ options for the basic completion
@@ -75,6 +81,10 @@
   _sep_parts
     Utility used for completing words with multiple separate parts, such as
     `<user>@<host>'
+  _set_options
+  _unset_options
+    These can be used to complete only set or unset options. For this to
+    work, you'll have to un-comment a few lines in _main_complete.
 Base:
   You will almost certainly want these files, too, which handle standard
   tasks like completing files.  However, you may want to edit them for

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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