The work from this repository has been merged to officially supporrted elixir-mode. Please update your elixir-mode
and you should be okay to use elixir-format
. Do check README for more instructions to setup.
elixir-format (INACTIVE - work merged to https://github.com/elixir-editors/emacs-elixir)
Emacs package to format your Elixir code.
Customize the elixir and mix pathes
In Emacs, run following command to customize option
M-x customize-option
Customize-variable: elixir-format-elixir-path
and set your elixir executable path there. After that run:
M-x customize-option
Customize-variable: elixir-format-mix-path
and set your mix executable path there.
Alternavively you can define variables as below
(setq elixir-format-elixir-path "/usr/local/bin/elixir")
(setq elixir-format-mix-path "/usr/local/bin/mix")
Your machine's elixir and mix executable paths can be found with which
command as shown below
$ which mix
/usr/local/bin/mix
;; require from Emacs
(require 'elixir-format)
;; Use it
M-x elixir-format
;; Create a buffer-local hook to run elixir-format on save, only when we enable elixir-mode.
(add-hook 'elixir-mode-hook
(lambda () (add-hook 'before-save-hook 'elixir-format nil t)))
To use a .formatter.exs
you can either set elixir-format-arguments
globally to a path like this:
(setq elixir-format-arguments (list "--dot-formatter" "/path/to/.formatter.exs"))
or you set elixir-format-arguments
in a hook like this:
(add-hook elixir-format-hook '(lambda ()
(if (projectile-project-p)
(setq elixir-format-arguments (list "--dot-formatter" (concat (projectile-project-root) "/.formatter.exs")))
(setq elixir-format-arguments nil))))
In this example we use Projectile to get the project root and set elixir-format-arguments
accordingly.
Feel free to contribute
(anil@anilwadghule.com) ; anil wadghule