Code Monkey home page Code Monkey logo

alchemist.el's Introduction

License GPL 3 Build Status MELPA MELPA Stable Gratipay


Alchemist Logo

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

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 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)

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.

  • 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

Project configuration file

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"
}

Mix

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.

Compile And Execute

Compile functions

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.

Execute functions

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.

Project

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

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.

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.

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.

Alchemist Help Minor Mode Key Summary

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

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

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.

Debug

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.

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

Complete & Documentation lookup

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.

IEx Completion and Docs lookup

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.

Hooks

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

Modeline

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 Build Status

Keymap

Alchemist comes with a default keymap.

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

Contributing

Contributions are very welcome!

  1. Fork alchemist.el
  2. Create a topic branch - git checkout -b my_branch
  3. Push to your branch - git push origin my_branch
  4. Send me a pull-request for your topic branch
  5. That's it!

License

Copyright © 2014-2015 Samuel Tonini and contributors.

Distributed under the GNU General Public License, version 3

alchemist.el's People

Contributors

pragdave avatar tonini avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.