Prevent unsaved prompts when formatting #1498

The fix for #1489 (in 13f5a762) gives the temp buffer (where formatting
is performed) a real buffer-file-name, which causes it to prompt to save
it when it is killed.
This commit is contained in:
Henrik Lissner 2019-06-16 12:42:17 +02:00
parent 0b1ecb8105
commit 9bba39bd3a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -134,18 +134,19 @@ See `+format/buffer' for the interactive version of this function, and
(origin-buffer-file-name (buffer-file-name (buffer-base-buffer))) (origin-buffer-file-name (buffer-file-name (buffer-base-buffer)))
(origin-default-directory default-directory)) (origin-default-directory default-directory))
(with-temp-buffer (with-temp-buffer
(insert output) (with-silent-modifications
;; Ensure this temp buffer _seems_ as much like the origin (insert output)
;; buffer as possible. ;; Ensure this temp buffer _seems_ as much like the origin
(setq default-directory origin-default-directory ;; buffer as possible.
buffer-file-name origin-buffer-file-name) (setq default-directory origin-default-directory
;; Since we're piping a region of text to the formatter, remove buffer-file-name origin-buffer-file-name)
;; any leading indentation to make it look like a file. ;; Since we're piping a region of text to the formatter, remove
(when preserve-indent-p ;; any leading indentation to make it look like a file.
(setq indent (+format--current-indentation)) (when preserve-indent-p
(when (> indent 0) (setq indent (+format--current-indentation))
(indent-rigidly (point-min) (point-max) (- indent)))) (when (> indent 0)
(funcall f-function executable mode-result))))) (indent-rigidly (point-min) (point-max) (- indent))))
(funcall f-function executable mode-result))))))
(unwind-protect (unwind-protect
(cond ((null output) 'error) (cond ((null output) 'error)
((eq output t) 'noop) ((eq output t) 'noop)