* PATCH: compstate
@ 1999-07-14 8:41 Sven Wischnowsky
0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 1999-07-14 8:41 UTC (permalink / raw)
To: zsh-workers
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@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 2+ messages in thread
* PATCH: compstate
@ 1999-03-26 10:17 Sven Wischnowsky
0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 1999-03-26 10:17 UTC (permalink / raw)
To: zsh-workers
Ok, here are the things I wanted to add to compstate.
- `list_max' - this is used like the LISTMAX parameter, with the
same possible values
- `last_prompt' - used like ALWAYS_LAST_PROMPT
- `to_end' - interface to ALWAYS_TO_END, but it allows more
control over when the cursor is moved to the end
That's it. Things I don't plan to put into compstate:
- Control over when to beep (I think this isn't that important, right?).
- I once suggested this, but don't like it any more: a key that would
be used when the widget is called via `compctl -i foo', saying if
and where the completion code should continue. In most cases using
`compctl -i foo -tn + -tc' or something like that should be enough.
And then I think widgets should not care about from where they were
called and when one uses a widget via `-i' one should know better
where to continue than the one who wrote the widget.
Bye
Sven
diff -u os/Zle/comp.h Src/Zle/comp.h
--- os/Zle/comp.h Fri Mar 26 09:13:06 1999
+++ Src/Zle/comp.h Fri Mar 26 09:45:20 1999
@@ -298,7 +298,10 @@
#define CP_PATINSERT (1 << 23)
#define CP_UNAMBIG (1 << 24)
#define CP_UNAMBIGC (1 << 25)
+#define CP_LISTMAX (1 << 26)
+#define CP_LASTPROMPT (1 << 27)
+#define CP_TOEND (1 << 28)
-#define CP_NUM 26
+#define CP_NUM 29
#define CP_ALLMASK ((1 << CP_NUM) - 1)
diff -u os/Zle/comp1.c Src/Zle/comp1.c
--- os/Zle/comp1.c Fri Mar 26 09:13:06 1999
+++ Src/Zle/comp1.c Fri Mar 26 09:44:39 1999
@@ -103,7 +103,8 @@
long compcurrent,
compnmatches,
compmatcher,
- compmatchertot;
+ compmatchertot,
+ complistmax;
/**/
char **compwords,
@@ -124,7 +125,9 @@
*compexact,
*compexactstr,
*comppatmatch,
- *comppatinsert;
+ *comppatinsert,
+ *complastprompt,
+ *comptoend;
/**/
Param *comppms;
@@ -439,7 +442,7 @@
compcontext = compparameter = compredirect = compquote =
compquoting = comprestore = complist = compinsert =
compexact = compexactstr = comppatmatch = comppatinsert =
- compforcelist = NULL;
+ compforcelist = complastprompt = comptoend = NULL;
makecompparamsptr = NULL;
comp_setunsetptr = NULL;
return 0;
@@ -487,6 +490,8 @@
zsfree(compexactstr);
zsfree(comppatmatch);
zsfree(comppatinsert);
+ zsfree(complastprompt);
+ zsfree(comptoend);
return 0;
}
diff -u os/Zle/compctl.c Src/Zle/compctl.c
--- os/Zle/compctl.c Fri Mar 26 09:13:06 1999
+++ Src/Zle/compctl.c Fri Mar 26 09:47:01 1999
@@ -2152,7 +2152,11 @@
{ "pattern_match", PM_SCALAR, VAL(comppatmatch), NULL, NULL },
{ "pattern_insert", PM_SCALAR, VAL(comppatinsert), NULL, NULL },
{ "unambiguous", PM_SCALAR | PM_READONLY, NULL, NULL, VAL(get_unambig) },
- { "unambiguous_cursor", PM_INTEGER | PM_READONLY, NULL, NULL, VAL(get_unambig_curs) },
+ { "unambiguous_cursor", PM_INTEGER | PM_READONLY, NULL, NULL,
+ VAL(get_unambig_curs) },
+ { "list_max", PM_INTEGER, VAL(complistmax), NULL, NULL },
+ { "last_prompt", PM_SCALAR, VAL(complastprompt), NULL, NULL },
+ { "to_end", PM_SCALAR, VAL(comptoend), NULL, NULL },
{ NULL, 0, NULL, NULL, NULL }
};
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c Fri Mar 26 09:13:07 1999
+++ Src/Zle/zle_tricky.c Fri Mar 26 10:56:39 1999
@@ -78,6 +78,12 @@
static int usemenu, useglob, useexact, useline, uselist;
+/* This is used to decide when the cursor should be moved to the end of *
+ * the inserted word: 0 - never, 1 - only when a single match is inserted, *
+ * 2 - when a full match is inserted (single or menu), 3 - always. */
+
+static int movetoend;
+
/* != 0 if we are in the middle of a menu completion */
static int menucmp;
@@ -650,7 +656,13 @@
int n = 0, br = 1;
if (*b == Inbrace) {
- /* If this is a ${...}, ignore the possible (...) flags. */
+ char *tb = b;
+
+ /* If this is a ${...}, see if we are before the '}'. */
+ if (!skipparens(Inbrace, Outbrace, &tb))
+ return NULL;
+
+ /* Ignore the possible (...) flags. */
b++, br++;
n = skipparens(Inpar, Outpar, &b);
}
@@ -4014,6 +4026,12 @@
zsfree(compforcelist);
compforcelist = ztrdup("");
haspattern = 0;
+ complistmax = getiparam("LISTMAX");
+ zsfree(complastprompt);
+ complastprompt = ztrdup(((isset(ALWAYSLASTPROMPT) && zmult == 1) ||
+ (unset(ALWAYSLASTPROMPT) && zmult != 1)) ?
+ "yes" : "");
+ movetoend = ((cs == we || isset(ALWAYSTOEND)) ? 2 : 1);
/* Make sure we have the completion list and compctl. */
if (makecomplist(s, incmd, lst)) {
@@ -4069,9 +4087,8 @@
g = g->next;
}
if (!tr) {
- clearflag = ((isset(USEZLE) && !termflags &&
- (isset(ALWAYSLASTPROMPT) && zmult == 1)) ||
- (unset(ALWAYSLASTPROMPT) && zmult != 1));
+ clearflag = (isset(USEZLE) && !termflags &&
+ complastprompt && *complastprompt);
if (clearflag && up + nlnct < lines)
tcmultout(TCUP, TCMULTUP, up + nlnct);
@@ -4109,6 +4126,8 @@
set = -1 & ~(CP_PARAMETER | CP_REDIRECT | CP_QUOTE | CP_QUOTING |
CP_EXACTSTR | CP_FORCELIST | (useglob ? 0 : CP_PATMATCH));
+ if (!*complastprompt)
+ set &= ~CP_LASTPROMPT;
zsfree(compcontext);
zsfree(compparameter);
zsfree(compredirect);
@@ -4260,6 +4279,11 @@
compexact = ztrdup("");
set &= ~CP_EXACT;
}
+ zsfree(comptoend);
+ if (movetoend == 1)
+ comptoend = ztrdup("single");
+ else
+ comptoend = ztrdup("match");
incompfunc = 1;
startparamscope();
makecompparamsptr();
@@ -4298,6 +4322,15 @@
useline = usemenu = 0;
useexact = (compexact && !strcmp(compexact, "accept"));
+ if (!comptoend || !*comptoend)
+ movetoend = 0;
+ else if (!strcmp(comptoend, "single"))
+ movetoend = 1;
+ else if (!strcmp(comptoend, "always"))
+ movetoend = 3;
+ else
+ movetoend = 2;
+
zfree(comppms, CP_NUM * sizeof(Param));
comppms = ocpms;
}
@@ -6653,6 +6686,10 @@
fromcomp = ((isset(AUTOMENU) ? FC_LINE : 0) |
((atend && cs != lastend) ? FC_INWORD : 0));
+ /* Probably move the cursor to then end. */
+ if (movetoend == 3)
+ cs = lastend;
+
/* If the LIST_AMBIGUOUS option (meaning roughly `show a list only *
* if the completion is completely ambiguous') is set, and some *
* prefix was inserted, return now, bypassing the list-displaying *
@@ -6721,8 +6758,7 @@
/* We are currently not in a menu-completion, *
* so set the position variables. */
menupos = wb;
- /* previously: menuwe = (cs == we) || isset(ALWAYSTOEND); */
- menuwe = isset(ALWAYSTOEND);
+ menuwe = (movetoend >= 2 || (movetoend = 1 && !menucmp));
menuend = we;
}
/* If we are already in a menu-completion or if we have done a *
@@ -6972,7 +7008,6 @@
Cexpl *e;
int nlines = 0, ncols, nlist = 0, longest = 1, pnl = 0;
int of = isset(LISTTYPES), opl = 0;
- int listmax = getiparam("LISTMAX");
#ifdef DEBUG
/* Sanity check */
@@ -6987,8 +7022,7 @@
showinglist = 0;
clearflag = (isset(USEZLE) && !termflags &&
- (isset(ALWAYSLASTPROMPT) && zmult == 1)) ||
- (unset(ALWAYSLASTPROMPT) && zmult != 1);
+ complastprompt && *complastprompt);
for (g = amatches; g; g = g->next) {
char **pp = g->ylist;
@@ -7067,7 +7101,8 @@
}
/* Maybe we have to ask if the user wants to see the list. */
- if ((listmax && nlist > listmax) || (!listmax && nlines >= lines)) {
+ if ((complistmax && nlist > complistmax) ||
+ (!complistmax && nlines >= lines)) {
int qup;
zsetterm();
qup = printfmt("zsh: do you wish to see all %n possibilities? ", nlist, 1);
diff -u od/Zsh/compwid.yo Doc/Zsh/compwid.yo
--- od/Zsh/compwid.yo Thu Mar 25 15:31:08 1999
+++ Doc/Zsh/compwid.yo Fri Mar 26 11:09:04 1999
@@ -186,6 +186,18 @@
list. Setting tt(force_list) to an non-empty string makes the list be
shown even if there is only one match.
)
+item(tt(list_max))(
+Initially this is set to the value of the tt(LISTMAX) parameter.
+Completion widgets may set it to any other numeric value and the value
+stored at when the widget finishes will be used in the same way the
+value of tt(LISTMAX) is used.
+)
+item(tt(last_prompt))(
+If this is set to an non-empty string, the completion code will move
+the cursor back to the previous prompt after the list of completions
+has been displayed. Initially this is set depending on the setting of
+the tt(ALWAYS_LAST_PROMPT) option.
+)
item(tt(insert))(
This will be unset by the completon code if the contents of the
command line will not be changed. It is set to tt(unambiguous),
@@ -193,6 +205,26 @@
inserted or if the first match will be inserted and menu completion
will be started (due to tt(MENU_COMPLETE) or tt(AUTO_MENU) being set),
respectively.
+)
+item(tt(to_end))(
+On entry to the completion widget this is set to tt(single) if the
+cursor would be moved to the end of the word only if completion
+generated only one match and that is inserted into the line. Depending
+on the original position of the cursor and the setting of the option
+tt(ALWAYS_TO_END) this may also be set to the string tt(match) if the
+cursor would be moved to the end if a whole match would be inserted
+(either if there is only one match or if menucompletion is used).
+
+The value of this key after the completion widget exits will be used
+to determin when the cursor will be moved to the end of the string
+inserted into the line. If it is unset or set to the empty string, the
+cursor will never be moved to the end. If it is set to tt(single), it
+will be moved to the end only if completion generated only one
+match. A value of tt(always) says to move the cursor always to the end
+(even with normal completion when an unambiguous string is inserted),
+and any other value says to move the cursor to the end when a full
+match is inserted (a single match or the first match when using
+menucompletion).
)
item(tt(exact))(
This is set to tt(accept) if an exact match would be accepted by the
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-07-14 8:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-14 8:41 PATCH: compstate Sven Wischnowsky
-- strict thread matches above, loose matches on Subject: below --
1999-03-26 10:17 Sven Wischnowsky
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).