fix(format): prefix arg inhibiting format-on-save (part 2)

Experimenting with a new approach to this issue, in an effort to avoid
advice on such low level commands ({basic-,}save-buffer). I don't like
that we're still stacking new behavior on top of their pre-existing
prefix arg behavior (manipulating backup-on-save functionality), but
maybe it's not useful enough to worry about?

Fix: #8420
Amend: f0c8290ae2
This commit is contained in:
Henrik Lissner
2025-08-10 16:40:06 +02:00
parent 0ed0072ff2
commit 9a38ee2428
3 changed files with 25 additions and 7 deletions

View File

@@ -45,11 +45,10 @@ This is controlled by `+format-on-save-disabled-modes'."
(set-debug-variable! 'apheleia-log-only-errors nil)
(set-debug-variable! 'apheleia-log-debug-info t 2)
(defadvice! +format--inhibit-reformat-on-prefix-arg-a (orig-fn &optional arg)
"Make it so \\[save-buffer] with prefix arg inhibits reformatting."
:around #'basic-save-buffer
(let ((apheleia-inhibit (or apheleia-inhibit current-prefix-arg)))
(funcall orig-fn)))
;; UX: Use prefix-arg on `save-buffer' or `basic-save-buffer' to inhibit
;; format-on-save behavior.
(define-key apheleia-mode-map [remap basic-save-buffer] #'+format/save-buffer-no-reformat)
(define-key apheleia-mode-map [remap save-buffer] #'+format/save-buffer)
;; HACK: Apheleia suppresses notifications that the current buffer has
;; changed, so plugins that listen for them need to be manually informed: