Skip to content

bkearns/emacs-elixir

 
 

Repository files navigation

Elixir Mode

Provides font-locking, indentation and navigation support for the Elixir programming language.

Installation

ELPA

elixir-mode is available on the community maintained repository - MELPA. Just run M-x package-install [RET] elixir-mode [RET] inside your emacs and you're ready to go.

If you're not already using ELPA, check the emacswiki page to get familiar with it.

Install the most recent version

Clone this repository somewhere

$ cd ~/.emacs.d/plugins
$ git clone https://github.com/elixir-lang/emacs-elixir

Add the following in your .emacs file:

(add-to-list 'load-path "~/path/to/emacs-elixir/")
(require 'elixir-mode)

Usage

Interactive Commands

Command (For the M-x prompt.) Description
elixir-mode Switches to elixir-mode.
elixir-mode-compile-file Compile Elixir files. Works fine on *.exs files, too, if needed.
elixir-cos-mode Applies compile-on-save minor mode.
elixir-mode-iex Launch iex inside Emacs. Use C-u univesal-argument to run iex with some additional arguments.
elixir-mode-eval-on-region Evaluates the Elixir code on the marked region. This is bound to C-c ,r while in elixir-mode.
elixir-mode-eval-on-current-line Evaluates the Elixir code on the current line. This is bound to C-c ,c while in elixir-mode.
elixir-mode-eval-on-current-buffer Evaluates the Elixir code in the current buffer. This is bound to C-c ,b while in elixir-mode.
elixir-mode-string-to-quoted-on-region Get the representation of the expression on the marked region. This is bound to C-c ,a while in elixir-mode.
elixir-mode-string-to-quoted-on-current-line Get the representation of the expression on the current line. This is bound to C-c ,l while in elixir-mode.
elixir-mode-opengithub Open the GitHub page for Elixir.
elixir-mode-open-elixir-home Go to Elixir README in the browser.
elixir-mode-open-docs-master Open the Elixir documentation for the master.
elixir-mode-open-docs-stable Open the Elixir documentation for the latest stable release.
elixir-mode-run-tests Run ERT tests for `elixir-mode`.
elixir-mode-show-version Print version info for elixir-mode.

Configuration

Any file that matches the glob *.ex[s] or *.elixir is automatically opened in elixir-mode, but you can change this functionality easily.

;; Highlights *.elixir2 as well
(add-to-list 'auto-mode-alist '("\\.elixir2\\'" . elixir-mode))

Custom variables for elixir-mode.

Variable Default Description
elixir-compiler-command (string) "elixirc" Command to compile Elixir code.
elixir-iex-command (string) "iex" Command to start an interactive REPL in IEX.
elixir-mode-highlight-operators (boolean) t Should operators be colored? (Currently not working properly.)
elixir-mode-cygwin-paths (boolean) t Should Cygwin paths be used on Windows?
elixir-mode-cygwin-prefix (string) "/cygdrive/C" The prefix for Cygwin-style paths.

Hooks

Hooks can be used to add functionality to elixir-mode. This example adds compile on save.

(defun elixir-mode-compile-on-save ()
  "Elixir mode compile files on save."
	(and (file-exists (buffer-file-name))
	     (file-exists (elixir-mode-compiled-file-name))
			 (elixir-cos-mode t)))
(add-hook 'elixir-mode-hook 'elixir-mode-compile-on-save)

Keymapping

Keymaps can be added to the elixir-mode-map variable.

Notes

If you want to use ruby-end-mode for a more comfortable editing experience, you can add the following to your elixir-mode-hook:

(add-to-list 'elixir-mode-hook
             (defun auto-activate-ruby-end-mode-for-elixir-mode ()
               (set (make-variable-buffer-local 'ruby-end-expand-keywords-before-re)
                    "\\(?:^\\|\\s-+\\)\\(?:do\\)")
               (set (make-variable-buffer-local 'ruby-end-check-statement-modifiers) nil)
               (ruby-end-mode +1)))

Mix

If you looking for integrated emacs mix support, see here: elixir-mix.el

History

This mode is based on the Emacs mode by secondplanet.

Contributions are very welcome!

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

About

Emacs major mode for Elixir

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Emacs Lisp 97.6%
  • Ruby 2.4%