Package: emacs;
Reported by: Yuri Khan <yurivkhan <at> gmail.com>
Date: Fri, 14 Dec 2018 22:26:02 UTC
Severity: normal
Found in version 26.1
Message #17 received at 33749 <at> debbugs.gnu.org (full text, mbox):
From: Yuri Khan <yuri.v.khan <at> gmail.com> To: 33749 <at> debbugs.gnu.org Cc: Yuri Khan <yuri.v.khan <at> gmail.com> Subject: [PATCH] Preserve echo area contents when decoding an empty key sequence (Bug#33749) Date: Sun, 16 Dec 2018 15:29:57 +0700
* src/keyboard.h (struct kboard): New terminal-local variable `input-decode-preserve-echo'. * src/keyboard.c (read_key_sequence): If the current sequence is mapped via `input-decode-map' to an empty sequence and `input-decode-preserve-echo' is non-nil, return -1. * src/keyboard.c (command_loop_1): Save echo area contents before calling `read-key-sequence'. If it returns -1 and `input-decode-preserve-echo' is non-nil, restore echo area contents. --- src/keyboard.c | 27 ++++++++++++++++++++++++++- src/keyboard.h | 9 +++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/keyboard.c b/src/keyboard.c index baf2f514409..70390ccf88c 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1239,6 +1239,7 @@ command_loop_1 (void) EMACS_INT prev_modiff = 0; struct buffer *prev_buffer = NULL; bool already_adjusted = 0; + volatile Lisp_Object previous_echo_area_message; kset_prefix_arg (current_kboard, Qnil); kset_last_prefix_arg (current_kboard, Qnil); @@ -1341,6 +1342,7 @@ command_loop_1 (void) Vthis_original_command = Qnil; Vthis_command_keys_shift_translated = Qnil; + previous_echo_area_message = Fcurrent_message (); /* Read next key sequence; i gets its length. */ raw_keybuf_count = 0; Lisp_Object keybuf[READ_KEY_ELTS]; @@ -1362,6 +1364,9 @@ command_loop_1 (void) Just loop around and read another command. */ if (i == -1) { + if (! NILP (KVAR (current_kboard, Vinput_decode_preserve_echo)) + && ! NILP (previous_echo_area_message)) + message_with_string ("%s", previous_echo_area_message, 0); cancel_echoing (); this_command_key_count = 0; this_single_command_key_start = 0; @@ -8787,7 +8792,9 @@ void init_raw_keybuf_count (void) storing it in KEYBUF, a buffer of size READ_KEY_ELTS. Prompt with PROMPT. Return the length of the key sequence stored. - Return -1 if the user rejected a command menu. + Return -1 if the user rejected a command menu, or + `input-decode-preserve-echo' is non-nil and the user entered + a sequence that is mapped via `input-decode-map' to an empty vector. Echo starting immediately unless `prompt' is 0. @@ -9540,6 +9547,9 @@ read_key_sequence (Lisp_Object *keybuf, Lisp_Object prompt, if (done) { mock_input = diff + max (t, mock_input); + if (! NILP (KVAR (current_kboard, Vinput_decode_preserve_echo)) + && mock_input == 0) + return -1; goto replay_sequence; } } @@ -10817,6 +10827,7 @@ init_kboard (KBOARD *kb, Lisp_Object type) kset_system_key_syms (kb, Qnil); kset_window_system (kb, type); kset_input_decode_map (kb, Fmake_sparse_keymap (Qnil)); + kset_input_decode_preserve_echo (kb, Qnil); kset_local_function_key_map (kb, Fmake_sparse_keymap (Qnil)); Fset_keymap_parent (KVAR (kb, Vlocal_function_key_map), Vfunction_key_map); kset_default_minibuffer_frame (kb, Qnil); @@ -11644,6 +11655,19 @@ and its return value (a key sequence) is used. The events that come from bindings in `input-decode-map' are not themselves looked up in `input-decode-map'. */); + DEFVAR_KBOARD ("input-decode-preserve-echo", Vinput_decode_preserve_echo, + doc: /* Preserve the echo area contents while decoding input. + +It is possible for `input-decode-map' to map a sequence to an empty vector, +for example, to ignore irrelevant sequences sent by the terminal. + +If this variable is `nil', `read-key-sequence' will loop waiting for the +sequence to continue. The echo area may show the original sequence. This +is the historic Emacs behavior. + +If this variable is set to `t', `read-key-sequence' will return -1, and +the command loop will restore the echo area contents. */); + DEFVAR_LISP ("function-key-map", Vfunction_key_map, doc: /* The parent keymap of all `local-function-key-map' instances. Function key definitions that apply to all terminal devices should go @@ -11956,6 +11980,7 @@ mark_kboards (void) mark_object (KVAR (kb, system_key_syms)); mark_object (KVAR (kb, Vwindow_system)); mark_object (KVAR (kb, Vinput_decode_map)); + mark_object (KVAR (kb, Vinput_decode_preserve_echo)); mark_object (KVAR (kb, Vlocal_function_key_map)); mark_object (KVAR (kb, Vdefault_minibuffer_frame)); mark_object (KVAR (kb, echo_string)); diff --git a/src/keyboard.h b/src/keyboard.h index ce4630b8a37..7c778292f50 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -151,6 +151,10 @@ struct kboard DEFVAR for more documentation. */ Lisp_Object Vinput_decode_map_; + /* Save and restore the echo area across sequences that are mapped + to the empty vector by `input-decode-map'. */ + Lisp_Object Vinput_decode_preserve_echo_; + /* Minibufferless frames on this display use this frame's minibuffer. */ Lisp_Object Vdefault_minibuffer_frame_; @@ -197,6 +201,11 @@ kset_input_decode_map (struct kboard *kb, Lisp_Object val) kb->Vinput_decode_map_ = val; } INLINE void +kset_input_decode_preserve_echo (struct kboard *kb, Lisp_Object val) +{ + kb->Vinput_decode_preserve_echo_ = val; +} +INLINE void kset_last_command (struct kboard *kb, Lisp_Object val) { kb->Vlast_command_ = val; -- 2.20.1
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.