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(-) 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 1.4.1