all repos — nixfiles @ 92e147362d3724e0a98c1580f9630d06ca928947

System and user configuration, managed by nix and home-manager

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
commit

92e147362d3724e0a98c1580f9630d06ca928947

parent

2350d3ee98995de0d68f82224cbee2333091a385

1 files changed, 7 insertions(+), 10 deletions(-)

jump to
M user/emacs/init.eluser/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)))