asdf-elixir: mix format fails when running from Emacs
Background
macOS 10.14.4 erlang 21.3.4 elixir 1.8.1
I’m using spacemacs with the elixir package installed.
Expected behaviour
Running elixir-format emacs command from emacs-elixir will format the current file and on save hook will also format the file.
Actual behaviour
Running elixir-format hook in emacs-elixir results in the following error message being displayed:
** (SyntaxError) /Users/josiah/.asdf/shims/mix:3: syntax error before: '.'
(elixir) lib/code.ex:767: Code.require_file/2
The on save hook fails silently.
Other Information
This problem only seems to crop up when elixir is installed with asdf, when I had elixir installed with brew I had no problems.
Any help pointing me in the right direction is much appreciated 😃
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (13 by maintainers)
Commits related to this issue
- elixir-mode: this plus manually editing shims works on the t480 https://github.com/asdf-vm/asdf-elixir/issues/62#issuecomment-499629939 — committed to bradediger/emacs.d-2020 by bradediger 4 years ago
The issue is that
elixir-format
runselixir /path/to/mix format
and not/path/to/mix format
. https://github.com/elixir-editors/emacs-elixir/blob/master/elixir-format.el I’m not exactly sure why, but it might be worth asking in their repository. When usingasdf
,mix
executable is a shell script, and therefore, it fails.Fortunately, it seems that they get the
mix
path using a function calledelixir-format--mix-executable
, so while waiting for a more permanent fix, you can override this function. Try adding the following to your~/.emacs
(or~/.spacemacs
if you use Spacemacs I suppose)This runs after
elixir-mode
, which provideselixir-format
, has been loaded, and overrideselixir-format--mix-executable
to return the result ofasdf which mix
instead of trying to look formix
in the path.I’m not really sure there is much we can do about it on our side, as this is how shims work, but I will leave this open in case somebody wants to propose a solution.
Now is working: