From 499708ec41e69fefdfee1f9db1bbcfbc7db5b87f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 28 Jan 2022 19:39:03 -0800 Subject: linenoise: Ctrl-V Ctrl-J now inserts CR not LF. If newlines are inserted into the input, they don't behave well. The is_balanced_line callback doesn't recognize them as line terminators for the purposes of delimiting ; comments. Also, they make a mess in the ~/.txr_history file. Plus, users of shells like Bash are used to Ctrl-V Ctrl-J inserting a line break; some users have that in their muscle memory. So let's just do that as a special case: Ctrl-V Ctrl-J behaves like Ctrl-V Ctrl-M. * linenoise/linenoise.c (history_search, edit): Remap a verbatim Ctrl-J to a carriage return. --- linenoise/linenoise.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index ddb25b0f..e783a2f5 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -763,6 +763,8 @@ static int history_search(lino_t *l) verbatim: if (hl >= convert(int, nelem(hpat))) break; + if (c == CTL('J')) + c = '\r'; hpat[hl++] = c; /* fallthrough */ if (0) { @@ -2129,6 +2131,8 @@ static int edit(lino_t *l, const wchar_t *prompt) if (verbatim || (paste && c != ESC && c != BACKSPACE && c != CTL('H'))) { + if (verbatim && c == CTL('J')) + c = '\r'; if (edit_insert(l,c)) { l->error = lino_ioerr; goto out; -- cgit v1.2.3