2017-06-27 22:58:38 +02:00
|
|
|
;;; lang/ocaml/config.el -*- lexical-binding: t; -*-
|
2017-06-27 11:39:15 -07:00
|
|
|
|
2020-02-25 20:03:33 -05:00
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
|
2019-02-21 16:08:27 -05:00
|
|
|
(when (featurep! +lsp)
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! '(tuareg-mode-local-vars-hook reason-mode-local-vars-hook)
|
|
|
|
#'lsp!))
|
2019-02-21 16:08:27 -05: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
|
2020-08-12 18:52:14 -04:00
|
|
|
(set-ligatures! 'tuareg-mode :alist
|
2018-09-21 00:06:12 +01:00
|
|
|
(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
|
|
|
|
2019-07-08 21:42:19 +02:00
|
|
|
(setq-hook! 'tuareg-mode-hook
|
|
|
|
comment-line-break-function #'+ocaml/comment-indent-new-line)
|
|
|
|
|
2019-10-13 20:36:49 +09:00
|
|
|
(map! :localleader
|
|
|
|
:map tuareg-mode-map
|
|
|
|
"a" #'tuareg-find-alternate-file)
|
2018-10-16 02:45:12 -04:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! utop
|
2019-07-08 21:58:05 +02:00
|
|
|
:when (featurep! :tools eval)
|
2020-02-25 22:33:43 -05:00
|
|
|
:hook (tuareg-mode-local-vars . +ocaml-init-utop-h)
|
2018-10-16 02:45:12 -04:00
|
|
|
:init
|
2019-07-08 21:58:05 +02:00
|
|
|
(set-repl-handler! 'tuareg-mode #'utop)
|
|
|
|
(set-eval-handler! 'tuareg-mode #'utop-eval-region)
|
2019-09-13 21:59:03 -04:00
|
|
|
(defun +ocaml-init-utop-h ()
|
2019-07-08 21:58:05 +02:00
|
|
|
(when (executable-find "utop")
|
2019-12-08 16:17:39 +07:00
|
|
|
(utop-minor-mode)))
|
|
|
|
:config
|
|
|
|
(set-popup-rule! "^\\*utop\\*" :quit nil)))
|
2018-10-16 02:45:12 -04:00
|
|
|
|
2019-07-08 21:58:05 +02:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! merlin
|
2019-07-08 21:58:05 +02:00
|
|
|
:unless (featurep! +lsp)
|
2020-02-25 22:33:43 -05:00
|
|
|
:hook (tuareg-mode-local-vars . +ocaml-init-merlin-h)
|
2019-07-08 21:58:05 +02:00
|
|
|
:init
|
2019-09-13 21:59:03 -04:00
|
|
|
(defun +ocaml-init-merlin-h ()
|
2019-07-08 21:58:05 +02:00
|
|
|
"Activate `merlin-mode' if the ocamlmerlin executable exists."
|
|
|
|
(when (executable-find "ocamlmerlin")
|
|
|
|
(merlin-mode)))
|
|
|
|
|
|
|
|
(after! tuareg
|
2018-10-16 02:45:12 -04:00
|
|
|
(set-company-backend! 'tuareg-mode 'merlin-company-backend)
|
2020-02-02 02:36:21 -05:00
|
|
|
(set-lookup-handlers! 'tuareg-mode :async t
|
2018-10-16 02:45:12 -04:00
|
|
|
:definition #'merlin-locate
|
|
|
|
:references #'merlin-occurrences
|
2019-07-08 21:58:05 +02:00
|
|
|
:documentation #'merlin-document))
|
|
|
|
:config
|
|
|
|
(setq merlin-completion-with-doc t)
|
2018-10-16 02:45:12 -04:00
|
|
|
|
2019-07-08 21:58:05 +02:00
|
|
|
(map! :localleader
|
|
|
|
:map tuareg-mode-map
|
2019-10-13 20:36:49 +09:00
|
|
|
"t" #'merlin-type-enclosing)
|
2018-10-16 02:45:12 -04:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! flycheck-ocaml
|
2020-01-14 03:04:26 -05:00
|
|
|
:when (featurep! :checkers syntax)
|
2019-09-13 21:59:03 -04:00
|
|
|
:hook (merlin-mode . +ocaml-init-flycheck-h)
|
2019-07-08 21:58:05 +02:00
|
|
|
:config
|
2019-09-13 21:59:03 -04:00
|
|
|
(defun +ocaml-init-flycheck-h ()
|
2019-10-13 11:26:49 +09:00
|
|
|
"Activate `flycheck-ocaml`"
|
|
|
|
;; Disable Merlin's own error checking
|
|
|
|
(setq merlin-error-after-save nil)
|
|
|
|
;; Enable Flycheck checker
|
|
|
|
(flycheck-ocaml-setup)))
|
2018-09-21 00:06:12 +01:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! merlin-eldoc
|
2019-07-08 21:58:05 +02:00
|
|
|
:hook (merlin-mode . merlin-eldoc-setup))
|
2018-09-21 00:06:12 +01:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! merlin-iedit
|
2019-07-08 21:58:05 +02:00
|
|
|
:when (featurep! :editor multiple-cursors)
|
2018-10-16 02:45:12 -04:00
|
|
|
:defer t
|
|
|
|
:init
|
2019-07-08 21:58:05 +02:00
|
|
|
(map! :map tuareg-mode-map
|
|
|
|
:v "R" #'merlin-iedit-occurrences))
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! merlin-imenu
|
2019-07-08 21:58:05 +02:00
|
|
|
:when (featurep! :emacs imenu)
|
|
|
|
:hook (merlin-mode . merlin-use-merlin-imenu)))
|
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! ocp-indent
|
2019-07-08 21:58:05 +02:00
|
|
|
;; 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
|
2020-02-25 22:33:43 -05:00
|
|
|
:hook (tuareg-mode-local-vars . +ocaml-init-ocp-indent-h)
|
2019-07-08 21:58:05 +02:00
|
|
|
:config
|
2019-09-13 21:59:03 -04:00
|
|
|
(defun +ocaml-init-ocp-indent-h ()
|
2019-07-08 21:58:05 +02:00
|
|
|
"Run `ocp-setup-indent', so long as the ocp-indent binary exists."
|
|
|
|
(when (executable-find "ocp-indent")
|
|
|
|
(ocp-setup-indent))))
|
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! ocamlformat
|
2019-07-08 21:58:05 +02:00
|
|
|
:when (featurep! :editor format)
|
|
|
|
:commands ocamlformat
|
2020-02-25 22:33:43 -05:00
|
|
|
:hook (tuareg-mode-local-vars . +ocaml-init-ocamlformat-h)
|
2019-07-08 21:58:05 +02:00
|
|
|
:config
|
|
|
|
(set-formatter! 'ocamlformat #'ocamlformat
|
|
|
|
:modes '(caml-mode tuareg-mode))
|
|
|
|
;; TODO Fix region-based formatting support
|
2019-09-13 21:59:03 -04:00
|
|
|
(defun +ocaml-init-ocamlformat-h ()
|
2019-07-08 21:58:05 +02:00
|
|
|
(setq +format-with 'ocp-indent)
|
|
|
|
(when (and (executable-find "ocamlformat")
|
|
|
|
(locate-dominating-file default-directory ".ocamlformat"))
|
2021-04-12 20:18:49 -07:00
|
|
|
(when buffer-file-name
|
|
|
|
(let ((ext (file-name-extension buffer-file-name t)))
|
|
|
|
(cond ((equal ext ".eliom")
|
|
|
|
(setq-local ocamlformat-file-kind 'implementation))
|
|
|
|
((equal ext ".eliomi")
|
|
|
|
(setq-local ocamlformat-file-kind 'interface)))))
|
2019-07-08 21:58:05 +02:00
|
|
|
(setq +format-with 'ocamlformat))))
|
2021-10-19 01:54:17 +01:00
|
|
|
|
|
|
|
;; Tree sitter
|
|
|
|
(eval-when! (featurep! +tree-sitter)
|
|
|
|
(add-hook! 'tuareg-mode-hook #'turn-on-tree-sitter-mode))
|