Created
August 16, 2018 15:02
-
-
Save nxtr/83ac3c549aff23428d130c1993918893 to your computer and use it in GitHub Desktop.
with-file-temp-buffer: (FILENAME &rest BODY)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro with-file-temp-buffer (filename &rest body) | |
"Create a temporary buffer visiting FILENAME, and evaluate BODY there like | |
`progn'." | |
(declare (indent 1) (debug t)) | |
(let* ((temp-buffer (make-symbol "temp-buffer"))) | |
`(let* ((truename (abbreviate-file-name (file-truename ,filename))) | |
(number (nthcdr 10 (file-attributes truename))) | |
(,temp-buffer (find-file-noselect-1 | |
(create-file-buffer ,filename) | |
,filename 'nowarn nil truename number))) | |
(with-current-buffer ,temp-buffer | |
(unwind-protect | |
(progn ,@body) | |
(and (buffer-name ,temp-buffer) | |
(kill-buffer ,temp-buffer))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment