summaryrefslogtreecommitdiffstatshomepage
path: root/nroam.el
diff options
context:
space:
mode:
authorGravatar Nicolas Petton2021-02-24 17:03:31 +0100
committerGravatar Nicolas Petton2021-02-24 17:03:31 +0100
commite6ecd9f5f687415bfc3e6336127d22a01ebcccc2 (patch)
treed41b172d50cb75af34eaea5347d171eba63a3146 /nroam.el
parent34e21d6880c7c6fe1eed86ecd7cfc303c3338ad5 (diff)
downloadnroam-e6ecd9f5f687415bfc3e6336127d22a01ebcccc2.tar.gz
nroam-e6ecd9f5f687415bfc3e6336127d22a01ebcccc2.zip
Advice org-capture to remove nroam sections when capturing
Nroam sections need to be pruned as they are in read-only, otherwise `org-capture' will fail to insert the capture template.
Diffstat (limited to 'nroam.el')
-rw-r--r--nroam.el17
1 files changed, 15 insertions, 2 deletions
diff --git a/nroam.el b/nroam.el
index ed635ee..e7cf780 100644
--- a/nroam.el
+++ b/nroam.el
@@ -37,10 +37,23 @@
(require 'org-roam)
(require 'org-roam-buffer)
(require 'org-element)
+(require 'org-capture)
(require 'seq)
(require 'subr-x)
(require 'bookmark)
+(defun nroam--handle-org-capture (&rest _)
+ "Setup the `org-capture' buffer.
+
+Nroam sections need to be pruned as they are in read-only,
+otherwise `org-capture' will fail to insert the capture
+template."
+ (when-let ((buf (org-capture-get :buffer)))
+ (with-current-buffer buf
+ (nroam--prune))))
+
+(advice-add 'org-capture-place-template :before #'nroam--handle-org-capture)
+
(defcustom nroam-sections
'(nroam-backlinks-section)
"List of functions to be called to insert sections in nroam buffers."
@@ -119,8 +132,8 @@ Make the region inserted by BODY read-only, and marked with
(defun nroam-backlinks-section ()
"Insert org-roam backlinks for the current buffer."
- (when-let* ((backlinks (nroam--get-backlinks))
- (groups (seq-reverse (nroam--group-backlinks backlinks))))
+ (let* ((backlinks (nroam--get-backlinks))
+ (groups (seq-reverse (nroam--group-backlinks backlinks))))
(nroam--ensure-empty-line)
(nroam--insert-backlinks-heading (seq-length backlinks))
(seq-do #'nroam--insert-backlink-group groups)