Elixir Tooling Integration Into Emacs
Alchemist comes with a bunch of features, which are:
- Powerful IEx integration
- Mix integration
- Compile & Execution of Elixir code
- Inline code evaluation
- Documentation lookup
- Smart code completion
- Elixir project management
- Integration with company-mode
- Installation
- Configuration
- Mix
- Compile & Execute
- Project
- Documentation lookup
- Auto-completion
- IEx
- Eval
- Hooks
- Modeline
- Keymap
- Contributing
package.el
is the built-in package manager in Emacs.
Alchemist.el is available on the three major community maintained repositories - MELPA STABLE, MELPA and Marmalade.
You can install Alchemist
with the following commnad:
M-x package-install [RET] alchemist [RET]
or by adding this bit of Emacs Lisp code to your Emacs initialization file
(.emacs
or init.el
):
(unless (package-installed-p 'alchemist)
(package-install 'alchemist))
If the installation doesn't work try refreshing the package list:
M-x package-refresh-contents [RET]
Keep in mind that MELPA packages are built automatically from
the master
branch, meaning bugs might creep in there from time to
time. Never-the-less, installing from MELPA is the recommended way of
obtaining Alchemist, as the master
branch is normally quite stable and
"stable" (tagged) builds are released somewhat infrequently.
With the most recent builds of Emacs, you can pin Alchemist to always use MELPA Stable by adding this to your Emacs initialization:
(add-to-list 'package-pinned-packages '(alchemist . "melpa-stable") t)
el-get is another popular package manager for Emacs. If you're an el-get user just do M-x el-get-install [RET] alchemist [RET].
You can install Alchemist manually by placing Alchemist on your load-path
and
require
ing it. Many people favour the folder ~/.emacs.d/vendor
.
(add-to-list 'load-path "~/.emacs.d/vendor/alchemist.el/")
(require 'alchemist)
There are some ways Alchemist can be adjusted that certain workflows operating differently.
- Disable ansi color formatted documentation:
(setq alchemist-help-ansi-color-docs nil) ;; default: t
- Enable compilation if needed when do documentation lookup or completion on Elixir project current codebase.
(setq alchemist-project-compile-when-needed t) ;; default nil
-
The function
alchemist-project-toggle-compile-when-needed
can also be used to enable/disable compilation on the fly. -
By default, the error output of failed completions will be displayed in a separat buffer.
Example output:
== ALCHEMIST COMPLETION FAILED ==
== OUTPUT BEGIN:
** (CompileError) mix.exs:5: function asdas/0 undefined
(stdlib) lists.erl:1336: :lists.foreach/2
(stdlib) erl_eval.erl:657: :erl_eval.do_apply/6
== OUTPUT END:
This behavior can be disabled with set the following variable.
(setq alchemist-complete-debug-mode nil) ;; default t
To setup custom configurations for different Elixir projects, create a
.alchemist
file in the root of the project.
Example:
{
"ansi-color-docs": "nil",
"compile-when-needed": "t"
}
Command (For the M-x prompt.) |
Description |
---|---|
alchemist-mix |
Prompt for a mix command including a list of all available mix commands. |
alchemist-mix-new |
Create a new Elixir application. |
alchemist-mix-test |
Run the whole Elixir application test suite. |
alchemist-mix-test-this-buffer |
Run the current buffer through mix test command. |
alchemist-mix-test-file |
Run a file through mix test command. |
alchemist-mix-test-at-point |
Run the test at point. |
alchemist-mix-compile |
Compile the whole Elixir application. |
alchemist-mix-run |
Runs the given expression in the Elixir application context. |
alchemist-mix-deps-with-prompt |
Prompt for mix deps commands. |
alchemist-mix-local-with-prompt |
Prompt for mix local commands. |
alchemist-mix-local-install |
Prompt for mix local.install PATH or URL. |
alchemist-mix-local-install-with-path |
Runs mix local.install and prompt for a PATH as argument. |
alchemist-mix-local-install-with-url |
Runs mix local.install and prompt for a URL as argument. |
alchemist-mix-help |
Show help output for a specific mix command. |
alchemist-mix-execute |
Prompt for a mix command. |
alchemist-mix-hex-search |
Display packages matching the given search query. |
Command (For the M-x prompt.) |
Description |
---|---|
alchemist-compile-this-buffer |
Compile the current buffer with elixirc . |
alchemist-compile-file |
Compile the given FILENAME . |
alchemist-compile |
Run a custom compile command with elixirc . |
Command (For the M-x prompt.) |
Description |
---|---|
alchemist-execute-this-buffer |
Run the current buffer through elixir .
|
alchemist-execute-file
| Run elixir with the given FILENAME .
|
alchemist-execute
| Run a custom execute command with elixir .
|
Keybinding | Description |
---|---|
C-c a p f | Open project test directory and list all test files. alchemist-project-find-test |
C-c a p t | Opens the appropriate test file for the current buffer file in a new window. alchemist-project-open-tests-for-current-file |
There is the alchemist-help-minor-mode
for a complete fully functional
interface to the Elixir documentation. The alchemist-help-minor-mode
uses the
same functions like Elixir's IEx.
What does that mean? It means no matter which Elixir version is currently
installed on the system, the documentation you get by alchemist
is the same
IEx
would deliver.
Command (For the M-x prompt.) |
Description |
---|---|
alchemist-help |
Run a custom search. |
alchemist-help-history |
Toggle through search history. |
alchemist-help-search-at-point |
Run alchemist-help with the expression under the
cursor. (example: is_binary or Code.eval_string ) |
alchemist-help-search-marked-region |
Run alchemist-help with the current marked region. |
Inside of the alchemist-help-minor-mode
(*elixir help*
buffer) the key ?
will
open a keymap summary in the minibuffer
with the following functionality:
You're always be able to continue to search inside the *elixir help*
buffer.
Key | Description |
---|---|
q |
Quit *elixir help* buffer window |
e |
alchemist-help-search-at-point |
m |
alchemist-help-search-marked-region |
s |
alchemist-help |
h |
alchemist-help-history |
? |
alchemist-help-minor-mode-key-binding-summary |
Alchemist users are advised to use company-mode to enable auto-completion inside of Elixir source code.
Alchemist enables a company-mode elixir backend by default if company-mode is installed.
When the keybinding C-d is used on one of the selected completion candidates, a documentation lookup for the candidate will be made and displayed in another window.
The function alchemist-complete-debug-mode
can be used to enable/disable the
debug mode. When disabled, the error output from the completion will not be displayed.
Alchemist provides a REPL
buffer, connected to an
Elixir IEx subprocess.
To start an IEx process just run M-x alchemist-iex-run
To start an IEx process in the context of an Elixir project (iex -S mix
) just run M-x alchemist-iex-project-run
To start a custom IEx process with additional arguments (like: iex --sname custom
) just use the
universal-argument C-u
before run M-x alchemist-iex-run
Keybinding | Description |
---|---|
C-c a i i | Start an IEx process. alchemist-iex-run |
C-c a i p | Start an IEx process with mix (iex -S mix ). alchemist-iex-project-run |
C-c a i l | Sends the current line to the IEx process. alchemist-iex-send-current-line |
C-c a i c | Sends the current line to the IEx process and jump to the buffer.. alchemist-iex-send-current-line-and-go |
C-c a i r | Sends the marked region to the IEx process. alchemist-iex-send-region |
C-c a i m | Sends the marked region to the IEx process and jump to the buffer. alchemist-iex-send-region-and-go |
C-c a i b | Compiles the current buffer in the IEx process. alchemist-iex-compile-this-buffer |
When Alchemist finds company-mode it enables completion inside in IEx process buffer.
Documention lookup inside an IEx process buffer will also be activated.
When the keybinding C-d is used on one of the selected completion candidates, a documentation lookup for the candidate will be made and displayed in another window.
Alchemist comes with the functionality to evaluate code inside the buffer.
Keybinding | Description |
---|---|
C-c a v l | Evaluate the Elixir code on the current line. alchemist-eval-current-line . |
C-c a v k | Evaluate the Elixir code on the current line and insert the result. alchemist-eval-print-current-line . |
C-c a v j | Get the Elixir code representation of the expression on the current line. alchemist-eval-quoted-current-line . |
C-c a v h | Get the Elixir code representation of the expression on the current line and insert the result. alchemist-eval-print-quoted-current-line . |
C-c a v o | Evaluate the Elixir code on marked region. alchemist-eval-region . |
C-c a v i | Evaluate the Elixir code on marked region and insert the result. alchemist-eval-print-region . |
C-c a v u | Get the Elixir code representation of the expression on marked region. alchemist-eval-quoted-region . |
C-c a v y | Get the Elixir code representation of the expression on marked region and insert the result. alchemist-eval-print-quoted-region . |
C-c a v q | Evaluate the Elixir code in the current buffer. alchemist-eval-buffer . |
C-c a v w | Evaluate the Elixir code in the current buffer and insert the result. alchemist-eval-print-buffer . |
C-c a v e | Get the Elixir code representation of the expression in the current buffer. alchemist-eval-quoted-buffer . |
C-c a v r | Get the Elixir code representation of the expression in the current buffer and insert result. alchemist-eval-print-quoted-buffer . |
There is a after-save-hook
called alchemist-hooks--test-on-save
which runs
the whole elixir test suite via alchemist-mix-test
. The alchemist-mix-test
will just run if the current buffer is in major elixir-mode
.
If you would like to use it just set the alchemist-hooks-test-on-save
variable
via (setq alchemist-hooks-test-on-save t)
or M-x customize-group [RET] alchemist-hooks
By default the status of alchemist-mix-test
, alchemist-compile
etc will be
represented via the colorized mode-name
. In our case that will be the elixir-mode
.
If you don't like that just set the alchemist-buffer-status-modeline
variable
via (setq alchemist-buffer-status-modeline nil)
or M-x customize-group [RET] alchemist-buffer
Alchemist comes with a default keymap.
You find and overview of all the key-bindings on the Alchemist-Refcard.
Contributions are very welcome!
- Fork alchemist.el
- Create a topic branch -
git checkout -b my_branch
- Push to your branch -
git push origin my_branch
- Send me a pull-request for your topic branch
- That's it!
Copyright © 2014-2015 Samuel Tonini and contributors.
Distributed under the GNU General Public License, version 3