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

PATCH: compstate



If you had asked me last week, I would have said that I don't think
that we would add another key to compstate any time soon.

But then I tried to add a %-sequence to the i-c-w-prompt that shows
the number of matches -- and got very irritating numbers because
$compstate[nmatches] counts all matches, including those in the
alternate set (the ones `ignored' with the `fignore' array).

So I added the key `normal_nmatches' which counts only the matches in
the normal set (there may be a better prefix than `normal_'). And I
think that it's important to give access to this information.

The patch also changes i-c-w: the sequence `%n' gives the number of
matches and `%a' is replaced with ` -alt-' if the only matching
strings are in the alternate set. These are not used by the default
prompt.


Bye
 Sven

P.S.: The stuff in comp.h is mainly re-indentation of some CPN_*s.

diff -u os/Zle/comp.h Src/Zle/comp.h
--- os/Zle/comp.h	Wed Jul 14 08:34:27 1999
+++ Src/Zle/comp.h	Wed Jul 14 10:01:02 1999
@@ -349,25 +349,25 @@
 
 
 #define CPN_NMATCHES   0
-#define CP_NMATCHES    (1 <<  CPN_NMATCHES)
+#define CP_NMATCHES    (1 << CPN_NMATCHES)
 #define CPN_MATCHER    1
-#define CP_MATCHER     (1 <<  CPN_MATCHER)
+#define CP_MATCHER     (1 << CPN_MATCHER)
 #define CPN_MATCHERSTR 2
-#define CP_MATCHERSTR  (1 <<  CPN_MATCHERSTR)
+#define CP_MATCHERSTR  (1 << CPN_MATCHERSTR)
 #define CPN_MATCHERTOT 3
-#define CP_MATCHERTOT  (1 <<  CPN_MATCHERTOT)
+#define CP_MATCHERTOT  (1 << CPN_MATCHERTOT)
 #define CPN_CONTEXT    4
-#define CP_CONTEXT     (1 <<  CPN_CONTEXT)
+#define CP_CONTEXT     (1 << CPN_CONTEXT)
 #define CPN_PARAMETER  5
-#define CP_PARAMETER   (1 <<  CPN_PARAMETER)
+#define CP_PARAMETER   (1 << CPN_PARAMETER)
 #define CPN_REDIRECT   6
-#define CP_REDIRECT    (1 <<  CPN_REDIRECT)
+#define CP_REDIRECT    (1 << CPN_REDIRECT)
 #define CPN_QUOTE      7
-#define CP_QUOTE       (1 <<  CPN_QUOTE)
+#define CP_QUOTE       (1 << CPN_QUOTE)
 #define CPN_QUOTING    8
-#define CP_QUOTING     (1 <<  CPN_QUOTING)
+#define CP_QUOTING     (1 << CPN_QUOTING)
 #define CPN_RESTORE    9
-#define CP_RESTORE     (1 <<  CPN_RESTORE)
+#define CP_RESTORE     (1 << CPN_RESTORE)
 #define CPN_LIST       10
 #define CP_LIST        (1 << CPN_LIST)
 #define CPN_FORCELIST  11
@@ -398,6 +398,8 @@
 #define CP_OLDINS      (1 << CPN_OLDINS)
 #define CPN_VARED      24
 #define CP_VARED       (1 << CPN_VARED)
+#define CPN_NNMATCHES  25
+#define CP_NNMATCHES   (1 << CPN_NNMATCHES)
 
-#define CP_KEYPARAMS   25
+#define CP_KEYPARAMS   26
 #define CP_ALLKEYS     ((unsigned int) 0xffffff)
diff -u os/Zle/comp1.c Src/Zle/comp1.c
--- os/Zle/comp1.c	Wed Jul 14 09:21:05 1999
+++ Src/Zle/comp1.c	Wed Jul 14 10:01:25 1999
@@ -105,6 +105,7 @@
 /**/
 zlong compcurrent,
       compnmatches,
+      compnnmatches,
       compmatcher,
       compmatchertot,
       complistmax;
diff -u os/Zle/compctl.c Src/Zle/compctl.c
--- os/Zle/compctl.c	Wed Jul 14 09:21:06 1999
+++ Src/Zle/compctl.c	Wed Jul 14 10:01:49 1999
@@ -2210,6 +2210,7 @@
     { "old_list", PM_SCALAR, VAL(compoldlist), NULL, NULL },
     { "old_insert", PM_SCALAR, VAL(compoldins), NULL, NULL },
     { "vared", PM_SCALAR, VAL(compvared), NULL, NULL },
+    { "normal_nmatches", PM_INTEGER, VAL(compnnmatches), NULL, NULL },
     { NULL, 0, NULL, NULL, NULL }
 };
 
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Wed Jul 14 09:57:16 1999
+++ Src/Zle/zle_tricky.c	Wed Jul 14 10:04:16 1999
@@ -209,9 +209,9 @@
 
 static Cmgroup mgroup;
 
-/* A match counter. */
+/* Match counters: all matches, normal matches (not alternate set). */
 
-static int mnum;
+static int mnum, nmnum;
 
 /* The match counter when unambig_data() was called. */
 
@@ -3551,6 +3551,8 @@
     ai->line = join_clines(ai->line, line);
 
     mnum++;
+    if (!alt)
+	nmnum++;
     ai->count++;
     
     /* Allocate and fill the match structure. */
@@ -3900,6 +3902,7 @@
 		}
 	    }
 	    compnmatches = mnum;
+	    compnnmatches = nmnum;
 	    if (dat->exp)
 		addexpl();
 	    if (dat->apar)
@@ -4623,6 +4626,7 @@
 	compqisuffix = ztrdup(qisuf ? qisuf : "");
 	compcurrent = (usea ? (clwpos + 1 - aadd) : 0);
 	compnmatches = mnum;
+	compnnmatches = nmnum;
 
 	zsfree(complist);
 	switch (uselist) {
@@ -4837,7 +4841,7 @@
 	if (!validlist)
 	    lastambig = 0;
 	amatches = NULL;
-	mnum = 0;
+	mnum = nmnum = 0;
 	unambig_mnum = -1;
 	isuf = NULL;
 	insmnum = insgnum = 1;
@@ -5254,6 +5258,7 @@
 	    inbackt = oib;
 	    autoq = oaq;
 	    compnmatches = mnum;
+	    compnnmatches = nmnum;
 	} LASTALLOC;
     } SWITCHBACKHEAPS;
 
@@ -5329,6 +5334,7 @@
 	    autoq = oaq;
 	    offs = ooffs;
 	    compnmatches = mnum;
+	    compnnmatches = nmnum;
 	    zsfree(cmdstr);
 	    freearray(clwords);
 	    cmdstr = os;
diff -u od/Zsh/compwid.yo Doc/Zsh/compwid.yo
--- od/Zsh/compwid.yo	Tue Jul 13 16:40:23 1999
+++ Doc/Zsh/compwid.yo	Wed Jul 14 10:30:18 1999
@@ -175,6 +175,12 @@
 item(tt(nmatches))(
 The number of matches generated and accepted by the completion code so far.
 )
+item(tt(normal_nmatches))(
+Like tt(nmatches), but counts only matches in the normal set. I.e. file
+names with one of the suffixes from the tt(fignore) array and matches
+put into the alternate set using the tt(-a) option of the tt(compadd)
+builtin command (see below) are not counted.
+)
 item(tt(matcher))(
 When completion is performed with a global match specification as defined
 by
diff -u of/Zle/incremental-complete-word Functions/Zle/incremental-complete-word
--- of/Zle/incremental-complete-word	Wed Jul 14 10:05:00 1999
+++ Functions/Zle/incremental-complete-word	Wed Jul 14 10:25:56 1999
@@ -20,9 +20,13 @@
 #    with `-no match-', `-no prefix-', or an empty string if there is
 #    no completion matching the word on the line, if the matches have 
 #    no common prefix different from the word on the line or if there is
-#    such a common prefix, respectively. Finally, the sequence `%c' is
-#    replaced by the name of the completer function that generated the
-#    matches (without the leading underscore).
+#    such a common prefix, respectively. The sequence `%c' is replaced
+#    by the name of the completer function that generated the matches
+#    (without the leading underscore). Finally, `%n' is replaced by the
+#    number of matches generated and `%a' is replaced by an empty string
+#    if the matches are in the normal set (i.e. the one without file names
+#    with one of the suffixes from `fignore') and with ` -alt-' if the
+#    matches are in the alternate set.
 #
 #  incremental_stop
 #    Pattern matching keys which will cause icompletion to stop and the
@@ -43,7 +47,8 @@
 emulate -L zsh
 unsetopt autolist menucomplete automenu # doesn't work well
 
-local key lbuf="$LBUFFER" rbuf="$RBUFFER" pmpt word lastl lastr wid twid
+local key lbuf="$LBUFFER" rbuf="$RBUFFER" pmpt word
+local lastl lastr wid twid num alt
 
 [[ -n "$compconfig[incremental_completer]" ]] &&
     set ${(s.:.)compconfig[incremental_completer]}
@@ -68,7 +73,12 @@
   word="${_lastcomp[unambiguous]}"
   state=''
 fi
-zle -R "${${${pmpt//\\%u/$word}//\\%s/$state}//\\%c/${_lastcomp[completer][2,-1]}}"
+num=$_lastcomp[normal_nmatches]
+if (( ! num )); then
+  num="${_lastcomp[nmatches]}"
+  alt=' -alt-'
+fi
+zle -R "${${${${${pmpt//\\%u/$word}//\\%s/$state}//\\%c/${_lastcomp[completer][2,-1]}}//\\%n/$num}//\\%a/$alt}"
 read -k key
 
 while [[ '#key' -ne '#\\r' && '#key' -ne '#\\n' &&
@@ -105,7 +115,14 @@
     word="${_lastcomp[unambiguous]}"
     state=''
   fi
-  zle -R "${${${pmpt//\\%u/$word}//\\%s/$state}//\\%c/${_lastcomp[completer][2,-1]}}"
+  num=$_lastcomp[normal_nmatches]
+  if (( ! num )); then
+    num="${_lastcomp[nmatches]}"
+    alt=' -alt-'
+  else
+    alt=''
+  fi
+  zle -R "${${${${${pmpt//\\%u/$word}//\\%s/$state}//\\%c/${_lastcomp[completer][2,-1]}}//\\%n/$num}//\\%a/$alt}"
   read -k key
 done
 

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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