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

Re: PATCH: completion



Tanaka Akira wrote:

> But many commands accept both short and long options, there should be
> a completer that handle both.
> 
> I feel `_arguments' is very good as basis of that.  Is it easy to
> extend `_arguments' to handle short options?

Yes, I was thinking about the same. We would still have to tell
`_arguments' about this with some option, because it can currently
handle multi-character options and in the mode that would replace
`_complete_opts' it would have to look at those as option lists
sharing one `-'.

> # If it is available, I'll throw `complete_opts' away.

I think I'll have a look at this...

> > Ok. I don't know if you like this grouping/description stuff, all
> > comments are welcome.
> 
> Is there a way to disable options completion until a user insert `-'
> explicitly?  I like the behaviour since some commands have many
> options and they may bury completions for non-option arguments.

We can easily add this. The patch below makes `_arguments' use the
configuration key `option_prefix'. It can be set to a string
containing `short', `long', or `all' to get short/long option names
only if a `-' or `--' is given on the line (`all' is the same as
`shortlong').

(A question is if we should make other functions use this key,
too. Maybe even remove the `-t' option from `_long_options' and just
let it use this key... Opinions?)

> And, I found some problems.
> 
> is27e1u11% pnmpad -l<TAB>
> 
> ->
> 
> is27e1u11% pnmpad -l- 
> 
> `+' and `-' should not be completed, I think.

Definitely, yes. Maybe sometime I'll learn that extendedglob is not
always available in the completion functions.

> is27e1u11% pnmscale -height <TAB>
> 
> ->
> 
> is27e1u11% pnmscale -height  
> 
> In this case, " " is completed. Is this intended behaviour?

No, it was a result of a last-minute change in `_message'.

> is27e1u11% compconfig[message_format]='%d'
> is27e1u11% compconfig[description_format]='%d'
> is27e1u11% pnmcomp <TAB>
> 
> ->
> 
> is27e1u11% pnmcomp      
> option
> overlay file
> -alpha          Config/         Misc/           config.cache    configure.in 
> -invert         Doc/            README          config.guess*   install-sh*
> -xoff           Etc/            Src/            config.h        mkinstalldirs*
> -yoff           Functions/      StartupFiles/   config.h.in     stamp-h 
> CVS/            INSTALL         Util/           config.log      stamp-h.in 
> ChangeLog       META-FAQ        acconfig.h      config.status*  
> ChangeLog.3.0   Makefile        aclocal.m4      config.sub*     
> Completion/     Makefile.in     aczsh.m4        configure*      
> 
> Although I don't know completion group behaviour well, I feel this
> very strange because options and files are mixed.

Just set `compconf group_matches=yes'. Btw, I forgot to ask if maybe
we should give any of these new config keys default values? This
`group_matches' key may be a good candidate (or we could rename it to
`join_matches' or something like that and reverse it's meaning).

> Also, I found some typos.

Thanks a lot! (It was a rather tedious task, so I expected typos...)

Bye
 Sven

diff -u od/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- od/Zsh/compsys.yo	Fri Aug 20 09:04:03 1999
+++ Doc/Zsh/compsys.yo	Fri Aug 20 09:24:45 1999
@@ -215,7 +215,7 @@
 The fourth form is like the third, but the var(function) will be
 called only if no function for the command itself was found or if one
 was found and it set the tt(_compskip) parameter to a value em(not)
-containing the sub-string `tt(patterns)'.
+containing the substring `tt(patterns)'.
 
 The fifth form defines a widget with the same name as the var(function)
 which will be called for each of the var(key-sequences); this is like the
@@ -943,6 +943,14 @@
 tt(_long_options) function where appropriate by giving it the string
 `tt(--)' as an argument. All arguments after this will be given
 unchanged to the tt(_long_options) function.
+
+This function also uses one configuration key: tt(option_prefix). If
+this is set to a string containing `tt(short)' or `tt(all)' as a
+substring, option names beginning with a single minus sign are added
+as possible matches only if the word on the line begins with a minus
+sign. If the value contains one of the substrings `tt(long)' or
+`tt(all)', option names beginning with two minus signs will be
+added as matches only if the two minus signs are given on the line.
 
 Example:
 
diff -u -r oc/Base/_arguments Completion/Base/_arguments
--- oc/Base/_arguments	Thu Aug 19 16:00:21 1999
+++ Completion/Base/_arguments	Fri Aug 20 09:31:21 1999
@@ -3,7 +3,9 @@
 # Complete the arguments of the current command according to the
 # descriptions given as arguments to this function.
 
-local long args rest ws cur nth def nm expl descr action opt arg tmp
+setopt localoptions extendedglob
+
+local long args rest ws cur nth def nm expl descr action opt arg tmp ret=1
 
 # Associative arrays used to collect information about the options.
 
@@ -336,10 +338,17 @@
       # We aren't in an argument directly after a option name, so
       # all option names are possible matches.
 
-      _description expl option
-      compadd "$expl[@]" - "${(@k)opts}" "${(@k)mopts}" \
-                           "${(@k)dopts}" "${(@k)dmopts}" \
-			   "${(@k)odopts}" "${(@k)odmopts}"
+      if [[ "$compconfig[option_prefix]" != *(short|all)* ||
+            "$PREFIX" = -* ]]; then
+        _description expl option
+        compadd "$expl[@]" - "${(@k)opts}" "${(@k)mopts}" \
+                             "${(@k)dopts}" "${(@k)dmopts}" \
+			     "${(@k)odopts}" "${(@k)odmopts}" && ret=0
+      fi
+      [[ $#long -ne 0 &&
+         ( "$compconfig[option_prefix]" != *(long|all)* ||
+           "$PREFIX" = --* ) ]] && \
+          _long_options && ret=0
     fi
   fi
 
@@ -362,7 +371,7 @@
 
       # An empty action means that we should just display a message.
       _message "$descr"
-      return 1
+      return ret
     elif [[ "$action[1]" = \( ]]; then
 
       # Anything inside `(...)' is added directly.
diff -u -r oc/Core/_message Completion/Core/_message
--- oc/Core/_message	Fri Aug 20 09:04:33 1999
+++ Completion/Core/_message	Fri Aug 20 09:32:21 1999
@@ -14,6 +14,4 @@
     compadd -X "${format//\\%d/$1}" -n ''
   fi
   compstate[force_list]=yes
-else
-  compadd -n ''
 fi

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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