Emacsclient does not respond to mouse clicks
Asked Answered
V

1

6

When I run emacsclient it does not respond to mouse clicks. My main Emacs process runs in a terminal and responds to mouse clicks correctly because I have the following code in my Emacs config file:

(xterm-mouse-mode 1)

Why does emacsclient not respond to mouse clicks? Is there a way to make it do so?

Veronique answered 24/6, 2011 at 0:40 Comment(0)
H
10

This is probably because certain settings in Emacs are specific to the terminal, and manipulating such settings in your init file will only affect the terminal which is active at the time the init file was evaluated.

The following Q+A deals with much the same issue, and goes into the details:

Run command on new frame with daemon/client in Emacs

For your issue, I think this should do the trick:

(defun my-terminal-config (&optional frame)
  "Establish settings for the current terminal."
  (if (not frame) ;; The initial call.
      (xterm-mouse-mode 1)
    ;; Otherwise called via after-make-frame-functions.
    (if xterm-mouse-mode
        ;; Re-initialise the mode in case of a new terminal.
        (xterm-mouse-mode 1))))
;; Evaluate both now (for non-daemon emacs) and upon frame creation
;; (for new terminals via emacsclient).
(my-terminal-config)
(add-hook 'after-make-frame-functions 'my-terminal-config)
Hemistich answered 23/7, 2011 at 4:45 Comment(10)
Excellent! I was actually having this problem only in GNU Screen sessions, but this solves it.Veronique
Good to hear. I've just realised that as xterm-mouse-mode is a global minor mode, my code was flawed in that if you intentionally disable that mode, and then create a new frame, it would get switched back on again. I've edited the code accordingly. I think the mode is smart enough to not need the window-system check I initially included (and which wasn't sufficient to identify an xterm in any case).Hemistich
Just wanted to mention that this can cause bug #28800 with rxvt.Jacobsohn
@AndreaRichiardi, what do you mean by "this"? Using xterm-mouse-mode? Using it in after-make-frame-functions? Something else?Hemistich
Sorry for the delay, but basically the call in after-make-frame-functions works well. The (my-terminal-config) calls probably triggers the bug. Commenting it out solves. Also note that this is a emacsclient -nw bug only.Jacobsohn
Anybody stumbling on this: I'm pretty sure that when you use this hook, and then close out the frame and return to the terminal, mouse actions start printing escape sequences instead of working normally. Super annoying side-effect, I'll try and see if I can detect frames closing and restore normal mouse behavior.Chevaldefrise
@Chevaldefrise Assuming that you can reproduce the issue from emacs -Q, I would M-x report-emacs-bug about that.Hemistich
Uhm, so I would run emacs -Q (or rather, the emacs-daemon without a config file), then add this hook manually, and then see if the issue persist?Chevaldefrise
Yes indeed. You can use emacs --daemon -Q -- those arguments work together. If it turns out that the problem doesn't occur under those conditions, then you might start recursively bisecting your init file to figure out what other factors are involved.Hemistich
Hm okay, it did find a way to fix it by sending an escape sequence that resets the xterm mouse behavior back to normal. So if you do (send-string-to-terminal "\033[?1000l") before emacs closes the frame then the problem goes away.Chevaldefrise

© 2022 - 2024 — McMap. All rights reserved.