Emacs: avoid double auto-formatting Remove format-all from mode hooks where apheleia is already supported. Automatically disable format-all-mode when apheleia is enabled, in case apheleia gains support for modes that format-all also supports
Alan Pearce alan@alanpearce.eu
Sun, 09 Jul 2023 08:13:09 +0200
1 files changed, 7 insertions(+), 10 deletions(-)
jump to
M user/emacs/init.el → user/emacs/init.el
@@ -1082,23 +1082,19 @@ ;;;; Reformat on save (use-package format-all :defer 10 - :ghook ('(css-mode-hook - clojure-mode-hook + :ghook ('(clojure-mode-hook dockerfile-mode-hook emacs-lisp-mode-hook - javascript-mode-hook json-mode-hook markdown-mode-hook - scss-mode-hook - sgml-mode-hook - sh-mode-hook sql-mode-hook - toml-mode-hook - typescript-mode-hook)) + toml-mode-hook)) :gfhook #'format-all-ensure-formatter :init (progn (advice-add 'format-all-ensure-formatter - :around #'quiet)) + :around #'quiet) + (defun turn-off-format-all-mode () + (format-all-mode -1))) :config (progn (setq format-all-show-errors 'never))) @@ -1108,7 +1104,8 @@ :config (progn (setf (alist-get 'shfmt apheleia-formatters) '("shfmt")) (setf (alist-get 'nixfmt apheleia-formatters) - '("nixpkgs-fmt"))) + '("nixpkgs-fmt")) + (add-hook 'apheleia-mode-hook #'turn-off-format-all-mode)) :init (progn (apheleia-global-mode +1)))