unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Platon Pronko <platon7pronko@gmail.com>
Cc: 45292@debbugs.gnu.org
Subject: bug#45292: Acknowledgement (28.0.50; first key typed ignores current input method (in magit commit buffer))
Date: Wed, 23 Dec 2020 18:32:20 -0500	[thread overview]
Message-ID: <jwv1rfgt8ko.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <1f8c0245-61bc-6546-e776-f5ccf8ffa855@gmail.com> (Platon Pronko's message of "Thu, 17 Dec 2020 19:31:57 +0300")

> Digged into it further. Here's what I found:
>
> 1. quail-input-method is used to translate keys according current keymap.
>
> 2. At the time of the first keystroke ("j" in my example) quail-input-method
> sees incorrect buffer (verified this by calling and printing buffer-name
> from inside quail-input-method). It sees "magit: test-repo" on the first
> keystroke, and "COMMIT_EDITMSG" on subsequent keystrokes. And since "magit:
> test-repo" is read-only, no translation is done and key is returned as-is.
>
> 3. So apparently record_asynch_buffer_change() was crucial to update the current buffer.

Here's what's happening:
1- after hitting `c c`, Magit launches `git` in the background
2- at this point we're entering `read_char` and the current buffer is the
   Magit buffer.
3- soon after, git launches the editor, which Magit has set to emacsclient
4- emacsclient contacts us
5- while still in `read_char` is waiting in `sit_for`, we process
   emacsclient which sets up the git-commit buffer,
   displays it and select it as the main window.
6- `sit_for` carefully preserves the current buffer so after step 5,
   we're still in the Magit buffer even though the selected windows is
   not the git-commit one.
7- we hit `j` in the git-commit buffer/window but it's read while in
   cvs-commit
8- boom!

I installed the patch below which fixes this problem.


        Stefan


diff --git a/src/dispnew.c b/src/dispnew.c
index bcea26a66a..534002584e 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -6062,6 +6062,8 @@ sit_for (Lisp_Object timeout, bool reading, int display_option)
   intmax_t sec;
   int nsec;
   bool do_display = display_option > 0;
+  bool curbuf_eq_winbuf
+    = (current_buffer == XBUFFER (XWINDOW (selected_window)->contents));
 
   swallow_events (do_display);
 
@@ -6116,6 +6118,13 @@ sit_for (Lisp_Object timeout, bool reading, int display_option)
   wait_reading_process_output (sec, nsec, reading ? -1 : 1, do_display,
 			       Qnil, NULL, 0);
 
+  if (reading && curbuf_eq_winbuf)
+    /* Timers and process filters/sentinels may have changed the selected
+       window (e.g. in response to a connection from emacsclient), in which
+       case we should follow it (unless we weren't in the selected-window's
+       buffer to start with).  */
+    set_buffer_internal (XBUFFER (XWINDOW (selected_window)->contents));
+
   return detect_input_pending () ? Qnil : Qt;
 }
 






  reply	other threads:[~2020-12-23 23:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17 12:52 bug#45292: 28.0.50; first key typed ignores current input method (in magit commit buffer) Platon Pronko
     [not found] ` <handler.45292.B.16082095764744.ack@debbugs.gnu.org>
2020-12-17 13:45   ` bug#45292: Acknowledgement (28.0.50; first key typed ignores current input method (in magit commit buffer)) Platon Pronko
2020-12-17 16:31     ` Platon Pronko
2020-12-23 23:32       ` Stefan Monnier [this message]
2020-12-24  7:26         ` Platon Pronko
2021-04-04  1:00           ` bug#45292: 28.0.50; first key typed ignores current input method (in magit commit buffer) Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv1rfgt8ko.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=45292@debbugs.gnu.org \
    --cc=platon7pronko@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).