Search code examples
emacselisp

How do I display a prompt when the cursor enters an overlay in emacs?


I'm writing a minor mode which dispenses writing advice. I am using overlays to highlight mistakes. When the point enters the overlay, I want to display more detail (with message for now, but maybe in a separate buffer.)

help-echo is almost what I want, but I use Gnu Emacs in the terminal, and help-echo is for the mouse pointer, not the point.

point-entered is also almost what I want, but point-entered doesn't have any effect in overlays, only text properties.

Overlays looked appealing in the first place because it is easy to obliterate them when I reparse the buffer (I'm cribbing from what re-builder does here.) Should I continue using overlays but use point motion hooks to find the overlays, extract the prompts, and display them? Should I be using text properties instead of overlays?


Solution

  • You might like to try cursor-sensor-mode (which is new in Emacs-25) which lets you place actions on the cursor-sensor-functions text properties (including via overlays).

    It is intended to replace the point-entered property and reacts to movements of the cursor rather than to movements of point (the two are closely related, yet different: a given command can move point many times internally, but the cursor will only be moved once, at the end when the display is updated).