From e6ecd9f5f687415bfc3e6336127d22a01ebcccc2 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Wed, 24 Feb 2021 17:03:31 +0100 Subject: 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. --- nroam.el | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'nroam.el') 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) -- cgit v1.2.3-54-g00ecf