branch: externals/denote
commit 0f71f126cca5a80859ac3552332fda3d6857324d
Author: duli <[email protected]>
Commit: duli <[email protected]>
Fix front-matter retrieving when buffer is unsaved or file missing
This addresses a regression where
'denote-rename-file-using-front-matter' would fail to recognize changes
in an unsaved buffer, or fail entirely if the file had not yet been
created on disk (as described in
https://github.com/protesilaos/denote/pull/670).
The logic now consistently prioritizes the content of an open buffer
over the file on disk. Previously, the code would revert to reading the
file if the buffer was marked as modified; however, since we cannot
reliably detect if a modification affects the front-matter, it is safe
to always use the live buffer state.
* (denote--file-with-temp-buffer-subr): Remove.
(denote--file-with-temp-buffer): Refactor to prioritize buffer content
and remove the dependency on the internal subr.
Fixes: https://github.com/protesilaos/denote/pull/670
---
denote.el | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)
diff --git a/denote.el b/denote.el
index 6eb8b74363..358db62ae8 100644
--- a/denote.el
+++ b/denote.el
@@ -2624,30 +2624,17 @@ Also see `denote-extract-keywords-from-path' (alias
(when (string-match denote-title-regexp filename)
(match-string 1 filename))))
-(defun denote--file-with-temp-buffer-subr (file)
- "Return path to FILE or its buffer together with the appropriate function.
-Subroutine of `denote--file-with-temp-buffer'."
- (let* ((buffer (get-file-buffer file))
- (file-exists (file-exists-p file))
- (buffer-modified (buffer-modified-p buffer)))
- (cond
- ((and file-exists
- buffer
- (not buffer-modified))
- (cons #'insert-buffer buffer))
- ((and file-exists
- (or (null buffer) buffer-modified))
- (cons #'insert-file-contents file))
- ;; (t
- ;; (error "Cannot find anything about file `%s'" file))
- )))
-
(defmacro denote--file-with-temp-buffer (file &rest body)
- "If FILE exists, insert its contents in a temp buffer and call BODY."
+ "If a buffer is visiting FILE, insert its contents into a temporary
+buffer. Otherwise, insert the contents of FILE. Then call BODY."
(declare (indent 1))
- `(when-let* ((file-and-function (denote--file-with-temp-buffer-subr ,file)))
+ `(let* ((buffer (get-file-buffer ,file))
+ (file-exist (file-exists-p ,file)))
(with-temp-buffer
- (funcall (car file-and-function) (cdr file-and-function))
+ (cond
+ (buffer (insert-buffer buffer))
+ (file-exist (insert-file-contents ,file))
+ (t (error "Cannot find anything about file `%s'" ,file)))
(goto-char (point-min))
,@body)))