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: Command substitution parsing issues (not really Re: completion)
Date: Sun, 18 Jan 2015 16:36:04 +0000	[thread overview]
Message-ID: <20150118163604.37a0a75a@ntlworld.com> (raw)
In-Reply-To: <150116185732.ZM30791@torch.brasslantern.com>

On Fri, 16 Jan 2015 18:57:32 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> And history recall screws up with aliases:
> 
> schaefer<501> echo $(ls)        
> Config/ config.modules config.status* Etc/ Src/ config.h config.modules.local
> core.28047 foo/ stamp-h config.log config.modules.sh Doc/ Makefile Test/
> schaefer<502> echo $(lsls -CF)

This fixes this but not the issue with completion when there's an alias
in the command substitution.

pws

diff --git a/Src/hist.c b/Src/hist.c
index e5c48db..11d9722 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -329,7 +329,16 @@ static void
 ihwaddc(int c)
 {
     /* Only if history line exists and lexing has not finished. */
-    if (chline && !(errflag || lexstop)) {
+    if (chline && !(errflag || lexstop) &&
+	/*
+	 * If we're reading inside a word for command substitution
+	 * we allow the lexer to expand aliases but don't deal
+	 * with them here.  Note matching code in ihungetc().
+	 * TBD: it might be neater to deal with all aliases in this
+	 * fashion as we never need the expansion in the history
+	 * line, only in the lexer and above.
+	 */
+	!((histactive & HA_INWORD) && (inbufflags & INP_ALIAS))) {
 	/* Quote un-expanded bangs in the history line. */
 	if (c == bangchar && stophist < 2 && qbang)
 	    /* If qbang is not set, we do not escape this bangchar as it's *
@@ -892,11 +901,16 @@ ihungetc(int c)
 	    zlemetall--;
 	    exlast++;
 	}
-	DPUTS(hptr <= chline, "BUG: hungetc attempted at buffer start");
-	hptr--;
-	DPUTS(*hptr != (char) c, "BUG: wrong character in hungetc() ");
-	qbang = (c == bangchar && stophist < 2 &&
-		 hptr > chline && hptr[-1] == '\\');
+	if (!(histactive & HA_INWORD) || !(inbufflags & INP_ALIAS)) {
+	    DPUTS(hptr <= chline, "BUG: hungetc attempted at buffer start");
+	    hptr--;
+	    DPUTS(*hptr != (char) c, "BUG: wrong character in hungetc() ");
+	    qbang = (c == bangchar && stophist < 2 &&
+		     hptr > chline && hptr[-1] == '\\');
+	} else {
+	    /* No active bangs in aliases */
+	    qbang = 0;
+	}
 	if (doit)
 	    inungetc(c);
 	if (!qbang)
diff --git a/Src/lex.c b/Src/lex.c
index 6d45c70..e4dfdfa 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1674,7 +1674,7 @@ parse_subst_string(char *s)
 /* Called below to report word positions. */
 
 /**/
-mod_export void
+static void
 gotword(void)
 {
     we = zlemetall + 1 - inbufct + (addedx == 2 ? 1 : 0);


  parent reply	other threads:[~2015-01-18 16:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-17  0:19 completion Ray Andrews
2015-01-17  2:57 ` Command substitution parsing issues (not really Re: completion) Bart Schaefer
2015-01-17  3:29   ` Ray Andrews
2015-01-17 13:25     ` Vin Shelton
2015-01-19 10:29     ` Peter Stephenson
2015-01-19 10:39       ` Peter Stephenson
2015-01-22  0:34       ` make check problem Ray Andrews
2015-01-22  8:49         ` Peter Stephenson
2015-01-22 16:00           ` Ray Andrews
2015-01-22 16:40         ` Jun T.
2015-01-22 17:38           ` Ray Andrews
2015-01-22 17:56             ` Bart Schaefer
2015-01-22 18:24               ` Ray Andrews
2015-01-23  4:02                 ` Bart Schaefer
2015-01-23  4:48                   ` Ray Andrews
2015-01-22 19:04               ` --enable-pcre and regex comparison (Was: make check problem) Lawrence Velázquez
2015-01-23  4:04                 ` Bart Schaefer
2015-01-18 16:36   ` Peter Stephenson [this message]
2015-01-18 17:31   ` Command substitution parsing issues (not really Re: completion) Peter Stephenson
2015-01-18 22:34     ` Peter Stephenson

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=20150118163604.37a0a75a@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).