From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#46243: [External] : Re: bug#46243: 26.3; If invoke menu item that reads a char, get keystrokes echo Date: Wed, 03 Feb 2021 14:56:40 -0500 Message-ID: References: <83r1lz60so.fsf@gnu.org> <83a6sm5rlr.fsf@gnu.org> <83pn1h401u.fsf@gnu.org> <83k0rp3wew.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30837"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 46243@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 03 21:07:04 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7OQZ-0007s7-L0 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 03 Feb 2021 21:07:03 +0100 Original-Received: from localhost ([::1]:51202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7OQY-0007bz-JW for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 03 Feb 2021 15:07:02 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7OGs-0008Qd-LC for bug-gnu-emacs@gnu.org; Wed, 03 Feb 2021 14:57:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l7OGs-0007iD-CU for bug-gnu-emacs@gnu.org; Wed, 03 Feb 2021 14:57:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l7OGs-0002m1-BD for bug-gnu-emacs@gnu.org; Wed, 03 Feb 2021 14:57:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Feb 2021 19:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46243 X-GNU-PR-Package: emacs Original-Received: via spool by 46243-submit@debbugs.gnu.org id=B46243.161238221110644 (code B ref 46243); Wed, 03 Feb 2021 19:57:02 +0000 Original-Received: (at 46243) by debbugs.gnu.org; 3 Feb 2021 19:56:51 +0000 Original-Received: from localhost ([127.0.0.1]:38919 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7OGg-0002lc-QN for submit@debbugs.gnu.org; Wed, 03 Feb 2021 14:56:51 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:43863) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7OGf-0002lP-Bp for 46243@debbugs.gnu.org; Wed, 03 Feb 2021 14:56:49 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id B3A49101F42; Wed, 3 Feb 2021 14:56:43 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A3648100707; Wed, 3 Feb 2021 14:56:41 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1612382201; bh=E7uBKJSsEnnmFz/rk9WsBoOs3nEDDTZrDdzMGCzFHZA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Ap5Clyi8KKsTCkyN8e9VGGUPrj4kw7yt/YVzKAVGT8gV0w/UAtrNSzHCqWFwplCCL fMpRuFhklIp/kq+CgUFjxFH9y97zqGTJDi6tVaMRgHKhnvro+m20oR5edqsoRArHyG CVvalF0joRxCZaHA/aFDGZ0XoRK3KNR40gYUurFj492JskesGxuwxpII5DY/0DrNNh whoJOWOw0wkFnVRc/UHdc4W7m8hNx42GuD+i5MocNvfBOv7YSaCAx1kJ6v9zHuyDmH l//Ep85HAIJeWFoaRawJJS2VK0jQRpqZGY08ghWp1sbzuuqtHRAtWGHhNBqppVoSon U2Tu0dqe3cG/A== Original-Received: from alfajor (76-10-182-85.dsl.teksavvy.com [76.10.182.85]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 6F5441204DE; Wed, 3 Feb 2021 14:56:41 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Wed, 03 Feb 2021 12:42:03 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:199239 Archived-At: >> Do you happen to remember how you came to think that >> echo_message_buffer was involved in that old bug report's scenario? > Sadly, no. But I do have some relevant indirect info (it may seem unrelated at first, but bear with me): I was trying to write a test case for bug#15332. Here's what I have so far: (ert-deftest keyboard-tests--echo-keystrokes-bug15332 () (let ((msgs '()) (unread-command-events nil) (redisplay--interactive t) (echo-keystrokes 2)) (setq unread-command-events '(?\C-u)) (let* ((timer1 (run-with-timer 3 1 (lambda () (setq unread-command-events '(?5))))) (timer2 (run-with-timer 2.5 1 (lambda () (push (current-message) msgs))))) (run-with-timer 5 nil (lambda () (cancel-timer timer1) (cancel-timer timer2) (throw 'exit msgs))) (recursive-edit) (should (equal msgs '("C-u 55-" "C-u 5-" "C-u-")))))) It works when Emacs is run interactively: when I revert the offending patch, the test signals an error because the collected messages are only `(nil "C-u 5-" "C-u-")` since the timer that collects the messages runs just when the second `?5` event causes the echo to be erroneously temporarily erased (until the next `echo-keystrokes` timeout). Now I tried to make it work in batch mode, but so far I haven't been successful. As you can guess from the code above I added a `redisplay--interactive` variable to the C code to force it code to use the "interactive" paths at various places and I managed to make it work well enough that the above code does indeed collect echo messages, but somehow those messages end up correct regardless of the offending patch. So I suspect that the test of `echo_message_buffer` is affected by other events (which apparently don't occur in batch mode). I know it's a pretty faint signal, I'm sorry it's all I have so far. See below the patch I'm using, Stefan diff --git a/src/keyboard.c b/src/keyboard.c index 9ee4c4f6d6..b2dad0ca2d 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2539,8 +2539,9 @@ read_char (int commandflag, Lisp_Object map, if (/* There currently is something in the echo area. */ !NILP (echo_area_buffer[0]) - && (/* It's an echo from a different kboard. */ - echo_kboard != current_kboard + && (!EQ (echo_area_buffer[0], echo_message_buffer) + /* It's an echo from a different kboard. */ + || echo_kboard != current_kboard /* Or we explicitly allow overwriting whatever there is. */ || ok_to_echo_at_next_pause == NULL)) cancel_echoing (); @@ -2636,7 +2637,7 @@ read_char (int commandflag, Lisp_Object map, && !current_kboard->immediate_echo && (this_command_key_count > 0 || !NILP (call0 (Qinternal_echo_keystrokes_prefix))) - && ! noninteractive + && (redisplay__interactive || ! noninteractive) && echo_keystrokes_p () && (/* No message. */ NILP (echo_area_buffer[0]) diff --git a/src/xdisp.c b/src/xdisp.c index efca6f641f..3985daa699 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -11150,12 +11150,13 @@ message3_nolog (Lisp_Object m) { struct frame *sf = SELECTED_FRAME (); - if (FRAME_INITIAL_P (sf)) + if (FRAME_INITIAL_P (sf) && !redisplay__interactive) message_to_stderr (m); /* Error messages get reported properly by cmd_error, so this must be just an informative message; if the frame hasn't really been initialized yet, just toss it. */ - else if (INTERACTIVE && sf->glyphs_initialized_p) + else if ((INTERACTIVE || redisplay__interactive) + && sf->glyphs_initialized_p) { /* Get the frame containing the mini-buffer that the selected frame is using. */ @@ -35603,6 +35604,10 @@ syms_of_xdisp (void) mouse stays within the extent of a single glyph (except for images). */); mouse_fine_grained_tracking = false; + DEFVAR_BOOL ("redisplay--interactive", redisplay__interactive, + doc: /* If non-nil, redisplay will proceed even in batch mode. */); + redisplay__interactive = false; + DEFVAR_BOOL ("redisplay-skip-initial-frame", redisplay_skip_initial_frame, doc: /* Non-nil to skip redisplay in initial frame. The initial frame is not displayed anywhere, so skipping it is diff --git a/test/src/keyboard-tests.el b/test/src/keyboard-tests.el index 607d2eafd4..e9a6c497a9 100644 --- a/test/src/keyboard-tests.el +++ b/test/src/keyboard-tests.el @@ -23,14 +23,15 @@ (ert-deftest keyboard-unread-command-events () "Test `unread-command-events'." - (should (equal (progn (push ?\C-a unread-command-events) - (read-event nil nil 1)) - ?\C-a)) - (should (equal (progn (run-with-timer - 1 nil - (lambda () (push '(t . ?\C-b) unread-command-events))) - (read-event nil nil 2)) - ?\C-b))) + (let ((unread-command-events nil)) + (should (equal (progn (push ?\C-a unread-command-events) + (read-event nil nil 1)) + ?\C-a)) + (should (equal (progn (run-with-timer + 1 nil + (lambda () (push '(t . ?\C-b) unread-command-events))) + (read-event nil nil 2)) + ?\C-b)))) (ert-deftest keyboard-lossage-size () "Test `lossage-size'." @@ -46,6 +47,27 @@ keyboard-lossage-size (should-error (lossage-size (1- min-value))) (should (= lossage-orig (lossage-size lossage-orig))))) +(ert-deftest keyboard-tests--echo-keystrokes-bug15332 () + (let ((msgs '()) + (unread-command-events nil) + (redisplay--interactive t) + (echo-keystrokes 2)) + (setq unread-command-events '(?\C-u)) + (let* ((timer1 + (run-with-timer 3 1 + (lambda () + (setq unread-command-events '(?5))))) + (timer2 + (run-with-timer 2.5 1 + (lambda () + (push (current-message) msgs))))) + (run-with-timer 5 nil + (lambda () + (cancel-timer timer1) + (cancel-timer timer2) + (throw 'exit msgs))) + (recursive-edit) + (should (equal msgs '("C-u 55-" "C-u 5-" "C-u-")))))) (provide 'keyboard-tests) ;;; keyboard-tests.el ends here