branch: externals/denote
commit c36550139cca32d0e241501da75e8ef97b5ff093
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: Protesilaos Stavrou <i...@protesilaos.com>

    Improve denote--file-with-temp-buffer macro to also check unsaved buffers
    
    This gives us the opportunity to insert the contents of a Denote
    buffer that has not been saved yet, such as those that are generated
    right after we invoke the 'denote' command.
---
 denote.el | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/denote.el b/denote.el
index 45863a5008..9279ebfba9 100644
--- a/denote.el
+++ b/denote.el
@@ -1370,12 +1370,20 @@ Run `denote-desluggify' on title if the extraction is 
sucessful."
       (denote-desluggify title)
     (file-name-base file)))
 
+(defun denote--file-with-temp-buffer-1 (file)
+  "Return path to FILE or its buffer together with the appropriate function.
+Subroutine of `denote--file-with-temp-buffer'."
+  (when file
+    (if (file-exists-p file)
+        (cons #'insert-file-contents buffer-file-name)
+      (cons #'insert-buffer (get-file-buffer file)))))
+
 (defmacro denote--file-with-temp-buffer (file &rest body)
   "If FILE exists, insert its contents in a temp buffer and call BODY."
   (declare (indent 1))
-  `(when (file-exists-p ,file)
+  `(when-let ((file-and-function (denote--file-with-temp-buffer-1 ,file)))
      (with-temp-buffer
-       (insert-file-contents ,file)
+       (funcall (car file-and-function) (cdr file-and-function))
        (goto-char (point-min))
        ,@body)))
 

Reply via email to