From 7af2d769e58062e904ba236db2916442d579c625 Mon Sep 17 00:00:00 2001 From: Vedang Manerikar Date: Wed, 14 Oct 2020 08:05:12 +0530 Subject: [PATCH] Add tasks to the org-brain entry in visualize mode 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. --- org-brain.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/org-brain.el b/org-brain.el index 945b1d8..87224c6 100644 --- a/org-brain.el +++ b/org-brain.el @@ -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." @@ -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)