如何在日历中仅标记一个日期 - 删除叠加层

时间:2013-12-13 01:36:55

标签: emacs elisp

错误讯息:let: Wrong type argument: overlayp, (#<overlay from 478 to 480 in *Calendar*>)

mouse-1在日历中成功标记了日期。内置函数仅用于删除所有叠加层,而不是仅删除一个特定日期。任何人都可以帮我删除一个标记日期的叠加层 - 我想这可能是mouse-2U。我想过使用skip-syntax-forwards / backwards,因为有些日期只有一位数,有些有两位数 - 光标可能在两位数之间或日期的两边。我认为我们需要一个起点和终点。

(define-key calendar-mode-map [mouse-1] (lambda () (interactive)
  (calendar-mark-visible-date (calendar-cursor-to-date t))))

(define-key calendar-mode-map "U" (lambda () (interactive)
  (cond
    ((save-excursion (> 0 (skip-syntax-backward "w")))
      (skip-syntax-backward "w")
      (let ((beg (point)))
        (skip-syntax-forward "w")
          (let ((end (point)))
            (delete-overlay (overlays-in beg end)))))
    ((save-excursion (< 0 (skip-syntax-forward "w")))
      (skip-syntax-forward "w")
      (let ((end (point)))
        (skip-syntax-backward "w")
          (let ((beg (point)))
            (delete-overlay (overlays-in beg end))))))))

编辑(2013年12月12日):基于@Drew的有用答案的第一份工作草案。添加了mouse-set-point和交互式代码以支持所述功能。合并键盘快捷键,以便mouse-1在点处激活/停用叠加层 - 现在使用overlays-at

编辑(2014年1月1日):要区分一个或多个重叠点,请参阅以下主题:How to distinguish between different overlays at point使用该主题中的示例,可能会发生不同的操作,具体取决于关于特定叠加是否存在于点。

(defvar lawlist-calendar-face (make-face 'lawlist-calendar-face))
(set-face-attribute 'lawlist-calendar-face nil
  :background "LightCoral" :foreground "black")

(define-key calendar-mode-map [mouse-1] (lambda (event) (interactive "e")
  (mouse-set-point event)
  (if (not (overlays-at (point)))
    (calendar-mark-visible-date (calendar-cursor-to-date t) lawlist-calendar-face)
  (cond
    ;; cursor is one whitespace to the left of 1 to 9
    ((and
        (save-excursion (< 0 (skip-chars-forward " \t")))
        (not (save-excursion (< 0 (skip-syntax-forward "w")))))
      (save-excursion
        (let ((beg (point)))
          (skip-chars-forward " \t")
          (skip-syntax-forward "w")
            (let ((end (point)))
              (mapc 'delete-overlay (overlays-in beg end))))))
    ;; cursor is sandwiched between a digit on each side.
    ((and
        (save-excursion (> 0 (skip-syntax-backward "w")))
        (save-excursion (< 0 (skip-syntax-forward "w"))))
      (save-excursion
        (skip-syntax-backward "w")
        (let ((beg (point)))
          (skip-syntax-forward "w")
            (let ((end (point)))
              (mapc 'delete-overlay (overlays-in beg end))))))
    ;; cursor is to the far right of one or two digit dates
    ((and
        (save-excursion (> 0 (skip-syntax-backward "w")))
        (not (save-excursion (< 0 (skip-syntax-forward "w")))))
      (save-excursion
        (skip-syntax-backward "w")
        (let ((beg (point)))
          (skip-syntax-forward "w")
            (let ((end (point)))
              (mapc 'delete-overlay (overlays-in beg end))))))
    ;; cursor to the far left of one or two digits dates
    ((and
        (save-excursion (< 0 (skip-syntax-forward "w")))
        (not (save-excursion (> 0 (skip-syntax-backward "w")))))
      (save-excursion
        (skip-syntax-forward "w")
        (let ((end (point)))
          (skip-syntax-backward "w")
            (let ((beg (point)))
              (mapc 'delete-overlay (overlays-in beg end))))))))))

1 个答案:

答案 0 :(得分:2)

错误:

delete-overlay期望单个叠加层作为其参数。您传递的是覆盖列表(空或非空)。您应该遍历列表,例如,使用whiledolistmapc