* Aborted command saved in history @ 2016-01-28 1:06 Mikael Magnusson 2016-01-28 5:45 ` Bart Schaefer 0 siblings, 1 reply; 4+ messages in thread From: Mikael Magnusson @ 2016-01-28 1:06 UTC (permalink / raw) To: zsh workers If i type {<enter> and press ctrl-c, the " {" is saved in my history file without consulting zshaddhistory() (which would not have added a line starting with a space) and despite the line being aborted. I found this surprising. It also happens in zsh -f. -- Mikael Magnusson ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Aborted command saved in history 2016-01-28 1:06 Aborted command saved in history Mikael Magnusson @ 2016-01-28 5:45 ` Bart Schaefer 2016-01-28 6:56 ` Mikael Magnusson 0 siblings, 1 reply; 4+ messages in thread From: Bart Schaefer @ 2016-01-28 5:45 UTC (permalink / raw) To: zsh workers On Jan 28, 2:06am, Mikael Magnusson wrote: } } If i type } {<enter> } and press ctrl-c, the " {" is saved in my history file without } consulting zshaddhistory() zshaddhistory is consulted, it just immediately returns without doing anything because the error condition from the keyboard interrupt is still persisting. I'm a little reluctant to push this down into callhookfunc() because it may be the right thing in other contexts that an error condition prevents hooks from running? Although if that's true we could save a lot of no-op doshfunc() calls by testing errflag in callhookfunc(). Moved hookargs to the closer scope because why not, and so that the newlinklist() happens inside queue_signals(). diff --git a/Src/hist.c b/Src/hist.c index 007366a..7f9e4db 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -1378,7 +1378,6 @@ should_ignore_line(Eprog prog) mod_export int hend(Eprog prog) { - LinkList hookargs = newlinklist(); int flag, hookret, stack_pos = histsave_stack_pos; /* * save: @@ -1418,9 +1417,17 @@ hend(Eprog prog) DPUTS(hptr < chline, "History end pointer off start of line"); *hptr = '\0'; } - addlinknode(hookargs, "zshaddhistory"); - addlinknode(hookargs, chline); - callhookfunc("zshaddhistory", hookargs, 1, &hookret); + { + LinkList hookargs = newlinklist(); + int save_errflag = errflag; + errflag = 0; + + addlinknode(hookargs, "zshaddhistory"); + addlinknode(hookargs, chline); + callhookfunc("zshaddhistory", hookargs, 1, &hookret); + + errflag |= save_errflag; + } /* For history sharing, lock history file once for both read and write */ hf = getsparam("HISTFILE"); if (isset(SHAREHISTORY) && !lockhistfile(hf, 0)) { ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Aborted command saved in history 2016-01-28 5:45 ` Bart Schaefer @ 2016-01-28 6:56 ` Mikael Magnusson 2016-01-28 7:26 ` Bart Schaefer 0 siblings, 1 reply; 4+ messages in thread From: Mikael Magnusson @ 2016-01-28 6:56 UTC (permalink / raw) To: Bart Schaefer; +Cc: zsh workers On Thu, Jan 28, 2016 at 6:45 AM, Bart Schaefer <schaefer@brasslantern.com> wrote: > On Jan 28, 2:06am, Mikael Magnusson wrote: > } > } If i type > } {<enter> > } and press ctrl-c, the " {" is saved in my history file without > } consulting zshaddhistory() > > zshaddhistory is consulted, it just immediately returns without doing > anything because the error condition from the keyboard interrupt is > still persisting. Ah, I only checked with an echo. Is it expected that the line is saved at all though? If you do a get-line and then ctrl-c twice, it is not saved, so a possible argument that "you accepted the first part of the line when you pressed enter" seems a bit weak to me. Usually when I get a continuation prompt it's because I mistyped something, so I press ctrl-c to get out of the continuation and then retrieve it with uparrow and try again. Saving all these mistakes in the history doesn't seem useful, and I don't see any reasonable way that zshaddhistory would be able to tell that it was a continuation line? -- Mikael Magnusson ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Aborted command saved in history 2016-01-28 6:56 ` Mikael Magnusson @ 2016-01-28 7:26 ` Bart Schaefer 0 siblings, 0 replies; 4+ messages in thread From: Bart Schaefer @ 2016-01-28 7:26 UTC (permalink / raw) To: zsh workers On Jan 28, 7:56am, Mikael Magnusson wrote: } } Is it expected that the line is saved [on keyboard interrupt] } at all though? If you do a get-line and then ctrl-c twice, it is not } saved, so a possible argument that "you accepted the first part of the } line when you pressed enter" seems a bit weak to me. The decision is made based on whether the parser returned anything. In the PS2 prompt case, the parser was invoked upon the first accept-line, whereas in the get-line case the parser was never invoked at all. This is how it has always worked (and I believe also how history is handled in csh, whence this is all derived) but I'm not averse to someone investigating how to change it. I just don't plan to do so myself. Incidentally ZLE_LINE_ABORTED only gets the part that hasn't already been through the parser, e.g. from the PS2 prompt in the first example. If we remove the "prebuffer" from the history, we should put it into ZLE_LINE_ABORTED instead. Although I suspect that might confuse some uses of ZLE_LINE_ABORTED. } Usually when I get a continuation prompt it's because I mistyped } something, so I press ctrl-c to get out of the continuation and then } retrieve it with uparrow and try again. Incidentally this is exactly what push-line-or-edit is for, and is very nearly what it does. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-01-28 7:25 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-01-28 1:06 Aborted command saved in history Mikael Magnusson 2016-01-28 5:45 ` Bart Schaefer 2016-01-28 6:56 ` Mikael Magnusson 2016-01-28 7:26 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).