如何区分不同的叠加点 [英] How to distinguish between different overlays at point
问题描述
ORIGINAL QUESTION :我正在寻找一些帮助来区分可能存在于点的叠加层。如果覆盖在
点,则使用 lawlist-red-face
进行,然后执行 X
。如果覆盖在
点是使用 calendar-holiday-marker
进行的,则执行 Y
。覆盖层用这两个功能进行。
ORIGINAL QUESTION: I'm looking for some assistance, please, to distinguish between overlays that may exist at point. If the overlays-at
point is made with the lawlist-red-face
then do X
. If the overlays-at
point is made with calendar-holiday-marker
, then do Y
. The overlays are made with these two functions.
(calendar-mark-visible-date (car holiday) lawlist-red-face)
(calendar-mark-visible-date (car holiday) calendar-holiday-marker)
EDIT (2014年1月1日):@Drew在 calendar + .el中写了一个不错的测试
( http://www.emacswiki.org/emacs/calendar %2B.el ):
EDIT (January 1, 2014): @Drew wrote a nice test for this in calendar+.el
( http://www.emacswiki.org/emacs/calendar%2B.el ):
(when
(memq lawlist-red-face
(mapcar (function (lambda (ovr)
(overlay-get ovr 'face))) (overlays-at (point))))
... )
编辑(2014年2月13日)列出的片段也可以与(while(re-search-backward[0-9]nil t)
一起使用,以创建日期的组合列表覆盖 - 月,日,年均用提取日历提取日
, calendar-extract-month
和 calendar-extract-year
- 日期是使用(calendar-cursor-to-nearest-date)
获得的:
EDIT (February 13, 2014): The above-listed snippet can also be used in conjunction with something like (while (re-search-backward "[0-9]" nil t)
to create a combined list of dates with overlays -- month, day and year are extracted with calendar-extract-day
, calendar-extract-month
and calendar-extract-year
-- the date is obtained with (calendar-cursor-to-nearest-date)
:
;; modified with the help of @phils based on comments down below.
(setq lawlist-mouse-marked
(append lawlist-mouse-marked
`((holiday-sexp '(list ,month ,day ,year) ""))))
然后,该列表可以与 calendar-holiday-list
(或修改后的代码)在生成新的日历布局之后注明日期。如果用户手动标记日期(例如,使用鼠标)并希望这些日期在向前/向后滚动日历之后重新出现,这将非常有用。库 holidays.el
包含函数 holiday-sexp
,它使用过滤函数过滤器可见日历
来编辑日期列表,以便只有在新日历上可见的内容被标记:
That list can then be used with something like calendar-holiday-list
(or the modified code below) to remark dates on a new calendar layout after it has been generated. This is useful if the user has manually marked dates (e.g., with the mouse) and wants those dates to reappear after scrolling the calendar forwards / backwards. The library holidays.el
contains the function holiday-sexp
which uses a filtering function holiday-filter-visible-calendar
to edit the list of dates so that only those that are visible on the new calendar get marked:
(dolist (holiday
(let (res h err)
(sort
(dolist (p lawlist-mouse-marked res)
(if (setq h (eval p))
(setq res (append h res))))
'calendar-date-compare)))
(calendar-mark-visible-date (car holiday) lawlist-mouse-calendar-face))
推荐答案
让我们试着弄清楚(没有真正了解日历的任何内容)。
Ok, let's try to figure this out (without really knowing anything about the calendar).
(overlay-at)
返回重叠列表。我会保持这个简单,只有处理第一个,如果你想检查所有的,只需循环,直到找到一个适合的。
(overlays-at)
returns a list of overlays. I will keep this simple and only handle the first, if you want to examine all of them, simply loop over them until you find one that is suitable.
另外, 面对
的属性可能比简单的面部名称更复杂,如果是这样,您还需要处理这种情况。
Also, the face
property can be more complex than simply the name of the face, if that is the case you would need to handle that as well.
但无论如何,这里是一个简单的代码(希望)执行你想要的:
But anyway, here is a simple piece of code that (hopefully) does what you want:
(let ((overlays (overlays-at (point))))
(if overlays
(let ((face (overlay-get (car overlays) 'face)))
(cond ((eq face 'lawlist-red-face)
;; Do something
)
((eq face 'holiday)
;; Do another thing
)
(t
;; Do something else)))))
这篇关于如何区分不同的叠加点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!