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 fi开发者_如何学编程nd the overlays, extract the prompts, and display them? Should I be using text properties instead of overlays?
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).
For some ideas, check out auto-complete mode.
It pops up a menu at point that people can scroll through. This may not be exactly what you want - sounds like you don't want a menu - but looking into the code might be interesting.
Also see the tooltip-show method, part of tooltip.el.
tooltip-show is a compiled Lisp function in `tooltip.el'.
(tooltip-show TEXT &optional USE-ECHO-AREA)
Show a tooltip window displaying TEXT.
Text larger than `x-max-tooltip-size' is clipped.
If the alist in `tooltip-frame-parameters' includes `left' and `top'
parameters, they determine the x and y position where the tooltip
is displayed. Otherwise, the tooltip pops at offsets specified by
`tooltip-x-offset' and `tooltip-y-offset' from the current mouse
position.
Optional second arg USE-ECHO-AREA non-nil means to show tooltip
in echo area.
In general, it is not a good design to react on mouse movements, as the mouse will most probably pass by your areas for many reasons.
I would advice you to implement this on, for example, the right menu button.
When it comes to overlays vs. text properties -- one difference is that text properties are retained when doing buffer-substring
, which is probably not what you want. Another is that text properties are shared between inherited buffers (even though this is a seldom used feature).
精彩评论