Skip to content
This repository has been archived by the owner on Jul 1, 2019. It is now read-only.
/ mix-format.el Public archive

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

License

Notifications You must be signed in to change notification settings

anildigital/mix-format.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

(anil@anilwadghule.com) ; anil wadghule

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published