From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.bugs Subject: bug#33749: [PATCH] Preserve echo area contents when decoding an empty key sequence (Bug#33749) Date: Sun, 16 Dec 2018 15:29:57 +0700 Message-ID: <20181216082957.13445-1-yuri.v.khan@gmail.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1544949052 31757 195.159.176.226 (16 Dec 2018 08:30:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 16 Dec 2018 08:30:52 +0000 (UTC) Cc: Yuri Khan To: 33749@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Dec 16 09:30:47 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gYRp1-00085Z-1X for geb-bug-gnu-emacs@m.gmane.org; Sun, 16 Dec 2018 09:30:47 +0100 Original-Received: from localhost ([::1]:41647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYRr2-0007DQ-89 for geb-bug-gnu-emacs@m.gmane.org; Sun, 16 Dec 2018 03:32:52 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYRqr-0007BF-5b for bug-gnu-emacs@gnu.org; Sun, 16 Dec 2018 03:32:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gYRpG-0000OO-O2 for bug-gnu-emacs@gnu.org; Sun, 16 Dec 2018 03:31:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45623) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gYRpG-0000OA-JP for bug-gnu-emacs@gnu.org; Sun, 16 Dec 2018 03:31:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gYRpG-0001hp-78 for bug-gnu-emacs@gnu.org; Sun, 16 Dec 2018 03:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuri Khan Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 16 Dec 2018 08:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33749 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 33749-submit@debbugs.gnu.org id=B33749.15449490496532 (code B ref 33749); Sun, 16 Dec 2018 08:31:02 +0000 Original-Received: (at 33749) by debbugs.gnu.org; 16 Dec 2018 08:30:49 +0000 Original-Received: from localhost ([127.0.0.1]:49881 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gYRp2-0001hE-27 for submit@debbugs.gnu.org; Sun, 16 Dec 2018 03:30:48 -0500 Original-Received: from mail-lf1-f65.google.com ([209.85.167.65]:34789) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gYRoz-0001gw-Dd for 33749@debbugs.gnu.org; Sun, 16 Dec 2018 03:30:45 -0500 Original-Received: by mail-lf1-f65.google.com with SMTP id p6so7267454lfc.1 for <33749@debbugs.gnu.org>; Sun, 16 Dec 2018 00:30:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bdTiATyvjlE7dmAO73XNl7hZAtHhiQv9F26LkSvdDhU=; b=i5bpNnkzd5bHcVGAVvYqoZFFhgrEE0NNAlrlUK0mM6ovcGCAMsYyaJTDn/r4czPcp9 EGZOgA1o142tcaRLzE3ZcvXoxyQpE5LCw/zKyFdz3VCxC44baztH6WdWRBeaLqRs3ei1 vner3kVi5O1WSowvSgvzcSrhB5bmsPu3GiPUFH5dC/6+JQsAmcW/TP2LgPyTssTxCWAB jYLdEQFaWBdW59EIBZEb6n7rC3L402a5vARlDgnQO/fKcEDfbtpX+NGICocRrAvEt9Yf yBW6CmfqKm6v6UcK9lGQapt/vuhSUuKTHJYnmFCn2nSnBpIllfQs3mlu8mq4lGmsZLQU w3dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=bdTiATyvjlE7dmAO73XNl7hZAtHhiQv9F26LkSvdDhU=; b=FKnDtjxtUc3lWSIQSniG9dPqTIRd0IuLtKeudE9eYbEbXBaLx9jzNYW79Poos7xE2n zhsWZg8el3uiFjXlhxnZ9eI6gcU2mIA0eov0ank2Fig6nF6YtDP3fjBbJtu1/1svdgSa WbVijyYkV+/vSgaqh6TxwvXQIGqvqvl/YzEnkOXLDHXCjYEpbVyfb8nuVWXePaQMUKrA NcsEsc6HGZecOH8yeZdarlEYP+73ciS8bSs/49McGq/6gL84v6xe+0bRwO2nOxXTQdSk uZJjkpspNkvTwINhRL8xUVRNk6LiAWXt/E4+D65fYierLcwW0dmisf38ngGt+XDd/SU0 T6Vg== X-Gm-Message-State: AA+aEWbV0TInDTJpznYUdQYlOlof2PHYtUmnGfyxUpC84qh4zcj2pCgO iSehThIaUrfsg41Wb9HHZMMziLvU X-Google-Smtp-Source: AFSGD/XUp6kuguJe6tigOju4npXag5hQxFSc68RzlBt/E/EpMQBdvUGFzU3+M2AuTB91Lcl5nY7h3Q== X-Received: by 2002:a19:a28e:: with SMTP id l136mr5511770lfe.87.1544949038898; Sun, 16 Dec 2018 00:30:38 -0800 (PST) Original-Received: from centaur-pc.khan.test (static.90.189.159.140.sinor.ru. [90.189.159.140]) by smtp.gmail.com with ESMTPSA id z9sm1877870lfj.79.2018.12.16.00.30.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Dec 2018 00:30:37 -0800 (PST) X-Mailer: git-send-email 2.20.1 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:153492 Archived-At: * 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