From b909ccd800a2f92f078823034c9ce57aad218553 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Sun, 28 Feb 2021 21:32:54 +0100 Subject: Insert sections when turning the mode on if the buffer file exists. * nroam.el (nroam-mode): Conditionally insert sections when turning enabling `nroam-mode'. (nroam--maybe-insert-immediately): New function. --- nroam.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nroam.el b/nroam.el index 329111c..711aded 100644 --- a/nroam.el +++ b/nroam.el @@ -99,11 +99,16 @@ Make the region inserted by BODY read-only, and marked with (nroam--init-work-buffer) (add-hook 'before-save-hook #'nroam--prune nil t) (add-hook 'after-save-hook #'nroam--update-maybe nil t) - (nroam-update)) + (nroam--maybe-insert-immediately)) (remove-hook 'before-save-hook #'nroam--prune t) (remove-hook 'after-save-hook #'nroam--update-maybe t) (nroam--prune))) +(defun nroam--maybe-insert-immediately () + "Insert nroam sections iff the buffer file exists." + (when (file-exists-p buffer-file-name) + (nroam-update))) + ;;;###autoload (defun nroam-ctrl-c-ctrl-c () "Update the sections for the current buffer, or fallback to `org-ctrl-c-ctrl-c'." -- cgit v1.2.3-54-g00ecf