From: Oliver Kiddle <opk@u.genie.co.uk>
To: Zsh workers <zsh-workers@sunsite.auc.dk>
Subject: PATCH: selective parameter completion
Date: Thu, 10 Aug 2000 21:06:09 +0100 [thread overview]
Message-ID: <39930B31.C6C3876D@u.genie.co.uk> (raw)
I've implemented the change to _parameters which I mentioned yesterday
and modified a few other completion functions to make use of it. In the
process, it has raised a few questions:
In _arrays, _wanted is used but _parameters also calls _wanted so the
description of what is to be completed - 'array' - is replaced by
'parameter'. _files manages to avoid this problem so how is it done and
what should _parameters be doing here?
How does the implementation of _math differ from if compset -P and
compset -S were used to move the patterns from PREFIX to IPREFIX and
SUFFIX to ISUFFIX? It would be nice if spaces were treated more
cleanly, for example:
: $(( <tab>
doesn't complete parameters but quotes the space.
I have made _vars complete arrays and associations separately so that a
'[' suffix can be added automatically. The trouble here is that it has
to be quoted unless the glob option is not set otherwise a message
about no matches being found will be printed when the command is run.
Is it worth checking the state of the glob option before quoting this
suffix. If so, should _precommand be doing a 'setopt localoptions
noglob' when the noglob command is being completed to ensure the option
is set during the completion of the command after it?
Also, it would make sense to use _vars instead of _parameters when
completing in command position but the square brackets aren't treated
as a pattern there so how can I detect that it is being used in command
postion: is [[ CURRENT = 1 ]] going to work?
As far as I can tell, the existing code in _vars for completing
association keys after an opening square-bracket is only useful when we
have quoting because _subscript will do the job otherwise. I would add
similar code for array indexes but it seems a bit pointless to be
repeating code that we already have in _subscript. Calling _subscript
doesn't seem to work so what would be a good way to avoid this
repetition?
Oliver
Index: Completion/Base/_math
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_math,v
retrieving revision 1.2
diff -u -r1.2 _math
--- Completion/Base/_math 2000/05/09 17:16:08 1.2
+++ Completion/Base/_math 2000/08/10 21:01:00
@@ -9,4 +9,4 @@
SUFFIX="${SUFFIX%%[^a-zA-Z0-9_]*}"
fi
-_parameters
+_parameters -g '(integer|float)*'
Index: Completion/Builtins/_arrays
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_arrays,v
retrieving revision 1.2
diff -u -r1.2 _arrays
--- Completion/Builtins/_arrays 2000/06/22 08:42:36 1.2
+++ Completion/Builtins/_arrays 2000/08/10 21:01:00
@@ -2,4 +2,4 @@
local expl
-_wanted arrays expl array compadd -k "parameters[(R)*array*~*local*]"
+_wanted arrays expl array _parameters "$@" -g '*array*'
Index: Completion/Builtins/_vars
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_vars,v
retrieving revision 1.4
diff -u -r1.4 _vars
--- Completion/Builtins/_vars 2000/08/09 21:20:41 1.4
+++ Completion/Builtins/_vars 2000/08/10 21:01:00
@@ -1,9 +1,10 @@
#compdef getopts unset vared
# This will handle completion of keys of associative arrays, e.g. at
-# `vared foo[<TAB>'. However, in this version the [ must be added
-# by hand.
+# `vared foo[<TAB>'.
+local ret=1
+
if [[ $PREFIX = *\[* ]]; then
local var=${PREFIX%%\[*}
local elt="${PREFIX#*\]}${SUFFIX%\]}"
@@ -11,7 +12,7 @@
compset -p $(( ${#var} + 1 ))
if ! compset -S \]; then
- addclose=(-S ']')
+ addclose=(-S "${${QIPREFIX:+]}:-\]}")
fi
if [[ ${(tP)var} = assoc* ]]; then
local expl
@@ -20,5 +21,13 @@
compadd $addclose -k "$var"
fi
else
- _parameters "$@"
+ _parameters -g '^a*' "$@" && ret=0
+
+ if compset -S '\[*'; then
+ set - -S "" "$@"
+ else
+ set - -qS"${${QIPREFIX:+[}:-\[}" "$@"
+ fi
+ _parameters -g 'a*' "$@" && ret=0
+ return ret
fi
Index: Completion/Builtins/_zpty
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_zpty,v
retrieving revision 1.8
diff -u -r1.8 _zpty
--- Completion/Builtins/_zpty 2000/05/31 09:38:26 1.8
+++ Completion/Builtins/_zpty 2000/08/10 21:01:00
@@ -10,7 +10,7 @@
'(-r -w -L -e -b)-d[delete command]:*:name:->name' \
'(-r -L -e -b -d)-w[send string to command]:name:->name:*:strings to write' \
'(: -r -w -e -b -d)-L[list defined commands as calls]' \
- '(: -w -L -e -b -d)-r[read string from command]:name:->name:param: _parameters:pattern:' \
+ '(: -w -L -e -b -d)-r[read string from command]:name:->name:param: _vars:pattern:' \
'(-r -w -L -d):zpty command name:' \
'(-r -w -L -d):cmd: _command_names -e' \
'(-r -w -L -d)*::args:_precommand' && return 0
@@ -21,7 +21,7 @@
# - read \
# '-r[read string from command]' \
# ':name:->name' \
-# ':param: _parameters' \
+# ':param: _vars' \
# ':pattern:' \
# - write \
# '-w[send string to command]' \
Index: Completion/Commands/_bash_completions
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Commands/_bash_completions,v
retrieving revision 1.5
diff -u -r1.5 _bash_completions
--- Completion/Commands/_bash_completions 2000/08/03 13:35:43 1.5
+++ Completion/Commands/_bash_completions 2000/08/10 21:01:00
@@ -34,7 +34,7 @@
'!') _main_complete _command_names
;;
'$') _main_complete - parameters _wanted parameters expl 'exported parameters' \
- compadd -k 'parameters[(R)*export*]'
+ _parameters -g '*export*'
;;
'@') _main_complete _hosts
;;
Index: Completion/Core/_parameters
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_parameters,v
retrieving revision 1.2
diff -u -r1.2 _parameters
--- Completion/Core/_parameters 2000/06/22 08:42:36 1.2
+++ Completion/Core/_parameters 2000/08/10 21:01:00
@@ -3,6 +3,13 @@
# This should be used to complete parameter names if you need some of the
# extra options of compadd. It completes only non-local parameters.
-local expl
+# If you specify a -g option with a pattern, the pattern will be used to
+# restrict the type of parameters matched.
-_wanted parameters expl parameter compadd "$@" -k 'parameters[(R)^*local*]'
+local expl pattern
+
+pattern=(-g \*)
+zparseopts -D -K -E g:=pattern
+
+_wanted parameters expl parameter compadd "$@" \
+ -k "parameters[(R)${pattern[2]}~*local*]"
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.90
diff -u -r1.90 compsys.yo
--- Doc/Zsh/compsys.yo 2000/08/02 13:45:52 1.90
+++ Doc/Zsh/compsys.yo 2000/08/10 21:01:27
@@ -3470,8 +3470,12 @@
)
findex(_parameters)
item(tt(_parameters))(
-This should be used to complete parameter names. All arguments are
-passed unchanged to the tt(compadd) builtin.
+This should be used to complete parameter names. tt(_parameters) can
+take a tt(-g var(pattern)) option which specifies that only parameters
+whose type matches the var(pattern) should be completed. Strings of
+the same form as those returned by the tt(t) parameter expansion flag
+are used here when matching the type. All other arguments are passed
+unchanged to the tt(compadd) builtin.
)
findex(_path_files)
item(tt(_path_files))(
next reply other threads:[~2000-08-10 21:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-08-10 20:06 Oliver Kiddle [this message]
2000-08-11 7:44 Sven Wischnowsky
2000-08-11 12:16 Sven Wischnowsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=39930B31.C6C3876D@u.genie.co.uk \
--to=opk@u.genie.co.uk \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).