zsh-workers
 help / color / mirror / code / Atom feed
* Re: incremental matchers in matcher-list
@ 2001-02-23  9:43 Sven Wischnowsky
  2001-02-27 16:06 ` PATCH: " Andrej Borsenkow
  0 siblings, 1 reply; 2+ messages in thread
From: Sven Wischnowsky @ 2001-02-23  9:43 UTC (permalink / raw)
  To: zsh-workers


Andrej Borsenkow wrote:

> Not sure just how useful it is.
> 
> It allows you to add matchers to previous list instead of replacing them to
> avoid repetitions. I expect most common usage to try more general patterns in
> turn, so it allows you to do
> 
> zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' '+r:|[._-]=* r:|=*'
> '+r:|[.-]=** r:|=**'
> 
> without repeating ealrlier patterns everytime.
> 
> If it accepted, doc and compinstall will follow.

Would be ok for me (a bit like Bart's zstyle+).

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

* PATCH: RE: incremental matchers in matcher-list
  2001-02-23  9:43 incremental matchers in matcher-list Sven Wischnowsky
@ 2001-02-27 16:06 ` Andrej Borsenkow
  0 siblings, 0 replies; 2+ messages in thread
From: Andrej Borsenkow @ 2001-02-27 16:06 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 515 bytes --]

> >
> > It allows you to add matchers to previous list instead of
> replacing them to
> > avoid repetitions.
> >
> > If it accepted, doc and compinstall will follow.
>
> Would be ok for me (a bit like Bart's zstyle+).
>

Well, here is a patch with two problems. The matcher-list configuration screen
does not fit on standard 80x24 anymore; I do not see any text to remove. And
doc addition just mentions the possibility, without explaining much ... Peter,
could you look at compinstall?

-andrej

attached as usual

[-- Attachment #2: matcher-style.diff --]
[-- Type: application/octet-stream, Size: 9115 bytes --]

Index: Completion/Core/_ignored
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_ignored,v
retrieving revision 1.4
diff -u -r1.4 _ignored
--- Completion/Core/_ignored	2000/06/26 09:36:12	1.4
+++ Completion/Core/_ignored	2001/02/27 16:01:56
@@ -10,7 +10,8 @@
   comp=( "${(@)_completers[1,_completer_num-1][(R)_ignored(|:*),-1]}" )
 
 local _comp_no_ignore=yes tmp expl \
-      _completer _completer_num _matcher _matchers _matcher_num
+      _completer _completer_num \
+      _matcher _c_matcher _matchers _matcher_num
 
 _completer_num=1
 
@@ -30,7 +31,13 @@
       _matchers=( '' )
 
   _matcher_num=1
-  for _matcher in "$_matchers[@]"; do
+  _matcher=''
+  for _c_matcher in "$_matchers[@]"; do
+    if [[ "$_c_matcher" == +* ]]; then
+      _matcher="$_matcher $_c_matcher[2,-1]"
+    else
+      _matcher="$_c_matcher"
+    fi
     if [[ "$tmp" != _ignored ]] && "$tmp"; then
       if zstyle -s ":completion:${curcontext}:" single-ignored tmp &&
          [[ $compstate[old_list] != shown &&
Index: Completion/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_main_complete,v
retrieving revision 1.43
diff -u -r1.43 _main_complete
--- Completion/Core/_main_complete	2000/10/19 08:58:17	1.43
+++ Completion/Core/_main_complete	2001/02/27 16:01:56
@@ -25,8 +25,8 @@
 
 local func funcs ret=1 tmp _compskip format nm call match min max i num\
       _completers _completer _completer_num curtag _comp_force_list \
-      _matchers _matcher _matcher_num _comp_tags _comp_mesg mesg str \
-      context state line opt_args val_args curcontext="$curcontext" \
+      _matchers _matcher _c_matcher _matcher_num _comp_tags _comp_mesg  \
+      mesg str 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]}" \
@@ -143,7 +143,14 @@
       _matchers=( '' )
 
   _matcher_num=1
-  for _matcher in "$_matchers[@]"; do
+  _matcher=''
+  for _c_matcher in "$_matchers[@]"; do
+    if [[ "$_c_matcher" == +* ]]; then
+      _matcher="$_matcher $_c_matcher[2,-1]"
+    else
+      _matcher="$_c_matcher"
+    fi
+
     _comp_mesg=
     if [[ -n "$call" ]]; then
       if "${(@)argv[3,-1]}"; then
Index: Completion/Core/_prefix
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_prefix,v
retrieving revision 1.3
diff -u -r1.3 _prefix
--- Completion/Core/_prefix	2000/05/08 08:16:32	1.3
+++ Completion/Core/_prefix	2001/02/27 16:01:56
@@ -5,7 +5,8 @@
 [[ _matcher_num -gt 1 || -z "$SUFFIX" ]] && return 1
 
 local comp curcontext="$curcontext" tmp \
-      _completer _completer_num _matcher _matchers _matcher_num
+      _completer _completer_num \
+      _matcher _c_matcher _matchers _matcher_num
 
 zstyle -a ":completion:${curcontext}:" completer comp ||
   comp=( "${(@)_completers[1,_completer_num-1][(R)_prefix(|:*),-1]}" )
@@ -35,7 +36,14 @@
       _matchers=( '' )
 
   _matcher_num=1
-  for _matcher in "$_matchers[@]"; do
+  _matcher=''
+  for _c_matcher in "$_matchers[@]"; do
+    if [[ "$_c_matcher" == +* ]]; then
+      _matcher="$_matcher $_c_matcher[2,-1]"
+    else
+      _matcher="$_c_matcher"
+    fi
+
     [[ "$tmp" != _prefix ]] && "$tmp" && return 0
     (( _matcher_num++ ))
   done
Index: Completion/Core/compinstall
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/compinstall,v
retrieving revision 1.18
diff -u -r1.18 compinstall
--- Completion/Core/compinstall	2000/07/12 11:04:07	1.18
+++ Completion/Core/compinstall	2001/02/27 16:01:57
@@ -856,6 +856,10 @@
   else
     # toggle off
     eval "${1}[$2]=' '"
+    if [[ $c_list[$2] == ' ' && $C_list[$2] == ' ' && \
+	  $p_list[$2] == ' ' && $s_list[$2] == ' ' ]]; then
+      a_or_r[$2]=' '
+    fi
     return 1
   fi
 }
@@ -867,7 +871,7 @@
   # More specific use of matchers is usually covered by completion functions.
 
   local mlist m_ci m_pw m_sub c_list C_list p_list s_list pw_seps key key2 elt
-  local pw_dstar
+  local pw_dstar a_or_r i
   integer eltcnt lastnz
 
   __ci_get_this_style matcher-list mlist
@@ -876,13 +880,14 @@
   eval "mlist=($mlist)"
   # ?_list say whether the four possible matchers are set for passes 1,
   # 2, 3, 4, in an easy-to-read manner, i.e. the Nth part of the string
-  # is either N (on) or space (off).
+  # is one of N (on) or space (off).
+  a_or_r="    "                 # replace by default
   n_list="    "			# null completion, i.e. standard
   c_list="    "			# case match one way
   C_list="    "			# case match both ways
   p_list="    "			# partial word completion
   s_list="    "			# substring completion
-  # $pws_seps gives the separators used for partial-word completion
+  # $pw_seps gives the separators used for partial-word completion
   # by element of the matcher list; these can be edited separately.
   pw_seps=('._-' '._-' '._-' '._-')
   pw_dstar=('' '' '' '')
@@ -890,6 +895,7 @@
   # See what's in the matcher initially.  If these have been edited,
   # we're in trouble, but that's pretty much true of everything.
   for (( eltcnt = 1; eltcnt <= $#mlist; eltcnt++ )); do
+    [[ $mlist[eltcnt] == "+"* ]] && a_or_r[$eltcnt]='+'
     [[ -z $mlist[$eltcnt] ]] && n_list[$eltcnt]=$eltcnt
     [[ $mlist[$eltcnt] = *"m:{a-z}={A-Z}"* ]] && c_list[$eltcnt]=$eltcnt
     [[ $mlist[$eltcnt] = *"m:{a-zA-Z}={A-Za-z}"* ]] && C_list[$eltcnt]=$eltcnt
@@ -912,14 +918,16 @@
 
 \`Matchers' allow the completion code to play extra tricks when comparing
 the string on the command line with a possible match, as listed below.
-A list of different matchers can be given; each is tried until at least
-one possible completion is found.  The numbers given below show what is
-included in each element of the list; everything for 1 is tried at the same
-time, and if necessary everything for 2, etc.  If no matcher is set
-ordinary completion will be done at that point.  Elements from 1 to 4 can
-be set; empty trailing elements will be removed, and if nothing is set, the
-style will not be set.
+A list of different matchers can be given. The numbers given below show what is
+included in each element of the list; by default everything for 1 is tried
+at the same time, then if necessary everything for 2, etc. until at least
+one possible completion is found. You can change it so that every element
+in the list is added to preceding one(s) instead; this indicated by '+' over
+the element. If no matcher is set ordinary completion will be done at that
+point. Elements from 1 to 4 can be set; empty trailing elements will be
+removed, and if nothing is set, the style will not be set.
 
+   ($a_or_r)
 n. ($n_list)\
  No matchers; you may want to try this as the first choice.
 c. ($c_list)\
@@ -933,6 +941,7 @@
  Substring completion:  complete on substrings, not just initial
           strings.  Warning: it is recommended this not be used for element 1.
 
+t.        Toggle replace/augment for matcher group
 q.        Return without saving.
 0.        Done setting matchers.
 "
@@ -981,6 +990,18 @@
 	      read -q key && pw_dstar[$key2]='*'
 	    fi
 	    ;;
+      [tT])
+	    read -k key2'?Toggle augment/replace for elements number (1234)? '
+	    if [[ $key2 == [1234] ]]; then
+	      if [[ $a_or_r[$key2] == ' ' ]]; then
+	        a_or_r[$key2]='+'
+	      else
+	        a_or_r[$key2]=' '
+	      fi
+	    else
+	      print "Only 1, 2, 3 and 4 are handled."
+	    fi
+	    ;;
       [sS]) __ci_toggle_matcher s_list $key2
 	    ;;
       [qQ]) return 1
@@ -1010,6 +1031,7 @@
 	elt="${elt:+$elt }l:|=* r:|=*"
       fi
     fi
+    [[ $a_or_r[$eltcnt] != ' ' ]] && elt="+$elt"
     [[ -n $elt || $n_list[$eltcnt] != ' ' ]] && lastnz=$eltcnt
     mlist[$eltcnt]=$elt
   done
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.105
diff -u -r1.105 compsys.yo
--- Doc/Zsh/compsys.yo	2001/01/15 09:11:33	1.105
+++ Doc/Zsh/compsys.yo	2001/02/27 16:01:59
@@ -1538,6 +1538,13 @@
 
 example(zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}')
 
+By default every specification replaces previous ones. If specification
+is prefixed with tt(+), it is added to the existing list. This allows
+testing more general patterns without repeating the whole list every
+time, as in:
+
+example(zstyle ':completion:*' matcher-list '' '+m{a-Z}={A-Z}' '+m{A-Z}={a-z}')
+
 The style allows even finer control by specifying a particular completer,
 without the leading underscore, in the third field of the completion
 context.  For example, if one uses the completers tt(_complete) and

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-02-27 16:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-23  9:43 incremental matchers in matcher-list Sven Wischnowsky
2001-02-27 16:06 ` PATCH: " Andrej Borsenkow

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).