summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-02 07:05:40 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-02 07:05:40 -0700
commitb75a472f44d05977c00c7b3be4f3c3d203c38979 (patch)
tree0ccb3928ae48e2e37f66842234adc8bd75123580
parentc4a66ad7ed5c74cda3a16b191c6763c1a5cedc6d (diff)
downloadtxr-b75a472f44d05977c00c7b3be4f3c3d203c38979.tar.gz
txr-b75a472f44d05977c00c7b3be4f3c3d203c38979.tar.bz2
txr-b75a472f44d05977c00c7b3be4f3c3d203c38979.zip
linenoise: Ctrl-X/Ctrl-[AWR] relative to hist pos.
* linenoise/linenoise.c (edit): The recall previous word, atom and line features now offset relative to the current navigation position in the history. Previous line means the line before the currently showing history line, not the line most recently entered into the history. * txr.1: Documented.
-rw-r--r--linenoise/linenoise.c15
-rw-r--r--txr.110
2 files changed, 17 insertions, 8 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index b5b9908f..973acce5 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -1733,8 +1733,9 @@ static int edit(lino_t *l, const char *prompt)
break;
case CTL('W'): case 'w':
extended = 0;
- if (l->history_len > 1 && extend_num != 0) {
- char *prev_line = l->history[l->history_len - 2];
+ if (l->history_len > 1 + l->history_index && extend_num != 0) {
+ char *prev_line = l->history[l->history_len - 2
+ - l->history_index];
char *word_end = prev_line + strlen(prev_line);
char *word_start = word_end;
@@ -1764,9 +1765,10 @@ static int edit(lino_t *l, const char *prompt)
extended = 0;
if (extend_num < 0)
extend_num = 1;
- if (l->history_len > 1 && l->atom_callback)
+ if (l->history_len > 1 + l->history_index && l->atom_callback)
{
- char *prev_line = l->history[l->history_len - 2];
+ char *prev_line = l->history[l->history_len - 2
+ - l->history_index];
char *word = l->atom_callback(l, prev_line,
extend_num, l->ca_ctx);
int res = 0;
@@ -1786,9 +1788,10 @@ static int edit(lino_t *l, const char *prompt)
extended = 0;
if (extend_num < 0)
extend_num = 1;
- if (l->history_len > extend_num) {
+ if (l->history_len > extend_num + l->history_index) {
char *prev_line = l->history[l->history_len - 1
- - extend_num];
+ - extend_num
+ - l->history_index];
int res = edit_insert_str(l, prev_line, strlen(prev_line));
if (res) {
l->error = lino_ioerr;
diff --git a/txr.1 b/txr.1
index 46899907..2fbad601 100644
--- a/txr.1
+++ b/txr.1
@@ -34223,7 +34223,10 @@ The number 1 specifies that the last word is to be inserted, 2 specifies
the second last word, 3 the third word from the right and so on.
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-W or w to do nothing.
+causes the Ctrl-W or w to do nothing. Note that "previous line" means
+relative to the current location in the history. If the 42nd most recent
+history line is currently recalled, this command takes material from the 43rd
+history line.
.NP* Insert Previous Atom
@@ -34242,7 +34245,8 @@ atoms by position from the end. The number 1 specifies the last atom,
2 the second last and so on.
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.
+causes the Ctrl-A or a to do nothing. Note that "previous line"
+has the same meaning as for the Ctrl-X, Ctrl-W (insert previous word) command.
.NP* Insert Previous Line
@@ -34251,6 +34255,8 @@ 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.
+If this command is used during history navigation, it references previous
+lines relative to the currently recalled history line.
.NP* Symbolic Completion