* PATCH: new-style completion for parameters and options
@ 1999-03-23 15:13 Sven Wischnowsky
1999-03-24 11:15 ` Andrej Borsenkow
0 siblings, 1 reply; 3+ messages in thread
From: Sven Wischnowsky @ 1999-03-23 15:13 UTC (permalink / raw)
To: zsh-workers
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@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: PATCH: new-style completion for parameters and options
1999-03-23 15:13 PATCH: new-style completion for parameters and options Sven Wischnowsky
@ 1999-03-24 11:15 ` Andrej Borsenkow
0 siblings, 0 replies; 3+ messages in thread
From: Andrej Borsenkow @ 1999-03-24 11:15 UTC (permalink / raw)
To: Sven Wischnowsky, zsh-workers
>
> 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.
>
Again I must beg your pardon for (partial) noice yesterday :-(
1. Parameter completion.
This does not solve the problem generally enough. First of all, if user has
existing compctl, this will be called (with the same problem); second, you
cannot prevent users from calling compgen -vANIOpZN directly (I am not sure,
if all of them has this problem)
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. (The
only case is user-defined ZLE widgets, and they did not exist in 3.0.x)
For really perversed, compgen -v || compgen -k "something with typeset"
could be used :-) And I think, that typeset addition is still useful.
2. options completion
I was taken away by the fact, that old compctl examples did it the same way
you do in this patch:
###compctl -s '$(setopt 2>/dev/null)' + -o + -x 's[no]' -o -- unsetopt
###compctl -s '$(unsetopt)' + -o + -x 's[no]' -o -- setopt
so, I was accustomed to the fact, that only unset/set options are completed.
As it stands now, compgen -o completes *any* option (irrespectively of
wether they are set or not) and does *not* have the above problem at all.
So, this patch is probably an overkill ...
But the idea with assoc array for options is still nice ...
cheers
/andrej
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: PATCH: new-style completion for parameters and options
@ 1999-03-25 8:35 Sven Wischnowsky
0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 1999-03-25 8:35 UTC (permalink / raw)
To: zsh-workers
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@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1999-03-25 8:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-23 15:13 PATCH: new-style completion for parameters and options Sven Wischnowsky
1999-03-24 11:15 ` Andrej Borsenkow
1999-03-25 8:35 Sven Wischnowsky
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).