如何使用Emacs Calendar在Lisp中实现24个节气

时间:2014-01-26 15:23:15

标签: emacs calendar lisp elisp

我尝试在Emacs源代码中学习cal-china.el中的代码,并找到以下代码:

;;;###holiday-autoload
(defun holiday-chinese-winter-solstice ()
  "Date of Chinese winter solstice, if visible in calendar.
Returns (((MONTH DAY YEAR) TEXT)), where the date is Gregorian."
  (when (memq displayed-month '(11 12 1)) ; is December visible?
    (list (list (calendar-gregorian-from-absolute
             (calendar-chinese-zodiac-sign-on-or-after
              (calendar-absolute-from-gregorian
               (list 12 15 (if (eq displayed-month 1)
                               (1- displayed-year)
                             displayed-year)))))
            "Winter Solstice Festival"))))

此代码用于计算winter solstice。我也知道计算solar terms需要24 Chinese calendar。所以我想知道如何计算Lisp中的所有24个节气。

谢谢。

1 个答案:

答案 0 :(得分:1)

对于任何对中国日历感兴趣的人,请参考此仓库以获取详细信息。

https://github.com/xwl/cal-china-x

安装cal-china-x

后,可以使用以下代码来计算太阳项
;;;###autoload
(defun holiday-solar-term (solar-term str)
  "A holiday(STR) on SOLAR-TERM day.
See `cal-china-x-solar-term-name' for a list of solar term names ."
  (cal-china-x-sync-solar-term displayed-year)
  (let ((terms cal-china-x-solar-term-alist)
        i date)
    (while terms
      (setq i (car terms)
            terms (cdr terms))
      (when (string= (cdr i) solar-term)
        (let ((m (caar i))
              (y (cl-caddar i)))
          ;; displayed-year, displayed-month is accurate for the centered month
          ;; only. Cross year view: '(11 12 1), '(12 1 2)
          (when (or (and (cal-china-x-cross-year-view-p)
                         (or (and (= displayed-month 12)
                                  (= m 1)
                                  (= y (1+ displayed-year)))
                             (and (= displayed-month 1)
                                  (= m 12)
                                  (= y (1- displayed-year)))))
                    (= y displayed-year))
            (setq terms '()
                  date (car i))))))
    (holiday-fixed (car date) (cadr date) str)))