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

Re: INTERACTIVE_COMMENTS regression



On Wed, 24 Jan 2018 14:50:23 +0100
İsmail Dönmez <ismail@xxxxxxxx> wrote:
> With the latest git head:
> 
> ~ > setopt INTERACTIVE_COMMENTS
> ~ > # ls
> <Press up arrow in keyboard>
> ~ > setopt INTERACTIVE_COMMENT
> 
> Looks like comment is getting lost, tested the same config with zsh
> 5.3.1 and it works fine.

This isn't particularly elegant but it ought to do the trick.
(Although when I commit it I might change the name of the
variable to "hist_keep_comment" for clarity, come to think of it.)

pws


diff --git a/Src/hist.c b/Src/hist.c
index e08984f..76c3df4 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -204,6 +204,9 @@ int hlinesz;
  
 static zlong defev;
 
+/* Flag that line was aborted but we want to keep it even if no words */
+static int hist_aborted;
+
 /* Remember the last line in the history file so we can find it again. */
 static struct histfile_stats {
     char *text;
@@ -258,6 +261,7 @@ hist_context_save(struct hist_stack *hs, int toplevel)
     hs->addtoline = addtoline;
     hs->hlinesz = hlinesz;
     hs->defev = defev;
+    hs->hist_aborted = hist_aborted;
     /*
      * We save and restore the command stack with history
      * as it's visible to the user interactively, so if
@@ -303,6 +307,7 @@ hist_context_restore(const struct hist_stack *hs, int toplevel)
     addtoline = hs->addtoline;
     hlinesz = hs->hlinesz;
     defev = hs->defev;
+    hist_aborted = hs->hist_aborted;
     if (cmdstack)
 	zfree(cmdstack, CMDSTACKSZ);
     cmdstack = hs->cstack;
@@ -1462,7 +1467,7 @@ hend(Eprog prog)
 	    } else
 		save = 0;
 	}
-	if (chwordpos <= 2)
+	if (chwordpos <= 2 && !hist_aborted)
 	    save = 0;
 	else if (should_ignore_line(prog))
 	    save = -1;
@@ -1565,6 +1570,7 @@ hend(Eprog prog)
      */
     while (histsave_stack_pos > stack_pos)
 	pophiststack();
+    hist_aborted = 0;
     unqueue_signals();
     return !(flag & HISTFLAG_NOEXEC || errflag);
 }
@@ -1591,6 +1597,7 @@ ihwabort(void)
 {
     if (chwordpos%2)
 	chwordpos--;
+    hist_aborted = 1;
 }
 
 /* add a word to the history List */
diff --git a/Src/zsh.h b/Src/zsh.h
index ba2f8cd..8bc0125 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2997,6 +2997,7 @@ struct hist_stack {
     void (*addtoline) _((int));
     unsigned char *cstack;
     int csp;
+    int hist_aborted;
 };
 
 /*



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