mirror of
https://github.com/org-roam/org-roam
synced 2025-08-03 12:27:23 -05:00
(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:
@ -525,6 +525,11 @@ also run Org-capture's template expansion."
|
|||||||
(when-let ((ref (plist-get org-roam-capture--info :ref)))
|
(when-let ((ref (plist-get org-roam-capture--info :ref)))
|
||||||
(org-roam-ref-add 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 ()
|
(defun org-roam-capture--goto-location ()
|
||||||
"Initialize the buffer, and goto the location of the new capture.
|
"Initialize the buffer, and goto the location of the new capture.
|
||||||
Return the ID of the location."
|
Return the ID of the location."
|
||||||
@ -535,7 +540,7 @@ Return the ID of the location."
|
|||||||
(setq path (expand-file-name
|
(setq path (expand-file-name
|
||||||
(string-trim (org-roam-capture--fill-template path t))
|
(string-trim (org-roam-capture--fill-template path t))
|
||||||
org-roam-directory))
|
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))
|
(when new-file-p (org-roam-capture--put :new-file path))
|
||||||
(set-buffer (org-capture-target-buffer path))
|
(set-buffer (org-capture-target-buffer path))
|
||||||
(widen)
|
(widen)
|
||||||
@ -544,7 +549,7 @@ Return the ID of the location."
|
|||||||
(setq path (expand-file-name
|
(setq path (expand-file-name
|
||||||
(string-trim (org-roam-capture--fill-template path t))
|
(string-trim (org-roam-capture--fill-template path t))
|
||||||
org-roam-directory))
|
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))
|
(when new-file-p (org-roam-capture--put :new-file path))
|
||||||
(set-buffer (org-capture-target-buffer path))
|
(set-buffer (org-capture-target-buffer path))
|
||||||
(setq p (point-min))
|
(setq p (point-min))
|
||||||
@ -555,7 +560,7 @@ Return the ID of the location."
|
|||||||
(setq path (expand-file-name
|
(setq path (expand-file-name
|
||||||
(string-trim (org-roam-capture--fill-template path t))
|
(string-trim (org-roam-capture--fill-template path t))
|
||||||
org-roam-directory))
|
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))
|
(set-buffer (org-capture-target-buffer path))
|
||||||
(when new-file-p
|
(when new-file-p
|
||||||
(org-roam-capture--put :new-file path)
|
(org-roam-capture--put :new-file path)
|
||||||
@ -566,7 +571,7 @@ Return the ID of the location."
|
|||||||
(setq path (expand-file-name
|
(setq path (expand-file-name
|
||||||
(string-trim (org-roam-capture--fill-template path t))
|
(string-trim (org-roam-capture--fill-template path t))
|
||||||
org-roam-directory))
|
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))
|
(set-buffer (org-capture-target-buffer path))
|
||||||
(widen)
|
(widen)
|
||||||
(when new-file-p
|
(when new-file-p
|
||||||
|
Reference in New Issue
Block a user