all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”
@ 2013-09-27  0:01 Anders Kaseorg
  2020-12-06 15:27 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Anders Kaseorg @ 2013-09-27  0:01 UTC (permalink / raw)
  To: 15469

When using Emacs in server mode and ‘emacsclient -c’ as my preferred
editor, new windows opened by emacsclient often fail to grab keyboard
focus, correlated with Emacs asking minibuffer questions like “Revert
buffer from file?” as the file is opened (e.g. on .git/COMMIT_EDITMSG
which is frequently modified both inside and outside Emacs).  I can
reproduce this reliably as follows:

1. emacs -Q /tmp/foo
2. M-x server-start
3. Type some text into the buffer; do not save.
4. Click outside the Emacs window to unfocus it.
5. Click inside the Emacs window to focus it.
6. Click outside the Emacs window to unfocus it.
7. Modify /tmp/foo outside Emacs.
8. emacsclient -c /tmp/foo
9. An _unfocused_ Emacs window pops up to ask “Revert buffer from file
/tmp/foo?”.

(If I skip step 5, or if I replace step 5 with clicking on the _title
bar_ of the first Emacs window to focus it, then the new window has no
trouble grabbing focus; I can only reproduce when clicking _inside_ the
Emacs window to focus it.)

My window manager, if it matters, is gnome-shell 3.8.4-0ubuntu5.

In GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.8.2)
  of 2013-07-26 on roseapple, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11402901
System Description:	Ubuntu Saucy Salamander (development branch)

Configured using:
  `configure '--build' 'x86_64-linux-gnu' '--build' 'x86_64-linux-gnu'
  '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
  '--localstatedir=/var/lib' '--infodir=/usr/share/info'
  '--mandir=/usr/share/man' '--with-pop=yes'

'--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.3/site-lisp:/usr/share/emacs/site-lisp'
  '--with-crt-dir=/usr/lib/x86_64-linux-gnu' '--with-x=yes'
  '--with-x-toolkit=gtk3' '--with-toolkit-scroll-bars'
  'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector
  --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall'
  'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'
  'CPPFLAGS=-D_FORTIFY_SOURCE=2''

Important settings:
   value of $LC_MONETARY: en_US.UTF-8
   value of $LC_NUMERIC: en_US.UTF-8
   value of $LC_TIME: en_US.UTF-8
   value of $LANG: en_US.UTF-8
   value of $XMODIFIERS: @im=none
   locale-coding-system: utf-8-unix
   default enable-multibyte-characters: t

Major mode: Fundamental

Minor modes in effect:
   tooltip-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   line-number-mode: t
   transient-mark-mode: t

Recent input:
M-x s e r v e r - s t a r t <return> f o o <return>=20
<down-mouse-1> <mouse-1> <help-echo> <down-mouse-1>=20
<mouse-movement> <mouse-1> n o <return> M-x r e p o=20
r t - e m a c s - b u g <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
(New file)
When done with a buffer, type C-x #

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils server time-date tooltip ediff-hook
vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment lisp-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process dbusbind dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty emacs)





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”
  2013-09-27  0:01 bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?” Anders Kaseorg
@ 2020-12-06 15:27 ` Lars Ingebrigtsen
  2020-12-06 15:32   ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-06 15:27 UTC (permalink / raw)
  To: Anders Kaseorg; +Cc: 15469

Anders Kaseorg <andersk@MIT.EDU> writes:

> When using Emacs in server mode and ‘emacsclient -c’ as my preferred
> editor, new windows opened by emacsclient often fail to grab keyboard
> focus, correlated with Emacs asking minibuffer questions like “Revert
> buffer from file?” as the file is opened (e.g. on .git/COMMIT_EDITMSG
> which is frequently modified both inside and outside Emacs).  I can
> reproduce this reliably as follows:
>
> 1. emacs -Q /tmp/foo
> 2. M-x server-start
> 3. Type some text into the buffer; do not save.
> 4. Click outside the Emacs window to unfocus it.
> 5. Click inside the Emacs window to focus it.
> 6. Click outside the Emacs window to unfocus it.
> 7. Modify /tmp/foo outside Emacs.
> 8. emacsclient -c /tmp/foo
> 9. An _unfocused_ Emacs window pops up to ask “Revert buffer from file
> /tmp/foo?”.

(This bug report unfortunately got no response at the time.)

I can confirm that this bug is still present in Emacs 28, but I have not
tried to debug it.  Anybody with a guess at what's going on?

The new frame that's popped up does have focus, as expected, if the
"revert buffer" query isn't done.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”
  2020-12-06 15:27 ` Lars Ingebrigtsen
@ 2020-12-06 15:32   ` Eli Zaretskii
  2020-12-06 15:44     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-12-06 15:32 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 15469, andersk

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Sun, 06 Dec 2020 16:27:30 +0100
> Cc: 15469@debbugs.gnu.org
> 
> > 1. emacs -Q /tmp/foo
> > 2. M-x server-start
> > 3. Type some text into the buffer; do not save.
> > 4. Click outside the Emacs window to unfocus it.
> > 5. Click inside the Emacs window to focus it.
> > 6. Click outside the Emacs window to unfocus it.
> > 7. Modify /tmp/foo outside Emacs.
> > 8. emacsclient -c /tmp/foo
> > 9. An _unfocused_ Emacs window pops up to ask “Revert buffer from file
> > /tmp/foo?”.
> 
> (This bug report unfortunately got no response at the time.)
> 
> I can confirm that this bug is still present in Emacs 28, but I have not
> tried to debug it.  Anybody with a guess at what's going on?

We ask the question before we switch to the new frame, so I guess the
question appears in the previous frame?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”
  2020-12-06 15:32   ` Eli Zaretskii
@ 2020-12-06 15:44     ` Lars Ingebrigtsen
  2020-12-06 16:00       ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-06 15:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 15469, andersk

Eli Zaretskii <eliz@gnu.org> writes:

> We ask the question before we switch to the new frame, so I guess the
> question appears in the previous frame?

No, it appears in the new frame.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”
  2020-12-06 15:44     ` Lars Ingebrigtsen
@ 2020-12-06 16:00       ` Eli Zaretskii
  2020-12-06 16:14         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-12-06 16:00 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 15469, andersk

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: andersk@MIT.EDU,  15469@debbugs.gnu.org
> Date: Sun, 06 Dec 2020 16:44:08 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > We ask the question before we switch to the new frame, so I guess the
> > question appears in the previous frame?
> 
> No, it appears in the new frame.

OK, but still: we raise the frame only when we are done, right?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”
  2020-12-06 16:00       ` Eli Zaretskii
@ 2020-12-06 16:14         ` Lars Ingebrigtsen
  2020-12-06 16:51           ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-06 16:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 15469, andersk

Eli Zaretskii <eliz@gnu.org> writes:

>> > We ask the question before we switch to the new frame, so I guess the
>> > question appears in the previous frame?
>> 
>> No, it appears in the new frame.
>
> OK, but still: we raise the frame only when we are done, right?

Yes.  I instrumented raise-frame, and it was indeed called after I
answered "yes" to the "revert" question:

Debugger entered--entering a function:
* raise-frame(#<frame  *Minibuf-1* 0x5652caf5a498>)
  select-frame-set-input-focus(#<frame  *Minibuf-1* 0x5652caf5a498>)
  server-switch-buffer(#<buffer foo> nil nil #<frame  *Minibuf-1* 0x5652caf5a498>)
  server-execute(#<process server <2>> (("/tmp/foo")) nil nil t #<frame  *Minibuf-1* 0x5652caf5a498> window-system)
  #f(compiled-function () #<bytecode -0x1de923e1af168e73>)()
  server-execute-continuation(#<process server <2>>)
  server-process-filter(#<process server <2>> "-env SHELL=/bin/bash -env SESSION_MANAGER=local/xo...")

So just raising the frame before we process the buffers seems to fix the
problem for me.

Comments?

diff --git a/lisp/server.el b/lisp/server.el
index 2fd94552dd..aa7297ba48 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1328,6 +1328,8 @@ server-execute
   ;; inhibit-quit flag, which is good since `commands' (as well as
   ;; find-file-noselect via the major-mode) can run arbitrary code,
   ;; including code that needs to wait.
+  (when (and frame server-raise-frame)
+    (select-frame-set-input-focus frame))
   (with-local-quit
     (condition-case err
         (let ((buffers (server-visit-files files proc nowait)))
@@ -1676,9 +1678,7 @@ server-switch-buffer
                   (switch-to-buffer next-buffer))
 	      ;; After all the above, we might still have ended up with
 	      ;; a minibuffer/dedicated-window (if there's no other).
-	      (error (pop-to-buffer next-buffer)))))))
-    (when server-raise-frame
-      (select-frame-set-input-focus (window-frame)))))
+	      (error (pop-to-buffer next-buffer)))))))))
 
 ;;;###autoload
 (defun server-save-buffers-kill-terminal (arg)


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”
  2020-12-06 16:14         ` Lars Ingebrigtsen
@ 2020-12-06 16:51           ` Eli Zaretskii
  2020-12-07 13:31             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-12-06 16:51 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 15469, andersk

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: 15469@debbugs.gnu.org,  andersk@MIT.EDU
> Date: Sun, 06 Dec 2020 17:14:45 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> So just raising the frame before we process the buffers seems to fix the
> problem for me.
> 
> Comments?

There be dragons: we've had several changes in this area, each one of
them caused unintended "misfeatures" in other use cases.  So I would
suggest to review bug reports related to emacsclient for the recent,
say, 3 years, and make sure the various use cases described there
still work correctly, both with TTY frames and GUI frames.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”
  2020-12-06 16:51           ` Eli Zaretskii
@ 2020-12-07 13:31             ` Lars Ingebrigtsen
  2020-12-23  5:59               ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-07 13:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 15469, andersk

Eli Zaretskii <eliz@gnu.org> writes:

> There be dragons: we've had several changes in this area, each one of
> them caused unintended "misfeatures" in other use cases.

Indeed.

> So I would suggest to review bug reports related to emacsclient for
> the recent, say, 3 years, and make sure the various use cases
> described there still work correctly, both with TTY frames and GUI
> frames.

Well, that sounds like work, but I did go through the VC log for
server.el and ran through the cases for reproduction of bugs fixed over
the past two years, and they were not affected by this change, so I went
ahead and applied it.

I guess we'll find out whether this regresses something when people
start using it.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”
  2020-12-07 13:31             ` Lars Ingebrigtsen
@ 2020-12-23  5:59               ` Lars Ingebrigtsen
  0 siblings, 0 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-23  5:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 15469, andersk

Lars Ingebrigtsen <larsi@gnus.org> writes:

> I guess we'll find out whether this regresses something when people
> start using it.

It did, so I've now reverted the change and reopened this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-23  5:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-27  0:01 bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?” Anders Kaseorg
2020-12-06 15:27 ` Lars Ingebrigtsen
2020-12-06 15:32   ` Eli Zaretskii
2020-12-06 15:44     ` Lars Ingebrigtsen
2020-12-06 16:00       ` Eli Zaretskii
2020-12-06 16:14         ` Lars Ingebrigtsen
2020-12-06 16:51           ` Eli Zaretskii
2020-12-07 13:31             ` Lars Ingebrigtsen
2020-12-23  5:59               ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.