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

Re: lexer issue



On Sat, 31 Mar 2018 18:17:21 +0100
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> When we  do the recursive parse of the command subst we
> abort and flush the history on failure. But inside a string it
> doesn't bother finishing off the history line. That's important in
> this case because we're using that line directly as the string
> we get from the nested lex.

Here's the patch.  Second test release will follow.

pws

diff --git a/Src/hist.c b/Src/hist.c
index b798be8..dbdc1e4 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -465,8 +465,26 @@ herrflush(void)
 {
     inpopalias();
 
-    while (!lexstop && inbufct && !strin)
-	hwaddc(ingetc());
+    if (lexstop)
+	return;
+    /*
+     * The lex_add_raw test is needed if we are parsing a command
+     * substitution when expanding history for ZLE: strin is set but we
+     * need to finish off the input because the string we are reading is
+     * going to be used directly in the line that goes to ZLE.
+     *
+     * Note that this is a side effect --- this is not the usual reason
+     * for testing lex_add_raw which is to add the text to a different
+     * buffer used when we are actually parsing the command substituion
+     * (nothing to do with ZLE).  Sorry.
+     */
+    while (inbufct && (!strin || lex_add_raw)) {
+	int c = ingetc();
+	if (!lexstop) {
+	    hwaddc(c);
+	    addtoline(c);
+	}
+    }
 }
 
 /*
diff --git a/Src/lex.c b/Src/lex.c
index 2379804..44ad880 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -158,7 +158,7 @@ mod_export int nocomments;
 /* add raw input characters while parsing command substitution */
 
 /**/
-static int lex_add_raw;
+int lex_add_raw;
 
 /* variables associated with the above */
 
diff --git a/Test/X03zlebindkey.ztst b/Test/X03zlebindkey.ztst
index 013d3df..298d7df 100644
--- a/Test/X03zlebindkey.ztst
+++ b/Test/X03zlebindkey.ztst
@@ -126,3 +126,20 @@
 >CURSOR: 1
 >BUFFER: ホ
 >CURSOR: 1
+
+  zpty_run 'bindkey " " magic-space'
+  setopt interactivecomments
+  zletest 'echo $(( x ) x ) y'
+  zletest 'echo $(( ##x ) ##x ) y'
+  unsetopt interactivecomments
+  zletest 'echo $(( x ) x ) y'
+  zletest 'echo $(( ##x ) ##x ) y'
+0:history expansion of failed command substitution using magic-space binding
+>BUFFER: echo $(( x ) x ) y
+>CURSOR: 18
+>BUFFER: echo $(( ##x ) ##x ) y
+>CURSOR: 22
+>BUFFER: echo $(( x ) x ) y
+>CURSOR: 18
+>BUFFER: echo $(( ##x ) ##x ) y
+>CURSOR: 22



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