From 7d4b41b52aeabb6f6f95f9bdfdab96b5fd66909a Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sat, 23 Sep 2017 19:23:53 +0100 Subject: 41747: Don't create hash entry if just checking existence. Pass a flag in indicating this case. --- Src/hist.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Src/hist.c') diff --git a/Src/hist.c b/Src/hist.c index da5a8b29f..177250f31 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -1083,7 +1083,6 @@ hbegin(int dohist) } else histactive = HA_ACTIVE | HA_NOINC; - hf = getsparam("HISTFILE"); /* * For INCAPPENDHISTORYTIME, when interactive, save the history here * as it gives a better estimate of the times of commands. @@ -1104,8 +1103,10 @@ hbegin(int dohist) */ if (isset(INCAPPENDHISTORYTIME) && !isset(SHAREHISTORY) && !isset(INCAPPENDHISTORY) && - !(histactive & HA_NOINC) && !strin && histsave_stack_pos == 0) + !(histactive & HA_NOINC) && !strin && histsave_stack_pos == 0) { + hf = getsparam("HISTFILE"); savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST); + } } /**/ -- cgit v1.2.3 From 36fcaeb16799738631d4519e74d2e6398478776d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 8 Jan 2018 17:25:04 +0000 Subject: 42245: Abort last word on interactve comment. Last recorded word should be the previous one. --- ChangeLog | 5 +++++ Src/hist.c | 22 ++++++++++++++++++++++ Src/lex.c | 2 +- Src/zsh.h | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) (limited to 'Src/hist.c') diff --git a/ChangeLog b/ChangeLog index 72d243d80..ad9bf98e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-01-08 Peter Stephenson + + * 42245: Src/hist.c, Src/lex.c, Src/zsh.h: Abort last word on + interactive comment to avoid it becoming a useless word. + 2018-01-05 Oliver Kiddle * dana: 42231: Completion/Darwin/Command/_caffeinate, diff --git a/Src/hist.c b/Src/hist.c index 177250f31..e08984f00 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -45,6 +45,9 @@ void (*hwaddc) _((int)); /**/ void (*hwbegin) _((int)); +/**/ +void (*hwabort) _((void)); + /**/ void (*hwend) _((void)); @@ -250,6 +253,7 @@ hist_context_save(struct hist_stack *hs, int toplevel) hs->hungetc = hungetc; hs->hwaddc = hwaddc; hs->hwbegin = hwbegin; + hs->hwabort = hwabort; hs->hwend = hwend; hs->addtoline = addtoline; hs->hlinesz = hlinesz; @@ -294,6 +298,7 @@ hist_context_restore(const struct hist_stack *hs, int toplevel) hungetc = hs->hungetc; hwaddc = hs->hwaddc; hwbegin = hs->hwbegin; + hwabort = hs->hwabort; hwend = hs->hwend; addtoline = hs->addtoline; hlinesz = hs->hlinesz; @@ -985,6 +990,11 @@ nohw(UNUSED(int c)) { } +static void +nohwabort(void) +{ +} + static void nohwe(void) { @@ -1057,6 +1067,7 @@ hbegin(int dohist) hungetc = inungetc; hwaddc = nohw; hwbegin = nohw; + hwabort = nohwabort; hwend = nohwe; addtoline = nohw; } else { @@ -1066,6 +1077,7 @@ hbegin(int dohist) hungetc = ihungetc; hwaddc = ihwaddc; hwbegin = ihwbegin; + hwabort = ihwabort; hwend = ihwend; addtoline = iaddtoline; if (!isset(BANGHIST)) @@ -1571,6 +1583,16 @@ ihwbegin(int offset) chwords[chwordpos++] = hptr - chline + offset; } +/* Abort current history word, not needed */ + +/**/ +void +ihwabort(void) +{ + if (chwordpos%2) + chwordpos--; +} + /* add a word to the history List */ /**/ diff --git a/Src/lex.c b/Src/lex.c index c2a59661c..2379804f2 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -677,7 +677,7 @@ gettok(void) (char *)hcalloc(lexbuf.siz = LEX_HEAP_SIZE); add(c); } - hwend(); + hwabort(); while ((c = ingetc()) != '\n' && !lexstop) { hwaddc(c); addtoline(c); diff --git a/Src/zsh.h b/Src/zsh.h index 92f75769a..ba2f8cd9f 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2992,6 +2992,7 @@ struct hist_stack { void (*hungetc) _((int)); void (*hwaddc) _((int)); void (*hwbegin) _((int)); + void (*hwabort) _((void)); void (*hwend) _((void)); void (*addtoline) _((int)); unsigned char *cstack; -- cgit v1.2.3 From 758966502caa6f91abcbaaebf2610609250de1fb Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 24 Jan 2018 17:40:56 +0000 Subject: 42322 (tweaked): Fix interactive_comments history with just a coment. Don't discard the line from the history merely because it produced no synactic words. --- ChangeLog | 7 +++++++ Src/hist.c | 13 ++++++++++++- Src/zsh.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'Src/hist.c') diff --git a/ChangeLog b/ChangeLog index 3037edda4..31b0dea64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2018-01-24 Peter Stephenson + + * 42322 (tweaked): Src/hist.c, Src/zsh.h: don't discard a + history line with just an interactive comment simply because + there were no words, since the comment now doesn't produce + words. + 2018-01-23 Barton E. Schaefer * Joey Pabalinas: 42313: Src/subst.c: avoid null-pointer deref diff --git a/Src/hist.c b/Src/hist.c index e08984f00..b798be8e4 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -204,6 +204,13 @@ int hlinesz; static zlong defev; +/* + * Flag that we stopped reading line when we got to a comment, + * but we want to keep it in the histofy even if there were no words + * (i.e. the comment was the entire line). + */ +static int hist_keep_comment; + /* Remember the last line in the history file so we can find it again. */ static struct histfile_stats { char *text; @@ -258,6 +265,7 @@ hist_context_save(struct hist_stack *hs, int toplevel) hs->addtoline = addtoline; hs->hlinesz = hlinesz; hs->defev = defev; + hs->hist_keep_comment = hist_keep_comment; /* * We save and restore the command stack with history * as it's visible to the user interactively, so if @@ -303,6 +311,7 @@ hist_context_restore(const struct hist_stack *hs, int toplevel) addtoline = hs->addtoline; hlinesz = hs->hlinesz; defev = hs->defev; + hist_keep_comment = hs->hist_keep_comment; if (cmdstack) zfree(cmdstack, CMDSTACKSZ); cmdstack = hs->cstack; @@ -1462,7 +1471,7 @@ hend(Eprog prog) } else save = 0; } - if (chwordpos <= 2) + if (chwordpos <= 2 && !hist_keep_comment) save = 0; else if (should_ignore_line(prog)) save = -1; @@ -1565,6 +1574,7 @@ hend(Eprog prog) */ while (histsave_stack_pos > stack_pos) pophiststack(); + hist_keep_comment = 0; unqueue_signals(); return !(flag & HISTFLAG_NOEXEC || errflag); } @@ -1591,6 +1601,7 @@ ihwabort(void) { if (chwordpos%2) chwordpos--; + hist_keep_comment = 1; } /* add a word to the history List */ diff --git a/Src/zsh.h b/Src/zsh.h index ba2f8cd9f..8b4898477 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_keep_comment; }; /* -- cgit v1.2.3 From 3517e4a9a5caf2c3385a0b223a0474724c703d96 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 4 Apr 2018 18:33:00 +0100 Subject: 42581(?): Fix ZLE inline history expansion. Seen with magic-space. If there's a parse error in command subtitution we need to complete reading history to ensure the command line buffer is finished. --- ChangeLog | 6 ++++++ Src/hist.c | 22 ++++++++++++++++++++-- Src/lex.c | 2 +- Test/X03zlebindkey.ztst | 17 +++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) (limited to 'Src/hist.c') diff --git a/ChangeLog b/ChangeLog index a2e83fb6e..b3eef2519 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-04-04 Peter Stephenson + + * 42581(?): Src/hist.c, Src/lex.c, Test/X03zlebindkey.ztst: history + expansion within ZLE needs history to be read to conclusion on + error. + 2018-03-31 Oliver Kiddle * 42572: Completion/Linux/Command/_ethtool, diff --git a/Src/hist.c b/Src/hist.c index b798be8e4..dbdc1e4e5 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 2379804f2..44ad88043 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 013d3dfb3..298d7df5d 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 -- cgit v1.2.3