我的 Emacs agenda+calendar 的展示界面如下:
agenda+calendar
一眼看上去,agenda中有日出日落,有月相,有中文的天干地支,也有周计数。而在 calendar 界面中呢,国内的节日以“大红”的颜色标注,海外的节日以粉色标注。
接下来将会分步拆解上述界面的配置过程。
一、安装前准备
M-x 调用 package-install 从 Melpa 库中安装 `cal-china-x` 这个包。安装完毕,手工设置好路径等。
- (Add-to-list 'load-path "~/.zeroemacs/elpa/cal-china-x-20200924.1837")
- (require 'cal-china-x)
只需要这一个包,因此准备完毕。
二、搭建 dirary 的环境
1)实现从agenda中展示 diray 信息,须先配置好文件:
- ;;
- ;; diary in org-agenda-view
- (setq org-agenda-include-diary t)
- (setq org-agenda-diary-file "~/Documents/OrgMode/ORG/Master/standard-diary")
- (setq diary-file "~/Documents/OrgMode/ORG/Master/standard-diary")
2) 然后设定当前位置的坐标:
- # Coordinates
- (setq calendar-longitude ***) ;;long是经度, 东经
- (setq calendar-latitude ***) ;;lat, flat, 北纬
3) 自定义两个日出与日落的函数:
- ;;Sunrise and Sunset
- ;;日出而作
- (defun diary-sunrise ()
- (let ((dss (diary-sunrise-sunset)))
- (with-temp-buffer
- (insert dss)
- (goto-char (point-min))
- (while (re-search-forward " ([^)]*)" nil t)
- (replace-match "" nil nil))
- (goto-char (point-min))
- (search-forward ",")
- (buffer-substring (point-min) (match-beginning 0)))))
-
- ;; sunset 日落而息
- (defun diary-sunset ()
- (let ((dss (diary-sunrise-sunset))
- start end)
- (with-temp-buffer
- (insert dss)
- (goto-char (point-min))
- (while (re-search-forward " ([^)]*)" nil t)
- (replace-match "" nil nil))
- (goto-char (point-min))
- (search-forward ", ")
- (setq start (match-end 0))
- (search-forward " at")
- (setq end (match-beginning 0))
- (goto-char start)
- (capitalize-word 1)
- (buffer-substring start end))))
4) 最后,写好中文历法的天干地支:
- ;; 中文的天干地支
- (setq calendar-chinese-celestial-stem ["甲" "乙" "丙" "丁" "戊" "己" "庚" "辛" "壬" "癸"])
- (setq calendar-chinese-terrestrial-branch ["子" "丑" "寅" "卯" "辰" "巳" "午" "未" "申" "酉" "戌" "亥"])
三、搭建 Calendar 环境
1) 首先设置 calendar 以周一为一周之始。
- ;;设置一周从周一开始.
- (setq calendar-week-start-day 1)
2) 标记重要的节日
- (setq mark-holidays-in-calendar t)
- (setq cal-china-x-important-holidays cal-china-x-chinese-holidays)
- (setq calendar-holidays
- (append cal-china-x-important-holidays
- cal-china-x-general-holidays
- holiday-general-holidays
- holiday-christian-holidays
- ))
- ;;中美的节日.
两步设置之后,就能呈现出来,本文开开篇的效果。
四、整合日历与日记的时间展示:
配置从agenda的头部展示农历和阳历的信息:
- ;; display Chinese date
- (setq org-agenda-format-date 'zeroemacs/org-agenda-format-date-aligned)
-
- (defun zeroemacs/org-agenda-format-date-aligned (date)
- "Format a DATE string for display in the daily/weekly agenda, or timeline.
- This function makes sure that dates are aligned for easy reading."
- (require 'cal-iso)
- (let* ((dayname (aref cal-china-x-days
- (calendar-day-of-week date)))
- (day (cadr date))
- (month (car date))
- (year (nth 2 date))
- (cn-date (calendar-chinese-from-absolute (calendar-absolute-from-gregorian date)))
- (cn-month (cl-caddr cn-date))
- (cn-day (cl-cadddr cn-date))
- (cn-month-string (concat (aref cal-china-x-month-name
- (1- (floor cn-month)))
- (if (integerp cn-month)
- ""
- "(闰月)")))
- (cn-day-string (aref cal-china-x-day-name
- (1- cn-day))))
- (format "%04d-%02d-%02d 周%s %s%s" year month
- day dayname cn-month-string cn-day-string)))
五、从日历里掌控时间
日历操作的基本单位,日,周,月,季度,最后是年,emacs 默认只展示三个月份。我们想象时间是无限长卷,横向3个月,而纵向无限长度。Emacs 的这三个月犹如从时间长卷中开的窗口,我们得以停下脚步凝视端详。