|
|
ff19ae |
diff --git a/lib/readline/bind.c b/lib/readline/bind.c
|
|
|
ff19ae |
--- a/lib/readline/bind.c
|
|
|
ff19ae |
+++ b/lib/readline/bind.c
|
|
|
ff19ae |
@@ -1428,6 +1428,7 @@ static const struct {
|
|
|
ff19ae |
{ "convert-meta", &_rl_convert_meta_chars_to_ascii, 0 },
|
|
|
ff19ae |
{ "disable-completion", &rl_inhibit_completion, 0 },
|
|
|
ff19ae |
{ "echo-control-characters", &_rl_echo_control_chars, 0 },
|
|
|
ff19ae |
+ { "enable-bracketed-paste", &_rl_enable_bracketed_paste, 0 },
|
|
|
ff19ae |
{ "enable-keypad", &_rl_enable_keypad, 0 },
|
|
|
ff19ae |
{ "enable-meta-key", &_rl_enable_meta, 0 },
|
|
|
ff19ae |
{ "expand-tilde", &rl_complete_with_tilde_expansion, 0 },
|
|
|
ff19ae |
diff --git a/lib/readline/funmap.c b/lib/readline/funmap.c
|
|
|
ff19ae |
--- a/lib/readline/funmap.c
|
|
|
ff19ae |
+++ b/lib/readline/funmap.c
|
|
|
ff19ae |
@@ -68,6 +68,7 @@ static const FUNMAP default_funmap[] = {
|
|
|
ff19ae |
{ "backward-word", rl_backward_word },
|
|
|
ff19ae |
{ "beginning-of-history", rl_beginning_of_history },
|
|
|
ff19ae |
{ "beginning-of-line", rl_beg_of_line },
|
|
|
ff19ae |
+ { "bracketed-paste-begin", rl_bracketed_paste_begin },
|
|
|
ff19ae |
{ "call-last-kbd-macro", rl_call_last_kbd_macro },
|
|
|
ff19ae |
{ "capitalize-word", rl_capitalize_word },
|
|
|
ff19ae |
{ "character-search", rl_char_search },
|
|
|
ff19ae |
diff --git a/lib/readline/kill.c b/lib/readline/kill.c
|
|
|
ff19ae |
--- a/lib/readline/kill.c
|
|
|
ff19ae |
+++ b/lib/readline/kill.c
|
|
|
ff19ae |
@@ -656,6 +656,55 @@ rl_yank_last_arg (count, key)
|
|
|
ff19ae |
return retval;
|
|
|
ff19ae |
}
|
|
|
ff19ae |
|
|
|
ff19ae |
+/* Having read the special escape sequence denoting the beginning of a
|
|
|
ff19ae |
+ `bracketed paste' sequence, read the rest of the pasted input until the
|
|
|
ff19ae |
+ closing sequence and insert the pasted text as a single unit without
|
|
|
ff19ae |
+ interpretation. */
|
|
|
ff19ae |
+int
|
|
|
ff19ae |
+rl_bracketed_paste_begin (int count, int key)
|
|
|
ff19ae |
+{
|
|
|
ff19ae |
+ int retval, c;
|
|
|
ff19ae |
+ size_t len, cap;
|
|
|
ff19ae |
+ char *buf;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ retval = 1;
|
|
|
ff19ae |
+ len = 0;
|
|
|
ff19ae |
+ buf = xmalloc (cap = 64);
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ RL_SETSTATE (RL_STATE_MOREINPUT);
|
|
|
ff19ae |
+ while ((c = rl_read_key ()) >= 0)
|
|
|
ff19ae |
+ {
|
|
|
ff19ae |
+ if (RL_ISSTATE (RL_STATE_MACRODEF))
|
|
|
ff19ae |
+ _rl_add_macro_char (c);
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ if (c == '\r') /* XXX */
|
|
|
ff19ae |
+ c = '\n';
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ if (len == cap)
|
|
|
ff19ae |
+ buf = xrealloc (buf, cap *= 2);
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ buf[len++] = c;
|
|
|
ff19ae |
+ if (len >= BRACK_PASTE_SLEN && c == BRACK_PASTE_LAST &&
|
|
|
ff19ae |
+ STREQN (buf + len - BRACK_PASTE_SLEN, BRACK_PASTE_SUFF, BRACK_PASTE_SLEN))
|
|
|
ff19ae |
+ {
|
|
|
ff19ae |
+ len -= BRACK_PASTE_SLEN;
|
|
|
ff19ae |
+ break;
|
|
|
ff19ae |
+ }
|
|
|
ff19ae |
+ }
|
|
|
ff19ae |
+ RL_UNSETSTATE (RL_STATE_MOREINPUT);
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ if (c >= 0)
|
|
|
ff19ae |
+ {
|
|
|
ff19ae |
+ if (len == cap)
|
|
|
ff19ae |
+ buf = xrealloc (buf, cap + 1);
|
|
|
ff19ae |
+ buf[len] = '\0';
|
|
|
ff19ae |
+ retval = rl_insert_text (buf);
|
|
|
ff19ae |
+ }
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ xfree (buf);
|
|
|
ff19ae |
+ return (retval);
|
|
|
ff19ae |
+}
|
|
|
ff19ae |
+
|
|
|
ff19ae |
/* A special paste command for users of Cygnus's cygwin32. */
|
|
|
ff19ae |
#if defined (__CYGWIN__)
|
|
|
ff19ae |
#include <windows.h>
|
|
|
ff19ae |
diff --git a/lib/readline/readline.c b/lib/readline/readline.c
|
|
|
ff19ae |
--- a/lib/readline/readline.c
|
|
|
ff19ae |
+++ b/lib/readline/readline.c
|
|
|
ff19ae |
@@ -95,6 +95,8 @@ static void readline_initialize_everything PARAMS((void));
|
|
|
ff19ae |
static void bind_arrow_keys_internal PARAMS((Keymap));
|
|
|
ff19ae |
static void bind_arrow_keys PARAMS((void));
|
|
|
ff19ae |
|
|
|
ff19ae |
+static void bind_bracketed_paste_prefix PARAMS((void));
|
|
|
ff19ae |
+
|
|
|
ff19ae |
static void readline_default_bindings PARAMS((void));
|
|
|
ff19ae |
static void reset_default_bindings PARAMS((void));
|
|
|
ff19ae |
|
|
|
ff19ae |
@@ -285,6 +287,11 @@ int _rl_revert_all_at_newline = 0;
|
|
|
ff19ae |
characters corresponding to keyboard-generated signals. */
|
|
|
ff19ae |
int _rl_echo_control_chars = 1;
|
|
|
ff19ae |
|
|
|
ff19ae |
+/* Non-zero means to attempt to put the terminal in `bracketed paste mode',
|
|
|
ff19ae |
+ where it will prefix pasted text with an escape sequence and send
|
|
|
ff19ae |
+ another to mark the end of the paste. */
|
|
|
ff19ae |
+int _rl_enable_bracketed_paste = 0;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
/* **************************************************************** */
|
|
|
ff19ae |
/* */
|
|
|
ff19ae |
/* Top Level Functions */
|
|
|
ff19ae |
@@ -1143,6 +1150,10 @@ readline_initialize_everything ()
|
|
|
ff19ae |
/* Try to bind a common arrow key prefix, if not already bound. */
|
|
|
ff19ae |
bind_arrow_keys ();
|
|
|
ff19ae |
|
|
|
ff19ae |
+ /* Bind the bracketed paste prefix assuming that the user will enable
|
|
|
ff19ae |
+ it on terminals that support it. */
|
|
|
ff19ae |
+ bind_bracketed_paste_prefix ();
|
|
|
ff19ae |
+
|
|
|
ff19ae |
/* Enable the meta key, if this terminal has one. */
|
|
|
ff19ae |
if (_rl_enable_meta)
|
|
|
ff19ae |
_rl_enable_meta_key ();
|
|
|
ff19ae |
@@ -1234,6 +1245,22 @@ bind_arrow_keys ()
|
|
|
ff19ae |
#endif
|
|
|
ff19ae |
}
|
|
|
ff19ae |
|
|
|
ff19ae |
+static void
|
|
|
ff19ae |
+bind_bracketed_paste_prefix (void)
|
|
|
ff19ae |
+{
|
|
|
ff19ae |
+ Keymap xkeymap;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ xkeymap = _rl_keymap;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ _rl_keymap = emacs_standard_keymap;
|
|
|
ff19ae |
+ rl_bind_keyseq_if_unbound (BRACK_PASTE_PREF, rl_bracketed_paste_begin);
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ _rl_keymap = vi_insertion_keymap;
|
|
|
ff19ae |
+ rl_bind_keyseq_if_unbound (BRACK_PASTE_PREF, rl_bracketed_paste_begin);
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ _rl_keymap = xkeymap;
|
|
|
ff19ae |
+}
|
|
|
ff19ae |
+
|
|
|
ff19ae |
/* **************************************************************** */
|
|
|
ff19ae |
/* */
|
|
|
ff19ae |
/* Saving and Restoring Readline's state */
|
|
|
ff19ae |
diff --git a/lib/readline/readline.h b/lib/readline/readline.h
|
|
|
ff19ae |
--- a/lib/readline/readline.h
|
|
|
ff19ae |
+++ b/lib/readline/readline.h
|
|
|
ff19ae |
@@ -172,6 +172,7 @@ extern int rl_yank PARAMS((int, int));
|
|
|
ff19ae |
extern int rl_yank_pop PARAMS((int, int));
|
|
|
ff19ae |
extern int rl_yank_nth_arg PARAMS((int, int));
|
|
|
ff19ae |
extern int rl_yank_last_arg PARAMS((int, int));
|
|
|
ff19ae |
+extern int rl_bracketed_paste_begin PARAMS((int, int));
|
|
|
ff19ae |
/* Not available unless __CYGWIN__ is defined. */
|
|
|
ff19ae |
#ifdef __CYGWIN__
|
|
|
ff19ae |
extern int rl_paste_from_clipboard PARAMS((int, int));
|
|
|
ff19ae |
diff --git a/lib/readline/rlprivate.h b/lib/readline/rlprivate.h
|
|
|
ff19ae |
--- a/lib/readline/rlprivate.h
|
|
|
ff19ae |
+++ b/lib/readline/rlprivate.h
|
|
|
ff19ae |
@@ -195,6 +195,14 @@ extern int rl_blink_matching_paren;
|
|
|
ff19ae |
|
|
|
ff19ae |
/* kill.c */
|
|
|
ff19ae |
extern int rl_set_retained_kills PARAMS((int));
|
|
|
ff19ae |
+#define BRACK_PASTE_PREF "\033[200~"
|
|
|
ff19ae |
+#define BRACK_PASTE_SUFF "\033[201~"
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+#define BRACK_PASTE_LAST '~'
|
|
|
ff19ae |
+#define BRACK_PASTE_SLEN 6
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+#define BRACK_PASTE_INIT "\033[?2004h"
|
|
|
ff19ae |
+#define BRACK_PASTE_FINI "\033[?2004l\r"
|
|
|
ff19ae |
|
|
|
ff19ae |
/* terminal.c */
|
|
|
ff19ae |
extern void _rl_set_screen_size PARAMS((int, int));
|
|
|
ff19ae |
@@ -452,6 +460,7 @@ extern int _rl_output_meta_chars;
|
|
|
ff19ae |
extern int _rl_bind_stty_chars;
|
|
|
ff19ae |
extern int _rl_revert_all_at_newline;
|
|
|
ff19ae |
extern int _rl_echo_control_chars;
|
|
|
ff19ae |
+extern int _rl_enable_bracketed_paste;
|
|
|
ff19ae |
extern char *_rl_comment_begin;
|
|
|
ff19ae |
extern unsigned char _rl_parsing_conditionalized_out;
|
|
|
ff19ae |
extern Keymap _rl_keymap;
|
|
|
ff19ae |
diff --git a/lib/readline/rltty.c b/lib/readline/rltty.c
|
|
|
ff19ae |
--- a/lib/readline/rltty.c
|
|
|
ff19ae |
+++ b/lib/readline/rltty.c
|
|
|
ff19ae |
@@ -60,6 +60,12 @@ static void set_winsize PARAMS((int));
|
|
|
ff19ae |
/* */
|
|
|
ff19ae |
/* **************************************************************** */
|
|
|
ff19ae |
|
|
|
ff19ae |
+/* Non-zero means that the terminal is in a prepped state. There are several
|
|
|
ff19ae |
+ flags that are OR'd in to denote whether or not we have sent various
|
|
|
ff19ae |
+ init strings to the terminal. */
|
|
|
ff19ae |
+#define TPX_PREPPED 0x01
|
|
|
ff19ae |
+#define TPX_BRACKPASTE 0x02
|
|
|
ff19ae |
+
|
|
|
ff19ae |
/* Non-zero means that the terminal is in a prepped state. */
|
|
|
ff19ae |
static int terminal_prepped;
|
|
|
ff19ae |
|
|
|
ff19ae |
@@ -595,7 +601,7 @@ void
|
|
|
ff19ae |
rl_prep_terminal (meta_flag)
|
|
|
ff19ae |
int meta_flag;
|
|
|
ff19ae |
{
|
|
|
ff19ae |
- int tty;
|
|
|
ff19ae |
+ int tty, nprep;
|
|
|
ff19ae |
TIOTYPE tio;
|
|
|
ff19ae |
|
|
|
ff19ae |
if (terminal_prepped)
|
|
|
ff19ae |
@@ -659,8 +665,16 @@ rl_prep_terminal (meta_flag)
|
|
|
ff19ae |
if (_rl_enable_keypad)
|
|
|
ff19ae |
_rl_control_keypad (1);
|
|
|
ff19ae |
|
|
|
ff19ae |
+ nprep = TPX_PREPPED;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ if (_rl_enable_bracketed_paste)
|
|
|
ff19ae |
+ {
|
|
|
ff19ae |
+ fprintf (rl_outstream, BRACK_PASTE_INIT);
|
|
|
ff19ae |
+ nprep |= TPX_BRACKPASTE;
|
|
|
ff19ae |
+ }
|
|
|
ff19ae |
+
|
|
|
ff19ae |
fflush (rl_outstream);
|
|
|
ff19ae |
- terminal_prepped = 1;
|
|
|
ff19ae |
+ terminal_prepped = nprep;
|
|
|
ff19ae |
RL_SETSTATE(RL_STATE_TERMPREPPED);
|
|
|
ff19ae |
|
|
|
ff19ae |
_rl_release_sigint ();
|
|
|
ff19ae |
@@ -680,6 +694,9 @@ rl_deprep_terminal ()
|
|
|
ff19ae |
|
|
|
ff19ae |
tty = rl_instream ? fileno (rl_instream) : fileno (stdout);
|
|
|
ff19ae |
|
|
|
ff19ae |
+ if (terminal_prepped & TPX_BRACKPASTE)
|
|
|
ff19ae |
+ fprintf (rl_outstream, BRACK_PASTE_FINI);
|
|
|
ff19ae |
+
|
|
|
ff19ae |
if (_rl_enable_keypad)
|
|
|
ff19ae |
_rl_control_keypad (0);
|