How can I add a custom formatter that will be picked up by doom-emacs' format ((format +onsave)) module?

I want to run the erlfmt program on save when editing Erlang files, but I'm not sure how I should configure that.

Doom seems to be using https://github.com/lassik/emacs-format-all-the-code under the hood, so I tried adding the following to config.el:

(define-format-all-formatter erlfm
  (:executable "erlfm")
  (:install (macos "brew install erlfmt"))
  (:languages "Erlang"
  (:format (format-all--buffer-easy executable "-")))

However, this just gives me the error “Don't know how to format erlang-mode code” when I run format-all-buffer. (I get the same error if I change to :languages "erlang-mode".)

  • This seems very close to: emacs.stackexchange.com/q/54351/2418 - not sure it's an exact duplicate though. – ideasman42 Jul 6 at 12:20
  • Did you reload your config.el (or restart emacs ) after the change? – NickD Jul 6 at 13:55
  • Please copy the important part of the linked pages to the question, since these pages may change or even disappear. – Stefan Jul 6 at 15:13
  • @Stefan Good point. Done. – beta Jul 9 at 9:03

In the end, putting the following in config.el worked:

(set-formatter! 'erlfmt  "erlfmt -" :modes '(erlang-mode))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.