diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-12-31 05:30:46 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-12-31 05:30:46 -0800 |
commit | 51322f6c66d153d2f008a227c5e517f6fb34dbab (patch) | |
tree | e1df325a64c7c570e72f0dec8e7f2c765fc2b7b2 | |
parent | de3c3e1d083d4fde847505b4626467e2cb8d4cd6 (diff) | |
download | txr-51322f6c66d153d2f008a227c5e517f6fb34dbab.tar.gz txr-51322f6c66d153d2f008a227c5e517f6fb34dbab.tar.bz2 txr-51322f6c66d153d2f008a227c5e517f6fb34dbab.zip |
linenoise: submit and stay in history.
* linenoise/linenoise.c (struct lino_state): New member
save_hist_idx.
(edit): If save_hist_idx is set, jump to that history position
and clear it. Handle ENTER in extended (Ctrl-X) mode
similarly to regular ENTER, but setting save_hist_idx.
* txr.1: Documented.
-rw-r--r-- | linenoise/linenoise.c | 19 | ||||
-rw-r--r-- | txr.1 | 14 |
2 files changed, 33 insertions, 0 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 93f4bf6c..1dd7577d 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -89,6 +89,7 @@ struct lino_state { char *clip; /* Selection */ int ifd; /* Terminal stdin file descriptor. */ int ofd; /* Terminal stdout file descriptor. */ + int save_hist_idx; /* Jump to history position on entry into edit */ /* Volatile state pertaining to just one linenoise call */ char buf[LINENOISE_MAX_DISP]; /* Displayed line bufer. */ @@ -1676,6 +1677,16 @@ static int edit(lino_t *l, const char *prompt) l->error = lino_ioerr; return ret; } + + if (l->save_hist_idx) { + int hi = l->history_len - l->save_hist_idx - 1; + l->history_index = l->save_hist_idx; + l->save_hist_idx = 0; + strcpy(l->data, l->history[hi]); + l->dpos = l->dlen = strlen(l->data); + l->need_refresh = 1; + } + while(1) { unsigned char byte; int c; @@ -1814,6 +1825,14 @@ static int edit(lino_t *l, const char *prompt) clear_sel(l); } break; + case ENTER: + if (l->mlmode) + edit_move_end(l); + if (l->need_refresh) + refresh_line(l); + ret = l->len; + l->save_hist_idx = l->history_index; + goto out; default: if (isdigit((unsigned char) c)) { if (extend_num < 0) @@ -38256,6 +38256,20 @@ Navigating to a history line manually using the up and down arrow keys (or Ctrl-P/Ctrl-N) has the same net effect same as locating that line using Ctrl-R search. +.NP* Submit and Stay in History + +Normally when the Enter key is used on a recalled history line, +the next time the listener is re-entered, it jumps back to the +newest history position where a new line is about to be composed. + +The alternative command sequence Ctrl-X, Enter provides a useful alternative +behavior. After the submitted line is processed, the listener doesn't jump to +the newest history position. Instead, it stays in the history, advancing +forward by one position to the successor of the submitted line. + +Ctrl-X, Enter can be used to conveniently submit a range of lines +from the history, one by one, in their original order. + .NP* Insert Previous Word The equivalent command sequences Ctrl-X, w and Ctrl-X, Ctrl-W insert |