(t
(start-process name buffer shell-file-name shell-command-switch
(mapconcat 'identity args " ")))))
-
+\f
(defmacro with-current-buffer (buffer &rest body)
"Execute the forms in BODY with BUFFER as the current buffer.
The value returned is the value of the last form in BODY."
(set-buffer ,buffer)
. ,body))
+(defmacro with-temp-file (file &rest forms)
+ "Create a new buffer, evaluate FORMS there, and write the buffer to FILE.
+Return the value of FORMS.
+If FILE is nil, just evaluate FORMS and don't save anything.
+If FILE is t, return the buffer contents as a string."
+ (let ((temp-file (make-symbol "temp-file"))
+ (temp-buffer (make-symbol "temp-buffer"))
+ (temp-results (make-symbol "temp-results")))
+ `(save-excursion
+ (let* ((,temp-file ,file)
+ (default-major-mode 'fundamental-mode)
+ (,temp-buffer
+ (progn
+ (set-buffer
+ (get-buffer-create
+ (generate-new-buffer-name " *temp file*")))
+ (buffer-disable-undo (current-buffer))
+ (current-buffer)))
+ ,temp-results)
+ (unwind-protect
+ (progn
+ (setq ,temp-results (progn ,@forms))
+ (cond
+ ;; Don't save anything.
+ ((null ,temp-file)
+ ,temp-results)
+ ;; Return the buffer contents.
+ ((eq ,temp-file t)
+ (set-buffer ,temp-buffer)
+ (buffer-string))
+ ;; Save a file.
+ (t
+ (set-buffer ,temp-buffer)
+ ;; Make sure the directory where this file is
+ ;; to be saved exists.
+ (when (not (file-directory-p
+ (file-name-directory ,temp-file)))
+ (make-directory (file-name-directory ,temp-file) t))
+ ;; Save the file.
+ (write-region (point-min) (point-max)
+ ,temp-file nil 'nomesg)
+ ,temp-results)))
+ ;; Kill the buffer.
+ (when (buffer-name ,temp-buffer)
+ (kill-buffer ,temp-buffer)))))))
+\f
(defmacro with-output-to-string (&rest body)
"Execute BODY, return the text it sent to `standard-output', as a string."
`(let ((standard-output (get-buffer-create " *string-output*")))
(cons (substring string start)
list)))
(nreverse list)))
-
+\f
(defun shell-quote-argument (argument)
"Quote an argument for passing as argument to an inferior shell."
(if (eq system-type 'ms-dos)