(fix): org-roam-dailies: fix false warning on new file (#1387)

Fixes #1358
This commit is contained in:
Jethro Kuan
2021-01-16 21:06:50 +08:00
committed by GitHub
parent cc2572e48b
commit 06e5814898

View File

@ -401,13 +401,14 @@ The file is saved if the original value of :no-save is not t and
file) file)
org-roam-directory))) org-roam-directory)))
(defun org-roam-capture--new-file () (defun org-roam-capture--new-file (&optional allow-existing-file-p)
"Return the path to the new file during an Org-roam capture. "Return the path to file during an Org-roam capture.
This function reads the file-name attribute of the currently This function reads the file-name attribute of the currently
active Org-roam template. active Org-roam template.
If the file path already exists, throw an error. If the file path already exists, and not ALLOW-EXISTING-FILE-P,
raise a warning.
Else, to insert the header content in the file, `org-capture' Else, to insert the header content in the file, `org-capture'
prepends the `:head' property of the Org-roam capture template. prepends the `:head' property of the Org-roam capture template.
@ -416,9 +417,7 @@ To prevent the creation of a new file if the capture process is
aborted, we do the following: aborted, we do the following:
1. Save the original value of the capture template's :no-save. 1. Save the original value of the capture template's :no-save.
2. Set the capture template's :no-save to t. 2. Set the capture template's :no-save to t.
3. Add a function on `org-capture-before-finalize-hook' that saves 3. Add a function on `org-capture-before-finalize-hook' that saves
the file if the original value of :no-save is not t and the file if the original value of :no-save is not t and
`org-note-abort' is not t." `org-note-abort' is not t."
@ -433,11 +432,11 @@ the file if the original value of :no-save is not t and
(roam-template (concat roam-head org-template))) (roam-template (concat roam-head org-template)))
(if (or (file-exists-p file-path) (if (or (file-exists-p file-path)
(find-buffer-visiting file-path)) (find-buffer-visiting file-path))
(unless allow-existing-file-p
(lwarn '(org-roam) :warning (lwarn '(org-roam) :warning
"Attempted to recreate existing file: %s. "Attempted to recreate existing file: %s.
This can happen when your org-roam db is not in sync with your notes. This can happen when your org-roam db is not in sync with your notes.
Using existing file..." Using existing file..." file-path))
file-path)
(make-directory (file-name-directory file-path) t) (make-directory (file-name-directory file-path) t)
(org-roam-capture--put :orig-no-save (org-capture-get :no-save) (org-roam-capture--put :orig-no-save (org-capture-get :no-save)
:new-file t) :new-file t)
@ -535,7 +534,7 @@ This function is used solely in Org-roam's capture templates: see
(org-roam-capture--new-file)) (org-roam-capture--new-file))
('dailies ('dailies
(org-capture-put :default-time (cdr (assoc 'time org-roam-capture--info))) (org-capture-put :default-time (cdr (assoc 'time org-roam-capture--info)))
(org-roam-capture--new-file)) (org-roam-capture--new-file 'allow-existing))
('ref ('ref
(if-let ((ref (cdr (assoc 'ref org-roam-capture--info)))) (if-let ((ref (cdr (assoc 'ref org-roam-capture--info))))
(pcase (org-roam--split-ref ref) (pcase (org-roam--split-ref ref)