[#58] Do not change the mode when saving

Closes #58
This commit is contained in:
Radon Rosborough 2022-01-04 21:07:17 -08:00
parent c073299a56
commit 41fa1f70ee
2 changed files with 8 additions and 6 deletions

View file

@ -48,10 +48,14 @@ The format is based on [Keep a Changelog].
versions of Rustfmt ([#69]).
* When a formatter cannot be found, orphaned stderr processes are no
longer created and left around forever ([#47]).
* Apheleia no longer resets the major mode to its default value when
formatting a buffer. This was never intended and the bug has now
been fixed ([#58]).
[#23]: https://github.com/raxod502/apheleia/issues/23
[#47]: https://github.com/raxod502/apheleia/issues/47
[#52]: https://github.com/raxod502/apheleia/issues/52
[#58]: https://github.com/raxod502/apheleia/issues/58
[#60]: https://github.com/raxod502/apheleia/issues/60
[#62]: https://github.com/raxod502/apheleia/issues/62
[#64]: https://github.com/raxod502/apheleia/issues/64

View file

@ -458,10 +458,8 @@ as in `write-region'. WRITE-REGION is used instead of the actual
(set-visited-file-modtime)
(set-buffer-modified-p nil)))
(defun apheleia--write-file-silently (&optional filename)
"Write contents of current buffer into file FILENAME, silently.
FILENAME defaults to value of variable `buffer-file-name'. Do not
mark the buffer as visiting FILENAME."
(defun apheleia--save-buffer-silently ()
"Save the current buffer to its backing file, silently."
(cl-letf* ((write-region (symbol-function #'write-region))
((symbol-function #'write-region)
(lambda (start end filename &optional
@ -484,7 +482,7 @@ mark the buffer as visiting FILENAME."
(lambda (&rest args)
(unless (equal args '(after-set-visited-file-name-hook))
(apply run-hooks args)))))
(write-file (or filename buffer-file-name))))
(save-buffer)))
(defun apheleia--create-rcs-patch (old-buffer new-buffer callback)
"Generate RCS patch from text in OLD-BUFFER to text in NEW-BUFFER.
@ -1004,7 +1002,7 @@ operating, to prevent an infinite loop.")
(with-demoted-errors "Apheleia: %s"
(when buffer-file-name
(let ((apheleia--format-after-save-in-progress t))
(apheleia--write-file-silently buffer-file-name)))
(apheleia--save-buffer-silently)))
(run-hooks 'apheleia-post-format-hook))))))))
;; Use `progn' to force the entire minor mode definition to be copied