kamadorueda / alejandra

The Uncompromising Nix Code Formatter
https://kamadorueda.github.io/alejandra/
The Unlicense
827 stars 40 forks source link

Doom Emacs integration after migrating to apheleia #403

Closed nyawox closed 5 months ago

nyawox commented 1 year ago

After doom migrating from format-all to apheleia (set-formatter! 'alejandra "alejandra --quiet" :modes '(nix-mode)) Does not work and gives error saying formatter must be a shell command or a lisp function See here

I got this snippet from random config on GitHub working, but I didn't know if it was good enough to make a PR.

(set-formatter! 'alejandra '("alejandra" "--quiet") :modes '(nix-mode))

(after! apheleia
  (push '(alejandra . ("alejandra" "-")) apheleia-formatters)
  (setf (alist-get 'nix apheleia-mode-alist) 'alejandra))

Some people can be using older version and nix-doom-emacs pins doom to older version, so I think it would be preferable to still leave document for older versions.

marienz commented 11 months ago

I think just (set-formatter! 'alejandra '("alejandra" "--quiet") :modes '(nix-mode)) is sufficient (and it works for me). And if I read the previous code right it will also work on pre-apheleia Doom, but someone should probably test that.

set-formatter! replaces any existing entries from apheleia-mode-alist and apheleia-formatters (and that's all it does). So the after! half of the above looks like it's overwriting the apheleia-formatters entry it just added with set-formatter!.

And it looks like the only problem is that the old code accepted either a string or a list for the command to run, while apheleia needs a list.

nyawox commented 5 months ago

I don't use doom emacs anymore except for magit, but I believe this can be closed now since #413 got merged