[#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]). versions of Rustfmt ([#69]).
* When a formatter cannot be found, orphaned stderr processes are no * When a formatter cannot be found, orphaned stderr processes are no
longer created and left around forever ([#47]). 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 [#23]: https://github.com/raxod502/apheleia/issues/23
[#47]: https://github.com/raxod502/apheleia/issues/47 [#47]: https://github.com/raxod502/apheleia/issues/47
[#52]: https://github.com/raxod502/apheleia/issues/52 [#52]: https://github.com/raxod502/apheleia/issues/52
[#58]: https://github.com/raxod502/apheleia/issues/58
[#60]: https://github.com/raxod502/apheleia/issues/60 [#60]: https://github.com/raxod502/apheleia/issues/60
[#62]: https://github.com/raxod502/apheleia/issues/62 [#62]: https://github.com/raxod502/apheleia/issues/62
[#64]: https://github.com/raxod502/apheleia/issues/64 [#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-visited-file-modtime)
(set-buffer-modified-p nil))) (set-buffer-modified-p nil)))
(defun apheleia--write-file-silently (&optional filename) (defun apheleia--save-buffer-silently ()
"Write contents of current buffer into file FILENAME, silently. "Save the current buffer to its backing file, silently."
FILENAME defaults to value of variable `buffer-file-name'. Do not
mark the buffer as visiting FILENAME."
(cl-letf* ((write-region (symbol-function #'write-region)) (cl-letf* ((write-region (symbol-function #'write-region))
((symbol-function #'write-region) ((symbol-function #'write-region)
(lambda (start end filename &optional (lambda (start end filename &optional
@ -484,7 +482,7 @@ mark the buffer as visiting FILENAME."
(lambda (&rest args) (lambda (&rest args)
(unless (equal args '(after-set-visited-file-name-hook)) (unless (equal args '(after-set-visited-file-name-hook))
(apply run-hooks args))))) (apply run-hooks args)))))
(write-file (or filename buffer-file-name)))) (save-buffer)))
(defun apheleia--create-rcs-patch (old-buffer new-buffer callback) (defun apheleia--create-rcs-patch (old-buffer new-buffer callback)
"Generate RCS patch from text in OLD-BUFFER to text in NEW-BUFFER. "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" (with-demoted-errors "Apheleia: %s"
(when buffer-file-name (when buffer-file-name
(let ((apheleia--format-after-save-in-progress t)) (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)))))))) (run-hooks 'apheleia-post-format-hook))))))))
;; Use `progn' to force the entire minor mode definition to be copied ;; Use `progn' to force the entire minor mode definition to be copied