Skip to content

Latest commit

 

History

History
252 lines (201 loc) · 10.9 KB

README.org

File metadata and controls

252 lines (201 loc) · 10.9 KB

Elixir layer

img/elixir.png with img/alchemist.png

Table of Contents

Description

This layer adds support for Elixir.

Alchemist brings the Elixir tooling to Emacs and comes with a bunch of features.

Features:

  • Powerful IEx integration
  • Mix integration
  • Compile & Execution of Elixir code
  • Inline code evaluation
  • Documentation lookup
  • Definition lookup
  • Smart code completion
  • Elixir project management
  • Integration with company-mode
  • Flycheck support for mix compile
  • Flycheck support for credo
  • Flycheck support for test results

Install

To use this configuration layer, add it to your ~/.spacemacs. You will need to add elixir to the existing dotspacemacs-configuration-layers list in this file.

Configuration

Flycheck

Note: since flycheck checkers are slow, the checks are enabled only at save time.

Credo

You need to install credo into your project. For this, add the following snippet to dependencies of your project (in file mix.exs):

{:credo, "~> 0.5", only: [:dev, :test]}

Then run in your shell:

$ mix deps.get

For more info about mix see.

You can tell flycheck-credo to call credo with the ’–strict’ argument.

(setq flycheck-elixir-credo-strict t)

Dogma

In order to lint your code, you also need to install dogma into your project. For this, add the following snippet to the dependencies in your mix.exs file:

{:dogma, "~> 0.1", only: [:dev]}

Then run in your shell:

$ mix deps.get

mix compile

Important:

Elixir compiler is based on macros and can execute arbitrary during compilation. Therefore Spacemacs disable flycheck compilation checker by default.

To enable flycheck support for compilation errors globally the variable elixir-enable-compilation-checking can be set explicitly to t in your dotfile but it is not recommended to do so because of the limitation described above.

Instead you should use directory local variables in order to enable the flycheck checker only for certain projects. Directory local variables are stored in a file named .dir-locals.el usually at the root of a project. To easily add a directory local variable use the key binding SPC f v d then choose the elixir-mode and the variable name elixir-enable-compilation-checking with a value of t. The result is a new file .dir-locals.el with the following contents:

;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")

((elixir-mode
  (elixir-enable-compilation-checking . t)))

Spacemacs marks the variable elixir-enable-compilation-checking as safe so Emacs won’t ask you if the variable is safe whenever an elixir file is opened.

Remember that you can verify the flycheck checkers status with SPC e v.

Key bindings

Refcard

You find and overview of all the key bindings on the Alchemist-Refcard.

Help

Key bindingDescription
SPC m h :Run custom search for help
SPC m h hShow help of the current expression
SPC m h HToggle through search history
SPC m h rShow help for current region

Mix

Key bindingDescription
SPC m m :Prompt for a mix command
SPC m m cCompile the whole application
SPC m m hShow help for a specific mix command
SPC m m xRun the given expression in the Elixir application context

Project

Key bindingDescription
SPC m g tToggle between a file and its tests in the current window.
SPC m g TToggle between a file and its tests in other window.

Evaluation in place

Key bindingDescription
SPC m e bEvaluate buffer
SPC m e BEvaluate buffer and insert result
SPC m e lEvaluate current line
SPC m e LEvaluate current line and insert result
SPC m e rEvaluate region
SPC m e REvaluate region and insert result

REPL interactions

Key bindingDescription
SPC m s cCompiles the current buffer in the IEx process.
SPC m s iStart an iex inferior process
SPC m s IStart an IEx process with mix (iex -S mix)
SPC m s lSend current line to REPL buffer
SPC m s LSend current line to REPL buffer and focus it in insert state
SPC m s mReloads the module in the current buffer in your IEx process
SPC m s rSend region to REPL buffer
SPC m s RSend region to REPL buffer and focus it in insert state

Tests

Key bindingDescription
SPC m g tOpen the test file for current buffer
SPC m t aRun all the tests
SPC m t bRun all the tests from current buffer
SPC m t BRun all the tests from current file; if test file not found, after confirm, create it
SPC m t fChoose test file to run
SPC m t tRun test under point
SPC m t rRerun the last test
SPC m t nJump to next test
SPC m t NJump to previous test
SPC m t sRun stale tests (mix test --stale)
SPC m t RToggle test report window
SPC m t FOpen project test directory and list all test files.

Compile

Key bindingDescription
SPC m c :Run a custom compile command with elixirc
SPC m c bCompile the current buffer with elixirc. elixirc
SPC m c fCompile the given filename with elixirc

Execute

Key bindingDescription
SPC m x :Run a custom execute command with elixir
SPC m x bRun the current buffer through elixir
SPC m x fRun elixir with the given filename

Code Definition Jump

Key bindingDescription
SPC m g gJump to the elixir expression definition at point.
SPC m .Jump to the elixir expression definition at point.
SPC m g bPop back to where SPC m g g was last invoked.
SPC m ,Pop back to where SPC m g g was last invoked.
SPC m g nJump to next symbol definition
SPC m g NJump to previous symbol definition
SPC m g jChoose which symbol definition to jump to

Hex (packages)

Hex is the package manager for Elixir & Erlang ecosystem. See https://hex.pm.

Key bindingDescription
SPC m X iDisplay Hex package information for the package at point
SPC m X rDisplay Hex package releases for the package at point
SPC m X RDisplay Hex package releases for a certain package
SPC m X IDisplay Hex package info for a certain package
SPC m X sSearch for Hex packages

Macro expand

Key bindingDescription
SPC m o lMacro expand once the Elixir code on the current line
SPC m o LMacro expand once the Elixir code on the current line and insert the result
SPC m o kMacro expand completely the Elixir code on the current line
SPC m o KMacro expand completely the Elixir code on the current line and insert the result
SPC m o iMacro expand once the Elixir code on marked region
SPC m o IMacro expand once the Elixir code on marked region once and insert the result
SPC m o rMacro expand completely the Elixir code on marked region
SPC m o RMacro expand completely the Elixir code on marked region and insert the result

Formatting

Key bindingDescription
SPC m =Format the current buffer