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

PATCH: compstate and globcomplete



I had forgotten this one (I had thought about it, had forgotten it,
had...). This adds the key `pattern_match' to `compstate'. If it is
set to a non-empty striing, the code will behave as if globcomplete is 
set. I could have called the key `globcomplete', of course, and
probably this is a better name, but `pattern_match' is more
exact. Also, since it can be set to any string, we could easily allow
different values with different meanings, if only I had ideas for
other things we might want to do here...

You'll need the patch from 5601 for this one...

Bye
 Sven

diff -u os/Zle/comp.h Src/Zle/comp.h
--- os/Zle/comp.h	Tue Mar  2 11:51:40 1999
+++ Src/Zle/comp.h	Tue Mar  2 13:41:50 1999
@@ -313,7 +313,8 @@
 #define CP_INSERT     (1 << 17)
 #define CP_EXACT      (1 << 18)
 #define CP_EXACTSTR   (1 << 19)
+#define CP_PATMATCH   (1 << 20)
 
-#define CP_NUM              20
+#define CP_NUM              21
 
 #define CP_ALLMASK    ((1 << CP_NUM) - 1)
diff -u os/Zle/comp1.c Src/Zle/comp1.c
--- os/Zle/comp1.c	Tue Mar  2 11:51:40 1999
+++ Src/Zle/comp1.c	Tue Mar  2 13:43:54 1999
@@ -117,7 +117,8 @@
      *complist,
      *compinsert,
      *compexact,
-     *compexactstr;
+     *compexactstr,
+     *comppatmatch;
 
 /**/
 Param *comppms;
@@ -430,7 +431,7 @@
     compprefix = compsuffix = compiprefix = compmatcherstr = 
 	compcontext = compparameter = compredirect = compquote =
 	compquoting = comprestore = complist = compinsert =
-	compexact = compexactstr = NULL;
+	compexact = compexactstr = comppatmatch = NULL;
     makecompparamsptr = NULL;
     comp_setunsetptr = NULL;
     return 0;
@@ -474,6 +475,7 @@
     zsfree(compinsert);
     zsfree(compexact);
     zsfree(compexactstr);
+    zsfree(comppatmatch);
     return 0;
 }
 
diff -u os/Zle/compctl.c Src/Zle/compctl.c
--- os/Zle/compctl.c	Tue Mar  2 11:51:40 1999
+++ Src/Zle/compctl.c	Tue Mar  2 13:42:17 1999
@@ -1851,6 +1851,7 @@
     { "insert", PM_SCALAR, VAR(compinsert) },
     { "exact", PM_SCALAR, VAR(compexact) },
     { "exact_string", PM_SCALAR, VAR(compexactstr) },
+    { "pattern_match", PM_SCALAR, VAR(comppatmatch) },
     { NULL, 0, NULL }
 };
 
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Tue Mar  2 11:51:42 1999
+++ Src/Zle/zle_tricky.c	Tue Mar  2 13:41:15 1999
@@ -644,7 +644,8 @@
 		e++;
 	else if (iident(*e))
 	    while (iident(*e) ||
-		   (useglob && (*e == Star || *e == Quest)))
+		   (comppatmatch && *comppatmatch &&
+		    (*e == Star || *e == Quest)))
 		e++;
 
 	/* Now make sure that the cursor is inside the name. */
@@ -4036,7 +4037,7 @@
 		    llpl -= pl;
 		    lpre += pl;
 		}
-		if (isset(GLOBCOMPLETE)) {
+		if (comppatmatch && *comppatmatch) {
 		    char *tmp = (char *) zhalloc(2 + llpl + llsl);
 
 		    strcpy(tmp, lpre);
@@ -4949,7 +4950,7 @@
 			strcpy(p + o, psuf);
 
 			/* Do we have to use globbing? */
-			if (ispattern || (ns && isset(GLOBCOMPLETE))) {
+			if (ispattern || (ns && comppatmatch && *comppatmatch)) {
 			    /* Yes, so append a `*' if needed. */
 			    if (ns) {
 				int tl = strlen(p);
@@ -5004,6 +5005,8 @@
 	uselist = (useline ?
 		   ((isset(AUTOLIST) && !isset(BASHAUTOLIST)) ? 
 		    (isset(LISTAMBIGUOUS) ? 3 : 2) : 0) : 1);
+	zsfree(comppatmatch);
+	comppatmatch = ztrdup(useglob ? "yes" : "");
 	haspattern = 0;
 
 	/* Make sure we have the completion list and compctl. */
@@ -5097,7 +5100,7 @@
 	comppms = (Param *) zalloc(CP_NUM * sizeof(Param));
 
 	set = -1 & ~(CP_PARAMETER | CP_REDIRECT | CP_QUOTE | CP_QUOTING |
-		     CP_EXACTSTR);
+		     CP_EXACTSTR | (useglob ? 0 : CP_PATMATCH));
 	zsfree(compcontext);
 	zsfree(compparameter);
 	zsfree(compredirect);
@@ -6095,7 +6098,7 @@
 
     /* But if we were asked not to do glob completion, we never treat the *
      * thing as a pattern.                                                */
-    if (!useglob)
+    if (!comppatmatch || !*comppatmatch)
 	ispattern = 0;
 
     if (ispattern) {
@@ -6173,7 +6176,7 @@
 	/* And the suffix. */
 	fsuf = dupstrpfx(rsuf, s2 - rsuf);
 
-	if (useglob && (ispattern & 2)) {
+	if (comppatmatch && *comppatmatch && (ispattern & 2)) {
 	    int t2;
 
 	    /* We have to use globbing, so compute the pattern from *
diff -u od/Zsh/compwid.yo Doc/Zsh/compwid.yo
--- od/Zsh/compwid.yo	Tue Mar  2 13:56:22 1999
+++ Doc/Zsh/compwid.yo	Tue Mar  2 13:58:48 1999
@@ -193,6 +193,14 @@
 This is set to the string of an exact match if one was found and unset 
 otherwise.
 )
+item(tt(pattern_match))(
+If the option tt(GLOB_COMPLETE) is set, this is initially set to
+tt(yes) and unset otherwise. If the completion widget sets it to a
+non-empty string, the completion code will from then on behave as if
+tt(GLOB_COMPLETE) is set, i.e.. if the strings in tt(PREFIX) and
+tt(SUFFIX) contain unquoted metacharacters, they will be treated as
+patterns.
+)
 enditem()
 )
 enditem()

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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