org-captureのテンプレート ver. 2021

かつてのorg-rememberとか、org-captureに移行してスグぐらいの頃は機能足りなかったせいか書き換えることが多かったけど、最近はテンプレートも安定してきた。

個人メモは1ファイルに書き連ねていくよりも org-journal で日々書き捨て、読み返したいものだけ(個人&パブリック)ブログにエクスポート方式の相性が良かったので、org-capture templateもその日のjournalに吐き出すものが多い。

(defun ladicle/get-today-diary ()
      (concat org-journal-dir
              (format-time-string "%Y%m%d.org" (current-time))))

(setq org-capture-templates
  '(("t" "Write down the thoughts of this moment with a timestamp." entry (file+headline ladicle/get-today-diary "Log") "* %T %^{Tweet}" :immediate-finish t)
    ("e" "Add event to the today's journal file." entry (file+headline ladicle/get-today-diary "Events") "* %^T %^{Title}" :immediate-finish t)
    ("h" "Create a private blog post to the today's journal file." entry (file+headline ladicle/get-today-diary "Memo") "%[~/Dropbox/org/capture_templates/hugo_post.org]" :jump-to-captured t)
    ("i" "Add a task to inbox." entry (file+headline task-file "Inbox") "* TODO %^{Action}")
    ("a" "Add a task to the today's journal." entry (file+headline ladicle/get-today-diary "Tasks") "* TODO %^{Action}\nSCHEDULED: %t\n" :immediate-finish t)
    ("b" "Add a new book." entry (file "~/Dropbox/org/books.org") "%[~/Dropbox/org/capture_templates/book.org]" :jump-to-captured t)
    ("p" "Add a new project." entry (file "~/Dropbox/org/projects.org") "%[~/Dropbox/org/capture_templates/project.org]" :jump-to-captured t)
    ("1" "Look back monthly work." entry (file+headline ladicle/get-today-diary "Memo") "%[~/Dropbox/org/capture_templates/1on1.org]" :immediate-finish t :jump-to-captured t)
    ("Q" "Look back quarter work." entry (file+headline ladicle/get-today-diary "Memo") "%[~/Dropbox/org/capture_templates/quarter_fb.org]" :immediate-finish t :jump-to-captured t)
    ("c" "Store the code-reading notes with GitHub and file links of the current cursor position." plain (function org-coding-capture--find-store-point) "%^{Summary}\n%(with-current-buffer (org-capture-get :original-buffer) (browse-at-remote-get-url))\n# %a\n" :immediate-finish t)
    ("j" "Immediately store code info about current cursor position." plain (function org-coding-capture--find-store-point) "%(with-current-buffer (org-capture-get :original-buffer) (browse-at-remote-get-url))\n# %a\n" :immediate-finish t)
    ))
Code 1: 現在のorg-captureテンプレート

前はtemplateをベタ書きしていたけどメンテしづらいのでファイルに落として %[PATH/TO/THE/FILE] で読み込む方式に変更した。便利。 例えば、上のCapture(h)の個人ブログのテンプレートはこんな感じ。

* %?
  :PROPERTIES:
  :EXPORT_FILE_NAME: %<%Y%m%d_%H%M%S>
  :EXPORT_HUGO_CUSTOM_FRONT_MATTER: :projects '()
  :EXPORT_HUGO_MENU: :menu
  :END:
Code 2: capture_templatesのhugo_post.org

Capture(c / j)など、標準関数だけでは指定できないtargetは function 使って定義している。これは以前に記事を書いているので コードリーティングの記録とOrg Capture 参照。

人のorg設定読むの面白くて好きなのでGitHubでちょいちょい漁ってる。

References

.