Emacs 系列（三）： Org 模式的补充
Org模式
![](/data/attachment/album/201812/09/195006oz8xr841oko616x3.png)


这是 [Emacs 和 Org 模式系列](https://changelog.complete.org/archives/tag/emacs2018)的第三篇。


### Todo 的跟进及关键字


当你使用 Org 模式来跟进你的 TODO 时，它有多种状态。你可以用 `C-c C-t` 来快速切换状态。我将它设为这样：



```
(setq org-todo-keywords '(
  (sequence "TODO(t!)" "NEXT(n!)" "STARTED(a!)" "WAIT(w@/!)" "OTHERS(o!)" "|" "DONE(d)" "CANCELLED(c)")
))
```

在这里，我设置了一个任务未完成的五种状态：`TODO`、`NEXT`、`STARTED`、`WAIT` 及 `OTHERS`。每一个状态都有单个字的快捷键（`t`、`n`、`a` 等）。管道符（`|`）之后的状态被认为是“完成”的状态。我有两个“完成”状态：`DONE`（已经完成）及 `CANCELLED`（还没完成，但由于其它的原因无法完成）。


`!` 的含义是记录某项更改为状态的时间。我不把这个添加到完成的状态，是因为它们已经被记录了。`@` 符号表示带理由的提示，所以当切换到 `WAIT` 时，Org 模式会问我为什么，并将这个添加到笔记中。


以下是项目状态发生变化的例子：



```
** DONE This is a test
   CLOSED: [2018-03-02 Fri 03:05]
  
   - State "DONE"       from "WAIT"       [2018-03-02 Fri 03:05]
   - State "WAIT"       from "TODO"       [2018-03-02 Fri 03:05] \\
     waiting for pigs to fly
   - State "TODO"       from "NEXT"       [2018-03-02 Fri 03:05]
   - State "NEXT"       from "TODO"       [2018-03-02 Fri 03:05]
```

在这里，最新的项目在最上面。


### 议程模式，日程及期限


当你处在一个待办事项时，`C-c C-s` 或 `C-c C-d` 可以为其设置相应的日程或期限。这些都是在议程模式中的功能。它们的区别在于其意图和表现。日程是你希望在某个时候完成的事情，而期限是在某个特定的时间应该完成的事情。默认情况下，议程视图将在项目的截止日期前提醒你。


在此过程中，[议程视图](https://orgmode.org/guide/Agenda-Views.html#Agenda-Views)将显示即将出现的项目，提供了一种基于纯文本或标记搜索项目的方法，甚至可以进行跨多个文件处理项目的批量操作。我在本系列的[第 2 部分](/article-10312-1.html)中介绍了为议程模式配置。


### 标签


Org 模式当然也支持标签了。你可以通过 `C-c C-q` 快速的建立标签。


你可能会想为一些常用的标签设置快捷键。就像这样:



```
  (setq org-tag-persistent-alist 
        '(("@phone" . ?p) 
          ("@computer" . ?c) 
          ("@websurfing" . ?w)
          ("@errands" . ?e)
          ("@outdoors" . ?o)
          ("MIT" . ?m)
          ("BIGROCK" . ?b)
          ("CONTACTS" . ?C)
          ("INBOX" . ?i)
          ))
```

你还可以按文件向该列表添加标记，也可以按文件为某些内容设置标记。我就在我的 `inbox.org` 和 `email.org` 文件中设置了一个 `INBOX` 的标签。然后我可以每天从日程视图中查看所有标记为 `INBOX` 的项目，像将它们重新归档到其他文件中的这样的简单操作将让它们去掉 `INBOX` 标记。


### 重新归档


“重新归档”就是在文件中或其他地方移动。它是使用标题来完成的。`C-c C-w` 就是做这个的。我设置成这样:



```
(setq org-outline-path-complete-in-steps nil)         ; Refile in a single go
(setq org-refile-use-outline-path 'file)
```

### 归档分类


一段时间后，你的文件就会被已经完成的事情弄得乱七八糟。Org 模式有一个[归档](https://orgmode.org/guide/Archiving.html#Archiving)特性，可以将主 `.org` 文件移到其他文件中，以备将来参考。如果你在 `git` 或其他软件中 有 Org 文件，你可能希望删除这些其他文件，因为无论如何都会在历史中拥有这些文件，但是我发现它们对于析取和搜索非常方便。


我会定期检查并归档文件中的所有内容。基于 [stackoverflow 的讨论](https://stackoverflow.com/questions/6997387/how-to-archive-all-the-done-tasks-using-a-single-command)，我有以下代码：



```
(defun org-archive-done-tasks ()
  (interactive)
  (org-map-entries
   (lambda ()
     (org-archive-subtree)
     (setq org-map-continue-from (outline-previous-heading)))
   "/DONE" 'file)
  (org-map-entries
   (lambda ()
     (org-archive-subtree)
     (setq org-map-continue-from (outline-previous-heading)))
   "/CANCELLED" 'file)
)
```

这基于[一个特定的答案](https://stackoverflow.com/a/27043756) —— 你可以从评论那获得一些额外的提示。现在你可以运行 `M-x org-archive-done-tasks`，当前文件中所有标记为 `DONE` 或 `CANCELED` 的内容都将放到另一个文件中。


### 下一篇


我将通过讨论在 Org 模式中自动接受邮件以及在不同的机器上同步来对 Org 模式进行总结。




---


via: <https://changelog.complete.org/archives/9877-emacs-3-more-on-org-mode>


作者：[John Goerzen](http://changelog.complete.org/archives/author/jgoerzen) 选题：[lujun9972](https://github.com/lujun9972) 译者：[oneforalone](https://github.com/oneforalone) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
This is third in [a series on Emacs and org-mode](https://changelog.complete.org/archives/tag/emacs2018).

**Todo tracking and keywords**

When using org-mode to [track your TODOs](https://orgmode.org/guide/TODO-Items.html#TODO-Items), it can have multiple states. You can press `C-c C-t` for a quick shift between states. I have set this:

(setq org-todo-keywords '( (sequence "TODO(t!)" "NEXT(n!)" "STARTED(a!)" "WAIT(w@/!)" "OTHERS(o!)" "|" "DONE(d)" "CANCELLED(c)") ))

Here, I set up 5 states that are for a task that is not yet done: TODO, NEXT, STARTED, WAIT, and OTHERS. Each has a single-character shortcut (t, n, a, etc). The states after the pipe symbol are ones that are considered “done”. I have two: DONE (for things that I have done) and CANCELED (for things that I haven’t done, but for whatever reason, won’t).

The exclamation mark means to log the time when an item was changed to a state. I don’t add this to the done states because those are already logged anyhow. The @ sign means to prompt for a reason; so when switching to WAIT, org-mode will ask me why and add this to the note.

Here’s an example of an entry that has had some state changes:

** DONE This is a test CLOSED: [2018-03-02 Fri 03:05] - State "DONE" from "WAIT" [2018-03-02 Fri 03:05] - State "WAIT" from "TODO" [2018-03-02 Fri 03:05] \\ waiting for pigs to fly - State "TODO" from "NEXT" [2018-03-02 Fri 03:05] - State "NEXT" from "TODO" [2018-03-02 Fri 03:05]

Here, the most recent items are on top.

**Agenda mode, schedules, and deadlines**

When you’re in a todo item, C-c C-s or C-c C-d can set a schedule or a deadline for it, respectively. These show up in agenda mode. The difference is in intent and presentation. A schedule is something that you expect to work on at around a time, while a deadline is something that is due at a specific time. By default, the agenda view will start warning you about deadline items in advance.

And while we’re at it, the [agenda view](https://orgmode.org/guide/Agenda-Views.html#Agenda-Views) will show you the items that you have coming up, offers a nice way to search for items based on plain text or tags, and handles bulk manipulation of items even across multiple files. I covered setting the files for agenda mode in [part 2](https://changelog.complete.org/archives/9865-emacs-2-introducing-org-mode) of this series.

**Tags**

Of course org-mode has [tags](https://orgmode.org/guide/Tags.html#Tags). You can quickly set them with C-c C-q.

You can set shortcuts for tags you might like to use often. Perhaps something like this:

(setq org-tag-persistent-alist '(("@phone" . ?p) ("@computer" . ?c) ("@websurfing" . ?w) ("@errands" . ?e) ("@outdoors" . ?o) ("MIT" . ?m) ("BIGROCK" . ?b) ("CONTACTS" . ?C) ("INBOX" . ?i) ))

You can also add tags to this list on a per-file basis, and also set tags for something on a per-file basis. I use that for my inbox.org and email.org files to set an INBOX tag. I can then review all items tagged INBOX from the agenda view each day, and the simple act of refiling them into other files will cause them to lost the INBOX tag.

**Refiling**

“Refiling” is moving things around, either within a file or elsewhere. It has completion using your headlines. `C-c C-w` does this. I like these settings:

(setq org-outline-path-complete-in-steps nil) ; Refile in a single go (setq org-refile-use-outline-path 'file)

**Archiving**

After awhile, you’ll get your files all cluttered with things that are done. org-mode has an [archive](https://orgmode.org/guide/Archiving.html#Archiving) feature to move things out of your main .org files and into some other files for future reference. If you have your org files in git or something, you may wish to delete these other files since you’d have things in history anyhow, but I find them handy for grepping and searching.

I periodically want to go through and archive everything in my files. Based on a [stackoverflow discussion](https://stackoverflow.com/questions/6997387/how-to-archive-all-the-done-tasks-using-a-single-command), I have this code:

(defun org-archive-done-tasks () (interactive) (org-map-entries (lambda () (org-archive-subtree) (setq org-map-continue-from (outline-previous-heading))) "/DONE" 'file) (org-map-entries (lambda () (org-archive-subtree) (setq org-map-continue-from (outline-previous-heading))) "/CANCELLED" 'file) )

This is based on [a particular answer](https://stackoverflow.com/a/27043756) — see the comments there for some additional hints. Now you can run `M-x org-archive-done-tasks` and everything in the current file marked DONE or CANCELED will be pulled out into a different file.

**Up next**

I’ll wrap up org-mode with a discussion of automatically receiving emails into org, and syncing org between machines.

**Resources to accompany this article**

What is the semantics of NEXT keyword? I’ve seen it in several setups but don’t get it.

It’s nothing special to the software, only to me. The rough meanings I have assigned for myself are:

TODO – working on it now

NEXT – I’ll work on it very soon (next actions)

STARTED – I omit this in some of my setups, but it’s an item I’ve begun work on

WAIT – I can’t do it right now because of something (waiting for a reply from someone, for someone else to do something, etc)

OTHERS – Someone else is doing it, but I’m keeping track of it

DONE / CANCELED – I did it, or I decided I won’t do it