Emacs major mode for working with ReasonML
Switch branches/tags
Nothing to show
Clone or download
wpcarro and anmonteiro Prefer function reader syntax (#29)
While passing a function as an argument in Elisp as
'function-name works, calling #'function-name may be
preferred since its intent is more obvious.
Latest commit 0ab99a0 Jul 30, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Improve Jsx indentation (#36) Jul 27, 2018
.gitignore Initial commit May 7, 2017
.travis.yml drop support for emacs < 24.3 Oct 15, 2017
Cask Introduce cask and improve testing harness Oct 8, 2017
LICENSE-MIT Initial commit May 7, 2017
README.md Prefer function reader syntax (#29) Jul 30, 2018
reason-indent.el Improve Jsx indentation (#36) Jul 27, 2018
reason-mode.el Sync keyword list (#38) Jul 22, 2018
refmt.el Convert OCaml region to Reason (and vice-versa) Oct 9, 2017
run_tests.sh Setup CI, fix tests Oct 8, 2017



Build Status

An Emacs major mode for ReasonML.



If your Emacs has package.el (which is automatically the case for Emacs >= 24), you can install reason-mode from the package in MELPA.


Alternatively, you can use quelpa and the following recipe:

(quelpa '(reason-mode :repo "reasonml-editor/reason-mode" :fetcher github :stable t))

Manual Installation

Download reason-indent.el, reason-interaction.el, reason-mode.el and refmt.el at the root of this repository and place it in a vendor file next to your Emacs configuration files. Then place the following somewhere in your .emacs.el:

(add-to-list 'load-path "/path/to/vendor")

Note: the following setup assumes Reason and Merlin are installed. This can be achieved by by installing them from OPAM (opam install reason.1.13.7 merlin.2.5.4). Make sure you're on ocaml 4.02.3!

Please verify your installation:

ocamlc -version # 4.02.3
which ocamlmerlin # a valid path to the ocamlmerlin binary, mandatorily

Add the following to your ~/.emacs or ~/.emacs.d/init.el file:

;; Reason setup

(defun shell-cmd (cmd)
  "Returns the stdout output of a shell command or nil if the command returned
   an error"
  (car (ignore-errors (apply 'process-lines (split-string cmd)))))

(defun reason-cmd-where (cmd)
  (let ((where (shell-cmd cmd)))
    (if (not (string-equal "unknown flag ----where" where))

(let* ((refmt-bin (or (reason-cmd-where "refmt ----where")
                      (shell-cmd "which refmt")))
       (merlin-bin (or (reason-cmd-where "ocamlmerlin ----where")
                       (shell-cmd "which ocamlmerlin")))
       (merlin-base-dir (when merlin-bin
                          (replace-regexp-in-string "bin/ocamlmerlin$" "" merlin-bin))))
  ;; Add merlin.el to the emacs load path and tell emacs where to find ocamlmerlin
  (when merlin-bin
    (add-to-list 'load-path (concat merlin-base-dir "share/emacs/site-lisp/"))
    (setq merlin-command merlin-bin))

  (when refmt-bin
    (setq refmt-command refmt-bin)))

(require 'reason-mode)
(require 'merlin)
(add-hook 'reason-mode-hook (lambda ()
                              (add-hook 'before-save-hook 'refmt-before-save)

(setq merlin-ac-setup t)

If you have iedit mode set up:

(require 'merlin-iedit)
(defun evil-custom-merlin-iedit ()
  (if iedit-mode (iedit-mode)
(define-key merlin-mode-map (kbd "C-c C-e") 'evil-custom-merlin-iedit)

(Thanks @sgrove: https://gist.github.com/sgrove/c9bdfed77f4da8db108dfb2c188f7baf)

This associates reason-mode with .re and .rei files. To enable it explicitly, do M-x reason-mode.


Reason-mode provides (opt-in) rtop support. At the moment only the native workflow is supported.

First of all you need to install the Utop Emacs integration. Make sure it is latest master because the feature is fairly new.

Then in your Emacs init file add:

(require 'utop)
(setq utop-command "opam config exec -- rtop -emacs")
(add-hook 'reason-mode-hook #'utop-minor-mode) ;; can be included in the hook above as well

After this, the function utop (C-c C-s) will start rtop in Reason buffers.


There is currently no official reason layer available, but you can install the reason-mode package automatically. Some are working on a layer in the meantime #1149.

      :location (recipe
        :repo "reasonml-editor/reason-mode"
        :fetcher github
        :files ("reason-mode.el" "refmt.el" "reason-indent.el" "reason-interaction.el")))

Afterwards add the snippet to your dotspacemacs/user-config.


Auto-format before saving

If you have refmt installed, you can add this to your .emacs file to enable auto-format:

(add-hook 'reason-mode-hook (lambda ()
          (add-hook 'before-save-hook #'refmt-before-save)))

Tests via Cask + ERT

The test folder contains tests that can be run via Cask. Once you install cask, if it is the first time run:

cask install
cask exec ./run_tests.sh

If it is not the first time you can omit the first line and execute the tests with the second one only. The environment variable EMACS controls the program that runs emacs.


reason-mode is distributed under the terms of both the MIT license and the Apache License (Version 2.0).