Skip to content

Commit

Permalink
Add tasks to the org-brain entry in visualize mode
Browse files Browse the repository at this point in the history
Add a key-binding (`C-c t`) to directly add a TODO entry to the
current entry in org-brain. This makes it possible to capture action
items about the current entry without leaving the
org-brain-visualization window.

This change depends on the capture templates introduced in the commit
before it and adds `org-brain-visualize-add-todo` and
`org-brain-add-todo` functions to enable adding tasks under a brain
entry.
  • Loading branch information
vedang committed Oct 14, 2020
1 parent 630e2d7 commit 7af2d76
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions org-brain.el
Original file line number Diff line number Diff line change
Expand Up @@ -2726,6 +2726,33 @@ Set up the capture templates we need in `org-brain-visualize-mode'."
org-capture-templates-contexts)
(setq org-brain-visualize--capture-templates-registered-p t)))))

;;;; Back to Visualize

(defun org-brain-add-todo (entry)
"Add a todo item to the ENTRY.
If called interactively, select ENTRY with
`org-brain-choose-entry', give a preference to
`org-brain-entry-at-pt', if any."
(interactive
(let ((def-choice (ignore-errors
(org-brain-entry-name (org-brain-entry-at-pt)))))
(list (org-brain-choose-entry "Add a TODO item to: "
'all nil nil def-choice))))
(when (not org-brain-visualize-use-capture-templates)
(user-error "The appropriate capture templates have not been set up. Check the README for instructions"))
(if (org-brain-filep entry)
;; Entry = File
(user-error "Only headline entries support adding a TODO item")
;; Entry = Headline
(org-capture nil (concat org-brain-visualize-capture-prefix-key "t"))))

(defun org-brain-visualize-add-todo ()
"Add a todo item to the currently active entry."
(interactive)
(if (eq major-mode 'org-brain-visualize-mode)
(org-brain-add-todo (org-brain-entry-at-pt))
(user-error "Not in org-brain-visualize")))

;;;###autoload
(defun org-brain-select-button ()
"Toggle selection of the entry linked to by the button at point."
Expand Down Expand Up @@ -2862,6 +2889,7 @@ point before the buffer was reverted."
(define-key org-brain-visualize-mode-map "e" 'org-brain-annotate-edge)
(define-key org-brain-visualize-mode-map "\C-c\C-w" 'org-brain-refile)
(define-key org-brain-visualize-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
(define-key org-brain-visualize-mode-map (kbd "C-c t") 'org-brain-visualize-add-todo)

(define-prefix-command 'org-brain-select-map)
(define-key org-brain-select-map "s" 'org-brain-clear-selected)
Expand Down

0 comments on commit 7af2d76

Please sign in to comment.