Skip to content

Commit

Permalink
Add a note to an org-brain entry
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vedang committed Oct 14, 2020
1 parent 7af2d76 commit c53b421
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions org-brain.el
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,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."
Expand Down Expand Up @@ -2890,6 +2913,7 @@ 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-prefix-command 'org-brain-select-map)
(define-key org-brain-select-map "s" 'org-brain-clear-selected)
Expand Down

0 comments on commit c53b421

Please sign in to comment.