emacs-format-all-the-code
emacs-format-all-the-code copied to clipboard
.dir-locals question
I've got forma-all working really well. Thank you for a great package! I'm a bit of a noob, and I can't figure out how to set format-all-formatters in .dir-locals. Can you point me in the right direction?
Here's a simple .dir-locals.el file:
((nil
(format-all-formatters
("JavaScript" prettier)
("Python" (yapf "--style" "google")))))
It formats all JavaScript files in that directory (and subdirectories) using Prettier with the default command line flags, and all Python files using yapf with the --style google flags. In both cases, if Prettier and yapf support their own configuration files, those are read as well.
(yapf has parentheses around it because it takes command line arguments. Format-All supports chaining multiple formatters for the same language, so the parentheses are needed to distinguish between a new formatter, and a new command line argument for the same formatter.)
The nil at the top means that it applies to all file types in that directory; the details of .dir-locals.el are explained in the Emacs manual.
Cool. I'll give that a try. I tried so many things, but not that exactly. I thought there had to be a "." after the "nil" for example. I did look at the manual, but it lacks any kind of examples to show the actual syntax. I use .dir-locals to set a couple of other settings, but this was more complicated.
I really appreciate the time you took to give a detailed example. Thank you.
You're welcome. The file format is confusing even to me. The . is an unfortunate complication in Lisp syntax (the "consing dot") and isn't needed in this case.
This is very helpful. It would be even better, if this can be found the REAME ;)
Can you make a PR that updates the readme?
hey, just a branched question. is there a way to specify the format-all-formatters value globally instead of using dir-locals? I had the following use-package config:
(use-package format-all
:bind
(("<f8>" . format-all-buffer)
("<f9>" . format-all-mode))
:custom
((format-all-formatters (("Python" black)
("Ruby" rubocop))))
:delight
:hook
((format-all-mode . format-all-ensure-formatter)
(prog-mode . format-all-mode)))
but apparently it doesn't set rubocop as the default for all ruby files.