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

Re: Command substitution parsing issues (not really Re: completion)



On Fri, 16 Jan 2015 18:57:32 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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);



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