gpt4 book ai didi

emacs - 如何区分点的不同叠加

转载 作者:行者123 更新时间:2023-12-01 12:45:15 25 4
gpt4 key购买 nike

原始问题:我正在寻求一些帮助,以区分可能存在的叠加层。如果 overlays-at 点是使用 lawlist-red-face 制作的,则执行 X。如果 overlays-at 点是使用 calendar-holiday-marker 制作的,则执行 Y。叠加层是用这两个函数制作的。

(calendar-mark-visible-date (car holiday) lawlist-red-face)

(calendar-mark-visible-date (car holiday) calendar-holiday-marker)

编辑(2014 年 1 月 1 日):@Drew 在 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-daycalendar-extract-month 提取月、日和年> 和 calendar-extract-year -- 使用 (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,它使用过滤函数 holiday-filter-visible-calendar 来编辑日期列表这样只有那些在新日历上可见的才会被标记:

(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))

最佳答案

好吧,让我们尝试解决这个问题(在对日历一无所知的情况下)。

(overlays-at) 返回覆盖列表。我会保持简单,只处理第一个,如果您想检查所有这些,只需循环遍历它们,直到找到合适的。

此外,face 属性可能比简单的人脸名称更复杂,如果是这种情况,您也需要处理它。

但无论如何,这里有一段简单的代码(希望)可以完成您想要的:

(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)))))

关于emacs - 如何区分点的不同叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20715445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com