2017-06-27 22:58:38 +02:00
|
|
|
;;; lang/ocaml/config.el -*- lexical-binding: t; -*-
|
2017-06-27 11:39:15 -07:00
|
|
|
|
2018-10-16 02:45:12 -04:00
|
|
|
(after! tuareg
|
2018-09-21 00:06:12 +01:00
|
|
|
;; tuareg-mode has the prettify symbols itself
|
|
|
|
(set-pretty-symbols! 'tuareg-mode :alist
|
|
|
|
(append tuareg-prettify-symbols-basic-alist
|
|
|
|
tuareg-prettify-symbols-extra-alist))
|
2018-10-16 02:45:12 -04:00
|
|
|
;; harmless if `prettify-symbols-mode' isn't active
|
2018-09-21 00:06:12 +01:00
|
|
|
(setq tuareg-prettify-symbols-full t)
|
2018-10-16 02:45:12 -04:00
|
|
|
|
2018-09-21 00:06:12 +01:00
|
|
|
;; Use opam to set environment
|
|
|
|
(setq tuareg-opam-insinuate t)
|
|
|
|
(tuareg-opam-update-env (tuareg-opam-current-compiler))
|
2018-10-16 02:45:12 -04:00
|
|
|
|
2018-09-21 00:06:12 +01:00
|
|
|
;; Spell-check comments
|
|
|
|
(when (featurep! :feature spellcheck)
|
2018-10-16 02:45:12 -04:00
|
|
|
(add-hook 'tuareg-mode-local-vars-hook #'flyspell-prog-mode))
|
|
|
|
|
|
|
|
|
|
|
|
(def-package! merlin
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(defun +ocaml|init-merlin ()
|
2018-10-16 23:30:47 +01:00
|
|
|
"Activate `merlin-mode' if the ocamlmerlin executable exists."
|
|
|
|
(when (executable-find "ocamlmerlin")
|
2018-10-16 02:45:12 -04:00
|
|
|
(merlin-mode)))
|
|
|
|
(add-hook 'tuareg-mode-hook #'+ocaml|init-merlin)
|
|
|
|
|
|
|
|
(set-company-backend! 'tuareg-mode 'merlin-company-backend)
|
|
|
|
(set-lookup-handlers! 'tuareg-mode
|
|
|
|
:definition #'merlin-locate
|
|
|
|
:references #'merlin-occurrences
|
|
|
|
:documentation #'merlin-document)
|
|
|
|
:config
|
|
|
|
(setq merlin-completion-with-doc t)
|
|
|
|
|
|
|
|
(map! :map tuareg-mode-map
|
|
|
|
:localleader
|
|
|
|
:n "t" #'merlin-type-enclosing
|
|
|
|
:n "a" #'tuareg-find-alternate-file))
|
|
|
|
|
|
|
|
|
|
|
|
(def-package! flycheck-ocaml
|
|
|
|
:when (featurep! :feature syntax-checker)
|
2018-10-16 23:30:47 +01:00
|
|
|
:init
|
|
|
|
(defun +ocaml|init-flycheck ()
|
|
|
|
"Activate `flycheck-ocaml` if the current project possesses a .merlin file."
|
|
|
|
(when (projectile-locate-dominating-file default-directory ".merlin")
|
|
|
|
;; Disable Merlin's own error checking
|
|
|
|
(setq merlin-error-after-save nil)
|
|
|
|
;; Enable Flycheck checker
|
|
|
|
(flycheck-ocaml-setup)))
|
|
|
|
(add-hook 'merlin-mode-hook #'+ocaml|init-flycheck))
|
2017-06-27 11:39:15 -07:00
|
|
|
|
2018-09-21 00:06:12 +01:00
|
|
|
|
2018-10-16 23:35:52 +01:00
|
|
|
(def-package! merlin-eldoc
|
|
|
|
:hook (merlin-mode . merlin-eldoc-setup))
|
|
|
|
|
|
|
|
|
2018-10-17 00:02:14 +01:00
|
|
|
(def-package! merlin-iedit
|
|
|
|
:when (featurep! :editor multiple-cursors)
|
|
|
|
:hook (merlin-mode . merlin-use-merlin-imenu)
|
|
|
|
:config
|
|
|
|
(map! :map tuareg-mode-map
|
|
|
|
:v "R" #'merlin-iedit-occurrences))
|
|
|
|
|
|
|
|
|
|
|
|
(def-package! merlin-imenu
|
|
|
|
:when (featurep! :emacs imenu)
|
|
|
|
:hook (merlin-mode . merlin-use-merlin-imenu))
|
|
|
|
|
|
|
|
|
2018-10-16 02:45:12 -04:00
|
|
|
(def-package! utop
|
|
|
|
:when (featurep! :feature eval)
|
|
|
|
:defer t ; loaded by hook below
|
|
|
|
:init
|
|
|
|
(set-repl-handler! 'tuareg-mode #'utop)
|
|
|
|
(set-eval-handler! 'tuareg-mode #'utop-eval-region)
|
|
|
|
(defun +ocaml|init-utop ()
|
|
|
|
(when (executable-find "utop")
|
|
|
|
(utop-minor-mode)))
|
|
|
|
(add-hook 'tuareg-mode-hook #'+ocaml|init-utop))
|
2018-09-21 00:06:12 +01:00
|
|
|
|
|
|
|
|
2018-10-16 02:45:12 -04:00
|
|
|
(def-package! ocp-indent
|
|
|
|
;; must be careful to always defer this, it has autoloads that adds hooks
|
|
|
|
;; which we do not want if the executable can't be found
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(defun +ocaml|init-ocp-indent ()
|
|
|
|
"Run `ocp-setup-indent', so long as the ocp-indent binary exists."
|
|
|
|
(when (executable-find "ocp-indent")
|
|
|
|
(ocp-setup-indent)))
|
|
|
|
(add-hook 'tuareg-mode-hook #'+ocaml|init-ocp-indent))
|
2018-09-21 00:06:12 +01:00
|
|
|
|
|
|
|
|
2018-10-16 02:45:12 -04:00
|
|
|
(def-package! ocamlformat
|
|
|
|
:when (featurep! :editor format)
|
|
|
|
:commands ocamlformat
|
|
|
|
:init
|
|
|
|
(set-formatter! 'ocamlformat #'ocamlformat
|
|
|
|
:modes '(caml-mode tuareg-mode))
|
|
|
|
;; TODO Fix region-based formatting support
|
|
|
|
(defun +ocaml|init-ocamlformat ()
|
|
|
|
(setq +format-with 'ocp-indent)
|
|
|
|
(when (and (executable-find "ocamlformat")
|
|
|
|
(locate-dominating-file default-directory ".ocamlformat"))
|
|
|
|
(setq +format-with 'ocamlformat)))
|
|
|
|
(add-hook 'tuareg-mode-hook #'+ocaml|init-ocamlformat)))
|