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

PATCH: menu style AND remarks



Ok, here are the enhancements for the menu style. This is now tested
like list-colors and so on, i.e. for the `default' tag and the tags
used when adding matches.

The value may be one of the `true' values to turn menu-completion on
if matches are added for that tag. It may be one of the `false' values 
to turn it of (if it was turned on elsewhere, e.g. by setting
MENU_COMPLETE. It may also set to `auto' to get auto-menu behavior
when matches for a certain tag are added. And finally the value may
also contain `select' (with an optional `=number', giving the minimum
number of matches to...) or `no-select' to turn on (or off)
menu-selection. The values for all used tags are combined, i.e. you
can give:

  compstyle '*:default' menu select
  compstyle '*:processes' menu yes

To normally don't use menu-completion, but always use menu-completion
for processes and there (as anywhere else) use selection instead of
normal menu-completion.

Also, the values for the normal tags override the value for the
default tag (I hope this is just how users would either expect or like 
it).

You'll also note that there is no C-code touched here.


So... that's it. Apart from bug-fixes (one will follow in a couple of
minutes) and cleanup, I don't plan to do any more until the next
official release (you'd never expected to hear that from me, would
you? ;-).

Where cleanup includes some things I plan to do soon and some I would
like to do just before release:

- cleanup the docs (soon)
- find out where and how the completion stuff could be made faster
  (moving things into computil)
- check the tag- and style-names used (now that I have some more
  experience I'm not that sure anymore that we should try to use only
  very few tags; I'll just wait until more people have some more
  experience and then try to remember to bring up this question again
  some day)
- the function renaming/moving-around I mentioned already
- remove compconf (it is terribly out-of-date already anyway)
- try to decide if the new completion system should not use $fignore
  anymore (now that we have the ignored-suffixes style)
- try to find good defaults for styles and _sort_tags (here I
  definitely need input from you)
- and then there is still the question if we should use `category' (as 
  suggested by Bart) instead of `tag' -- I'm a bit reluctant to change 
  all the functions that use _tags and the docs only to find that
  someone found a better suggestion

This also means that I don't plan to try to generalise the package
stuff myself. I'm willing to give anyone who wants to do that any help 
I can, though (e.g. by moving some stuff from computil into a general
utility module -- some things in it, like the style stuff, is really
completely independent of the completion system).

Bye
 Sven

diff -ru ../z.old/Completion/Core/_main_complete Completion/Core/_main_complete
--- ../z.old/Completion/Core/_main_complete	Wed Dec  8 09:36:59 1999
+++ Completion/Core/_main_complete	Wed Dec  8 14:10:41 1999
@@ -17,11 +17,14 @@
 # state than the global one for which you are completing.
 
 
-local comp post ret=1 _compskip _prio_num=1 _cur_context format
-local context state line opt_args val_args curcontext="$curcontext"
-local _saved_exact="$compstate[exact]" \
+local comp post ret=1 _compskip _prio_num=1 _cur_context format \
+      context state line opt_args val_args curcontext="$curcontext" \
+      _last_nmatches=-1 _last_menu_style _def_menu_style _menu_style sel \
+      _saved_exact="$compstate[exact]" \
       _saved_lastprompt="$compstate[last_prompt]" \
-      _saved_list="$compstate[list]"
+      _saved_list="$compstate[list]" \
+      _saved_insert="$compstate[insert]"
+
 typeset -U _offered_tags _tried_tags _failed_tags _used_tags _unused_tags
 
 _offered_tags=()
@@ -45,6 +48,8 @@
 # Initial setup.
 
 _setup default
+_def_menu_style=( "$_last_menu_style[@]" )
+_last_menu_style=()
 
 # Get the names of the completers to use in the positional parameters.
 
@@ -77,6 +82,59 @@
 comppostfuncs=()
 
 _lastdescr=( "\`${(@)^_lastdescr:#}'" )
+
+[[ _last_nmatches -ge 0 && _last_nmatches -ne compstate[nmatches] ]] &&
+    _menu_style=( "$_last_menu_style[@]" "$_menu_style[@]" )
+
+if [[ "$compstate[insert]" = "$_saved_insert" ]]; then
+  if [[ -n "$_menu_style[(r)(yes|true|1|on)]" ||
+        ( -n "$_menu_style[(r)auto*]" &&
+          "$compstate[insert]" = automenu ) ]]; then
+    compstate[insert]=menu
+  elif [[ -n "$_menu_style[(r)auto*]" &&
+          "$compstate[insert]" != automenu ]]; then
+    compstate[insert]=automenu-unambiguous
+  elif [[ -n "$_menu_style[(r)(no|false|0|off)]" ]]; then
+    compstate[insert]=unambiguous
+  elif [[ -n "$_def_menu_style[(r)(yes|true|1|on)]" ||
+        ( -n "$_def_menu_style[(r)auto*]" &&
+          "$compstate[insert]" = automenu ) ]]; then
+    compstate[insert]=menu
+  elif [[ -n "$_def_menu_style[(r)auto*]" &&
+          "$compstate[insert]" != automenu ]]; then
+    compstate[insert]=automenu-unambiguous
+  elif [[ -n "$_def_menu_style[(r)(no|false|0|off)]" ]]; then
+    compstate[insert]=unambiguous
+  fi
+fi
+
+_menu_style=( "$_menu_style[@]" "$_def_menu_style[@]" )
+
+if [[ "$compstate[insert]" = *menu ]]; then
+  if [[ -n "$_menu_style[(r)no-select*]" ]]; then
+    unset SELECTMIN
+  else
+    sel=( "${(@M)_menu_style:#select*}" )
+
+    if (( $# )); then
+      local min=9999999 i num
+
+      for i in "$sel[@]"; do
+        if [[ "$i" = *\=* ]]; then
+	  num="${i#*\=}"
+	  [[ num -lt 0 ]] && num=0
+	else
+	  num=0
+	fi
+	[[ num -lt min ]] && min="$num"
+
+	(( min )) || break
+      done
+
+      SELECTMIN="$min"
+    fi
+  fi
+fi
 
 _style -s warnings format format
 
diff -ru ../z.old/Completion/Core/_setup Completion/Core/_setup
--- ../z.old/Completion/Core/_setup	Wed Dec  8 09:37:01 1999
+++ Completion/Core/_setup	Wed Dec  8 10:35:49 1999
@@ -1,6 +1,6 @@
 #autoload
 
-local val
+local val nm="$compstate[nmatches]"
 
 if _style -a "$1" list-colors val; then
   if [[ "$1" = default ]]; then
@@ -48,4 +48,14 @@
   fi
 else
   compstate[exact]="$_saved_exact"
+fi
+
+[[ _last_nmatches -ge 0 && _last_nmatches -ne nm ]] &&
+    _menu_style=( "$_last_menu_style[@]" "$_menu_style[@]" )
+
+if _style -a "$1" menu val; then
+  _last_nmatches="$nm"
+  _last_menu_style=( "$val[@]" )
+else
+  _last_nmatches=-1
 fi
diff -ru ../z.old/Doc/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- ../z.old/Doc/Zsh/compsys.yo	Wed Dec  8 10:09:23 1999
+++ Doc/Zsh/compsys.yo	Wed Dec  8 14:31:17 1999
@@ -1075,7 +1075,31 @@
 numeric argument is given, correcting completion will not be performed.
 )
 item(tt(menu))(
-This is used by the tt(_oldlist) completer. It controls how menu
+This style is tested for the tt(default) tag and the tags used when
+adding matches. The value should be one of the `true' values (tt(yes), 
+tt(true), tt(1), or tt(on)) if menu completion should be started when
+matches for the given tag (or always in case of the tt(default) tag)
+are generated. If none of these values is defined for any of the tags
+used, but for at least one of these tags the value is the string
+tt(auto), this says that the same behavior as for the tt(AUTO_MENU)
+options should be used. Finally, if menu-completion is started by some 
+other means (e.g. by setting the tt(MENU_COMPLETE) option) and the
+value for one of the tags used is `false' (i.e. tt(no), tt(false),
+tt(0), or tt(off)), then menu-completion will em(not) be started for
+this completions. Note that the values defined for normal tags
+override the value set for the tt(default) tag.
+
+Either instead of or in addition to one of the values above, the value
+for this style may also contain the string tt(select), optionally
+followed by an equal sign and a number. In this case menu-selection
+(as defined by the tt(computil) module) will be started. Without the
+optional number, it will be started unconditionally and with a number
+it will be started only if at least that many matches are generated
+(if the values for more than one tag defines such a number, the
+smallest one is taken). Starting menu-selection can explicitly be
+turned off by defining a value containing the string tt(no-select).
+
+This is also used by the tt(_oldlist) completer. Here it controls how menu
 completion behaves when a completion has already been inserted and the
 user types a standard completion key type such as tt(TAB). The default
 behaviour of tt(_oldlist) is that menu completion always continues
diff -ru ../z.old/Doc/Zsh/mod_complist.yo Doc/Zsh/mod_complist.yo
--- ../z.old/Doc/Zsh/mod_complist.yo	Wed Dec  8 10:09:25 1999
+++ Doc/Zsh/mod_complist.yo	Wed Dec  8 13:50:19 1999
@@ -145,6 +145,11 @@
 tt(SELECTMIN) is set, but is 0, 1 or empty, menu selection will always be
 started during an ambiguous menu completion.
 
+When using the shell function based completion system, the
+tt(SELECTMIN) parameter should not be used (like the tt(ZLS_COLORS)
+and tt(ZLS_COLOURS) parameters described above). Instead, the tt(menu) 
+style should be used.
+
 After menu-selection is started, the matches will be listed. The
 matches to insert into the command line can be selected from this
 list. In the list one match is highlighted using the value for tt(ma)
@@ -154,17 +159,17 @@
 neither tt(ZLS_COLORS) nor tt(ZLS_COLOURS) is set, the same terminal
 control sequence as for the `tt(%S)' escape in prompts is used.
 
-Normally, the completion code may decide to not show of the matches in 
-the list. These hidden matches are either matches for which the
+The completion code sometimes decides not to show all of the matches
+in the list. These hidden matches are either matches for which the
 completion function which added them explicitly requested that they
-don't appear in the list (using the tt(-n) option of the tt(compadd)
-builtin command) or they are matches which show the the same string in 
-the list (because they differ only in things like prefixes or suffixes 
-that are never listed). In the list used for menu-selection, however,
-even these matches will be shown so that it is possible to select
-them. To be able to highlight such matches the tt(hi) and tt(mu)
-capabilities in the tt(ZLS_COLORS) and tt(ZLS_COLOURS) parameters are
-supported for hidden matches of the first and second kind, respectively.
+not appear in the list (using the tt(-n) option of the tt(compadd)
+builtin command) or they are matches which duplicate a string already
+in the list (because they differ only in things like prefixes or
+suffixes that are not displayed). In the list used for menu-selection,
+however, even these matches are shown so that it is possible to select
+them. To highlight such matches the tt(hi) and tt(mu) capabilities in
+the tt(ZLS_COLORS) and tt(ZLS_COLOURS) parameters are supported for
+hidden matches of the first and second kind, respectively.
 
 Selecting matches is done by moving the mark around using the zle movement
 functions. The zle functions tt(send-break) and tt(accept-line) can be used

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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