zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: _expand_alias does not expand aliases that contain an "!"
Date: Wed, 01 Oct 2014 22:20:31 -0700	[thread overview]
Message-ID: <141001222031.ZM11273@torch.brasslantern.com> (raw)
In-Reply-To: <141001181118.ZM6305@torch.brasslantern.com>

On Oct 1,  6:11pm, Bart Schaefer wrote:
} Subject: Re: _expand_alias does not expand aliases that contain an "!"
}
} On Oct 1,  5:39pm, Peter Stephenson wrote:
} } Subject: Re: _expand_alias does not expand aliases that contain an "!"
} }
} } > new makebangspecial() can be called from histcharsetfn() instead of
} } > doing a full inittyptab().
} } 
} } That certainly sounds possible, if you know where to put those calls.
} } 
} } Here's the other proposal, done entirely local to inittyptab(), and
} } untested.
} 
} This looks fine, though it doesn't solve the problem of needing to turn
} off special-ness during completion.
} 
} Let me see if I can produce a patch for this (and back out the changes
} to _expand_alias) before you do 5.0.7.

OK, here's that patch.  This starts with PWS's patch from 33311, merges
the semantics of specialcomma into typtab_flags (which sadly becomes
global to replace specialcomma) and adds makebangspecial(yesno), which
is then used in the smallest sensible scope in compcall().

There may be other places where makebangspecial() should be called, but
I don't think it's correct to blanket docompletion() with it the way
makecommaspecial() is used.  In fact that makecommaspecial() scope may
be too wide leading to other bugs, but I'm not going to mess with that
at this point.

Also add signal safety for inittyptab(), since we're munging globals.

All tests pass and the 'gc!' alias expansion from the original thread
now works as expected.

diff --git a/Completion/Base/Completer/_expand_alias b/Completion/Base/Completer/_expand_alias
index 9064ce8..8240e41 100644
--- a/Completion/Base/Completer/_expand_alias
+++ b/Completion/Base/Completer/_expand_alias
@@ -25,8 +25,6 @@ else
   pre=(_main_complete - aliases)
 fi
 
-[[ "$compstate[quoting]" = (single|double) ]] || word="${(Q)word}"
-
 zstyle -s ":completion:${curcontext}:" regular tmp || tmp=yes
 case $tmp in
 always) sel=r;;
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index ac7785a..35d410c 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -702,6 +702,7 @@ callcompfunc(char *s, char *fn)
 	}
 	zsfree(compprefix);
 	zsfree(compsuffix);
+	makebangspecial(0);
 	if (unset(COMPLETEINWORD)) {
 	    tmp = (linwhat == IN_MATH ? dupstring(s) : multiquote(s, 0));
 	    untokenize(tmp);
@@ -722,6 +723,7 @@ callcompfunc(char *s, char *fn)
 	    untokenize(ss);
 	    compsuffix = ztrdup(ss);
 	}
+	makebangspecial(1);
         zsfree(complastprefix);
         zsfree(complastsuffix);
         complastprefix = ztrdup(compprefix);
diff --git a/Src/utils.c b/Src/utils.c
index 9109f66..e6eb8e6 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3424,12 +3424,12 @@ equalsplit(char *s, char **t)
     return 0;
 }
 
-static int specialcomma;
 
 /* the ztypes table */
 
 /**/
 mod_export short int typtab[256];
+static int typtab_flags = 0;
 
 /* initialize the ztypes table */
 
@@ -3440,8 +3440,15 @@ inittyptab(void)
     int t0;
     char *s;
 
-    for (t0 = 0; t0 != 256; t0++)
-	typtab[t0] = 0;
+    if (!(typtab_flags & ZTF_INIT)) {
+	typtab_flags = ZTF_INIT;
+	if (interact && isset(SHINSTDIN))
+	    typtab_flags |= ZTF_INTERACT;
+    }
+
+    queue_signals();
+
+    memset(typtab, 0, sizeof(typtab));
     for (t0 = 0; t0 != 32; t0++)
 	typtab[t0] = typtab[t0 + 128] = ICNTRL;
     typtab[127] = ICNTRL;
@@ -3514,20 +3521,43 @@ inittyptab(void)
 #endif
     for (s = SPECCHARS; *s; s++)
 	typtab[STOUC(*s)] |= ISPECIAL;
-    if (specialcomma)
+    if (typtab_flags & ZTF_SP_COMMA)
 	typtab[STOUC(',')] |= ISPECIAL;
-    if (isset(BANGHIST) && bangchar && interact && isset(SHINSTDIN))
+    if (isset(BANGHIST) && bangchar && (typtab_flags & ZTF_INTERACT)) {
+	typtab_flags |= ZTF_BANGCHAR;
 	typtab[bangchar] |= ISPECIAL;
+    } else
+	typtab_flags &= ~ZTF_BANGCHAR;
+
+    unqueue_signals();
 }
 
 /**/
 mod_export void
 makecommaspecial(int yesno)
 {
-    if ((specialcomma = yesno) != 0)
+    if (yesno != 0) {
+	typtab_flags |= ZTF_SP_COMMA;
 	typtab[STOUC(',')] |= ISPECIAL;
-    else
+    } else {
+	typtab_flags &= ~ZTF_SP_COMMA;
 	typtab[STOUC(',')] &= ~ISPECIAL;
+    }
+}
+
+/**/
+mod_export void
+makebangspecial(int yesno)
+{
+    /* Name and call signature for congruence with makecommaspecial(),
+     * but in this case when yesno is nonzero we defer to the state
+     * saved by inittyptab().
+     */ 
+    if (yesno == 0) {
+	typtab[bangchar] &= ~ISPECIAL;
+    } else if (typtab_flags & ZTF_BANGCHAR) {
+	typtab[bangchar] |= ISPECIAL;
+    }
 }
 
 
diff --git a/Src/ztype.h b/Src/ztype.h
index 14f6610..eef0f23 100644
--- a/Src/ztype.h
+++ b/Src/ztype.h
@@ -59,6 +59,15 @@
 #define iwsep(X) zistype(X,IWSEP)
 #define inull(X) zistype(X,INULL)
 
+/*
+ * Bit flags for typtab_flags --- preserved after
+ * shell initialisation.
+ */
+#define ZTF_INIT     (0x0001) /* One-off initialisation done */
+#define ZTF_INTERACT (0x0002) /* Shell interative and reading from stdin */
+#define ZTF_SP_COMMA (0x0004) /* Treat comma as a special characters */
+#define ZTF_BANGCHAR (0x0008) /* Treat bangchar as a special character */
+
 #ifdef MULTIBYTE_SUPPORT
 #define WC_ZISTYPE(X,Y) wcsitype((X),(Y))
 #define WC_ISPRINT(X)	iswprint(X)

-- 
Barton E. Schaefer


  reply	other threads:[~2014-10-02  5:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-26 16:50 Jonathan H
2014-08-30 20:32 ` Bart Schaefer
2014-08-31  2:58   ` Jonathan H
2014-08-31 20:50     ` Bart Schaefer
2014-09-14 18:30       ` Bart Schaefer
2014-09-14 20:55         ` Bart Schaefer
2014-10-01 14:03           ` Peter Stephenson
2014-10-01 14:06             ` Peter Stephenson
2014-10-01 14:15               ` Peter Stephenson
2014-10-01 16:29                 ` Bart Schaefer
2014-10-01 16:39                   ` Peter Stephenson
2014-10-02  1:11                     ` Bart Schaefer
2014-10-02  5:20                       ` Bart Schaefer [this message]
2014-09-23  5:59         ` Jonathan H

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=141001222031.ZM11273@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).