zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: PATCH: configurability of pattern characters, part 2
Date: Sun, 9 Jun 2013 19:06:58 +0100	[thread overview]
Message-ID: <20130609190658.5ac533e3@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20130604094447.1260b2d5@pwslap01u.europe.root.pri>

On Tue, 04 Jun 2013 09:44:47 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Mon, 03 Jun 2013 23:45:39 -0700
> Bart Schaefer <schaefer@brasslantern.com> 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@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


      parent reply	other threads:[~2013-06-09 18:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-31 23:29 PATCH: configurability of pattern characters, part 1 Peter Stephenson
2013-06-01  6:22 ` Bart Schaefer
2013-06-01 20:18   ` Peter Stephenson
2013-06-02  7:16     ` Bart Schaefer
2013-06-03  8:40       ` Peter Stephenson
2013-06-03 15:05         ` Bart Schaefer
2013-06-03 15:31           ` Peter Stephenson
2013-06-01 23:09   ` PATCH: configurability of pattern characters, part 2 Peter Stephenson
2013-06-04  6:45     ` Bart Schaefer
2013-06-04  8:44       ` Peter Stephenson
2013-06-04 14:50         ` Bart Schaefer
2013-06-04 15:09           ` Peter Stephenson
2013-06-09 18:06         ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130609190658.5ac533e3@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).