如何使用日历光标到可见日期而不切换到*日历*

时间:2013-12-25 20:37:36

标签: emacs elisp

我无法弄清楚为什么with-current-bufferset-buffer不能与函数calendar-cursor-to-visible-date一起使用。我希望该功能在没有实际切换到日历窗口的情况下工作 - 即,即使在缓冲区被埋没时它也应该工作。我已经尝试了sit-for 0,但这没有任何影响。

我使用broken-example包含with-current-bufferworking-example使用select-window


编辑:我在2005年3月的Emacs邮件列表中发现了类似的问题:http://lists.gnu.org/archive/html/emacs-pretest-bug/2005-03/msg00170.html我会做更多测试,但以下代码行修复了{{1它在broken-example之后立即发生。

(calendar-cursor-to-visible-date date)

(set-window-point (get-buffer-window "*Calendar*" (selected-frame)) (point)))

2 个答案:

答案 0 :(得分:1)

这是我的建议:

(with-selected-window (or (get-buffer-window (current-buffer) 0)
                          (selected-window))
  (calendar-cursor-to-visible-date date))

当然,在事实之后调用set-window-point也是一个完全可以接受的选择。

答案 1 :(得分:0)

2013年12月25日:修订后的函数calendar-cursor-to-visible-date的第一份工作草案,使用set-window-point

(defun lawlist-calendar-cursor-to-visible-date (date)
  "Move the cursor to DATE that is on the screen."
  (let* (
      (month (calendar-extract-month date))
      (day (calendar-extract-day date))
      (year (calendar-extract-year date))
      (buffer (buffer-name)))
    (goto-char (point-min))
    (forward-line (+ calendar-first-date-row -1
                     (/ (+ day -1
                           (mod
                            (- (calendar-day-of-week (list month 1 year))
                               calendar-week-start-day)
                            7))
                        7)))
    (move-to-column (+ calendar-left-margin (1- calendar-day-digit-width)
                       (* calendar-month-width
                          (1+ (calendar-interval
                               displayed-month displayed-year month year)))
                       (* calendar-column-width
                          (mod
                           (- (calendar-day-of-week date)
                              calendar-week-start-day)
                           7))))
    (if (get-buffer-window buffer (selected-frame))
      (set-window-point (get-buffer-window buffer (selected-frame)) (point)))))