(fix)capture: check if file exists on disk before template insertion (#1713)

Co-authored-by: Jethro Kuan <jethrokuan95@gmail.com>
This commit is contained in:
Alan Zimmerman
2021-07-30 20:09:13 +01:00
committed by GitHub
parent 5fc57b2e06
commit cf918c3d18

View File

@ -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