帮你精通Emacs:配置日程,日记与日历的详细步骤

系统
本篇给大家详细介绍关于Emacs配置日程,日记与日历,希望对你有所帮助!

[[390120]]

我的 Emacs agenda+calendar 的展示界面如下:

agenda+calendar

一眼看上去,agenda中有日出日落,有月相,有中文的天干地支,也有周计数。而在 calendar 界面中呢,国内的节日以“大红”的颜色标注,海外的节日以粉色标注。

接下来将会分步拆解上述界面的配置过程。

一、安装前准备

M-x 调用 package-install 从 Melpa 库中安装 `cal-china-x` 这个包。安装完毕,手工设置好路径等。

  1. (Add-to-list 'load-path "~/.zeroemacs/elpa/cal-china-x-20200924.1837"
  2. (require 'cal-china-x) 

 只需要这一个包,因此准备完毕。

二、搭建 dirary 的环境

1)实现从agenda中展示 diray 信息,须先配置好文件:

  1. ;; 
  2. ;; diary in org-agenda-view 
  3. (setq org-agenda-include-diary t) 
  4. (setq org-agenda-diary-file "~/Documents/OrgMode/ORG/Master/standard-diary"
  5. (setq diary-file "~/Documents/OrgMode/ORG/Master/standard-diary"

 2) 然后设定当前位置的坐标:

  1. # Coordinates 
  2. (setq calendar-longitude ***) ;;long是经度, 东经 
  3. (setq calendar-latitude ***) ;;lat, flat, 北纬 

 3) 自定义两个日出与日落的函数:

  1. ;;Sunrise and Sunset 
  2. ;;日出而作 
  3. (defun diary-sunrise () 
  4.   (let ((dss (diary-sunrise-sunset))) 
  5.     (with-temp-buffer 
  6.       (insert dss) 
  7.       (goto-char (point-min)) 
  8.       (while (re-search-forward " ([^)]*)" nil t) 
  9.     (replace-match "" nil nil)) 
  10.       (goto-char (point-min)) 
  11.       (search-forward ","
  12.       (buffer-substring (point-min) (match-beginning 0))))) 
  13.  
  14. ;; sunset 日落而息 
  15. (defun diary-sunset () 
  16.   (let ((dss (diary-sunrise-sunset)) 
  17.         start end
  18.     (with-temp-buffer 
  19.       (insert dss) 
  20.       (goto-char (point-min)) 
  21.       (while (re-search-forward " ([^)]*)" nil t) 
  22.         (replace-match "" nil nil)) 
  23.       (goto-char (point-min)) 
  24.       (search-forward ", "
  25.       (setq start (match-end 0)) 
  26.       (search-forward " at"
  27.       (setq end (match-beginning 0)) 
  28.       (goto-char start) 
  29.       (capitalize-word 1) 
  30.       (buffer-substring start end)))) 

 4) 最后,写好中文历法的天干地支: 

  1. ;; 中文的天干地支 
  2. (setq calendar-chinese-celestial-stem ["甲" "乙" "丙" "丁" "戊" "己" "庚" "辛" "壬" "癸"]) 
  3. (setq calendar-chinese-terrestrial-branch ["子" "丑" "寅" "卯" "辰" "巳" "午" "未" "申" "酉" "戌" "亥"]) 

 三、搭建 Calendar 环境

1) 首先设置 calendar 以周一为一周之始。

  1. ;;设置一周从周一开始. 
  2. (setq calendar-week-start-day 1) 

 2) 标记重要的节日

  1. (setq mark-holidays-in-calendar t) 
  2. (setq cal-china-x-important-holidays cal-china-x-chinese-holidays) 
  3. (setq calendar-holidays 
  4.       (append cal-china-x-important-holidays 
  5.               cal-china-x-general-holidays 
  6.               holiday-general-holidays 
  7.               holiday-christian-holidays 
  8.               )) 
  9. ;;中美的节日. 

 两步设置之后,就能呈现出来,本文开开篇的效果。

四、整合日历与日记的时间展示:

配置从agenda的头部展示农历和阳历的信息:

  1. ;; display Chinese date 
  2. (setq org-agenda-format-date 'zeroemacs/org-agenda-format-date-aligned) 
  3.  
  4. (defun zeroemacs/org-agenda-format-date-aligned (date
  5.   "Format a DATE string for display in the daily/weekly agenda, or timeline. 
  6.       This function makes sure that dates are aligned for easy reading." 
  7.   (require 'cal-iso) 
  8.   (let* ((dayname (aref cal-china-x-days 
  9.                         (calendar-day-of-week date))) 
  10.          (day (cadr date)) 
  11.          (month (car date)) 
  12.          (year (nth 2 date)) 
  13.          (cn-date (calendar-chinese-from-absolute (calendar-absolute-from-gregorian date))) 
  14.          (cn-month (cl-caddr cn-date)) 
  15.          (cn-day (cl-cadddr cn-date)) 
  16.          (cn-month-string (concat (aref cal-china-x-month-name 
  17.                                         (1- (floor cn-month))) 
  18.                                   (if (integerp cn-month
  19.                                       "" 
  20.                                     "(闰月)"))) 
  21.          (cn-day-string (aref cal-china-x-day-name 
  22.                               (1- cn-day)))) 
  23.     (format "%04d-%02d-%02d 周%s %s%s" year month 
  24.             day dayname cn-month-string cn-day-string))) 

 五、从日历里掌控时间

日历操作的基本单位,日,周,月,季度,最后是年,emacs 默认只展示三个月份。我们想象时间是无限长卷,横向3个月,而纵向无限长度。Emacs 的这三个月犹如从时间长卷中开的窗口,我们得以停下脚步凝视端详。

 

责任编辑:姜华 来源: 今日头条
相关推荐

2021-04-01 10:16:01

EmacsJavaScript elisp

2020-10-19 15:20:51

Ansible系统运维

2021-03-26 07:51:51

Emacs应用buffer

2021-03-19 08:38:12

Emacs应用windows

2010-07-02 14:37:20

配置SSH协议

2009-12-14 17:32:46

路由选择协议

2011-01-21 17:00:49

Thunderbird日历

2009-08-11 15:46:15

C#日历控件

2020-02-26 13:47:57

Emacs电子邮件开源

2009-12-16 14:08:26

路由表配置

2021-01-13 11:25:12

JavaScript闭包函数

2020-12-21 10:55:41

Linux系统ls命令

2009-12-11 10:03:30

策略路由配置

2009-12-17 15:03:49

路由器配置DNS服务器

2021-04-08 09:14:24

js前端函数

2009-12-17 10:08:06

Cisco路由器配置信

2010-01-05 14:25:30

2011-06-23 09:13:59

Qt SDK Creator

2009-12-02 11:24:11

无线路由器配置

2022-02-21 16:16:24

灾难恢复解决方案备份
点赞
收藏

51CTO技术栈公众号