Skip to content

Commit

Permalink
Create capture templates for org-brain
Browse files Browse the repository at this point in the history
I plan to use these templates to implement functionality
`org-brain-add-todo` in a future commit. The summary of changes in
this commit are as follows:

1. Set up capture templates for brain.

I'm using "b" as a template prefix key for capture templates related
to org-brain. Since people may already be using this key in their own
capture templates, this functionality is turned off by default (via
`org-brain-visualize-use-capture-templates` var) and the user can
select a different prefix key (via
`org-brain-visualize-capture-prefix-key` var)

Since I was setting up capture templates, I also moved the capture
template described in the README to this code.

Finally, these templates only work in the context of
org-brain-visualize, to avoid clutter in other modes.

2. `org-brain-visualize--register-capture-templates`

This is a helper function to ensure that we set up the capture
templates only once. It's internal and invisible to the user.
  • Loading branch information
vedang committed Jan 27, 2021
1 parent f7939ef commit 4d5f2a3
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion org-brain.el
Original file line number Diff line number Diff line change
Expand Up @@ -2702,6 +2702,53 @@ See `org-brain-add-resource'."

(defalias 'org-brain-visualize-paste-resource #'org-brain-paste-resource)

;;;; Capture Templates

(defvar org-brain-visualize-use-capture-templates nil
"Add useful capture templates to your org-brain setup.
This variable is nil by default, since we are modifying
`org-capture-templates' which can have undesirable effects.
Set this to t to activate org-brain related capture templates.
These templates only work in the `org-brain-visualize-mode' and
are keyed off `org-brain-visualize-capture-prefix-key'.")

(defvar org-brain-visualize-capture-prefix-key "b"
"The default prefix key for org-brain capture templates.
Change this value if you already use 'b' for a different capture template.")

(defvar org-brain-visualize--capture-templates-registered-p nil
"A helper var.
Track if we've added the necessary org-brain capture templates to
`org-capture'.")

(defun org-brain-visualize--register-capture-templates ()
"A helper function.
Set up the capture templates we need in `org-brain-visualize-mode'."
(with-eval-after-load 'org-capture
(progn
(when (and org-brain-visualize-use-capture-templates
(not org-brain-visualize--capture-templates-registered-p))
(push `(,org-brain-visualize-capture-prefix-key
"Templates when working with org-brain")
org-capture-templates)
(push `(,(concat org-brain-visualize-capture-prefix-key "b")
"Brain Note"
plain
(function org-brain-goto-end)
"* %i%?"
:empty-lines 1)
org-capture-templates)
(push `(,(concat org-brain-visualize-capture-prefix-key "t")
"Brain Todo"
entry
(function org-brain-goto-current)
"* TODO %?\n%U\n%i"
:clock-keep t)
org-capture-templates)
(push '("b" ((in-mode . "org-brain-visualize-mode")))
org-capture-templates-contexts)
(setq org-brain-visualize--capture-templates-registered-p t)))))

;;;###autoload
(defun org-brain-select-button ()
"Toggle selection of the entry linked to by the button at point."
Expand Down Expand Up @@ -2794,7 +2841,8 @@ point before the buffer was reverted."
special-mode "Org-brain Visualize"
"Major mode for `org-brain-visualize'.
\\{org-brain-visualize-mode-map}"
(setq-local revert-buffer-function #'org-brain-visualize-revert))
(setq-local revert-buffer-function #'org-brain-visualize-revert)
(org-brain-visualize--register-capture-templates))

;;;;; Keybindings

Expand Down

0 comments on commit 4d5f2a3

Please sign in to comment.