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

Re: completion grouping



Bart Schaefer wrote:

> On Nov 3,  2:41pm, Sven Wischnowsky wrote:
> } Subject: completion grouping
> }
> } Completion functions should call the function `_tags' with the
> } tag-names of the types of matches they generate. Then they call
> } `_tags' repeatedly without arguments. This will set the parameter
> } `tags' to a colon-separated list of tags then should now be
> } tried. E.g. if a functions generates jobs (`%...') and pids, it should 
> } do something like:
> } 
> }   local prios tags
> 
> Can I first suggest that we spell out "priorities"? It's not like it's
> going to be typed very often, is it?

The patch below makes the definition of `prios' in completion
functions superfluous by using some $funcstack magic. Should have
thought about this before...

With that, function using `_tags' only have to define the `tags'
parameter, which is probably ok, because they will have to use that
anyway.

> I'm also never sure what to expect from "sorted by priority."  In this
> case a smaller number is a higher priority, right?  But a negative
> number is treated as bigger than any positive one?  That's a bit weird.
> Or am I misunderstanding?

No. Only tags with a positive (or zero) priority are used and then
smaller numbers mean higher priorities (hm, maybe we should change
that if people think that that would feel more natural). Tags with a
negative priority are never reported back at all, i.e. if a user gives 
a negative priority he says that he doesn't want to complete that type 
of matches.

> ...
> 
> }   comptag option+='*dvi*=1'
> } 
> }     the `+=' means that the definition is prepended to the already
> }     existing definition
> 
> Hrm.  I would have expected += to *append* rather than *prepend* (my
> C++ is showing).

Looking at my mail again I noticed that I forgot to mention that `+='
prepends and `=+' appends. With that said this hopefully looks more
sensible ;-)

But I'd like think about changing this function anyway. I.e. I hope to 
find a somewhat easier interface. Currently this is still too near to
the way things are stored in `$comptags' and I think the usershouldn't
have to worry/know about the internal representation. On the
completion function side this is already true -- you just call `_tags' 
with the names and don't have to think about how `_tags' looks them
up.
Also, I'm thinking about allowing users to use this function to modify 
`override_tags', too. So that we don't have to build those pattern-
priority lists ourselves. I think that's another good reason to think
about a better interface.

I also forgot to mention another thing that may be interesting: I
already used the style-stuff for `describe_option' and friends. That
was easy to think about because they allowed definitions on a per-
command basis already. But ther may be other things we currently use
config keys for which may be interesting to turn into styles so that
we can define them differently for different commands (the `ps_*' keys 
come to mind, but that may be a bad example). If we do that, however,
we probably should think about some standard structure for defining
styles. Things like multiple styles (separated by commas?), styles
with values (`[style_a=foo,style_b=bar]' or something like that). If
this turns out to be useful, I would like change `_tags' to report
styles in a format that is easier to parse in the calling functions.


Anyway, here is the patch to remove those `prios' parameters. Makes me 
feel better.

Bye
 Sven

diff -u -r oldcompletion/Base/_arguments Completion/Base/_arguments
--- oldcompletion/Base/_arguments	Thu Nov  4 09:05:42 1999
+++ Completion/Base/_arguments	Thu Nov  4 10:15:19 1999
@@ -154,7 +154,7 @@
 if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
   local nm="$compstate[nmatches]" action noargs aret expl local
   local next direct odirect equal single match matched ws tmp1 tmp2
-  local prios tags opts
+  local tags opts
 
   if comparguments -D descr action; then
     if comparguments -O next direct odirect equal; then
diff -u -r oldcompletion/Base/_describe Completion/Base/_describe
--- oldcompletion/Base/_describe	Thu Nov  4 09:05:43 1999
+++ Completion/Base/_describe	Thu Nov  4 10:15:28 1999
@@ -3,7 +3,7 @@
 # This can be used to add options or values with descriptions as matches.
 
 local cmd func opt expl tmps tmpd tmpmd tmpms ret=1 showd _nm hide
-local prios tags type=value
+local tags type=value
 
 cmd="$words[1]"
 func="$funcstack[2]"
diff -u -r oldcompletion/Base/_values Completion/Base/_values
--- oldcompletion/Base/_values	Thu Nov  4 09:05:44 1999
+++ Completion/Base/_values	Thu Nov  4 10:15:36 1999
@@ -2,7 +2,7 @@
 
 if compvalues -i "$@"; then
 
-  local tags prios noargs args opts descr action expl sep
+  local tags noargs args opts descr action expl sep
 
   if ! compvalues -D descr action; then
 
diff -u -r oldcompletion/Builtins/_kill Completion/Builtins/_kill
--- oldcompletion/Builtins/_kill	Thu Nov  4 09:05:45 1999
+++ Completion/Builtins/_kill	Thu Nov  4 10:15:47 1999
@@ -6,7 +6,7 @@
   _description expl signal
   compadd "$expl[@]" $signals[1,-3]
 else
-  local prios tags ret=1
+  local tags ret=1
   
   _tags job process
   
diff -u -r oldcompletion/Builtins/_wait Completion/Builtins/_wait
--- oldcompletion/Builtins/_wait	Thu Nov  4 09:05:45 1999
+++ Completion/Builtins/_wait	Thu Nov  4 10:15:52 1999
@@ -1,6 +1,6 @@
 #compdef wait
 
-local prios tags list ret=1 expl
+local tags list ret=1 expl
   
 _tags job process
   
diff -u -r oldcompletion/Core/_files Completion/Core/_files
--- oldcompletion/Core/_files	Thu Nov  4 09:05:48 1999
+++ Completion/Core/_files	Thu Nov  4 10:16:10 1999
@@ -1,6 +1,6 @@
 #autoload
 
-local opts opt type=file prios tags
+local opts opt type=file tags
 
 opts=()
 while getopts "P:S:qr:R:W:F:J:V:X:f/g:M:" opt; do
diff -u -r oldcompletion/Core/_main_complete Completion/Core/_main_complete
--- oldcompletion/Core/_main_complete	Thu Nov  4 09:05:48 1999
+++ Completion/Core/_main_complete	Thu Nov  4 10:16:03 1999
@@ -17,8 +17,9 @@
 # state than the global one for which you are completing.
 
 
-local comp post ret=1 _compskip prios tags
+local comp post ret=1 _compskip tags _prio_num=1
 typeset -U _offered_tags _tried_tags _failed_tags _used_tags _unused_tags
+typeset -A _prio_names
 
 _offered_tags=()
 _tried_tags=()
diff -u -r oldcompletion/Core/_tags Completion/Core/_tags
--- oldcompletion/Core/_tags	Thu Nov  4 09:05:49 1999
+++ Completion/Core/_tags	Thu Nov  4 10:14:47 1999
@@ -63,17 +63,21 @@
     done
   done
 
-  prios=( "${(@)tags:#}" )
+  prio="_prio_arr$(( _prio_num++ ))"
+  _prio_names[$funcstack]="$prio"
+  eval "${prio}=( \"\${(@)tags:#}\" )"
 
   return 0
 fi
 
+local prios="$_prio_names[$funcstack]"
+
 _failed_tags=( "$_failed_tags[@]" "$_last_tags[@]" )
 
-(( $#prios )) || return 1
+(( ${(P)#prios} )) || return 1
 
-tags="${prios[1]}:"
-shift 1 prios
+tags="${${(@P)prios}[1]}:"
+shift 1 "$prios"
 
 _last_tags=( "${(@s.:.)${${tags#:}%:}}" )
 _tried_tags=( "$_tried_tags[@]" "$_last_tags[@]" )

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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