Mix Format.el Save Abandoned

Emacs package to format Elixir code in Emacs with elixir-mode

Project README

P.S.

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.

Setup

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

Usage

;; require from Emacs
(require 'elixir-format)

;; Use it
M-x elixir-format

Add elixir-mode hook to run mix format on file save

;; 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.

Contribute

Feel free to contribute

Author

([email protected]) ; anil wadghule

Open Source Agenda is not affiliated with "Mix Format.el" Project. README Source: anildigital/mix-format.el
Stars
45
Open Issues
0
Last Commit
5 years ago

Open Source Agenda Badge

Open Source Agenda Rating