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

Re: PATCH: configurability of pattern characters, part 2



On Tue, 04 Jun 2013 09:44:47 +0100
Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Mon, 03 Jun 2013 23:45:39 -0700
> Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > schaefer<503> disable -p \*
> > schaefer<504> print *
> > zsh: no match
> 
> I think that's because I haven't yet got around to haswilds(), so it
> thinks there are patterns in it, but finds they don't turn into
> anything.  haswilds() is going to have to expand somewhat.

This fixes haswilds() and completion.  This should render the original
patch basically functional, however I think it needs a little work
within pattern.c to render disabling of features associated with
parentheses working (to be clear: I don't expect any existing feature to
be broken by anything I've done so far).  As I noted somewhere in the
documentation, I'm not planning on making the pattern enables and
disables affect parsing, just whether the pattern is used as a pattern.

Once I've fixed parentheses and written some tests that should be it.

diff --git a/Completion/compinit b/Completion/compinit
index 7b8a346..f9d2c57 100644
--- a/Completion/compinit
+++ b/Completion/compinit
@@ -163,8 +163,9 @@ _comp_options=(
 
 typeset -g _comp_setup='local -A _comp_caller_options;
              _comp_caller_options=(${(kv)options[@]});
-             setopt localoptions localtraps ${_comp_options[@]};
+             setopt localoptions localtraps localpatterns ${_comp_options[@]};
              local IFS=$'\'\ \\t\\r\\n\\0\''
+             enable -p \| \~ \( \? \* \[ \< \^ \#
              exec </dev/null;
              trap - ZERR
              local -a reply
diff --git a/Src/glob.c b/Src/glob.c
index db86d24..0defb1a 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -445,41 +445,6 @@ insert(char *s, int checked)
     unqueue_signals();
 }
 
-/* Check to see if str is eligible for filename generation. */
-
-/**/
-mod_export int
-haswilds(char *str)
-{
-    /* `[' and `]' are legal even if bad patterns are usually not. */
-    if ((*str == Inbrack || *str == Outbrack) && !str[1])
-	return 0;
-
-    /* If % is immediately followed by ?, then that ? is     *
-     * not treated as a wildcard.  This is so you don't have *
-     * to escape job references such as %?foo.               */
-    if (str[0] == '%' && str[1] == Quest)
-	str[1] = '?';
-
-    for (; *str; str++) {
-	switch (*str) {
-	    case Inpar:
-	    case Bar:
-	    case Star:
-	    case Inbrack:
-	    case Inang:
-	    case Quest:
-		return 1;
-	    case Pound:
-	    case Hat:
-		if (isset(EXTENDEDGLOB))
-		    return 1;
-		break;
-	}
-    }
-    return 0;
-}
-
 /* Do the globbing:  scanner is called recursively *
  * with successive bits of the path until we've    *
  * tried all of it.                                */
diff --git a/Src/pattern.c b/Src/pattern.c
index a90d3cd..b7897e7 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -3966,3 +3966,78 @@ clearpatterndisables(void)
 {
     memset(zpc_disables, 0, ZPC_COUNT);
 }
+
+
+/* Check to see if str is eligible for filename generation. */
+
+/**/
+mod_export int
+haswilds(char *str)
+{
+    char *start;
+
+    /* `[' and `]' are legal even if bad patterns are usually not. */
+    if ((*str == Inbrack || *str == Outbrack) && !str[1])
+	return 0;
+
+    /* If % is immediately followed by ?, then that ? is     *
+     * not treated as a wildcard.  This is so you don't have *
+     * to escape job references such as %?foo.               */
+    if (str[0] == '%' && str[1] == Quest)
+	str[1] = '?';
+
+    /*
+     * Note that at this point zpc_special has not been set up.
+     */
+    start = str;
+    for (; *str; str++) {
+	switch (*str) {
+	    case Inpar:
+		if ((!isset(SHGLOB) && !zpc_disables[ZPC_INPAR]) ||
+		    (str > start && isset(KSHGLOB) &&
+		     ((str[-1] == Quest && !zpc_disables[ZPC_KSH_QUEST]) ||
+		      (str[-1] == Star && !zpc_disables[ZPC_KSH_STAR]) ||
+		      (str[-1] == '+' && !zpc_disables[ZPC_KSH_PLUS]) ||
+		      (str[-1] == '!' && !zpc_disables[ZPC_KSH_BANG]) ||
+		      (str[-1] == '@' && !zpc_disables[ZPC_KSH_AT]))))
+		    return 1;
+		break;
+
+	    case Bar:
+		if (!zpc_disables[ZPC_BAR])
+		    return 1;
+		break;
+
+	    case Star:
+		if (!zpc_disables[ZPC_STAR])
+		    return 1;
+		break;
+
+	    case Inbrack:
+		if (!zpc_disables[ZPC_INBRACK])
+		    return 1;
+		break;
+
+	    case Inang:
+		if (!zpc_disables[ZPC_INANG])
+		    return 1;
+		break;
+
+	    case Quest:
+		if (!zpc_disables[ZPC_QUEST])
+		    return 1;
+		break;
+
+	    case Pound:
+		if (isset(EXTENDEDGLOB) && !zpc_disables[ZPC_HASH])
+		    return 1;
+		break;
+
+	    case Hat:
+		if (isset(EXTENDEDGLOB) && !zpc_disables[ZPC_HAT])
+		    return 1;
+		break;
+	}
+    }
+    return 0;
+}

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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