2021-07-22-Org学习
Date: 2021-07-22,四,11:42:20 Author: Wei Shaopeng Email: Chopong@qq.com
我必须承认,在使用了几十年的 vim 后, 我被 Emacs 吸引了。
长期以来,我一直对如何组织安排事情感到沮丧。我也有用过 GTD 和 ZTD 之类的方法,但是像邮件或是大型文件这样的事务真的很难来组织安排。
我一直在用 Asana 处理任务,用 Evernote 做笔记,用 Thunderbird 处理邮件,把 ikiwiki 和其他的一些项目组合作为个人知识库,而且还在电脑的归档了各种文件。当我的新工作需要将 Slack 也加入进来时,我终于忍无可忍了。
许多 TODO 管理工具与电子邮件集成的很差。当你想做“提醒我在一周内回复这个邮件”之类的事时,很多时候是不可能的,因为这个工具不能以一种能够轻松回复的方式存储邮件。而这个问题在 Slack 上更为严重。
就在那时,我偶然发现了 Carsten Dominik 在 Google Talk 上关于 org 模式的讲话。Carsten 是 org 模式的作者,即便是这个讲话已经有 10 年了,但它仍然很具有参考价值。
我之前有用过 org 模式,但是每次我都没有真正的深入研究它, 因为我当时的反应是“一个大纲编辑器?但我需要的是待办事项列表”。我就这么错过了它。但实际上 org 模式就是我所需要的。
什么是 Emacs?什么是 org 模式? Emacs 最初是一个文本编辑器,现在依然是一个文本编辑器,而且这种传统无疑贯穿始终。但是说 Emacs 是个编辑器是很不公平的。
Emacs 更像一个平台或是工具包。你不仅可以用它来编辑源代码,而且配置 Emacs 本身也是编程,里面有很多模式。就像编写一个 Firefox 插件一样简单,只要几行代码,然后,模式里的操作就改变了。
org 模式也一样。确实,它是一个大纲编辑器,但它真正所包含的不止如此。它是一个信息组织平台。它的网站上写着,“你可以用纯文本来记录你的生活:你可以用 org 模式来记笔记,处理待办事项,规划项目和使用快速有效的纯文本系统编写文档。”
捕获 如果你读过基于 GTD 的生产力指南,那么他们强调的一件事就是毫不费力地获取项目。这个想法是,当某件事突然出现在你的脑海里时,把它迅速输入一个受信任的系统,这样你就可以继续做你正在做的事情。org 模式有一个专门的捕获系统。我可以在 Emacs 的任何地方按下 C-c c 键,它就会空出一个位置来记录我的笔记。最关键的是,自动嵌入到笔记中的链接可以链接到我按下 C-c c 键时正在编辑的那一行。如果我正在编辑文件,它会链回到那个文件和我所在的行。如果我正在浏览邮件,它就会链回到那封邮件(通过邮件的 Message-Id,这样它就可以在任何一个文件夹中找到邮件)。聊天时也一样,甚至是当你在另一个 org 模式中也可也这样。
这样我就可以做一个笔记,它会提醒我在一周内回复某封邮件,当我点击这个笔记中的链接时,它会在我的邮件阅读器中弹出这封邮件 —— 即使我随后将它从收件箱中存档。
没错,这正是我要找的!
工具套件 一旦你开始使用 org 模式,很快你就会想将所有的事情都集成到里面。有可以从网络上捕获内容的浏览器插件,也有多个 Emacs 邮件或新闻阅读器与之集成,ERC(IRC 客户端)也不错。所以我将自己从 Thunderbird 和 mairix + mutt (用于邮件归档)换到了 mu4e,从 xchat + slack 换到了 ERC。
你可能不明白,我喜欢这些基于 Emacs 的工具,而不是具有相同功能的单独的工具。
一个小花絮:我又在使用离线 IMAP 了!我甚至在很久以前就用过 GNUS。
用一个 Emacs 进程来管理 我以前也经常使用 Emacs,那时,Emacs 是一个“大”的程序(现在显示电源状态的小程序占用的内存要比 Emacs 多)。当时存在在启动时间过长的问题,但是现在已经有连接到一个正在运行的 Emacs 进程的解决方法。
我喜欢用 Mod-p(一个 xmonad 中 dzen 菜单栏的快捷方式,但是在大多数传统的桌面环境中该功能的快捷键是 Alt-F2)来启动程序(LCTT 译注:xmonad 是一种平铺桌面;dzen 是 X11 窗口下管理消息、提醒和菜单的程序)。这个设置在不运行多个 emacs 们(emacsen)时很方便,因为这样就不会在试图捕获另一个打开的文件时出问题。这中方法很简单:创建一个叫 em 的脚本并将它放到我自己的环境变量中。就像这样:
#!/bin/bash exec emacsclient -c -a “” “$@” 如果没有 emacs 进程存在的话,就会创建一个新的 emacs 进程,否则的话就直接使用已存在的进程。这样做还有一个好处:-nw 之类的参数工作的很好,它实际上就像在 shell 提示符下输入 emacs 一样。它很适合用于设置 EDITOR 环境变量。
下一篇 接下来我将讨论我的使用情况,并展示以下的配置:
org 模式,包括计算机之间的同步、捕获、日程和待办事项、文件、链接、关键字和标记、各种导出(幻灯片)等。 mu4e,用于电子邮件,包括多个账户,bbdb 集成 ERC,用于 IRC 和即时通讯
在我 Emacs 系列中的第一篇文章里,我介绍了我在用了几十年的 vim 后转向了 Emacs,org 模式就是我为什么这样做的原因。
org 模式的精简和高效真的震惊了我,它真的是个“杀手”应用。
所以,org 模式到底是什么呢? 这是我昨天写的:
它是一个组织信息的平台,它的主页上这样写着:“一切都是纯文本:org 模式用于记笔记、维护待办事项列表、计划项目和使用快速有效的纯文本系统编写文档。” 这是事实,但并不是很准确。org 模式是一个你用来组织事务的小工具。它有一些非常合理的默认设置,但也允许你自己定制。
主要突出在这几件事上:
维护待办事项列表:项目可以分散在 org 文件中,包含附件,有标签、截止日期、时间表。有一个方便的“日程”视图,显示需要做什么。项目也可以重复。 编写文档:org 模式有个特殊的功能来生成 HTML、LaTeX、幻灯片(用 LaTeX beamer)和其他所有的格式。它也支持直接在缓冲区中运行和以 Emacs 所支持的的语言进行 文学编程(literate programming)。如果你想要深入了解这项功能的话,参阅这篇文学式 DevOps 的文章。而 整个 Worg 网站 是用 org 模式开发的。 记笔记:对,它也能做笔记。通过全文搜索,文件的交叉引用(类似 wiki),UUID,甚至可以与其他的系统进行交互(通过 Message-ID 与 mu4e 交互,通过 ERC 的日志等等……)。 入门 我强烈建议去阅读 Carsten Dominik 关于 org 模式的一篇很棒的 Google 讲话。那篇文章真的很赞。
在 Emacs 中带有 org 模式,但如果你想要个比较新的版本的话,Debian 用户可以使用命令 apt-get install org-mode 来更新,或者使用 Emacs 的包管理系统命令 M-x package-install RET org-mode RET。
现在,你可能需要阅读一下 org 模式的精简版教程中的导读部分,特别注意,你要设置下启动部分中提到的那些键的绑定。
一份好的教程 我会给出一些好的教程和介绍的链接,但这篇文章不会是一篇教程。特别是在本文末尾,有两个很不错的视频链接。
我的一些配置 我将在这里记录下一些我的配置并介绍它的作用。你没有必要每行每句将它拷贝到你的配置中 —— 这只是一个参考,告诉你哪些可以配置,要怎么在手册中查找,或许只是一个“我现在该怎么做”的参考。
首先,我将 Emacs 的编码默认设置为 UTF-8。
(prefer-coding-system ‘utf-8) (set-language-environment “UTF-8”) org 模式中可以打开 URL。默认的,它会在 Firefox 中打开,但我喜欢用 Chromium。
(setq browse-url-browser-function ‘browse-url-chromium) 我把基本的键的绑定和设为教程里的一样,再加上 M-RET 的操作的配置。
(global-set-key “\C-cl” ‘org-store-link) (global-set-key “\C-ca” ‘org-agenda) (global-set-key “\C-cc” ‘org-capture) (global-set-key “\C-cb” ‘org-iswitchb)
(setq org-M-RET-may-split-line nil) 捕获配置 我可以在 Emacs 的任何模式中按 C-c c,按下后它就会帮我捕获某些事,其中包括一个指向我正在处理事务的链接。
你可以通过定义捕获模板来配置它。我将保存两个日志文件,作为会议、电话等的通用记录。一个是私人用的,一个是办公用的。如果我按下 C-c c j,它就会帮我捕获为私人项. 下面包含 %a 的配置是表示我当前的位置(或是我使用 C-c l 保存的链接)的链接。
(setq org-default-notes-file “~/org/tasks.org”) (setq org-capture-templates ‘( (“t” “Todo” entry (file+headline “inbox.org” “Tasks”) “* TODO %?\n %i\n %u\n %a”) (“n” “Note/Data” entry (file+headline “inbox.org” “Notes/Data”) “* %? \n %i\n %u\n %a”) (“j” “Journal” entry (file+datetree “~/org/journal.org”) “* %?\nEntered on %U\n %i\n %a”) (“J” “Work-Journal” entry (file+datetree “~/org/wjournal.org”) “* %?\nEntered on %U\n %i\n %a”) )) (setq org-irc-link-to-logs t) 我喜欢通过 UUID 来建立链接,这让我在文件之间移动而不会破坏位置。当我要 org 存储一个链接目标以便将来插入时,以下配置有助于生成 UUID。
(require ‘org-id) (setq org-id-link-to-org-use-id ‘create-if-interactive) 议程配置 我喜欢将星期天作为一周的开始,当我将某件事标记为完成时,我也喜欢记下时间。
(setq org-log-done ‘time) (setq org-agenda-start-on-weekday 0) 文件归档配置 在这我将配置它,让它知道在议程中该使用哪些文件,而且在纯文本的搜索中添加一点点小功能。我喜欢保留一个通用的文件夹(我可以从其中移动或“重新归档”内容),然后将个人和工作项的任务、日志和知识库分开。
(setq org-agenda-files (list “~/org/inbox.org” “~/org/email.org” “~/org/tasks.org” “~/org/wtasks.org” “~/org/journal.org” “~/org/wjournal.org” “~/org/kb.org” “~/org/wkb.org” )) (setq org-agenda-text-search-extra-files (list “~/org/someday.org” “~/org/config.org” ))
(setq org-refile-targets ‘((nil :maxlevel . 2) (org-agenda-files :maxlevel . 2) (“~/org/someday.org” :maxlevel . 2) (“~/org/templates.org” :maxlevel . 2) ) ) (setq org-outline-path-complete-in-steps nil) ; Refile in a single go (setq org-refile-use-outline-path ‘file) 外观配置 我喜欢一个较漂亮的的屏幕。在你开始习惯 org 模式之后,你可以试试这个。
(add-hook ‘org-mode-hook (lambda () (org-bullets-mode t))) (setq org-ellipsis “⤵”) 下一篇 希望这篇文章展示了 org 模式的一些功能。接下来,我将介绍如何定制 TODO 关键字和标记、归档旧任务、将电子邮件转发到 org 模式,以及如何使用 git 在不同电脑之间进行同步。
你也可以查看本系列的所有文章列表。
这是 Emacs 和 Org 模式系列的第三篇。
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 可以为其设置相应的日程或期限。这些都是在议程模式中的功能。它们的区别在于其意图和表现。日程是你希望在某个时候完成的事情,而期限是在某个特定的时间应该完成的事情。默认情况下,议程视图将在项目的截止日期前提醒你。
在此过程中,议程视图将显示即将出现的项目,提供了一种基于纯文本或标记搜索项目的方法,甚至可以进行跨多个文件处理项目的批量操作。我在本系列的第 2 部分中介绍了为议程模式配置。
标签 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 模式有一个归档特性,可以将主 .org文件移到其他文件中,以备将来参考。如果你在 git 或其他软件中 有 Org 文件,你可能希望删除这些其他文件,因为无论如何都会在历史中拥有这些文件,但是我发现它们对于析取和搜索非常方便。
我会定期检查并归档文件中的所有内容。基于 stackoverflow 的讨论,我有以下代码:
(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) ) 这基于一个特定的答案 —— 你可以从评论那获得一些额外的提示。现在你可以运行 M-x org-archive-done-tasks,当前文件中所有标记为 DONE 或 CANCELED 的内容都将放到另一个文件中。
下一篇 我将通过讨论在 Org 模式中自动接受邮件以及在不同的机器上同步来对 Org 模式进行总结。
Emacs #4: Automated emails to org-mode and org-mode syncing
March 31, 2018Linux, Softwareemacs, emacs2018, org-mode This is fourth in a series on Emacs and org-mode.
Hopefully by now you’ve started to see how powerful and useful org-mode is. If you’re like me, you’re thinking:
“I’d really like to have this in sync across all my devices.”
and, perhaps:
“Can I forward emails into org-mode?”
This being Emacs, the answers, of course, are “Yes.”
Syncing
Since org-mode just uses text files, syncing is pretty easily accomplished using any number of tools. I use git with git-remote-gcrypt. Due to some limitations of git-remote-gcrypt, each machine tends to push to its own branch, and to master on command. Each machine merges from all the other branches and pushes the result to master after a merge. A cron job causes pushes to the machine’s branch to happen, and a bit of elisp coordinates it all — making sure to save buffers before a sync, refresh them from disk after, etc.
The code for this post is somewhat more extended, so I will be linking to it on github rather than posting inline.
I have a directory $HOME/org where all my org-stuff lives. In ~/org lives a Makefile that handles the syncing. It defines these targets:
push: adds, commits, and pushes to a branch named after the machine’s hostname fetch: does a simple git fetch sync: adds, commits, pulls remote changes, merges, and (assuming the merge was successful) pushes to the branch named after the machine’s hostname plus master Now, in my user’s crontab, I have this:
*/15 * * * * make -C $HOME/org push fetch 2>&1 | logger –tag ‘orgsync’ The accompanying elisp code defines a shortcut (C-c s) to cause a sync to occur. Thanks to the cronjob, as long as files were saved — even if I didn’t explicitly sync on the other boxen — they’ll be pulled in.
I have found this setup to work really well.
Emailing to org-mode
Before going down this path, one should ask the question: do you really need it? I use org-mode with mu4e, and the integration is excellent; any org task can link to an email by message-id, and this is ideal — it lets a person do things like make a reminder to reply to a message in a week.
However, org is not just about reminders. It’s also a knowledge base, authoring system, etc. And, not all of my mail clients use mu4e. (Note: things like MobileOrg exist for mobile devices). I don’t actually use this as much as I thought I would, but it has its uses and I thought I’d document it here too.
Now I didn’t want to just be able to accept plain text email. I wanted to be able to handle attachments, HTML mail, etc. This quickly starts to sound problematic — but with tools like ripmime and pandoc, it’s not too bad.
The first step is to set up some way to get mail into a specific folder. A plus-extension, special user, whatever. I then use a fetchmail configuration to pull it down and run my insorgmail script.
This script is where all the interesting bits happen. It starts with ripmime to process the message. HTML bits are converted from HTML to org format using pandoc. an org hierarchy is made to represent the structure of the email as best as possible. emails can get pretty complicated, with HTML and the rest, but I have found this does an acceptable job with my use cases.
Up next…
My last post on org-mode will talk about using it to write documents and prepare slides — a use for which I found myself surprisingly pleased with it, but which needed a bit of tweaking.
Emacs #5: Documents and Presentations with org-mode
April 4, 2018Softwareemacs, emacs2018 The Emacs series This is fifth in a series on Emacs and org-mode.
This blog post was generated from an org-mode source and is available as: a blog page, slides (PDF format), and a PDF document.
1 About org-mode exporting 1.1 Background org-mode isn’t just an agenda-making program. It can also export to lots of formats: LaTeX, PDF, Beamer, iCalendar (agendas), HTML, Markdown, ODT, plain text, man pages, and more complicated formats such as a set of web pages.
This isn’t just some afterthought either; it’s a core part of the system and integrates very well.
One file can be source code, automatically-generated output, task list, documentation, and presentation, all at once.
Some use org-mode as their preferred markup format, even for things like LaTeX documents. The org-mode manual has an extensive section on exporting.
1.2 Getting started From any org-mode document, just hit C-c C-e. From there will come up a menu, letting you choose various export formats and options. These are generally single-key options so it’s easy to set and execute. For instance, to export a document to a PDF, use C-c C-e l p or for HTML export, C-c C-e h h.
There are lots of settings available for all of these export options; see the manual. It is, in fact, quite possible to use LaTeX-format equations in both LaTeX and HTML modes, to insert arbitrary preambles and settings for different modes, etc.
1.3 Add-on packages ELPA containts many addition exporters for org-mode as well. Check there for details.
2 Beamer slides with org-mode 2.1 About Beamer Beamer is a LaTeX environment for making presentations. Its features include:
Automated generating of structural elements in the presentation (see, for example, the Marburg theme). This provides a visual reference for the audience of where they are in the presentation. Strong help for structuring the presentation Themes Full LaTeX available 2.2 Benefits of Beamer in org-mode org-mode has a lot of benefits for working with Beamer. Among them:
org-mode’s very easy and strong support for visualizing and changing the structure makes it very quick to reorganize your material. Combined with org-babel, live source code (with syntax highlighting) and results can be embedded. The syntax is often easier to work with. I have completely replaced my usage of LibreOffice/Powerpoint/GoogleDocs with org-mode and beamer. It is, in fact, rather frustrating when I have to use one of those tools, as they are nowhere near as strong as org-mode for visualizing a presentation structure.
2.3 Headline Levels org-mode’s Beamer export will convert sections of your document (defined by headings) into slides. The question, of course, is: which sections? This is governed by the H export setting (org-export-headline-levels).
There are many ways to go, which suit people. I like to have my presentation like this:
#+OPTIONS: H:2 #+BEAMER_HEADER: \AtBeginSection{\frame{\sectionpage}} This gives a standalone section slide for each major topic, to highlight major transitions, and then takes the level 2 (two asterisks) headings to set the slide. Many Beamer themes expect a third level of indirection, so you would set H:3 for them.
2.4 Themes and settings You can configure many Beamer and LaTeX settings in your document by inserting lines at the top of your org file. This document, for instance, defines:
#+TITLE: Documents and presentations with org-mode #+AUTHOR: John Goerzen #+BEAMER_HEADER: \institute{The Changelog} #+PROPERTY: comments yes #+PROPERTY: header-args :exports both :eval never-export #+OPTIONS: H:2 #+BEAMER_THEME: CambridgeUS #+BEAMER_COLOR_THEME: default 2.5 Advanced settings I like to change some colors, bullet formatting, and the like. I round out my document with:
We can’t just +BEAMER_INNER_THEME: default because that picks the theme default.
Override per https://tex.stackexchange.com/questions/11168/change-bullet-style-formatting-in-beamer
#+BEAMER_INNER_THEME: default #+LaTeX_CLASS_OPTIONS: [aspectratio=169] #+BEAMER_HEADER: \definecolor{links}{HTML}{0000A0} #+BEAMER_HEADER: \hypersetup{colorlinks=,linkcolor=,urlcolor=links} #+BEAMER_HEADER: \setbeamertemplate{itemize items}[default] #+BEAMER_HEADER: \setbeamertemplate{enumerate items}[default] #+BEAMER_HEADER: \setbeamertemplate{items}[default] #+BEAMER_HEADER: \setbeamercolor*{local structure}{fg=darkred} #+BEAMER_HEADER: \setbeamercolor{section in toc}{fg=darkred} #+BEAMER_HEADER: \setlength{\parskip}{\smallskipamount} Here, aspectratio=169 sets a 16:9 aspect ratio, and the remaining are standard LaTeX/Beamer configuration bits.
2.6 Shrink (to fit) Sometimes you’ve got some really large code examples and you might prefer to just shrink the slide to fit.
Just type C-c C-x p, set the BEAMER_opt property to shrink=15.
(Or a larger value of shrink). The previous slide uses this here.
2.7 Result Here’s the end result:
screenshot1
3 Interactive Slides 3.1 Interactive Emacs Slideshows With the org-tree-slide package, you can display your slideshow from right within Emacs. Just run M-x org-tree-slide-mode. Then, use C-> and C-< to move between slides.
You might find C-c C-x C-v (which is org-toggle-inline-images) helpful to cause the system to display embedded images.
3.2 HTML Slideshows There are a lot of ways to export org-mode presentations to HTML, with various levels of JavaScript integration. See the non-beamer presentations section of the org-mode wiki for details.
4 Miscellaneous 4.1 Additional resources to accompany this post orgmode.org beamer tutorial LaTeX wiki Generating section title slides Shrinking content to fit on slide A great resource: refcard-org-beamer See its Github repo Make sure to check out both the PDF and the .org file A nice Theme matrix 4.2 Up next in my Emacs series… mu4e for email!
One comment so far
https://changelog.complete.org/archives/tag/emacs2018