我的 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 信息,须先配置好文件:
;; ;;diaryinorg-agenda-view (setqorg-agenda-include-diaryt) (setqorg-agenda-diary-file"~/Documents/OrgMode/ORG/Master/standard-diary") (setqdiary-file"~/Documents/OrgMode/ORG/Master/standard-diary") 2) 然后设定当前位置的坐标:
#Coordinates (setqcalendar-longitude***);;long是经度,东经 (setqcalendar-latitude***);;lat,flat,北纬 3) 自定义两个日出与日落的函数:
;;SunriseandSunset ;;日出而作 (defundiary-sunrise() (let((dss(diary-sunrise-sunset))) (with-temp-buffer (insertdss) (goto-char(point-min)) (while(re-search-forward"([^)]*)"nilt) (replace-match""nilnil)) (goto-char(point-min)) (search-forward",") (buffer-substring(point-min)(match-beginning0))))) ;;sunset日落而息 (defundiary-sunset() (let((dss(diary-sunrise-sunset)) startend) (with-temp-buffer (insertdss) (goto-char(point-min)) (while(re-search-forward"([^)]*)"nilt) (replace-match""nilnil)) (goto-char(point-min)) (search-forward",") (setqstart(match-end0)) (search-forward"at") (setqend(match-beginning0)) (goto-charstart) (capitalize-word1) (buffer-substringstartend)))) 4) 最后,写好中文历法的天干地支:
;;中文的天干地支 (setqcalendar-chinese-celestial-stem["甲""乙""丙""丁""戊""己""庚""辛""壬""癸"]) (setqcalendar-chinese-terrestrial-branch["子""丑""寅""卯""辰""巳""午""未""申""酉""戌""亥"]) 三、搭建 Calendar 环境
1) 首先设置 calendar 以周一为一周之始。
;;设置一周从周一开始. (setqcalendar-week-start-day1) 2) 标记重要的节日
(setqmark-holidays-in-calendart) (setqcal-china-x-important-holidayscal-china-x-chinese-holidays) (setqcalendar-holidays (appendcal-china-x-important-holidays cal-china-x-general-holidays holiday-general-holidays holiday-christian-holidays )) ;;中美的节日. 两步设置之后,就能呈现出来,本文开开篇的效果。
四、整合日历与日记的时间展示:
配置从agenda的头部展示农历和阳历的信息:
;;displayChinesedate (setqorg-agenda-format-date'zeroemacs/org-agenda-format-date-aligned) (defunzeroemacs/org-agenda-format-date-aligned(date) "FormataDATEstringfordisplayinthedaily/weeklyagenda,ortimeline. Thisfunctionmakessurethatdatesarealignedforeasyreading." (require'cal-iso) (let*((dayname(arefcal-china-x-days (calendar-day-of-weekdate))) (day(cadrdate)) (month(cardate)) (year(nth2date)) (cn-date(calendar-chinese-from-absolute(calendar-absolute-from-gregoriandate))) (cn-month(cl-caddrcn-date)) (cn-day(cl-cadddrcn-date)) (cn-month-string(concat(arefcal-china-x-month-name (1-(floorcn-month))) (if(integerpcn-month) "" "(闰月)"))) (cn-day-string(arefcal-china-x-day-name (1-cn-day)))) (format"%04d-%02d-%02d周%s%s%s"yearmonth daydaynamecn-month-stringcn-day-string))) 五、从日历里掌控时间
日历操作的基本单位,日,周,月,季度,最后是年,emacs 默认只展示三个月份。我们想象时间是无限长卷,横向3个月,而纵向无限长度。Emacs 的这三个月犹如从时间长卷中开的窗口,我们得以停下脚步凝视端详。
原文地址:https://www.toutiao.com/i6941927202644591115/