about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-18 07:36:55 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-18 07:36:55 +0000
commitfe65ab1dd85195ae0bef29f11aea74209c00cb8b (patch)
tree1e435897e589f4e0e66f89ef6128bd5752b4e056
parent59da43689af6ca1048f2e956f10c18cd17774f2a (diff)
downloadzsh-fe65ab1dd85195ae0bef29f11aea74209c00cb8b.tar.gz
zsh-fe65ab1dd85195ae0bef29f11aea74209c00cb8b.tar.xz
zsh-fe65ab1dd85195ae0bef29f11aea74209c00cb8b.zip
completion list scrolling cleanup; *STATUS renamed to *PROMPT, styles for new used parameters, use local keymap when waiting at list-prompt (10801)
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Builtins/_zstyle3
-rw-r--r--Completion/Core/_main_complete10
-rw-r--r--Doc/Zsh/compsys.yo35
-rw-r--r--Doc/Zsh/compwid.yo2
-rw-r--r--Doc/Zsh/mod_complist.yo43
-rw-r--r--Src/Zle/complist.c77
7 files changed, 132 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index 2d38188c7..47f12fd0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2000-04-18  Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
 
+	* 10801: Completion/Builtins/_zstyle, Completion/Core/_main_complete,
+ 	Doc/Zsh/compsys.yo, Doc/Zsh/compwid.yo, Doc/Zsh/mod_complist.yo,
+ 	Src/Zle/complist.c: completion list scrolling cleanup; *STATUS
+ 	renamed to *PROMPT, styles for new used parameters, use local
+ 	keymap when waiting at list-prompt
+	
 	* 10799: Src/text.c: fix to get newlines in non-job-texts (I'm
  	sooo stupid)
 	
diff --git a/Completion/Builtins/_zstyle b/Completion/Builtins/_zstyle
index 5f078fddb..a2a19320d 100644
--- a/Completion/Builtins/_zstyle
+++ b/Completion/Builtins/_zstyle
@@ -41,6 +41,7 @@ styles=(
   list			 c:listwhen
   list-colors		 c:
   list-packed		 c:bool
+  list-prompt            c:
   list-rows-first	 c:bool
   local			 c:
   matcher-list		 c:
@@ -55,6 +56,8 @@ styles=(
   prefix-needed		 c:bool
   prompt		 c:
   remove-all-dups	 c:bool
+  select-prompt          c:
+  select-scroll          c:
   single-ignored         c:single-ignored
   sort			 c:bool
   special-dirs		 c:sdirs
diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete
index 795fe7442..0c0bd05b6 100644
--- a/Completion/Core/_main_complete
+++ b/Completion/Core/_main_complete
@@ -56,6 +56,16 @@ _def_menu_style=( "$_last_menu_style[@]"
                 )
 _last_menu_style=()
 
+if zstyle -s ":completion:${curcontext}:default" list-prompt LISTPROMPT &&
+   [[ -n "$LISTPROMPT" ]]; then
+  zmodload -i zsh/complist
+  compstate[list_max]=scroll
+fi
+zstyle -s ":completion:${curcontext}:default" select-prompt SELECTPROMPT ||
+    SELECTPROMPT='%SScrolling active: current selection at %p'
+zstyle -s ":completion:${curcontext}:default" select-scroll SELECTSCROLL ||
+    SELECTSCROLL=1
+
 # Get the names of the completers to use in the positional parameters.
 
 if (( $# )); then
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 5e698a9ae..84d301e5a 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1267,6 +1267,19 @@ for a tag, the matches added for it will be listed as if the
 tt(LIST_PACKED) option were set for them. If it is set to `false',
 they are listed normally.
 )
+kindex(list-prompt, completion style)
+item(tt(list-prompt))(
+If this style is set to a non-empty value for the tt(default) tag,
+completion lists that don't fit on the screen can be scrolled (see
+ifzman(the description of the tt(zsh/complist) module in zmanref(zshmodules))\
+ifnzman(noderef(The zsh/complist Module))\
+). The value will be displayed after every screenful, prompting for a
+key and may contain the escape `tt(%l)' which will be replaced by the
+number of the last line displayed and the total number of lines. As
+usual, the `tt(%S)', `tt(%s)', `tt(%B)', `tt(%b)', `tt(%U)', `tt(%u)',
+and `tt(%{)...tt(%})' escapes for the terminal display modes are
+understood, too.
+)
 kindex(list-rows-first, completion style)
 item(tt(list-rows-first))(
 This style is tested like the tt(list-packed) style and determines if
@@ -1559,6 +1572,28 @@ The tt(_history_complete_word) bindable command uses this to decide if
 all duplicate matches should be removed, rather than just consecutive
 duplicates.
 )
+kindex(select-prompt, completion style)
+item(tt(select-prompt))(
+If this is set to a non-empty string for the tt(default) tag, its
+value will be displayed during menu-selection (see the tt(menu) style
+above) when the completion list does not fit on the screen as a
+whole. The same escapes as for the tt(list-prompt) style are
+understood, plus `tt(%m)' which is replaced by the number of the
+currently selected match and the total number of matches and `tt(%p)'
+which is replaced by `tt(Top)' when the mark is on the first line,
+`tt(Bottom)' when it is on the last line and the relative position of
+the mark in the list given as a percentage.
+)
+kindex(select-scroll, completion style)
+item(tt(select-scroll))(
+This style is tested for the tt(default) tag and determines how a
+completion list is scrolled during a menu-selection (see the tt(menu)
+style above) when the completion list does not fit on the screen as a
+whole. Its value should be `tt(0)' (zero) to scroll by
+half-screenfuls, a positive integer to scroll by that many lines and a
+negative number to scroll by the number of lines of the screen minus
+that number (or plus the number, since it is negative).
+)
 kindex(single-ignored, completion style)
 item(tt(single-ignored))(
 This is used by the tt(_ignored) completer. It specifies what
diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo
index 340dc0752..f2280df77 100644
--- a/Doc/Zsh/compwid.yo
+++ b/Doc/Zsh/compwid.yo
@@ -247,7 +247,7 @@ there.
 vindex(list_max, compstate)
 item(tt(list_max))(
 Initially this is set to the value of the tt(LISTMAX) parameter.
-It may be set to any other numeric value; when the widget exits this value
+It may be set to any other value; when the widget exits this value
 will be used in the same way as the value of tt(LISTMAX).
 )
 vindex(list_lines, compstate)
diff --git a/Doc/Zsh/mod_complist.yo b/Doc/Zsh/mod_complist.yo
index 920df5fc1..e5484c941 100644
--- a/Doc/Zsh/mod_complist.yo
+++ b/Doc/Zsh/mod_complist.yo
@@ -133,26 +133,30 @@ To be able to scroll through a completion list, the tt(LISTMAX)
 parameter has to be set to the string `tt(scroll)'. If it has this
 value, the completion code will not ask if the list should be
 shown. Instead it immediately starts displaying the list, stopping
-after the first screenful, showing a simple prompt at the bottom,
-waiting for a keypress. The following keys have a special meaning:
+after the first screenful, showing a prompt at the bottom,
+waiting for a keypress after temporarily switching to the
+tt(listscroll) keymap. Some of the zle functions have special meaning:
 
 startitem()
-item(tt(Space), tt(Tab))(
-scroll forward one screenful
+item(tt(send-break))(
+stops listing discarding the key pressed
 )
-item(tt(Return), tt(Newline))(
-scroll forward one line
+xitem(tt(accept-line), tt(down-history), tt(down-line-or-history))
+item(tt(down-line-or-search), tt(vi-down-line-or-history))(
+scrolls forward one line
 )
-item(tt(q))(
-stops listing and redisplays the command line without inserting the
-`tt(q)'
+item(tt(complete-word), tt(menu-complete), tt(expand-or-complete))(
+item(tt(expand-or-complete-prefix), tt(menu-complete-or-expand))(
+scrolls forward one screenful
 )
 enditem()
 
 Every other character stops listing and immediately processes the key
-as usual.
+as usual. Any key that is not bound in the tt(listscroll) keymap or
+that is bound to tt(undefined-key) is looked up in the keymap
+currently selected.
 
-If the parameter tt(LISTSTATUS) is set, its value will be used as the
+If the parameter tt(LISTPROMPT) is set, its value will be used as the
 prompt.  The value may contain escapes of the form `tt(%x)'. It
 supports the escapes `tt(%B)', `tt(%b)', `tt(%S)', `tt(%s)', `tt(%U)',
 `tt(%u)' and `tt(%{...%})' known from the shell prompts and the
@@ -160,6 +164,11 @@ additional sequence `tt(%l)' which is replaced by the number of the
 last line shown and the total number of lines in the form
 `var(number)tt(/)var(total)'.
 
+As for the tt(ZLS_COLORS) and tt(ZLS_COLOURS) parameters,
+tt(LISTPROMPT) should not be set directly when using the shell
+function based completion system. Instead, the tt(list-prompt) style
+should be used.
+
 subsect(Menu selection)
 cindex(completion, selecting by cursor)
 vindex(SELECTMIN)
@@ -197,9 +206,9 @@ 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.
 
 If there are more matches than fit on the screen and the parameter
-tt(SELECTSTATUS) is set, its value will be shown below the
+tt(SELECTPROMPT) is set, its value will be shown below the
 matches. Next to the escape sequences understood for the
-tt(LISTSTATUS) parameter, a `tt(%m)' will be replaced by a string
+tt(LISTPROMPT) parameter, a `tt(%m)' will be replaced by a string
 containing the number of the match the mark is on and the total number 
 of matches in the form `var(number)tt(/)var(total)' and the sequence
 `tt(%p)' will be replaced with `tt(Top)', `tt(Bottom)' or the position
@@ -210,9 +219,15 @@ The tt(SELECTSCROLL) parameter can be used to specify how the list is
 scrolled. If the parameter is unset, this is done line by line, if it
 is set to `tt(0)' (zero), the list will scrolled half the number of
 lines of the screen. If the value is positive, it gives the number of
-lines to scroll and if it is negative, the list will be scrolled one
+lines to scroll and if it is negative, the list will be scrolled
 the number of lines of the screen minus the (absolute) value.
 
+As for the tt(ZLS_COLORS), tt(ZLS_COLOURS) and tt(LISTPROMPT)
+parameters, neither tt(SELECTPROMPT) nor tt(SELECTSCROLL) should be
+set directly when using the shell function based completion
+system. Instead, the tt(select-prompt) and tt(select-scroll) styles
+should be used.
+
 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
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index f3363cc97..9b9031f14 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -37,7 +37,7 @@
 
 
 static Widget w_menuselect;
-static Keymap mskeymap;
+static Keymap mskeymap, lskeymap;
 
 /* Indixes into the terminal string arrays. */
 
@@ -59,9 +59,8 @@ static Keymap mskeymap;
 #define COL_MA 15
 #define COL_HI 16
 #define COL_DU 17
-#define COL_ST 18
 
-#define NUM_COLS 19
+#define NUM_COLS 18
 
 /* Maximum number of in-string colours supported. */
 
@@ -71,14 +70,14 @@ static Keymap mskeymap;
 
 static char *colnames[] = {
     "no", "fi", "di", "ln", "pi", "so", "bd", "cd", "ex", "mi",
-    "lc", "rc", "ec", "tc", "sp", "ma", "hi", "du", "st", NULL
+    "lc", "rc", "ec", "tc", "sp", "ma", "hi", "du", NULL
 };
 
 /* Default values. */
 
 static char *defcols[] = {
     "0", "0", "1;34", "1;36", "33", "1;35", "1;33", "1;33", "1;32", NULL,
-    "\033[", "m", NULL, "0", "0", "7", "0", "0", "7"
+    "\033[", "m", NULL, "0", "0", "7", "0", "0"
 };
 
 /* This describes a terminal string for a file type. */
@@ -347,12 +346,9 @@ getcols(Listcols c)
 	
 	if ((s = tcstr[TCSTANDOUTBEG]) && s[0]) {
 	    c->files[COL_MA] = filecol(s);
-	    c->files[COL_ST] = filecol(s);
 	    c->files[COL_EC] = filecol(tcstr[TCSTANDOUTEND]);
-	} else {
+	} else
 	    c->files[COL_MA] = filecol(defcols[COL_MA]);
-	    c->files[COL_ST] = filecol(defcols[COL_ST]);
-	}
 	lr_caplen = 0;
 	if ((max_caplen = strlen(c->files[COL_MA]->col)) <
 	    (l = strlen(c->files[COL_EC]->col)))
@@ -657,32 +653,46 @@ static Cmgroup last_group;
 static int
 asklistscroll(int ml)
 {
-    int v, i;
+    Thingy cmd;
+    int i, ret = 0;
 
     compprintfmt(NULL, -1, 1, 1, ml, NULL);
 
     fflush(shout);
     zsetterm();
-    v = getzlequery(0);
+    selectlocalmap(lskeymap);
+    if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak))
+	ret = 1;
+    else if (cmd == Th(z_acceptline) ||
+	     cmd == Th(z_downhistory) ||
+	     cmd == Th(z_downlineorhistory) ||
+	     cmd == Th(z_downlineorsearch) ||
+	     cmd == Th(z_vidownlineorhistory))
+	mrestlines = 1;
+    else if (cmd == Th(z_completeword) ||
+		   cmd == Th(z_expandorcomplete) ||
+		   cmd == Th(z_expandorcompleteprefix) ||
+		   cmd == Th(z_menucomplete) ||
+		   cmd == Th(z_menuexpandorcomplete) ||
+		   !strcmp(cmd->nam, "menu-select") ||
+		   !strcmp(cmd->nam, "complete-word") ||
+		   !strcmp(cmd->nam, "expand-or-complete") ||
+		   !strcmp(cmd->nam, "expand-or-complete-prefix") ||
+		   !strcmp(cmd->nam, "menu-complete") ||
+	     !strcmp(cmd->nam, "menu-expand-or-complete"))
+	mrestlines = lines - 1;
+    else {
+	ungetkeycmd();
+	ret = 1;
+    }
+    selectlocalmap(NULL);
     settyinfo(&shttyinfo);
     putc('\r', shout);
     for (i = columns - 1; i--; )
 	putc(' ', shout);
-
     putc('\r', shout);
 
-    if (v == '\n' || v == '\r') {
-	mrestlines = 1;
-	return 0;
-    }
-    mrestlines = lines - 1;
-
-    if (v == ' ' || v == '\t')
-	return 0;
-    if (v != 'q')
-	ungetkey(v);
-
-    return 1;
+    return ret;
 }
 
 #define dolist(X)   ((X) >= mlbeg && (X) < mlend)
@@ -720,8 +730,8 @@ compprintfmt(char *fmt, int n, int dopr, int doesc, int ml, int *stop)
 	    if (!(fmt = mstatus))
 		return 0;
 	    cc = -1;
-	} else if (!(fmt = getsparam("LISTSTATUS")))
-	    fmt = "continue? ";
+	} else if (!(fmt = getsparam("LISTPROMPT")))
+	    fmt = "Continue? ";
     }
     for (p = fmt; *p; p++) {
 	if (doesc && *p == '%') {
@@ -1417,7 +1427,7 @@ complistmatches(Hookdef dummy, Chdata dat)
     mscroll = 0;
 
     if (mselect >= 0 || mlbeg >= 0 ||
-	((p = getsparam("LISTMAX")) && !strcmp(p, "scroll"))) {
+	((p = complistmax) && !strcmp(p, "scroll"))) {
 	trashzle();
 	showinglist = listshown = 0;
 
@@ -1536,8 +1546,8 @@ domenuselect(Hookdef dummy, Chdata dat)
 	    if ((step += lines - nlnct) < 0)
 		step = 1;
     }
-    mstatus = getsparam("SELECTSTATUS");
-    mhasstat = !!mstatus;
+    mstatus = getsparam("SELECTPROMPT");
+    mhasstat = (mstatus && *mstatus);
     fdat = dat;
     selectlocalmap(mskeymap);
     noselect = 0;
@@ -2054,6 +2064,14 @@ boot_(Module m)
     bindkey(mskeymap, "\33OB",  refthingy(t_downlineorhistory), NULL);
     bindkey(mskeymap, "\33OC",  refthingy(t_forwardchar), NULL);
     bindkey(mskeymap, "\33OD",  refthingy(t_backwardchar), NULL);
+    lskeymap = newkeymap(NULL, "listscroll");
+    linkkeymap(lskeymap, "listscroll", 1);
+    bindkey(lskeymap, "\t", refthingy(t_completeword), NULL);
+    bindkey(lskeymap, " ", refthingy(t_completeword), NULL);
+    bindkey(lskeymap, "\n", refthingy(t_acceptline), NULL);
+    bindkey(lskeymap, "\r", refthingy(t_acceptline), NULL);
+    bindkey(lskeymap, "\33[B",  refthingy(t_downlineorhistory), NULL);
+    bindkey(lskeymap, "\33OB",  refthingy(t_downlineorhistory), NULL);
     return 0;
 }
 
@@ -2068,6 +2086,7 @@ cleanup_(Module m)
     deletehookfunc("comp_list_matches", (Hookfn) complistmatches);
     deletehookfunc("menu_start", (Hookfn) domenuselect);
     unlinkkeymap("menuselect", 1);
+    unlinkkeymap("listscroll", 1);
     return 0;
 }