diff options
Diffstat (limited to 'Src/hist.c')
-rw-r--r-- | Src/hist.c | 68 |
1 files changed, 39 insertions, 29 deletions
diff --git a/Src/hist.c b/Src/hist.c index a1bc73636..f856eedff 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -130,8 +130,7 @@ mod_export int hist_skip_flags; /* Bits of histactive variable */ #define HA_ACTIVE (1<<0) /* History mechanism is active */ -#define HA_NOSTORE (1<<1) /* Don't store the line when finished */ -#define HA_NOINC (1<<2) /* Don't store, curhist not incremented */ +#define HA_NOINC (1<<1) /* Don't store, curhist not incremented */ /* Array of word beginnings and endings in current history line. */ @@ -180,6 +179,30 @@ int hlinesz; static zlong defev; +/* Remember the last line in the history file so we can find it again. */ +static struct histfile_stats { + char *text; + time_t stim, mtim; + off_t fpos, fsiz; + zlong next_write_ev; +} lasthist; + +static struct histsave { + struct histfile_stats lasthist; + char *histfile; + HashTable histtab; + Histent hist_ring; + zlong curhist; + zlong histlinect; + zlong histsiz; + zlong savehistsiz; + int locallevel; +} *histsave_stack; +static int histsave_stack_size = 0; +static int histsave_stack_pos = 0; + +static zlong histfile_linect; + /* add a character to the current history word */ static void @@ -1082,7 +1105,8 @@ should_ignore_line(Eprog prog) mod_export int hend(Eprog prog) { - int flag, save = 1; + LinkList hookargs = newlinklist(); + int flag, save = 1, hookret, stack_pos = histsave_stack_pos; char *hf; DPUTS(stophist != 2 && !(inbufflags & INP_ALIAS) && !chline, @@ -1092,7 +1116,7 @@ hend(Eprog prog) settyinfo(&shttyinfo); if (!(histactive & HA_NOINC)) unlinkcurline(); - if (histactive & (HA_NOSTORE|HA_NOINC)) { + if (histactive & HA_NOINC) { zfree(chline, hlinesz); zfree(chwords, chwordlen*sizeof(short)); chline = NULL; @@ -1103,6 +1127,10 @@ hend(Eprog prog) if (hist_ignore_all_dups != isset(HISTIGNOREALLDUPS) && (hist_ignore_all_dups = isset(HISTIGNOREALLDUPS)) != 0) histremovedups(); + + addlinknode(hookargs, "zshaddhistory"); + addlinknode(hookargs, chline); + callhookfunc("zshaddhistory", hookargs, 1, &hookret); /* For history sharing, lock history file once for both read and write */ hf = getsparam("HISTFILE"); if (isset(SHAREHISTORY) && lockhistfile(hf, 0)) { @@ -1123,7 +1151,7 @@ hend(Eprog prog) } if (chwordpos <= 2) save = 0; - else if (should_ignore_line(prog)) + else if (hookret || should_ignore_line(prog)) save = -1; } if (flag & (HISTFLAG_DONE | HISTFLAG_RECALL)) { @@ -1203,6 +1231,12 @@ hend(Eprog prog) if (isset(SHAREHISTORY)? histfileIsLocked() : isset(INCAPPENDHISTORY)) savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST); unlockhistfile(hf); /* It's OK to call this even if we aren't locked */ + /* + * No good reason for the user to push the history more than once, but + * it's easy to be tidy... + */ + while (histsave_stack_pos > stack_pos) + pophiststack(); unqueue_signals(); return !(flag & HISTFLAG_NOEXEC || errflag); } @@ -1942,30 +1976,6 @@ resizehistents(void) } } -/* Remember the last line in the history file so we can find it again. */ -static struct histfile_stats { - char *text; - time_t stim, mtim; - off_t fpos, fsiz; - zlong next_write_ev; -} lasthist; - -static struct histsave { - struct histfile_stats lasthist; - char *histfile; - HashTable histtab; - Histent hist_ring; - zlong curhist; - zlong histlinect; - zlong histsiz; - zlong savehistsiz; - int locallevel; -} *histsave_stack; -static int histsave_stack_size = 0; -static int histsave_stack_pos = 0; - -static zlong histfile_linect; - static int readhistline(int start, char **bufp, int *bufsiz, FILE *in) { |