How to distinguish between different overlays at point

牧云@^-^@ 提交于 2019-12-10 10:33:48

问题


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

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

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

回答1:


Ok, let's try to figure this out (without really knowing anything about the calendar).

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


来源:https://stackoverflow.com/questions/20715445/how-to-distinguish-between-different-overlays-at-point

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!