summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-21 21:05:35 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-21 21:05:35 -0700
commitb0467383501c9d99d36b1882edf6d2997105cdee (patch)
tree323620dd4f5aa6de0fda914c5b62e2d4f693f63a
parent515b0cdcc0b4c61c2636444b08d3868e902d380d (diff)
downloadtxr-b0467383501c9d99d36b1882edf6d2997105cdee.tar.gz
txr-b0467383501c9d99d36b1882edf6d2997105cdee.tar.bz2
txr-b0467383501c9d99d36b1882edf6d2997105cdee.zip
linenoise: multi-line behavior for del to bol/eol.
* linenoise/linenoise.c (edit_delete_prev_all): In multi-line mode, delete only to beginning of physical line, not the entire logical line. Also, detect noop cases and don't do record undo or produce any effect. (edit_delete_to_eol): New function. (edit): Use edit_delete_to_eol function for Ctrl-K instead of inline code. * txr.1: Documented.
-rw-r--r--linenoise/linenoise.c66
-rw-r--r--txr.19
2 files changed, 60 insertions, 15 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index 18106463..5753e7a4 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -1293,13 +1293,59 @@ static void edit_backspace(lino_t *l) {
/* Delete all characters to left of cursor. */
static void edit_delete_prev_all(lino_t *l)
{
- record_undo(l);
- delete_sel(l);
+ clear_sel(l);
+
+ if (!l->mlmode) {
+ if (l->dpos > 0) {
+ record_undo(l);
+ memmove(l->data, l->data + l->dpos, l->dlen - l->dpos + 1);
+ l->dlen -= l->dpos;
+ l->dpos = 0;
+ l->need_refresh = 1;
+ }
+ } else {
+ char *e = l->data + l->dpos, *s = e;
+ size_t delta;
+
+ while (s > l->data && s[-1] != '\r')
+ s--;
+
+ delta = e - s;
+
+ if (delta > 0) {
+ record_undo(l);
+ memmove(s, e, l->data + l->dlen - e);
+ l->dlen -= delta;
+ l->dpos -= delta;
+ l->data[l->dlen] = 0;
+ l->need_refresh = 1;
+ }
+ }
+}
+
+static void edit_delete_to_eol(lino_t *l)
+{
+ clear_sel(l);
- memmove(l->data, l->data + l->dpos, l->dlen - l->dpos + 1);
- l->dlen -= l->dpos;
- l->dpos = 0;
- l->need_refresh = 1;
+ if (l->dlen != l->dpos) {
+ if (!l->mlmode) {
+ record_undo(l);
+ l->data[l->dpos] = '\0';
+ l->dlen = l->dpos;
+ l->need_refresh = 1;
+ } else {
+ size_t delsize = strcspn(l->data + l->dpos, "\r");
+ if (delsize != 0) {
+ record_undo(l);
+ if (l->dlen - delsize)
+ memmove(l->data + l->dpos, l->data + l->dpos + delsize,
+ l->dlen - l->dpos - delsize);
+ l->dlen -= delsize;
+ l->data[l->dlen] = 0;
+ l->need_refresh = 1;
+ }
+ }
+ }
}
/* Delete the previosu word, maintaining the cursor at the start of the
@@ -1742,12 +1788,8 @@ static int edit(lino_t *l, const char *prompt)
if (l->clip != 0)
edit_insert_str(l, l->clip, strlen(l->clip));
break;
- case CTL('K'): /* delete from current to end of line. */
- record_undo(l);
- clear_sel(l);
- l->data[l->dpos] = '\0';
- l->dlen = l->dpos;
- l->need_refresh = 1;
+ case CTL('K'):
+ edit_delete_to_eol(l);
break;
case CTL('A'):
edit_move_home(l);
diff --git a/txr.1 b/txr.1
index 70a48a4b..673c1d5e 100644
--- a/txr.1
+++ b/txr.1
@@ -33624,11 +33624,17 @@ The Ctrl-U ("undo typing") command is a "super backspace" operation: it deletes
all characters to the left of the cursor position. The cursor is moved to
the leftmost position.
+In multi-line mode, Ctrl-U deletes only to the beginning of the current
+physical line, not all the way to the first position of the buffer.
+
.NP* Delete to End of Line
The Ctrl-K ("kill") command deletes the character under the cursor position
and all subsequent characters. The cursor position doesn't change.
+In multi-line mode, Ctrl-K deletes only until the end of the current
+physical line, not the entire buffer.
+
.NP* Verbatim Character Insert
The Ctrl-V ("verbatim") command places the listener's input editor into
@@ -33984,9 +33990,6 @@ breaks rather than being rendered as
To insert a line break character, use the sequence: Ctrl-V, Ctrl-M.
Or, equivalently: Ctrl-V, Enter.
-Note that the Ctrl-K and Ctrl-U commands regard the entire input to be one
-logical line, ignoring the line breaks.
-
Because carriage returns are not line terminators in text files,
lines which contain embedded carriage returns are correctly saved
into and retrieved from the persistent history file.