diff --git a/org-roam-capture.el b/org-roam-capture.el index 92a0b3c..d4f1304 100644 --- a/org-roam-capture.el +++ b/org-roam-capture.el @@ -525,6 +525,11 @@ also run Org-capture's template expansion." (when-let ((ref (plist-get org-roam-capture--info :ref))) (org-roam-ref-add ref))) +(defun org-roam-capture--new-file-p (path) + "Return t if PATH is for a new file with no visiting buffer." + (not (or (file-exists-p path) + (org-find-base-buffer-visiting path)))) + (defun org-roam-capture--goto-location () "Initialize the buffer, and goto the location of the new capture. Return the ID of the location." @@ -535,7 +540,7 @@ Return the ID of the location." (setq path (expand-file-name (string-trim (org-roam-capture--fill-template path t)) org-roam-directory)) - (setq new-file-p (not (org-find-base-buffer-visiting path))) + (setq new-file-p (org-roam-capture--new-file-p path)) (when new-file-p (org-roam-capture--put :new-file path)) (set-buffer (org-capture-target-buffer path)) (widen) @@ -544,7 +549,7 @@ Return the ID of the location." (setq path (expand-file-name (string-trim (org-roam-capture--fill-template path t)) org-roam-directory)) - (setq new-file-p (not (org-find-base-buffer-visiting path))) + (setq new-file-p (org-roam-capture--new-file-p path)) (when new-file-p (org-roam-capture--put :new-file path)) (set-buffer (org-capture-target-buffer path)) (setq p (point-min)) @@ -555,7 +560,7 @@ Return the ID of the location." (setq path (expand-file-name (string-trim (org-roam-capture--fill-template path t)) org-roam-directory)) - (setq new-file-p (not (org-find-base-buffer-visiting path))) + (setq new-file-p (org-roam-capture--new-file-p path)) (set-buffer (org-capture-target-buffer path)) (when new-file-p (org-roam-capture--put :new-file path) @@ -566,7 +571,7 @@ Return the ID of the location." (setq path (expand-file-name (string-trim (org-roam-capture--fill-template path t)) org-roam-directory)) - (setq new-file-p (not (org-find-base-buffer-visiting path))) + (setq new-file-p (org-roam-capture--new-file-p path)) (set-buffer (org-capture-target-buffer path)) (widen) (when new-file-p