1

Years ago, when Emacs was at 21.*, I had a function that displayed a tooltip when I hovered the mouse on certain words in the buffer. Now, in 26.3, I want to use that function again, but it does not work any more, apparently because Emacs is not passing mouse movement events to it.

Minimal example that worked fine in Emacs 21 but does nothing in Emacs 26:

(defun my-tooltip (event)
  (interactive "e")
  (tooltip-show "got mouse movement event")
  t)

(progn
  (tooltip-mode)
  (set (make-local-variable 'track-mouse) t)
  (setq tooltip-functions nil)
  (add-hook 'tooltip-functions 'my-tooltip))

One more thing: when I did M-x describe-key and moved the mouse, older Emacs versions used to tell me which command, if any, was bound to mouse-movement. In the same situation, Emacs 26 does nothing — it obviously does not see that I am moving the mouse, even when I set track-mouse to t globally.

Running Emacs with -Q does not change anything.

How should I catch mouse movement events in Emacs 26?

2
  • 25.3, 26.3, and 27.2 all do the same thing for me with that code -- when I hover over something with a tooltip, such as a menu item, I see your message from my-tooltip. If you want tooltips for "certain words in the buffer" you need to set the help-echo text property on those words. – phils yesterday
  • See C-h i g (elisp)Special Properties and (elisp)Tooltips – phils yesterday
0

Not exactly an answer, but a dirty workaround: give up using tooltip-functions and bind the function directly to mouse-movement, like this:

(defun my-tooltip (event)
  (interactive "e")
  (tooltip-show "got mouse movement event")
  t)
(tooltip-mode)
(set (make-local-variable 'track-mouse) t)
(local-set-key (kbd "<mouse-movement>") 'my-tooltip)

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.