mirror of
https://github.com/doomemacs/doomemacs
synced 2025-09-16 15:56:52 -05:00
Refactor lang/org
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
;;; lang/org/+capture.el -*- lexical-binding: t; -*-
|
||||
|
||||
(add-hook 'org-load-hook #'+org|init-capture)
|
||||
|
||||
;; Sets up some reasonable defaults, as well as two `org-capture' workflows that
|
||||
;; I like:
|
||||
;;
|
||||
@@ -28,68 +26,62 @@ Is relative to `org-directory', unless it is absolute. Is used in Doom's default
|
||||
|
||||
It is used in Doom's default `org-capture-templates'.")
|
||||
|
||||
(defvar org-capture-templates
|
||||
'(("t" "Personal todo" entry
|
||||
(file+headline +org-capture-todo-file "Inbox")
|
||||
"* [ ] %?\n%i\n%a" :prepend t :kill-buffer t)
|
||||
("n" "Personal notes" entry
|
||||
(file+headline +org-capture-notes-file "Inbox")
|
||||
"* %u %?\n%i\n%a" :prepend t :kill-buffer t)
|
||||
|
||||
;; Will use {project-root}/{todo,notes,changelog}.org, unless a
|
||||
;; {todo,notes,changelog}.org file is found in a parent directory.
|
||||
("p" "Templates for projects")
|
||||
("pt" "Project todo" entry ; {project-root}/todo.org
|
||||
(file+headline +org-capture-project-todo-file "Inbox")
|
||||
"* TODO %?\n%i\n%a" :prepend t :kill-buffer t)
|
||||
("pn" "Project notes" entry ; {project-root}/notes.org
|
||||
(file+headline +org-capture-project-notes-file "Inbox")
|
||||
"* TODO %?\n%i\n%a" :prepend t :kill-buffer t)
|
||||
("pc" "Project changelog" entry ; {project-root}/changelog.org
|
||||
(file+headline +org-capture-project-notes-file "Unreleased")
|
||||
"* TODO %?\n%i\n%a" :prepend t :kill-buffer t)))
|
||||
|
||||
|
||||
(defvar org-default-notes-file nil) ; defined in org.el
|
||||
|
||||
|
||||
;;
|
||||
(defun +org|init-capture ()
|
||||
(dolist (var '(+org-capture-todo-file
|
||||
+org-capture-notes-file))
|
||||
(set var (expand-file-name (symbol-value var) org-directory)))
|
||||
(unless org-default-notes-file
|
||||
(setq org-default-notes-file +org-capture-notes-file))
|
||||
;;; Bootstrap
|
||||
|
||||
(add-hook 'org-capture-after-finalize-hook #'+org-capture|cleanup-frame)
|
||||
(setq org-capture-templates
|
||||
'(("t" "Personal todo" entry
|
||||
(file+headline +org-capture-todo-file "Inbox")
|
||||
"* TODO %?\n%i\n%a" :prepend t :kill-buffer t)
|
||||
("n" "Personal notes" entry
|
||||
(file+headline +org-capture-notes-file "Inbox")
|
||||
"* %u %?\n%i\n%a" :prepend t :kill-buffer t)
|
||||
|
||||
(defun +org*expand-variable-paths (file)
|
||||
"If a variable is used for a file path in `org-capture-template', it is used
|
||||
;; Will use {project-root}/{todo,notes,changelog}.org, unless a
|
||||
;; {todo,notes,changelog}.org file is found in a parent directory.
|
||||
("p" "Templates for projects")
|
||||
("pt" "Project todo" entry ; {project-root}/todo.org
|
||||
(file+headline +org-capture-project-todo-file "Inbox")
|
||||
"* TODO %?\n%i\n%a" :prepend t :kill-buffer t)
|
||||
("pn" "Project notes" entry ; {project-root}/notes.org
|
||||
(file+headline +org-capture-project-notes-file "Inbox")
|
||||
"* TODO %?\n%i\n%a" :prepend t :kill-buffer t)
|
||||
("pc" "Project changelog" entry ; {project-root}/changelog.org
|
||||
(file+headline +org-capture-project-notes-file "Unreleased")
|
||||
"* TODO %?\n%i\n%a" :prepend t :kill-buffer t)))
|
||||
|
||||
(defvaralias '+org-capture-notes-file 'org-default-notes-file)
|
||||
|
||||
(add-hook 'org-capture-after-finalize-hook #'+org-capture|cleanup-frame)
|
||||
|
||||
(defun +org*capture-expand-variable-file (file)
|
||||
"If a variable is used for a file path in `org-capture-template', it is used
|
||||
as is, and expanded relative to `default-directory'. This changes it to be
|
||||
relative to `org-directory', unless it is an absolute path."
|
||||
(if (and (symbolp file) (boundp file))
|
||||
(expand-file-name (symbol-value file) org-directory)
|
||||
file))
|
||||
(advice-add #'org-capture-expand-file :filter-args #'+org*expand-variable-paths)
|
||||
(if (and (symbolp file) (boundp file))
|
||||
(expand-file-name (symbol-value file) org-directory)
|
||||
file))
|
||||
(advice-add #'org-capture-expand-file :filter-args #'+org*capture-expand-variable-file)
|
||||
|
||||
(defun +org*prevent-save-prompts-when-refiling (&rest _)
|
||||
"Fix #462: when refiling from org-capture, Emacs prompts to kill the
|
||||
(defun +org*prevent-save-prompts-when-refiling (&rest _)
|
||||
"Fix #462: when refiling from org-capture, Emacs prompts to kill the
|
||||
underlying, modified buffer. This fixes that."
|
||||
(when (bound-and-true-p org-capture-is-refiling)
|
||||
(org-save-all-org-buffers)))
|
||||
(advice-add 'org-refile :after #'+org*prevent-save-prompts-when-refiling)
|
||||
(when (bound-and-true-p org-capture-is-refiling)
|
||||
(org-save-all-org-buffers)))
|
||||
(advice-add 'org-refile :after #'+org*prevent-save-prompts-when-refiling)
|
||||
|
||||
(defun +org|show-target-in-capture-header ()
|
||||
(setq header-line-format
|
||||
(format "%s%s%s"
|
||||
(propertize (abbreviate-file-name (buffer-file-name (buffer-base-buffer)))
|
||||
'face 'font-lock-string-face)
|
||||
org-eldoc-breadcrumb-separator
|
||||
header-line-format)))
|
||||
(add-hook 'org-capture-mode-hook #'+org|show-target-in-capture-header)
|
||||
(defun +org|show-target-in-capture-header ()
|
||||
(setq header-line-format
|
||||
(format "%s%s%s"
|
||||
(propertize (abbreviate-file-name (buffer-file-name (buffer-base-buffer)))
|
||||
'face 'font-lock-string-face)
|
||||
org-eldoc-breadcrumb-separator
|
||||
header-line-format)))
|
||||
(add-hook 'org-capture-mode-hook #'+org|show-target-in-capture-header)
|
||||
|
||||
(when (featurep! :feature evil)
|
||||
(add-hook 'org-capture-mode-hook #'evil-insert-state))
|
||||
(when (featurep! :feature evil)
|
||||
(add-hook 'org-capture-mode-hook #'evil-insert-state))
|
||||
|
||||
(when (featurep! :ui doom-dashboard)
|
||||
(add-hook '+doom-dashboard-inhibit-functions #'+org-capture-frame-p)))
|
||||
(when (featurep! :ui doom-dashboard)
|
||||
(add-hook '+doom-dashboard-inhibit-functions #'+org-capture-frame-p))
|
||||
|
Reference in New Issue
Block a user