emacs - 在elisp中确定假期的函数

标签 emacs elisp

elisp中有判断当前系统日期是否节假日的函数。

像这样的功能。

(is-holiday (current-time))

最佳答案

答案要求用户设置预定义假期的日历,如本例所示。我已经包含了 5 月 9 日的测试假期——如果用户希望在 5 月 9 日以外的任何一天测试此功能,用户可能希望将任意测试假期更改为测试的任何一天正在执行——功能测试完成后,可以去掉测试入口。

有关如何格式化假期的示例,请参阅库 holidays.el 中变量 calendar-holidays 的文档字符串——例如,固定假期假期 float 假期-sexp; (月相)(太阳-昼夜平分点-至日)假日希伯来语; 假日伊斯兰; 假日巴哈教假日朱利安; 假期中文;等

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

所执行的测试是使用 Emacs 的最新公开版本完成的:2014 年 10 月 20 日的 GNU Emacs 24.4.1(x86_64-apple-darwin10.8.0,NS apple-appkit-1038.36) 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."))))

关于emacs - 在elisp中确定假期的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30136155/

相关文章:

emacs - 使用Emacs和Gdb设置断点,为什么提示总是 "Current buffer has no process"?

emacs - 为什么词法绑定(bind)在 emacs 的这个例子中不起作用?

functional-programming - lisp 语句中的字符串插值

linux - Bash/Sh 等 Shell 脚本的 IDE/Emacs 模式

emacs - Emacs Lisp 和 Common Lisp 之间的主要区别是什么?

linux - 在 Linux 上运行的基于文本的强大 Java IDE

emacs - 我怎样才能告诉 emacs 不要打破长行?

emacs - 期待一种在 Emacs 中让光标像心跳一样闪烁的方法

emacs - 是否存在匹配插件/配置的 emacs 智能括号?

emacs - 在 Emacs 中,如何在多个帧中打开相同的缓冲区(使用 ido/iswitch 时)?