2015-12-02 14:23:39 +00:00
|
|
|
|
#+TITLE: Elixir layer
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
|
|
[[file:img/elixir.png]] with [[file:img/alchemist.png]]
|
|
|
|
|
|
2016-03-31 02:59:55 +00:00
|
|
|
|
* Table of Contents :TOC_4_gh:noexport:
|
|
|
|
|
- [[#description][Description]]
|
|
|
|
|
- [[#install][Install]]
|
2016-06-01 01:34:51 +00:00
|
|
|
|
- [[#configuration][Configuration]]
|
2016-06-01 01:51:49 +00:00
|
|
|
|
- [[#flycheck][Flycheck]]
|
|
|
|
|
- [[#credo][Credo]]
|
|
|
|
|
- [[#mix-compile][mix compile]]
|
2016-03-31 02:59:55 +00:00
|
|
|
|
- [[#key-bindings][Key bindings]]
|
|
|
|
|
- [[#refcard][Refcard]]
|
|
|
|
|
- [[#help][Help]]
|
|
|
|
|
- [[#mix][Mix]]
|
|
|
|
|
- [[#project][Project]]
|
|
|
|
|
- [[#evaluation-in-place][Evaluation in place]]
|
|
|
|
|
- [[#repl-interactions][REPL interactions]]
|
|
|
|
|
- [[#tests][Tests]]
|
|
|
|
|
- [[#compile][Compile]]
|
|
|
|
|
- [[#execute][Execute]]
|
|
|
|
|
- [[#code-definition-jump][Code Definition Jump]]
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
|
|
* Description
|
|
|
|
|
This layer adds support for [[http://elixir-lang.org/][Elixir]] .
|
|
|
|
|
|
|
|
|
|
[[https://github.com/tonini/alchemist.el][Alchemist]] brings the Elixir tooling to Emacs and comes with a bunch of
|
|
|
|
|
features like:
|
|
|
|
|
- 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 [[http://company-mode.github.io/][company-mode]]
|
2016-06-01 01:34:51 +00:00
|
|
|
|
- Flycheck support for mix compile
|
2016-06-01 01:51:49 +00:00
|
|
|
|
- Flycheck support for [[https://github.com/rrrene/credo][credo]]
|
2016-06-01 02:15:19 +00:00
|
|
|
|
- Flycheck support for test results
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
|
|
* Install
|
2016-01-06 05:21:55 +00:00
|
|
|
|
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.
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
2016-06-01 01:34:51 +00:00
|
|
|
|
* Configuration
|
2016-06-01 01:51:49 +00:00
|
|
|
|
** Flycheck
|
2016-06-01 02:23:18 +00:00
|
|
|
|
*Note:* since flycheck checkers are slow, the checks are enabled only at save
|
|
|
|
|
time.
|
|
|
|
|
|
2016-06-01 01:51:49 +00:00
|
|
|
|
*** Credo
|
|
|
|
|
A flycheck checker for [[https://github.com/rrrene/credo][credo]] is installed. The check needs both =bunt= and
|
|
|
|
|
=credo= to be available, you can install them like this:
|
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC shell
|
|
|
|
|
git clone https://github.com/rrrene/bunt
|
|
|
|
|
cd bunt
|
|
|
|
|
mix archive.build
|
|
|
|
|
mix archive.install
|
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC shell
|
|
|
|
|
git clone https://github.com/rrrene/credo
|
|
|
|
|
cd credo
|
|
|
|
|
mix deps.get
|
|
|
|
|
mix archive.build
|
|
|
|
|
mix archive.install
|
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
|
|
*** mix compile
|
2016-06-01 01:34:51 +00:00
|
|
|
|
*Important:*
|
2016-06-08 03:51:33 +00:00
|
|
|
|
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-local.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-local.el= with the following
|
|
|
|
|
contents:
|
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
|
;;; Directory Local Variables
|
|
|
|
|
;;; For more information see (info "(emacs) Directory Variables")
|
|
|
|
|
|
|
|
|
|
((elixir-mode
|
|
|
|
|
(elixir-enable-compilation-checking . t)))
|
|
|
|
|
#+END_SRC
|
2016-06-01 01:34:51 +00:00
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
2016-06-08 03:51:33 +00:00
|
|
|
|
Remember that you can verify the flycheck checkers status with ~SPC e v~.
|
2016-06-01 01:34:51 +00:00
|
|
|
|
|
2015-06-10 16:44:30 +00:00
|
|
|
|
* Key bindings
|
|
|
|
|
** Refcard
|
|
|
|
|
You find and overview of all the key-bindings on the [[file:alchemist-refcard.pdf][Alchemist-Refcard]].
|
|
|
|
|
|
|
|
|
|
** Help
|
|
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|
|-------------+-------------------------------------|
|
|
|
|
|
| ~SPC m h :~ | Run custom search for help |
|
|
|
|
|
| ~SPC m h h~ | Show help of the current expression |
|
|
|
|
|
| ~SPC m h H~ | Toggle through search history |
|
|
|
|
|
| ~SPC m h r~ | Show help for current region |
|
|
|
|
|
|
|
|
|
|
** Mix
|
|
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|
|-------------+------------------------------------------------------------|
|
|
|
|
|
| ~SPC m m :~ | Prompt for a =mix= command |
|
|
|
|
|
| ~SPC m m c~ | Compile the whole application |
|
|
|
|
|
| ~SPC m m h~ | Show help for a specific =mix= command |
|
|
|
|
|
| ~SPC m m x~ | Run the given expression in the Elixir application context |
|
|
|
|
|
|
|
|
|
|
** Project
|
|
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|
|-------------+------------------------------------------------------------|
|
|
|
|
|
| ~SPC m p t~ | Open project test directory and list all test files. |
|
|
|
|
|
| ~SPC m g t~ | Toggle between a file and its tests in the current window. |
|
|
|
|
|
| ~SPC m g T~ | Toggle between a file and its tests in other window. |
|
|
|
|
|
|
|
|
|
|
** Evaluation in place
|
|
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|
|-------------+-----------------------------------------|
|
|
|
|
|
| ~SPC m e b~ | Evaluate buffer |
|
|
|
|
|
| ~SPC m e B~ | Evaluate buffer and insert result |
|
|
|
|
|
| ~SPC m e l~ | Evaluate current line |
|
|
|
|
|
| ~SPC m e L~ | Evaluate current line and insert result |
|
|
|
|
|
| ~SPC m e r~ | Evaluate region |
|
|
|
|
|
| ~SPC m e R~ | Evaluate region and insert result |
|
|
|
|
|
|
|
|
|
|
** REPL interactions
|
|
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|
|-------------+-----------------------------------------------------------------|
|
2015-12-10 13:33:06 +00:00
|
|
|
|
| ~SPC m s c~ | Compiles the current buffer in the IEx process. |
|
2015-06-10 16:44:30 +00:00
|
|
|
|
| ~SPC m s i~ | Start an =iex= inferior process |
|
|
|
|
|
| ~SPC m s I~ | Start an IEx process with mix (=iex -S mix=) |
|
|
|
|
|
| ~SPC m s l~ | Send current line to REPL buffer |
|
|
|
|
|
| ~SPC m s L~ | Send current line to REPL buffer and focus it in =insert state= |
|
2015-12-10 13:33:06 +00:00
|
|
|
|
| ~SPC m s m~ | Reloads the module in the current buffer in your IEx process |
|
2015-06-10 16:44:30 +00:00
|
|
|
|
| ~SPC m s r~ | Send region to REPL buffer |
|
|
|
|
|
| ~SPC m s R~ | Send region to REPL buffer and focus it in =insert state= |
|
|
|
|
|
|
|
|
|
|
** Tests
|
|
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|
|-------------+---------------------------------------|
|
|
|
|
|
| ~SPC m g t~ | Open the test file for current buffer |
|
|
|
|
|
| ~SPC m t a~ | Run all the tests |
|
|
|
|
|
| ~SPC m t b~ | Run all the tests from current buffer |
|
2015-12-09 16:07:56 +00:00
|
|
|
|
| ~SPC m t r~ | Rerun the last test |
|
2015-06-10 16:44:30 +00:00
|
|
|
|
| ~SPC m t t~ | Run test under point |
|
|
|
|
|
|
|
|
|
|
** Compile
|
|
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|
|-------------+----------------------------------------------------|
|
|
|
|
|
| ~SPC m c :~ | Run a custom compile command with =elixirc= |
|
|
|
|
|
| ~SPC m c b~ | Compile the current buffer with elixirc. =elixirc= |
|
|
|
|
|
| ~SPC m c f~ | Compile the given filename with =elixirc= |
|
|
|
|
|
|
|
|
|
|
** Execute
|
|
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|
|-------------+--------------------------------------------|
|
|
|
|
|
| ~SPC m x :~ | Run a custom execute command with =elixir= |
|
|
|
|
|
| ~SPC m x b~ | Run the current buffer through =elixir= |
|
|
|
|
|
| ~SPC m x f~ | Run =elixir= with the given filename |
|
|
|
|
|
|
|
|
|
|
** Code Definition Jump
|
|
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|
|-------------+----------------------------------------------------|
|
|
|
|
|
| ~SPC m g g~ | Jump to the elixir expression definition at point. |
|
2016-02-29 09:23:14 +00:00
|
|
|
|
| ~SPC m ,~ | Pop back to where ~SPC m g g~ was last invoked. |
|