Skip to content

Instantly share code, notes, and snippets.

@nicferrier
Created July 9, 2013 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicferrier/5958820 to your computer and use it in GitHub Desktop.
Save nicferrier/5958820 to your computer and use it in GitHub Desktop.
(defmacro with-transient-file (file-name &rest code)
"Load FILE-NAME into a buffer and eval CODE.
Then dispose of the buffer.
File loading errors may be generated as by any call to visit a
file."
(declare (indent 1)
(debug (sexp &rest form)))
(let ((fvn (make-symbol "fv"))
(bvn (make-symbol "bv")))
`(let* ((,fvn ,file-name)
(,bvn (get-buffer-create
(generate-new-buffer-name "transient"))))
(unwind-protect
(with-current-buffer ,bvn
(insert-file-contents-literally ,fvn)
,@code)
(progn
(set-buffer-modified-p nil)
(kill-buffer ,bvn))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment