Skip to content
Elixir Tooling Integration Into Emacs
Emacs Lisp Elixir Makefile
Latest commit c0c9bbf @tonini Merge pull request #214 from tonini/fix-expression-at-point
Fix issue with completion at specific places
Failed to load latest commit information.
alchemist-server Update Alchemist-Server
doc update REFCARD
images move logo/* into images/
test The char 'colon' is a none valid expression for completion
.ert-runner run ert-runner quietly
.gitignore fix project tests
.projectile add projectile ignore file
.travis.yml We need sudo when running on Travis CI
CHANGELOG.md Update CHANGELOG
CONTRIBUTING.md Update CONTRIBUTING.md
Cask require elixir-mode
Makefile Call Alchemist-Server Makefile directly
README.md Add optional mix compile after save hook
alchemist-company.el The char 'colon' is a none valid expression for completion
alchemist-compile.el Refine utils library
alchemist-complete.el Refine utils library
alchemist-eval.el Handle ansi sequences inside the evalution buffer
alchemist-execute.el Small grammar tweak.
alchemist-file.el Implement Alchemist-Phoenix minor mode
alchemist-goto.el Fixed - Erlang definition lookup failing
alchemist-help.el Implement macroexpand functionality
alchemist-hooks.el Add optional mix compile after save hook
alchemist-iex.el Tighten IEx prompt
alchemist-info.el Datatype lookup works also with marked region expressions
alchemist-interact.el Implement interaction library
alchemist-key.el Implement Alchemist-Phoenix minor mode
alchemist-macroexpand.el Refine macroexpand function names
alchemist-message.el missing defgroup for alchemist message
alchemist-mix.el Ensure no mix task duplication before server tasks
alchemist-phoenix.el Correct function comment
alchemist-project.el Start just one alchemist server process inside elixir codebase
alchemist-refcard.el Update integrated refcard with Macroexpand keys
alchemist-report.el Fix issue with false mode-name mutuation
alchemist-scope.el The char 'colon' is a none valid expression for completion
alchemist-server.el Merge pull request #196 from hunterboerner/quote-alchemist-server-she…
alchemist-test-mode.el Implement 'flunk' highlighting
alchemist-utils.el Add function to get the installed Elixir version
alchemist.el Bump v1.7 version

README.md

License GPL 3 Build Status MELPA MELPA Stable Paypal


Alchemist Logo

Elixir Tooling Integration Into Emacs

Alchemist comes with a bunch of features, which are:

  • Mix integration
  • Compile & Execution of Elixir code
  • Inline code evaluation
  • Inline macro expanding
  • Documentation lookup
  • Definition lookup
  • Powerful IEx integration
  • Smart code completion
  • Elixir project management
  • Phoenix support
  • Integration with company-mode

Installation

Requirements

Installation via package.el

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 command:

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)

Via el-get

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].

Manual

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)

Configuration

There are some ways Alchemist can be adjusted that certain workflows operating differently.

Mix setup

  • Use a different shell command for mix.
(setq alchemist-mix-command "/usr/local/bin/mix")
  • Use a different task for running tests.
(setq alchemist-mix-test-task "espec")
  • Use custom mix test task options.
(setq alchemist-mix-test-default-options '()) ;; default
  • Use a different environment variable in which mix tasks will run.

Mix tasks could always be executed in a specific environment with the usage of C-u (universal-argument). But if you like to change the run of Mix task permanently to a specific environment set it through the variable.

(setq alchemist-mix-env "prod")

IEx setup

  • Use a different shell command for iex.
(setq alchemist-iex-program-name "/usr/local/bin/iex") ;; default: iex

Execute setup

  • Use a different shell command for elixir.
(setq alchemist-execute-command "/usr/local/bin/elixir") ;; default: elixir

Compile setup

  • Use a different shell command for elixirc.
(setq alchemist-compile-command "/usr/local/bin/elixirc") ;; default: elixirc

Modeline setup

  • Disable the change of the modeline color with the last test run status.
(setq alchemist-test-status-modeline nil)

Keybindings

  • Use a different keybinding prefix than C-c a
(setq alchemist-key-command-prefix (kbd "C-c ,")) ;; default: (kbd "C-c a")

Testing Mode

  • Disable the use of a more significant syntax highlighting on functions like test, assert_* and refute_*
(setq alchemist-test-mode-highlight-tests nil) ;; default t
  • Don't ask to save changed file buffers before running tests.
(setq alchemist-test-ask-about-save nil)
  • Don't change the color of the mode-name when test run failed or passed.
(setq alchemist-test-status-modeline nil)
  • Show compilation output in test report.
(setq alchemist-test-display-compilation-output t)

Hooks

  • Run the whole test suite with alchemist-mix-test after saving a buffer.
(setq alchemist-hooks-test-on-save t)
  • Compile your project with alchemist-mix-compile after saving a buffer.
(setq alchemist-hooks-compile-on-save t)

Server

Alchemist works as a server & client model, where the Alchemist server is written in Elixir and Emacs takes the part of the client.

For each Elixir mix project Alchemist starts an independent server in the background. If an Elixir file gets opened in a buffer, Alchemist checks if a server is running for the current project or not and starts a new one if needed. If there is no Elixir mix project found, Alchemist starts a general unique server.

An Alchemist server can be started/restarted by hand with the call of the function alchemist-server-start. A prompt for the environment in which the server should run (default: dev) gets opened and the server will start/restart in the selected environment.

To get the server status for the current project, just call the function alchemist-server-status and a report will be displayed in the minibuffer:

Alchemist-Server-Status: [Project: /Users/tonini/Projects/ek/ Status: Connected]

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

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.

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 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 c 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 b 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 [s]-search [h]-history [?]-keys
Keybinding Description
q Quit *elixir help* buffer window
e alchemist-help-search-at-point
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 <f1> for documentation lookup for the current selected candidate. C-w to jump to the definition of the current selected candidate.

Alchemist Completion Candidate Functionalities

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 n i Prints information about any datatype under the cursor. alchemist-info-datatype-at-point
C-c a n 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

Support

If you hit any problems, please first ensure that you are using the latest version of this code, and that you have updated your packages to the most recent available versions.

  • To report bugs or feature requests: please use the issue tracker on Github.
  • To talk about the project with people in real time: please join the #emacs-elixir channel on IRC or the #emacs channel on Elixir Slack.

Contributing

We appreciate any contribution to Alchemist, so check out our Contribution guidelines for more information.

License

Copyright © 2014-2015 Samuel Tonini and contributors.

Distributed under the GNU General Public License, version 3

Something went wrong with that request. Please try again.