From 86c2e1926c3f79be2b81901578df30a2802dff52 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 | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/org-brain.el b/org-brain.el index 3f5e508..1b18455 100644 --- a/org-brain.el +++ b/org-brain.el @@ -2725,6 +2725,11 @@ Change this value if you already use 'b' for a different capture template.") Track if we've added the necessary org-brain capture templates to `org-capture'.") +(defvar org-brain-todo-capture-template + "* TODO %^{Description} :nobrain: \nDEADLINE: %^{When should this be done by?}t\n%U\n%i%?" + "The default template for capturing a TODO task against the current brain entry. +Customize this to use a different template when creating new TODO tasks.") + (defun org-brain-visualize--register-capture-templates () "A helper function. Set up the capture templates we need in `org-brain-visualize-mode'." @@ -2746,13 +2751,40 @@ Set up the capture templates we need in `org-brain-visualize-mode'." "Brain Todo" entry (function org-brain-goto-current) - "* TODO %?\n%U\n%i" + ,org-brain-todo-capture-template :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))))) +;;;; 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." @@ -2904,6 +2936,7 @@ Used as `bookmark-make-record-function' in `org-brain-visualize-mode'." (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)