5

I'm having trouble with getting local keymap:s to work in the mode-line, but only in terminals (with xterm-mouse-mode enabled).

This applies to both the standard mode-line entries (like mode-line-toggle-read-only) and entries I manually add.

For example, the following work in a GUI Emacs (tested on the NS port on macOS), but not in an Emacs running in a terminal. (When clicking on the PRESSME text in the mode-line, the message I was pressed should appear.):

(defun my-press-me ()
  (interactive)
  (message "I was pressed"))

(push '(:propertize "PRESSME"
                    local-map
                    (keymap
                     (mode-line .
                                (keymap
                                 (down-mouse-1 . my-press-me)))))
      mode-line-format)

Interestingly, when I press C-h k and click in the PRESSME text, it reports my-press-me both in a GUI Emacs and when running in the terminal.

Any thoughts?

3

IIUC this is a bug in Emacs's C code which was fixed recently in Emacs's master branch (i.e. it will be fixed in Emacs-27, but not Emacs-26).

There might be a way to workaround the bug with some fancy hack in xterm-mouse-mode in Emacs<27, but I'm not sure it's worth the effort to try and come up with it.

See https://debbugs.gnu.org/29104 for details.

  • Amazing! I was testing is against the master branch, but apparently it was a couple of weeks too old... (And it isn't the first time I've stumbled on ancient bugs only find them just fixed.) Thanks! – Lindydancer Dec 4 '17 at 13:42
2

I can reproduce this with Emacs 24.4 under Linux. I have a solution, but I don't claim to understand why it works. Although describe-key reads a down-mouse-1 event when you press the button, pressing the button actually triggers the binding for mouse-1. This works both in a terminal (with xterm-mouse-mode) and in an X11 window:

(push '(:propertize "PRESSME"
                    local-map
                    (keymap
                     (mode-line .
                                (keymap
                                 (mouse-1 . my-press-me)))))
      mode-line-format)
  • Unfortunately, this doesn't work on macOS running Terminal.app. – Lindydancer Dec 2 '17 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.