From 7f4fe8913a83bd61b72ff5fe0a87a123934985d6 Mon Sep 17 00:00:00 2001 From: Vedang Manerikar Date: Wed, 14 Oct 2020 08:11:00 +0530 Subject: [PATCH] Add a note to an org-brain entry Add a key-binding (`C-c z`) to directly trigger adding notes to the current entry in org-brain. This makes it possible to capture thoughts about the current entry without leaving the org-brain-visualization window. The commit provides two functions: - `org-brain-visualize-add-note` : This function is bound to `C-c z` in `org-brain-visualize-mode-map` and is the expected way to use this functionality. Adds a note to the current entry. - `org-brain-add-note`: This is a generic function that can be called from within org-mode. --- org-brain.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/org-brain.el b/org-brain.el index 8c7a5cc..0153c0e 100644 --- a/org-brain.el +++ b/org-brain.el @@ -2781,6 +2781,29 @@ If called interactively, select ENTRY with (org-brain-add-todo (org-brain-entry-at-pt)) (user-error "Not in org-brain-visualize"))) +(defun org-brain-add-note (entry) + "Add a note 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 note to: " 'all nil nil def-choice)))) + (if (org-brain-filep entry) + ;; Entry = File + (user-error "Only headline entries support adding a note") + ;; Entry = Headline + (org-with-point-at (org-brain-entry-marker entry) + (org-add-note)))) + +(defun org-brain-visualize-add-note () + "Add a note to the currently active entry." + (interactive) + (if (eq major-mode 'org-brain-visualize-mode) + (org-brain-add-note (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." @@ -2918,6 +2941,8 @@ point before the buffer was reverted." (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-key org-brain-visualize-mode-map (kbd "C-c z") 'org-brain-visualize-add-note) +(define-key org-brain-visualize-mode-map (kbd "C-c C-z") 'org-brain-visualize-add-note) (define-prefix-command 'org-brain-select-map) (define-key org-brain-select-map "s" 'org-brain-clear-selected)