lang/org: refactor & expand org-capture-templates

+ Adds three new default org-capture templates, for todo, notes and
  changelogs. It will use the first {todo,notes,changelog}.org file
  found up the file heirarchy from the current file, or will use
  {project-root}/X.org.
+ Variables in org-capture-templates are now resolved relative to
  org-directory, if they aren't absolute.
+ Display target file in org capture window header-line.

Mentioned in #886.
This commit is contained in:
Henrik Lissner 2018-09-19 23:26:53 -04:00
parent 1e710e94e3
commit 77255a63e0
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 103 additions and 22 deletions

View file

@ -3,7 +3,8 @@
(defvar org-capture-initial)
;; --- External frame ---------------------
;;
;; External frame
;;;###autoload
(defvar +org-capture-frame-parameters
@ -70,3 +71,35 @@ you're done. This can be called from an external shell script."
(defun +org-capture-available-keys ()
"TODO"
(string-join (mapcar #'car org-capture-templates) ""))
;;
;; Capture targets
(defun +org--capture-root (path)
(let ((filename (file-name-nondirectory path)))
(expand-file-name
filename
(or (locate-dominating-file (file-truename default-directory)
filename)
(if (doom-project-p 'nocache) (doom-project-root 'nocache))
(user-error "Couldn't detect a project")))))
;;;###autoload
(defun +org-capture-project-todo-file ()
"Find the nearest `+org-capture-todo-file' in a parent directory, otherwise,
opens a blank one at the project root. Throws an error if not in a project."
(+org--capture-root +org-capture-todo-file))
;;;###autoload
(defun +org-capture-project-notes-file ()
"Find the nearest `+org-capture-notes-file' in a parent directory, otherwise,
opens a blank one at the project root. Throws an error if not in a project."
(+org--capture-root +org-capture-notes-file))
;;;###autoload
(defun +org-capture-project-changelog-file ()
"Find the nearest `+org-capture-changelog-file' in a parent directory,
otherwise, opens a blank one at the project root. Throws an error if not in a
project."
(+org--capture-root +org-capture-changelog-file))