mirror of
https://github.com/protesilaos/denote.git
synced 2026-09-15 09:46:24 -04:00
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.
This commit is contained in:
parent
b954ade554
commit
c36550139c
12
denote.el
12
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)))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue