简体   繁体   English

当光标进入emacs中的叠加层时,如何显示提示?

[英]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.) 当点进入叠加层时,我想显示更多细节(现在有message ,但可能在单独的缓冲区中。)

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. help-echo 几乎就是我想要的,但是我在终端中使用Gnu Emacs,而help-echo用于鼠标指针,而不是点。

point-entered is also almost what I want, but point-entered doesn't have any effect in overlays, only text properties. point-entered几乎是我想要的,但point-entered对叠加没有任何影响,只有文本属性。

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? 叠加首先看起来很吸引人,因为当我重新分析缓冲区时很容易将它们删除(我正在re-builder这里的内容。)我应该继续使用叠加但是使用点运动挂钩找到叠加层,提取提示,并显示它们? 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). 您可能想尝试使用cursor-sensor-mode (这是Emacs-25中的新功能),它允许您对cursor-sensor-functions文本属性(包括通过叠加)进行操作。

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). 它的目的是取代point-entered性和反应的光标,而不是中移动的移动point (两个密切相关的,但不同的:一个给定的命令可以在内部移动点很多次,但光标只会移动一次,在显示更新结束时)。

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方法,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. 当涉及到覆盖与文本属性时 - 一个区别是在执行buffer-substring时保留了文本属性,这可能不是你想要的。 Another is that text properties are shared between inherited buffers (even though this is a seldom used feature). 另一个是文本属性在继承的缓冲区之间共享(即使这是一个很少使用的功能)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM