Mix

Keybinding Description
C-c a x Prompt for a mix command including a list of all available mix commands. alchemist-mix
C-c a m c Compile the whole elixir project. alchemist-mix-compile
C-c a m r Runs the given file or expression in the context of the application. alchemist-mix-run
C-c a m l Rerun the last mix task which was run by alchemist. alchemist-mix-rerun-last-task

Mix tasks could also be executed in a specific environment with the usage of C-u (universal-argument). Default environments are prod, dev and test. Mix environments

Mix Task Mode

The Mix tasks running in a separate alchemist-mix-mode, in which the following keybindings are available:

Keybinding Description
q Quit *mix* buffer window
i Send an input to the current running mix task process.
r Rerun the last mix task which was run by alchemist.

Mix Hex

Keybinding Description
C-c a X i Display Hex package information for the package at point.
C-c a X r Display Hex package releases for the package at point.
C-c a X I Display Hex package info for a certain package.
C-c a X R Display Hex package releases for a certain package.
C-c a X s Search for Hex packages.
C-c a X d Display Hex package dependencies for the current Mix project.

Testing

Keybinding Description
C-c a t Run the whole elixir test suite. alchemist-mix-test
C-c a r Rerun the last test that was run by alchemist. alchemist-mix-rerun-last-test
C-c a m t f Run alchemist-mix--test-file with the FILENAME. alchemist-mix-test-file
C-c a m t b Run the current buffer through mix test. alchemist-mix-test-this-buffer
C-c a m t . Run the test at point. alchemist-mix-test-at-point
C-c a m t s Run only stale tests (Elixir 1.3+). alchemist-mix-test-stale
C-c a m t r Rerun the last test that was run by alchemist. alchemist-mix-rerun-last-test
C-c M-r Toggle between displaying or hidding the test report buffer. alchemist-test-toggle-test-report-display

Compile And Execute

Compile functions

Keybinding Description
C-c a c b Compile the current buffer with the elixirc command. alchemist-compile-this-buffer
C-c a c f Compile the given FILENAME with the elixirc command. alchemist-compile-file
C-c a c c Run a custom compile command with elixirc. alchemist-compile

Execute functions

Keybinding Description
C-c a e b Run the current buffer through elixir command. alchemist-execute-this-buffer
C-c a e f Run elixir command with the given FILENAME. alchemist-execute-file
C-c a e e Run a custom execute command with elixir. alchemist-execute

Project

Keybinding Description
C-c a p s Toggle between a file and its tests in the current window. alchemist-project-toggle-file-and-tests
C-c a p o Toggle between a file and its tests in other window. alchemist-project-toggle-file-and-tests-other-window
C-c a p t Run the tests related to the current file. alchemist-project-run-tests-for-current-file
C-c a p f List all files available in the test directory. alchemist-project-find-test
C-c a p l List all files available in the lib directory. alchemist-project-find-lib

alchemist-phoenix-mode

Keybinding Description
C-c a n w List all files available in the web directory. alchemist-phoenix-find-web
C-c a n c List all controllers in web/controllers directory. alchemist-phoenix-find-controllers
C-c a n l List all channels in web/channels directory. alchemist-phoenix-find-channels
C-c a n t List all templates in web/templates directory. alchemist-phoenix-find-templates
C-c a n m List all models in web/models directory. alchemist-phoenix-find-models
C-c a n v List all views in web/views directory. alchemist-phoenix-find-views
C-c a n s List all files in web/static directory. alchemist-phoenix-find-static
C-c a n r Open the router.ex file in web directory. alchemist-phoenix-router
C-c a n R Run the Mix task phoenix.routes. alchemist-phoenix-routes

Documentation lookup

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.

Keybinding Description
C-c a h h Run a custom search. alchemist-help
C-c a h i Look through search history. alchemist-help-history
C-c a h e Run alchemist-help with the expression under the cursor. (example: is_binary  or Code.eval_string). If there is a currently marked region this will be used as the search term. alchemist-help-search-at-point
C-c a h r Open a buffer with a refcard of alchemist bindings. alchemist-refcard

Alchemist Help Minor Mode Keymap

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.

Hit ? to get the keybinding summary for the alchemist-help-minor-mode.

[q]-quit [e]-search-at-point [m]-search-module [s]-search [h]-history [?]-keys
Keybinding Description
q Quit *elixir help* buffer window
e alchemist-help-search-at-point
m alchemist-help-module
s alchemist-help
h alchemist-help-history
? alchemist-help-minor-mode-key-binding-summary

Definition lookup

With the function alchemist-goto-definition-at-point, which is bound to M-., you can jump to module and function definitions. If you want to jump back, just use M-, which calls alchemist-goto-jump-back.

You also can jump to the current selected completion candidate with just hit the same key as normally, M-..

By default you're able to jump to definitions of your own mix project codebase and dependencies. But if you would like to also jump to Elixir and Erlang source code you need to tell Alchemist where it can find the source code of Elixir and Erlang.

For that purpose there're two variables you can set:

(setq alchemist-goto-erlang-source-dir "/path/to/erlang/source/")
(setq alchemist-goto-elixir-source-dir "/path/to/elixir/source/")

If you inside an Erlang file and the erlang-mode is enabled you can't use alchemist-goto-jump-back anymore. But if you would like to use it also inside the erlang-mode just setup the following custom hook:

(defun custom-erlang-mode-hook ()
  (define-key erlang-mode-map (kbd "M-,") 'alchemist-goto-jump-back))

(add-hook 'erlang-mode-hook 'custom-erlang-mode-hook)

Definition Lookup

Symbol definitions

There is the function alchemist-goto-list-symbol-definitions which lets you jump to a specific module, function or macro definitions in the current file.

Auto-completion

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.

Alchemist Company

There are the same keybindings for documentation lookup and definition opening for the selected candidate available like company-mode provides.

C-h and \ for documentation lookup for the current selected candidate. C-w to jump to the definition of the current selected candidate.

Alchemist Completion Candidate Functionalities

Important Note:

  • Auto complete and jump to definition only works if your project or newly added file has been compiled.
  • If you moved the project to a different path you will need to compile it again at the current location.
  • If you compile the project inside a Docker container then the project will need to have the same path both inside the container and on the host, or you will need to run emacs inside the container.

IEx

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
C-c a i R Recompiles and reloads the current module in the IEx process. alchemist-iex-reload-module

Complete & Documentation lookup

When Alchemist finds company-mode it enables if for completion inside the IEx process buffer.

Eval

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.
C-c a v ! Quit the Elixir evaluation popup window. alchemist-eval-close-popup.

Macroexpand

Keybinding Description Command
C-c a o l Macro expand once on the current line. alchemist-macroexpand-once-current-line.
C-c a o L Macro expand once on the current line and print the result. alchemist-macroexpand-once-print-current-line.
C-c a o k Macro expand on the current line. alchemist-macroexpand-current-line.
C-c a o K Macro expand on the current line and print the result. alchemist-macroexpand-print-current-line.
C-c a o i Macro expand once on region. alchemist-macroexpand-once-region.
C-c a o I Macro expand once on region and print the result. alchemist-macroexpand-once-print-region.
C-c a o r Macro expand on region. alchemist-macroexpand-region.
C-c a o R Macro expand on region and print the result. alchemist-macroexpand-print-region.
C-c a o ! Quit the Elixir macroexpand popup window. alchemist-macroexpand-close-popup.

Note

Macroexpand works currently only for Elixir core macros, but why is this?

Macros are lexical: it is impossible to inject code or macros globally. In order to use a macro, you need to explicitly require or import the module that defines the macro.

The Alchemist-Server is currently under development to handle more knowledge about the current context. After that update expanding custom macros will supported too.

But if you like to expand a custom macro in the mean time and you know where it comes from, you can do something like the following with the Alchemist inline evaluation functionality.

As example, select the code and call the alchemist-eval-print-region and you get the macro expansion below.

require Unless # In order to use a macro, you need to explicitly require the module
expr = quote do: Unless.macro_unless(true, IO.puts "this should never be printed")
res  = Macro.expand_once(expr, __ENV__)
IO.puts Macro.to_string(res)
# => if(!true) do
# =>   IO.puts("this should never be printed")
# => end
# => :ok

Datatype Informations

With Elixir v1.2 comes two new IEx helper functions t/1 and i/1.

  • Display type docs with t(Module.type) and t(Module.type/arity)
  • Prints information about any data type with i/1.

These two helper functions are available now with the following keybindings/functions.

Keybinding Description
C-c a f i Prints information about any datatype under the cursor. alchemist-info-datatype-at-point
C-c a f t Prints information of types under the cursor. alchemist-info-types-at-point

Testing Mode

Alchemist comes with an minor mode for testing which will be enabled by default inside *_test.exs files.

Keybinding Description
C-c , s Run the test at point. alchemist-mix-test-at-point
C-c , v Run all tests in the current file. alchemist-mix-test-this-buffer
C-c , a Run the whole elixir test suite. alchemist-mix-test
C-c , f Run all tests of a specific file alchemist-mix-test-file
C-c , n Jump to the next test inside the current file. alchemist-test-mode-jump-to-next-test
C-c , p Jump to the previous test inside the current file alchemist-test-mode-jump-to-previous-test

Testing Report

The tests are reported in the alchemist-test-report-mode, which have the following keybindings:

Keybinding Description
r Rerun the latest test run. alchemist-mix-rerun-last-test
t Toggle truncating of long lines for the current test buffer. toggle-truncate-lines
M-n Jump to the next error in the test report. alchemist-test-next-result
M-p Jump to the previous error in the test report. alchemist-test-previous-result
M-N Jump to the next stacktrace file in the test report. alchemist-test-next-stacktrace-file
M-P Jump to the previous stacktrace file in the test report. alchemist-test-previous-stacktrace-file
C-c C-k Interrupt the current running report process. alchemist-report-interrupt-current-process
q Close the test report window

Keymap

Alchemist comes with a default keymap.

The the default prefix keybinding is C-c a

Refcards

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

There is also a refcard for usage inside Emacs, which gets dynamically generated with the current adjusted keybindings. If you use the keybinding i on a specific row, it will call describe-function on that function.

Just M-x alchemist-refcard RET