org-capture 〜Emacs + org-modeで素早くメモをとる新しい方法〜
ここでは、Emacsでメモをとる最新の方法を紹介します。
org-modeバージョン7系列リリース
7/19に org-mode 7.01がリリースされました。 長い6.xx時代が終わり、ついにメジャーバージョンアップしました。 細々なリリースが続けられています。
次世代メモ書きツール org-capture
去年初頭にorg-rememberというメモ環境構築を紹介 しましたが、org-captureという、より洗練された方法がデフォルトになりました。
org-rememberの方も存続しているので、無理に乗り換える必要はありません。 org-mode自体がEmacs標準添付になっていて、添付版のorg-modeはやや古いため、あと数年ほどはorg-rememberユーザがいると思われます。 新しいもの好きな人は、是非とも乗り換えてみましょう。
メリット
org-rememberでは、remember.elが作成する一時バッファをorg-modeにして、所定の場所に書き込む程度でした。 対して、org-captureはファイルに直接書き込む方式になったため、ファイルの内容に則した処理が行えるようになりました。
- 任意のツリーにメモを置くことができる
- org-rememberではレベル1の見出しとファイルの先頭・末尾のみ
- 現在計時中(clock-inしている)タスクのメモを書くことができる
- 設定次第でメモを置く場所のまわりを見ることができる
- 表の行を追加・編集することができる
- 年・月・日の見出しを自動作成し、日記のようなファイルを作成できる
デモンストレーション
org-captureは多機能なので、言葉で説明するよりも実際に動かしてみるとよくわかります。
以下のコードを評価してください。
(require 'org-capture) (defun org-capture-demo () (interactive) (let ((file "/tmp/org-capture.org") org-capture-templates) (find-file-other-window file) (unless (save-excursion (goto-char 1) (search-forward "* test\n" nil t)) (insert "* test\n** entry\n")) (other-window 1) (setq org-capture-templates `(("a" "ふつうのエントリー後に追加" entry (file+headline ,file "entry") "* %?\n%U\n%a\n") ("b" "ふつうのエントリー前に追加" entry (file+headline ,file "entry") "* %?\n%U\n%a\n" :prepend t) ("c" "即座に書き込み" entry (file+headline ,file "entry") "* immediate-finish\n" :immediate-finish t) ("d" "ナローイングしない" entry (file+headline ,file "entry") "* 全体を見る\n\n" :unnarrowed t) ("e" "クロック中のエントリに追加" entry (clock) "* clocking" :unnarrowed t) ("f" "リスト" item (file+headline ,file "list") "- リスト") ;; うまく動かない ("g" "チェックリスト" checkitem (file+headline ,file "list") "チェックリスト") ("h" "表の行" table-line (file+headline ,file "table") "|表|") ("i" "そのまま" plain (file+headline ,file "plain") "あいうえお") ("j" "ノードをフルパス指定して挿入" entry (file+olp ,file "test" "entry") "* %?\n%U\n%a\n") ;; これもうまく動かない ("k" "ノードを正規表現指定して挿入" entry (file+regexp ,file "list") "* %?\n%U\n%a\n") ;; 年月日エントリは追記される ("l" "年/月/日のエントリを作成する1" entry (file+datetree ,file)) ("m" "年/月/日のエントリを作成する2" item (file+datetree ,file)) ("o" "年/月/日のエントリを作成する prepend" entry (file+datetree ,file) "* a" :prepend t))) (org-capture))) (global-set-key "\C-x\C-z" 'org-capture-demo)
M-x install-elisp http://www.rubyist.net/~rubikitch/junk/2010-07-28-104637.org-capture-templates.el
でダウンロード・インストールできます。
C-x C-zにorg-captureコマンドを割り当てています。
すると、次のようなメニューが出てきます。 該当するキーを押せばCAPTUREバッファが登場します。 header-lineに説明があるように、C-c C-cを押せば所定の位置にメモを格納します。
Select a capture template
=========================[a] ふつうのエントリー後に追加
[b] ふつうのエントリー前に追加
[c] 即座に書き込み
[d] ナローイングしない
[e] クロック中のエントリに追加
[f] リスト
[g] チェックリスト
[h] 表の行
[i] そのまま
[j] ノードをフルパス指定して挿入
[k] ノードを正規表現指定して挿入
[l] 年/月/日のエントリを作成する1
[m] 年/月/日のエントリを作成する2
[o] 年/月/日のエントリを作成する prepend
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
[C] Customize org-capture-templates
[q] Abort
このデモンストレーションの目的は、メモがどのように格納されるのかを示すためです。
設定
最初から使う
デモンストレーションの後、実際に使ってみるには、org-capture-templates変数を設定します。 具体的にはこんな設定になると思います。 C-c cでorg-captureを実行するようになっています。
;; (save-window-excursion (shell-command (format "emacs-test -l test-minimum -l %s %s &" buffer-file-name buffer-file-name))) (require 'org-install) (setq org-startup-truncated nil) (setq org-return-follows-link t) (add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) (setq org-directory "~/memo/") (setq org-default-notes-file (concat org-directory "agenda.org")) (setq org-capture-templates '(("t" "Todo" entry (file+headline nil "Inbox") "** TODO %?\n %i\n %a\n %t") ("b" "Bug" entry (file+headline nil "Inbox") "** TODO %? :bug:\n %i\n %a\n %t") ("i" "Idea" entry (file+headline nil "New Ideas") "** %?\n %i\n %a\n %t"))) (global-set-key (kbd "C-c c") 'org-capture)
org-rememberから乗り換える
org-rememberからの乗り変えパスも用意されています。 M-x org-capture-import-remember-templates を実行し、2回yを押します。 すると、org-capture-templatesが設定されます。 あとはC-c c Cでカスタマイズ画面から保存するなり、C-u M-: org-capture-templatesでorg-capture-templatesの値を.emacsに貼り付けてください。
詳しい設定
org-capture-templatesの細かい仕様については、 <f1> v org-capture-templates あるいは、C-c c Cで表示される説明をどうぞ。