Skip to content

Instantly share code, notes, and snippets.

@jwalsh
Created October 25, 2017 18:06
Show Gist options
  • Select an option

  • Save jwalsh/80196d41f9103ea57550ebdaeb531062 to your computer and use it in GitHub Desktop.

Select an option

Save jwalsh/80196d41f9103ea57550ebdaeb531062 to your computer and use it in GitHub Desktop.
(add-to-list 'load-path "~/sandbox/reason-mode")
(let ((opam-share (ignore-errors (car (process-lines "opam" "config" "var" "share")))))
(when (and opam-share (file-directory-p opam-share))
;; Register Merlin
(add-to-list 'load-path (expand-file-name "emacs/site-lisp" opam-share))
(autoload 'merlin-mode "merlin" nil t nil)
;; Automatically start it in OCaml buffers
(add-hook 'tuareg-mode-hook 'merlin-mode t)
(add-hook 'caml-mode-hook 'merlin-mode t)
;; Use opam switch to lookup ocamlmerlin binary
(setq merlin-command 'opam)))
;;----------------------------------------------------------------------------
;; 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)))))
(let* ((refmt-bin (or (shell-cmd "refmt ----where")
(shell-cmd "which refmt")))
(merlin-bin (or (shell-cmd "ocamlmerlin ----where")
(shell-cmd "which ocamlmerlin")))
(merlin-base-dir (when merlin-bin
(replace-regexp-in-string "bin/ocamlmerlin$" "" merlin-bin))))
;; Add npm 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)
(merlin-mode)))
(setq merlin-ac-setup t)
;; ## added by OPAM user-setup for emacs / base ## 56ab50dc8996d2bb95e7856a6eddb17b ## you can edit, but keep this line
(require 'opam-user-setup "~/.emacs.d/opam-user-setup.el")
;; ## end of OPAM user-setup addition for emacs / base ## keep this line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment