diff options
-rw-r--r-- | linenoise/linenoise.c | 21 | ||||
-rw-r--r-- | txr.1 | 11 |
2 files changed, 30 insertions, 2 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index cc291d38..ff931121 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1072,7 +1072,7 @@ static void edit_in_editor(lino_t *l) { * The function returns the length of the current buffer. */ static int edit(lino_t *l, const char *prompt) { - int verbatim = 0, extended = 0; + int verbatim = 0, extended = 0, paste = 0; /* Populate the linenoise state that we pass to functions implementing * specific editing functionalities. */ @@ -1113,7 +1113,14 @@ static int edit(lino_t *l, const char *prompt) c = byte; - if (verbatim) { + if (paste && (c == CTL('X'))) { + paste = 0; + continue; + } + + if (verbatim || + (paste && c != ESC && c != BACKSPACE && c != CTL('H'))) + { if (edit_insert(l,c)) { l->error = lino_ioerr; return -1; @@ -1129,6 +1136,9 @@ static int edit(lino_t *l, const char *prompt) case CTL('E'): edit_in_editor(l); break; + case CTL('V'): + paste = 1; + break; default: generate_beep(l); break; @@ -1157,6 +1167,13 @@ static int edit(lino_t *l, const char *prompt) switch(c) { case ENTER: + if (paste) { + if (edit_insert(l,c)) { + l->error = lino_ioerr; + return -1; + } + break; + } if (l->history_len > 0) { l->history_len--; free(l->history[l->history_len]); @@ -33485,6 +33485,17 @@ a mode in which the next character is interpreted literally and inserted into the line, even if that character is a special character such as Enter, or a command character. +.NP* Verbatim Insert Mode +The two-character sequence Ctrl-X, Ctrl-V ("extended verbatim", "super paste") +enters into an verbatim insert mode useful for entry of free-form text. It is +particularly useful in multi-line mode. In this mode, almost every character +is inserted verbatim, including Enter. The only commands recognized are: +Ctrl-X, which terminates this mode, Backspace (both ASCII BS and DEL +variants) and arrow key navigation. Enter inserts a line break, which +appears as such in multi-line mode, or as +.code ^M +in line mode. + .NP* History Recall By default, the most recent 500 lines submitted to the interactive listener are |