about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Core/_options2
-rw-r--r--Completion/Core/_set_options2
-rw-r--r--Completion/Core/_unset_options2
-rw-r--r--Doc/Zsh/compwid.yo31
-rw-r--r--Src/Zle/comp.h1
-rw-r--r--Src/Zle/complete.c21
-rw-r--r--Src/Zle/compmatch.c12
-rw-r--r--Test/54compmatch.ztst12
9 files changed, 70 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 16ae04e78..6117cdf86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2000-06-19  Sven Wischnowsky  <wischnow@zsh.org>
 
+	* 11977: Completion/Core/_options, Completion/Core/_set_options,
+ 	Completion/Core/_unset_options, Doc/Zsh/compwid.yo,
+ 	Src/Zle/comp.h, Src/Zle/complete.c, Src/Zle/compmatch.c,
+ 	Test/54compmatch.ztst: new match spec characters bBeE, match only
+ 	word/line not both
+	
 	* 11973: Completion/Builtins/_zstyle, Completion/Core/_description,
  	Completion/Core/_expand, Doc/Zsh/compsys.yo, Src/Zle/zle_tricky.c:
  	allow _expand to expand braces; better detection of braces to
diff --git a/Completion/Core/_options b/Completion/Core/_options
index f86ec42a3..351220bde 100644
--- a/Completion/Core/_options
+++ b/Completion/Core/_options
@@ -5,4 +5,4 @@
 local expl
 
 _wanted zsh-options expl 'zsh option' \
-    compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -k options
+    compadd "$@" -M 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' -k options
diff --git a/Completion/Core/_set_options b/Completion/Core/_set_options
index 37de45cd0..b66826e46 100644
--- a/Completion/Core/_set_options
+++ b/Completion/Core/_set_options
@@ -7,4 +7,4 @@
 local expl
 
 _wanted zsh-options expl 'set zsh option' \
-    compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -a _set_options
+    compadd "$@" -M 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' -a _set_options
diff --git a/Completion/Core/_unset_options b/Completion/Core/_unset_options
index 49cf70598..718da2c9c 100644
--- a/Completion/Core/_unset_options
+++ b/Completion/Core/_unset_options
@@ -7,4 +7,4 @@
 local expl
 
 _wanted zsh-options expl 'unset zsh option' \
-    compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -a _unset_options
+    compadd "$@" -M 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' -a _unset_options
diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo
index c54caea31..b63889573 100644
--- a/Doc/Zsh/compwid.yo
+++ b/Doc/Zsh/compwid.yo
@@ -815,7 +815,9 @@ corresponding to var(tpat) which matches in the trial completion.
 xitem(tt(l:)var(lanchor)tt(|)var(lpat)tt(=)var(tpat))
 xitem(tt(L:)var(lanchor)tt(|)var(lpat)tt(=)var(tpat))
 xitem(tt(l:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))
-item(tt(L:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))(
+xitem(tt(L:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))
+xitem(tt(b:)var(lpat)tt(=)var(tpat))
+item(tt(B:)var(lpat)tt(=)var(tpat))(
 These letters are for patterns that are anchored by another pattern on
 the left side. Matching for var(lpat) and var(tpat) is as for tt(m) and
 tt(M), but the pattern var(lpat) matched on the command line must be
@@ -828,14 +830,21 @@ If no var(lpat) is given but a var(ranchor) is, this matches the gap
 between substrings matched by var(lanchor) and var(ranchor). Unlike
 var(lanchor), the var(ranchor) only needs to match the trial
 completion string.
+
+The tt(b) and tt(B) forms are similar to tt(l) and tt(L) with an empty 
+anchor, but need to match only the beginning of the trial completion
+or the word on the command line, respectively.
 )
 xitem(tt(r:)var(lpat)tt(|)var(ranchor)tt(=)var(tpat))
 xitem(tt(R:)var(lpat)tt(|)var(ranchor)tt(=)var(tpat))
 xitem(tt(r:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))
-item(tt(R:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))(
-As tt(l) and tt(L), with the difference that the command line and trial
-completion patterns are anchored on the right side.  Here an empty
-var(ranchor) forces the match to the end of the command line string.
+xitem(tt(R:)var(lanchor)tt(||)var(ranchor)tt(=)var(tpat))
+xitem(tt(e:)var(lpat)tt(=)var(tpat))
+item(tt(E:)var(lpat)tt(=)var(tpat))(
+As tt(l), tt(L), tt(b) and tt(B), with the difference that the command
+line and trial completion patterns are anchored on the right side.
+Here an empty var(ranchor) and the tt(e) and tt(E) forms force the
+match to the end of the trial completion or command line string.
 )
 enditem()
 
@@ -898,6 +907,18 @@ specification characters (tt(L) and tt(M)) guarantees that what has
 already been typed on the command line (in particular the prefix
 tt(no)) will not be deleted.
 
+Note that the use of tt(L) in the first part means that it matches
+only when at the beginning of both the command line string and the
+trial completion. I.e., the string `tt(_NO_f)' would not be
+completed to `tt(_NO_foo)', nor would `tt(NONO_f)' be completed to
+`tt(NONO_foo)' because of the leading underscore or the second
+`tt(NO)' on the line which makes the pattern fail even though they are 
+otherwise ignored. To fix this, one would use `tt(B:[nN][oO]=)'
+instead of the first part. As described above, this matches at the
+beginning of the trial completion, independent of other characters or
+substrings at the beginning of the command line word which are ignored
+by the same or other var(spec)s.
+
 The second example makes completion case insensitive.  This is just
 the same as in the option example, except here we wish to retain the
 characters in the list of completions:
diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h
index 93e3c68eb..506d85135 100644
--- a/Src/Zle/comp.h
+++ b/Src/Zle/comp.h
@@ -150,6 +150,7 @@ struct cmatcher {
 #define CMF_LINE  1
 #define CMF_LEFT  2
 #define CMF_RIGHT 4
+#define CMF_INTER 8
 
 struct cpattern {
     Cpattern next;		/* next sub-pattern */
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index 11f6d24ef..20da967ef 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -183,13 +183,13 @@ parse_cmatcher(char *name, char *s)
 {
     Cmatcher ret = NULL, r = NULL, n;
     Cpattern line, word, left, right;
-    int fl, ll, wl, lal, ral, err, both;
+    int fl, fl2, ll, wl, lal, ral, err, both;
 
     if (!*s)
 	return NULL;
 
     while (*s) {
-	lal = ral = both = 0;
+	lal = ral = both = fl2 = 0;
 	left = right = NULL;
 
 	while (*s && inblank(*s)) s++;
@@ -197,10 +197,14 @@ parse_cmatcher(char *name, char *s)
 	if (!*s) break;
 
 	switch (*s) {
+	case 'b': fl2 = CMF_INTER;
 	case 'l': fl = CMF_LEFT; break;
+	case 'e': fl2 = CMF_INTER;
 	case 'r': fl = CMF_RIGHT; break;
 	case 'm': fl = 0; break;
+	case 'B': fl2 = CMF_INTER;
 	case 'L': fl = CMF_LEFT | CMF_LINE; break;
+	case 'E': fl2 = CMF_INTER;
 	case 'R': fl = CMF_RIGHT | CMF_LINE; break;
 	case 'M': fl = CMF_LINE; break;
 	default:
@@ -220,7 +224,7 @@ parse_cmatcher(char *name, char *s)
 		zwarnnam(name, "missing patterns", NULL, 0);
 	    return pcm_err;
 	}
-	if (fl & CMF_LEFT) {
+	if ((fl & CMF_LEFT) && !fl2) {
 	    left = parse_pattern(name, &s, &lal, '|', &err);
 	    if (err)
 		return pcm_err;
@@ -236,7 +240,8 @@ parse_cmatcher(char *name, char *s)
 	} else
 	    left = NULL;
 
-	line = parse_pattern(name, &s, &ll, ((fl & CMF_RIGHT) ? '|' : '='),
+	line = parse_pattern(name, &s, &ll,
+			     (((fl & CMF_RIGHT) && !fl2) ? '|' : '='),
 			     &err);
 	if (err)
 	    return pcm_err;
@@ -246,10 +251,10 @@ parse_cmatcher(char *name, char *s)
 	    line = NULL;
 	    ll = 0;
 	}
-	if ((fl & CMF_RIGHT) && (!*s || !*++s)) {
+	if ((fl & CMF_RIGHT) && !fl2 && (!*s || !*++s)) {
 	    if (name)
 		zwarnnam(name, "missing right anchor", NULL, 0);
-	} else if (!(fl & CMF_RIGHT)) {
+	} else if (!(fl & CMF_RIGHT) || fl2) {
 	    if (!*s) {
 		if (name)
 		    zwarnnam(name, "missing word pattern", NULL, 0);
@@ -257,7 +262,7 @@ parse_cmatcher(char *name, char *s)
 	    }
 	    s++;
 	}
-	if (fl & CMF_RIGHT) {
+	if ((fl & CMF_RIGHT) && !fl2) {
 	    if (*s == '|') {
 		left = line;
 		lal = ll;
@@ -304,7 +309,7 @@ parse_cmatcher(char *name, char *s)
 
 	n = (Cmatcher) hcalloc(sizeof(*ret));
 	n->next = NULL;
-	n->flags = fl;
+	n->flags = fl | fl2;
 	n->line = line;
 	n->llen = ll;
 	n->word = word;
diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
index 130cb23b0..aa7890407 100644
--- a/Src/Zle/compmatch.c
+++ b/Src/Zle/compmatch.c
@@ -565,7 +565,9 @@ match_str(char *l, char *w, Brinfo *bpp, int bc, int *rwlp,
 					      NULL, NULL)) ||
 			      !match_parts(l + aoff, w + aoff, alen, part))))
 				continue;
-		    } else if (!both || il || iw)
+		    } else if (!both || ((mp->flags & CMF_INTER) ?
+					 ((mp->flags & CMF_LINE) ? iw : il) :
+					 (il || iw)))
 			continue;
 
 		    /* Fine, now we call ourselves recursively to find the
@@ -734,7 +736,9 @@ match_str(char *l, char *w, Brinfo *bpp, int bc, int *rwlp,
 					       tw - mp->lalen - mp->ralen,
 					       NULL, NULL));
 			else
-			    t = (!sfx && !il && !iw);
+			    t = (!sfx && !((mp->flags & CMF_INTER) ?
+					   ((mp->flags & CMF_LINE) ? iw : il) :
+					   (il || iw)));
 		    }
 		    if (mp->flags & CMF_RIGHT) {
 			/* Try to match the right anchor, if any. */
@@ -753,7 +757,9 @@ match_str(char *l, char *w, Brinfo *bpp, int bc, int *rwlp,
 					       mp->ralen - mp->lalen,
 					       NULL, NULL));
 			else
-			    t = (sfx && !il && !iw);
+			    t = (sfx && !((mp->flags & CMF_INTER) ?
+					  ((mp->flags & CMF_LINE) ? iw : il) :
+					  (il || iw)));
 		    }
 		    /* Now try to match the line and word patterns. */
 		    if (!t ||
diff --git a/Test/54compmatch.ztst b/Test/54compmatch.ztst
index eb7bdddd4..3fd1694c8 100644
--- a/Test/54compmatch.ztst
+++ b/Test/54compmatch.ztst
@@ -254,6 +254,18 @@
 >line: {tst ___list_beep__ }{}
 >COMPADD:{}
 
+ test_code 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' example1_list
+ comptest $'tst __no_listbe\t'
+0:Documentation example for options, input "__no_listbe"
+>line: {tst __no_listbeep }{}
+>COMPADD:{}
+
+ test_code 'B:[nN][oO]= M:_= M:{A-Z}={a-z}' example1_list
+ comptest $'tst nonono_listbe\t'
+0:Documentation example for options, input "nonono_listbe"
+>line: {tst nonono_listbeep }{}
+>COMPADD:{}
+
  lower_insensitive_M="M:{a-z}={A-Z}"
  lower_insensitive_m="m:{a-z}={A-Z}"
  example2_list=(ABC Abc abc)