幫你精通Emacs:配置日程,日記與日歷的詳細(xì)步驟
我的 Emacs agenda+calendar 的展示界面如下:
agenda+calendar
一眼看上去,agenda中有日出日落,有月相,有中文的天干地支,也有周計數(shù)。而在 calendar 界面中呢,國內(nèi)的節(jié)日以“大紅”的顏色標(biāo)注,海外的節(jié)日以粉色標(biāo)注。
接下來將會分步拆解上述界面的配置過程。
一、安裝前準(zhǔn)備
M-x 調(diào)用 package-install 從 Melpa 庫中安裝 `cal-china-x` 這個包。安裝完畢,手工設(shè)置好路徑等。
- (Add-to-list 'load-path "~/.zeroemacs/elpa/cal-china-x-20200924.1837")
- (require 'cal-china-x)
只需要這一個包,因此準(zhǔn)備完畢。
二、搭建 dirary 的環(huán)境
1)實現(xiàn)從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) 然后設(shè)定當(dāng)前位置的坐標(biāo):
- # Coordinates
- (setq calendar-longitude ***) ;;long是經(jīng)度, 東經(jīng)
- (setq calendar-latitude ***) ;;lat, flat, 北緯
3) 自定義兩個日出與日落的函數(shù):
- ;;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 環(huán)境
1) 首先設(shè)置 calendar 以周一為一周之始。
- ;;設(shè)置一周從周一開始.
- (setq calendar-week-start-day 1)
2) 標(biāo)記重要的節(jié)日
- (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
- ))
- ;;中美的節(jié)日.
兩步設(shè)置之后,就能呈現(xiàn)出來,本文開開篇的效果。
四、整合日歷與日記的時間展示:
配置從agenda的頭部展示農(nóng)歷和陽歷的信息:
- ;; 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 默認(rèn)只展示三個月份。我們想象時間是無限長卷,橫向3個月,而縱向無限長度。Emacs 的這三個月猶如從時間長卷中開的窗口,我們得以停下腳步凝視端詳。