在elisp中确定假期的功能

时间:2015-05-09 04:53:21

标签: emacs elisp

在elisp中有任何确定当前系统日期假期的功能。

这样的功能。

,,...,

1 个答案:

答案 0 :(得分:2)

答案要求用户设置预定义假期的日历,例如此示例。我已将5月9日的测试假期包括在内 - 如果用户希望在5月9日以外的任何一天测试此功能,用户可能希望将任意测试假日更改为测试的任何一天正在执行 - 在测试功能之后,可以删除测试条目。

有关如何设置假期格式的示例,请参阅库calendar-holidays中变量holidays.el的文档字符串 - 例如holiday-fixed; holiday-float; holiday-sexp; (lunar-phases); (solar-equinoxes-solstices); holiday-hebrew; holiday-islamic; holiday-bahai; holiday-julian; holiday-chinese;等

如何试用此示例?:将代码阻止/复制/粘贴到*scratch*缓冲区中;并输入M-x eval-buffer RET;然后键入M-x is-holiday RET。这是一份功能齐全的工作草案。如果你在尝试之后决定不喜欢它,只需重新启动Emacs,你就会在尝试之前回到原来的位置。

所执行的测试是使用最新公开发布的Emacs完成的: GNU Emacs 24.4.1(x86_64-apple-darwin10.8.0,NS apple-appkit-1038.36)2014-10-20 on builder10-6.porkrind.org

(require 'holidays)

(defcustom my-custom-holiday-list (mapcar 'purecopy '(
  (holiday-fixed 1 1 "New Year's Day")
  (holiday-float 1 1 3 "Martin Luther King Day")
  (holiday-float 2 1 3 "President's Day")
  (holiday-float 5 1 -1 "Memorial Day")
  ;; ARBITRARY TEST HOLIDAY -- MAY 9
  (holiday-fixed 5 9 "Arbitrary Test Holiday -- May 9")
  (holiday-fixed 7 4 "Independence Day")
  (holiday-float 9 1 1 "Labor Day")
  (holiday-float 10 1 2 "Columbus Day")
  (holiday-fixed 11 11 "Veteran's Day")
  (holiday-float 11 4 4 "Thanksgiving")
  (holiday-fixed 12 25 "Christmas")
  (solar-equinoxes-solstices)
  (holiday-sexp calendar-daylight-savings-starts
    (format "Daylight Saving Time Begins %s"
      (solar-time-string
        (/ calendar-daylight-savings-starts-time (float 60))
        calendar-standard-time-zone-name)))
  (holiday-sexp calendar-daylight-savings-ends
      (format "Daylight Saving Time Ends %s"
       (solar-time-string
         (/ calendar-daylight-savings-ends-time (float 60))
         calendar-daylight-time-zone-name))) ))
  "Custom holidays defined by the user."
  :type 'sexp
  :group 'holidays)

(defun is-holiday ()
  "Is today a holiday?"
(interactive)
  (let* (
      (d1 (time-to-days (current-time)))
      (date (calendar-gregorian-from-absolute d1))
      ee
      res-holidays
      (displayed-month (nth 0 date))
      (displayed-year (nth 2 date))
      (holiday-list
        (dolist (p my-custom-holiday-list res-holidays)
          (let* (h)
           (when (setq h (eval p))
             (setq res-holidays (append h res-holidays)))))) )
    (mapcar
      (lambda (x)
        (let ((txt (format "%s -- %s" (car x) (car (cdr x)))))
          (when (eq d1 (calendar-absolute-from-gregorian (car x)))
            (push txt ee))))
      holiday-list)
    (if ee
      (message "The following holiday(s) is/are today:  %s" (nreverse ee))
      (message "Today is not a holiday."))))