From bfd251f813aee284d9cd3886a5aeffdb58497ea6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 2 Oct 2015 06:48:26 -0700 Subject: linenoise: insert previous line command. * linenoise/linenoise.c (edit): Extended Ctrl-X Ctrl-R/r command added. * txr.1: Documented. --- linenoise/linenoise.c | 14 ++++++++++++++ txr.1 | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index de12bdb4..b5b9908f 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1782,6 +1782,20 @@ static int edit(lino_t *l, const char *prompt) } } break; + case CTL('R'): case 'r': + extended = 0; + if (extend_num < 0) + extend_num = 1; + if (l->history_len > extend_num) { + char *prev_line = l->history[l->history_len - 1 + - extend_num]; + int res = edit_insert_str(l, prev_line, strlen(prev_line)); + if (res) { + l->error = lino_ioerr; + goto out; + } + } + break; case CTL('Q'): extended = 0; { diff --git a/txr.1 b/txr.1 index bdfb6b08..b9781641 100644 --- a/txr.1 +++ b/txr.1 @@ -34227,6 +34227,14 @@ Only the most recent three decimal digits are retained, so the number can range from 0 to 999. A value of 0, or a value which exceeds the number of words causes the Ctrl-A or a to do nothing. +.NP* Insert Previous Line + +The command sequences Ctrl-X, Ctrl-R ("repeat") and Ctrl-X, r, which are +equivalent, insert an entire line of history into the current buffer. By +default, the previous line is inserted. A less recent line can be selected by +typing a numeric argument between the Ctrl-X and the Ctrl-R/r. The immediately +previous history line is numbered 1, the one before it 2 and so on. + .NP* Symbolic Completion If the Tab key is pressed while editing a line, it is interpreted as a -- cgit v1.2.3