branch: externals/denote
commit 159134fee119ee9b5a99f3ba0f835ae321e72ca7
Merge: 3563d2b3fe 0f71f126cc
Author: Protesilaos Stavrou <[email protected]>
Commit: GitHub <[email protected]>

    Merge pull request #672 from kilesduli/fix-file-not-saved-but-need-rename
    
    Fix front-matter retrieving when buffer is unsaved or file missing
---
 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)))
 

Reply via email to