From 02a791bf971c43dac2f95801a91bfd6a9f3756fc Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Tue, 23 Feb 2021 21:35:20 +0100 Subject: Fix org-capture with nroam Only enable nroam-mode on org-roam file buffers. --- nroam.el | 14 ++++++++++++-- readme.org | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/nroam.el b/nroam.el index b3e6242..322fd41 100644 --- a/nroam.el +++ b/nroam.el @@ -29,8 +29,8 @@ ;; buffer of Org-roam. Instead, it displays org-roam backlinks at the end of ;; org-roam buffers. ;; -;; To setup nroam for all org-mode buffer, evaluate the following: -;; (add-hook 'org-mode-hook #'nroam-mode) +;; To setup nroam for all org-roam buffers, evaluate the following: +;; (add-hook 'org-mode-hook #'nroam-setup-maybe) ;;; Code: @@ -70,6 +70,12 @@ Make the region inserted by BODY read-only, and marked with (define-key map (kbd "RET") #'nroam-return) map)) +;;;###autoload +(defun nroam-setup-maybe () + "Setup nroam for the current buffer iff an org-roam buffer." + (when (nroam--org-roam-file-p) + (nroam-mode))) + ;;;###autoload (define-minor-mode nroam-mode "Show nroam sections at the end of org-roam buffers." @@ -120,6 +126,10 @@ Make the region inserted by BODY read-only, and marked with (seq-do #'nroam--insert-backlink-group groups) (nroam--hide-drawers))) +(defun nroam--org-roam-file-p () + "Return non-nil if the current buffer is an org-roam buffer." + (org-roam--org-roam-file-p)) + (defun nroam--init-work-buffer () "Initiate nroam hidden buffer." (get-buffer-create nroam-work-buffer) diff --git a/readme.org b/readme.org index d16507d..36aafed 100644 --- a/readme.org +++ b/readme.org @@ -17,7 +17,7 @@ By making them an integral part of the org buffer, backlinks also become more po To setup nroam for all =org-mode= buffer, evaluate the following: #+begin_src elisp -(add-hook 'org-mode-hook #'nroam-mode) +(add-hook 'org-mode-hook #'nroam-setup-maybe) #+end_src The linked references section will be updated after each buffer save. -- cgit v1.2.3-54-g00ecf