Emacs中org-mode的Agenda功能

时间:2021-04-07 00:49:48

Emacs中org-mode的Agenda功能

Org-mode中的Agenda Views

Agenda view主要指将分布在一个或者多个文件中的下列内容收集起来,以特定的视图展示。

  • TODO items
  • time-stamped items
  • tagged headlines

Agenda views默认提供如下其中view:

  1. 日历视图,收集特定时期内的内容
    An agenda that is like a calendar and shows information for specific dates
  2. 代办视图,收集所有代办事项
    A TODO list that covers all unfinished action items.
  3. 匹配视图,根据输入的匹配内容和种类展示标题
    A match view, showings headlines based on the tags, properties, and TODO state associated with them.
  4. 时间轴视图,根据时间顺序展示单个org文件中的事项
    A timeline view that shows all events in a single org file, in time-sorted view.
  5. 文本搜索视图,略
    A text search view that shows all entries from multiple files that contain
    specified keywords
  6. 滞后项目视图,略
    A stuck projects view showing projects that currently don’t move along.
  7. 自定义视图,可以为上述内容的组合
    Custom views are special searches and combinations of different views.

Agenda files - 被提取的文件

org-agenda-files 为被提取的文件列表
可在Emacs启动配置文件中调整该变量。 比如

;; Collect all .org from my Org directory and subdirs
(load-library "find-lisp")
(setq org-agenda-files (find-lisp-find-files "~/MyPath/" "\.org$"))

打开Agenda View (Agenda dispatcher)

C-c a '(org-agenda) 命令打开Agenda dispatcher,然后决定具体进入哪个视图。
C-c a 的快捷键非默认提供,启动配置文件中自己绑定的。

Agenda View可能用到的概念

Priorities of TODOs

*** TODO [#A] Write letter to Sam Fortun

默认支持的Priority只有 ‘A’, ‘B’ 和 ‘C’。未设置的entry默认为 ‘B’。
S-<up>, S-<down> 可用于设置优先级。

habits (设置周期性代办事项)

为代办事项添加计划时间 SCHEDULED
可以将 property中的 STYLE 的值设置为 habit。 也可以不设,关键是 SCHEDULED 中时间项的管理。

 ** TODO Shave
    SCHEDULED: <2009-10-17 Sat .+2d/4d>
    :PROPERTIES:
    :STYLE:    habit
    :LAST_REPEAT: [2009-10-19 Mon 00:36]
    :END:
    - State "DONE" from "TODO" [2009-10-15 Thu]     - State "DONE" from "TODO" [2009-10-12 Mon]     - State "DONE" from "TODO" [2009-10-10 Sat]     - State "DONE" from "TODO" [2009-10-04 Sun]     - State "DONE" from "TODO" [2009-10-02 Fri]     - State "DONE" from "TODO" [2009-09-29 Tue]     - State "DONE" from "TODO" [2009-09-25 Fri]     - State "DONE" from "TODO" [2009-09-19 Sat]     - State "DONE" from "TODO" [2009-09-16 Wed]     - State "DONE" from "TODO" [2009-09-12 Sat]

org中的时间标签

timestamps

Timestamps, 直接添加到entries中即可

* Meet Peater at the movies
  <2016-11-01 Wed 19:15>

添加到Headlines下的timestamp将会被Agenda识别

C-c . 插入timestamps, 但仅插入日期
<2017-09-20 三>
C-c ! 可以插入日期,但不被Agenda View识别。
[2017-09-20 三]
C-u C-c . 插入日期和时间
<2017-09-20 三 00:34>
C-u C-c ! 插入日期和时间,但不被Agenda View识别。

插入时间时,可以直接输入 15-4-5 12:15 形式的内容来指定时间。

Deadlines and scheduling

Agenda Views中涉及时间的计划任务,主要指的就是 Deadlines and scheduling.

DEADLINE示例如下

*** TODO write article about the Earth for the Guide
    DEADLINE: <2004-02-29 Sun>
    The editor in charge is [[bbdb:Ford Prefect]]

SCHEDULED示例如下, scheduling指的是何时该开始任务

*** TODO Call Trillian for a date on New Years Eve.
    SCHEDULED: <2004-12-25 Sat>

C-c C-d 插入 deadline
C-c C-s 插入 schedule

周期性任务

如前面 habits 设置周期性代办事项 中所示, .+2d/4d 意味着

  • 周期至少为2天,至多为4天
  • 当任务标记为结束时,重新从 今天 开始记

描述时间周期的符号有三种

  1. +
    这个要求必须每次的任务都完成,如果落下,需要补上。比如说交房租
  2. .+
    之前未完成的可以忽略,当标记为结束时,从 今天 开始
  3. ++
    .+, 但当标记为结束时,从下个周期开始。比如前面那个例子下个任务会从2天后开始

自定义 Agenda View

Reference: https://blog.aaronbieber.com/2016/09/24/an-agenda-for-life-with-org-mode.html
可参考如上文章进行 Custom Agenda 设置, 摘抄内容如下

Classify all activities into one of four buckets

  1. Things I need to do, eventually;
  2. Things I need to complete by a specific date;
  3. Things I cannot (or won’t) start until a specific data; and
  4. Things I should do with some loose frequency

Each of these use cases aligns with an Org Mode feature, and those features are, respectively:

  1. A plain TODO entry,
  2. An entry with a DEADLINE time stamp,
  3. An entry with a SCHEDULED time stamp, and
  4. An entry with a STYLE property of “habit”.

Custom agenda view (three parts):

  1. High-priority(A) unfinished tasks
  2. Normal agenda view
  3. All normal priority tasks

The elisp code as follows:

   (defun air-org-skip-subtree-if-priority (priority) "Skip an agenda subtree if it has a priority of PRIORITY. PRIORITY may be one of the characters ?A, ?B, or ?C." (let ((subtree-end (save-excursion (org-end-of-subtree t))) (pri-value (* 1000 (- org-lowest-priority priority))) (pri-current (org-get-priority (thing-at-point 'line t)))) (if (= pri-value pri-current) subtree-end nil)))

   (defun air-org-skip-subtree-if-habit () "Skip an agenda entry if it has a STYLE property equal to \"habit\"." (let ((subtree-end (save-excursion (org-end-of-subtree t)))) (if (string= (org-entry-get nil "STYLE") "habit") subtree-end nil)))

   (setq org-agenda-custom-commands '(("c" "Simple agenda view" ((tags "PRIORITY=\"A\"" ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done)) (org-agenda-overriding-header "High-priority unfinished tasks:"))) (agenda "") (alltodo "" ((org-agenda-skip-function '(or (air-org-skip-subtree-if-priority ?A) (org-agenda-skip-if nil '(scheduled deadline))))))))))

tips

打开Agenda view

C-c a (org-agenda)
注意 `C-c a’ 快捷键是自己在配置文件中设定的

插入和设置TODO事项的优先级

C-c ,~ 插入优先级
S-<up>, ~S-<down> 调整优先级

Deadline和Schedule插入

C-c C-d 插入 deadline
C-c C-s 插入 schedule

timestamps中时间的调整

S-<right>/<left>
one day forward/backward
S-<down>/<up>
one week forward/backward
> / <
one month forward/backward