about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Completion/Builtins/_zstyle1
-rw-r--r--Completion/Core/_main_complete6
-rw-r--r--Doc/Zsh/compsys.yo9
-rw-r--r--Doc/Zsh/compwid.yo9
-rw-r--r--Src/Zle/compcore.c15
-rw-r--r--Src/Zle/zle_tricky.c11
7 files changed, 51 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index b600d1eb2..d92212a64 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2000-05-09  Sven Wischnowsky  <wischnow@zsh.org>
 
+	* 11274: Completion/Builtins/_zstyle, Completion/Core/_main_complete,
+ 	Doc/Zsh/compsys.yo, Doc/Zsh/compwid.yo, Src/Zle/compcore.c,
+ 	Src/Zle/zle_tricky.c: give control over insertion of tab when no
+ 	non-blank character before cursor; add insert-tab style
+	
 	* 11273: Completion/Base/_argument_sets,
  	Completion/Base/_arguments: option name clash in _arguments
 	
diff --git a/Completion/Builtins/_zstyle b/Completion/Builtins/_zstyle
index 9f5bf9352..7428a3b0f 100644
--- a/Completion/Builtins/_zstyle
+++ b/Completion/Builtins/_zstyle
@@ -40,6 +40,7 @@ styles=(
   ignore-parents         c:ignorepar
   ignored-patterns	 c:
   insert-ids             c:insert-ids
+  insert-tab             c:bool
   insert-unambiguous	 c:bool
   last-prompt		 c:bool
   list			 c:listwhen
diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete
index f079e38e2..aa061ec91 100644
--- a/Completion/Core/_main_complete
+++ b/Completion/Core/_main_complete
@@ -34,6 +34,12 @@ typeset -U _lastdescr _comp_ignore
 
 [[ -z "$curcontext" ]] && curcontext=:::
 
+if [[ "$compstate[insert]" = tab* ]]; then
+  zstyle -T ":completion:${curcontext}:" insert-tab && return 1
+
+  compstate[insert]="${compstate[insert]//tab /}"
+fi
+
 # Special completion contexts after `~' and `='.
 
 if compset -P 1 '='; then
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index fae8961b7..c4c632ef5 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1253,6 +1253,15 @@ is any other string, menucompletion will be entered when the string on
 the line is longer than the prefix of the IDs of all matching
 processes.
 )
+kindex(insert-tab, completion style)
+item(tt(insert-tab))(
+If this has one of the `true' values, the completion system will only
+insert the TAB character if the completion code would normally do that 
+(i.e. when there is no non-blank character to the left of the cursor
+yet). If set to `false', completion will be done even there.
+
+The default value of this style is `true'.
+)
 kindex(insert-unambiguous, completion style)
 item(tt(insert-unambiguous))(
 This is used by the tt(_match) and tt(_approximate) completer
diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo
index 1ca6d11a6..abf15a324 100644
--- a/Doc/Zsh/compwid.yo
+++ b/Doc/Zsh/compwid.yo
@@ -275,7 +275,10 @@ common prefix is to be inserted and the next invocation of the
 completion code may start menucompletion (due to the tt(AUTO_MENU)
 option being set); if set to tt(menu) or tt(automenu) menucompletion
 will be started for the matches currently generated (in the
-latter case this will happen because the tt(AUTO_MENU) is set).
+latter case this will happen because the tt(AUTO_MENU) is set). The
+value may also contain the string `tt(tab)' when the completion code
+woul normally not really do completion, but only insert the TAB
+character.
 
 On exit it may be set to any of the values above (where setting it to
 the empty string is the same as unsetting it), or to a number, in which
@@ -291,6 +294,10 @@ Both tt(menu) and tt(automenu) may also specify the the number of the
 match to insert, given after a colon.  For example, `tt(menu:2)' says
 to start menucompletion, beginning with the second match.
 
+Note that a value containing the substring `tt(tab)' makes the
+matches generated be ignored and only the character that was used to
+call the completion widget be inserted.
+
 Finally, it may also be set to tt(all), which makes all matches
 generated be inserted into the line.
 )
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index e04973b0a..941023769 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -292,7 +292,7 @@ do_completion(Hookdef dummy, Compldat dat)
 	compqstack[0] = '\'';
 
     hasunqu = 0;
-    useline = (lst != COMP_LIST_COMPLETE);
+    useline = (wouldinstab ? -1 : (lst != COMP_LIST_COMPLETE));
     useexact = isset(RECEXACT);
     zsfree(compexactstr);
     compexactstr = ztrdup("");
@@ -334,6 +334,8 @@ do_completion(Hookdef dummy, Compldat dat)
 	clearlist = 1;
 	ret = 1;
 	minfo.cur = NULL;
+	if (useline < 0)
+	    selfinsert(zlenoargs);
 	goto compend;
     }
     zsfree(lastprebr);
@@ -342,7 +344,9 @@ do_completion(Hookdef dummy, Compldat dat)
 
     if (comppatmatch && *comppatmatch && comppatmatch != opm)
 	haspattern = 1;
-    if (!useline && uselist) {
+    if (useline < 0)
+	selfinsert(zlenoargs);
+    else if (!useline && uselist) {
 	/* All this and the guy only wants to see the list, sigh. */
 	cs = 0;
 	foredel(ll);
@@ -430,7 +434,7 @@ do_completion(Hookdef dummy, Compldat dat)
     /* Print the explanation strings if needed. */
     if (!showinglist && validlist && usemenu != 2 && 
 	(nmatches != 1 || diffmatches) &&
-	useline != 2 && (!oldlist || !listshown)) {
+	useline >= 0 && useline != 2 && (!oldlist || !listshown)) {
 	onlyexpl = 1;
 	showinglist = -2;
     }
@@ -706,7 +710,8 @@ callcompfunc(char *s, char *fn)
 	    compinsert = "";
 	    kset &= ~CP_INSERT;
 	}
-	compinsert = ztrdup(compinsert);
+	compinsert = (useline < 0 ? tricat("tab ", "", compinsert) :
+		      ztrdup(compinsert));
 	if (useexact)
 	    compexact = ztrdup("accept");
 	else {
@@ -780,6 +785,8 @@ callcompfunc(char *s, char *fn)
 
 	if (!compinsert)
 	    useline = 0;
+	else if (strstr(compinsert, "tab"))
+	    useline = -1;
 	else if (!strcmp(compinsert, "unambig") ||
 		 !strcmp(compinsert, "unambiguous") ||
 		 !strcmp(compinsert, "automenu-unambiguous"))
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index cb5770452..8accf52fb 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -77,6 +77,11 @@ mod_export int offs;
 /**/
 mod_export int usemenu, useglob;
 
+/* != 0 if we would insert a TAB if we weren't calling a completion widget. */
+
+/**/
+mod_export int wouldinstab;
+
 /* != 0 if we are in the middle of a menu completion. May be == 2 to force *
  * menu completion even if using different widgets.                        */
 
@@ -153,9 +158,15 @@ usetab(void)
 {
     unsigned char *s = line + cs - 1;
 
+    wouldinstab = 0;
     for (; s >= line && *s != '\n'; s--)
 	if (*s != '\t' && *s != ' ')
 	    return 0;
+    if (compfunc) {
+	wouldinstab = 1;
+
+	return 0;
+    }
     return 1;
 }