2017-06-27 22:58:38 +02:00
|
|
|
;;; lang/ocaml/config.el -*- lexical-binding: t; -*-
|
2017-06-27 11:39:15 -07:00
|
|
|
|
2023-10-02 15:57:41 +02:00
|
|
|
(after! projectile
|
|
|
|
(pushnew! projectile-project-root-files "dune-project"))
|
|
|
|
|
2020-02-25 20:03:33 -05:00
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
|
2022-08-12 20:29:19 +02:00
|
|
|
(when (modulep! +lsp)
|
2022-07-25 18:12:03 +02:00
|
|
|
(add-hook! '(tuareg-mode-local-vars-hook
|
|
|
|
reason-mode-local-vars-hook)
|
|
|
|
:append #'lsp!))
|
2019-02-21 16:08:27 -05:00
|
|
|
|
|
|
|
|
2018-10-16 02:45:12 -04:00
|
|
|
(after! tuareg
|
2024-08-13 16:31:12 -04:00
|
|
|
(set-formatter! 'ocamlformat
|
|
|
|
'("ocamlformat" "-" "--name" filepath "--enable-outside-detected-project"
|
|
|
|
(if (locate-dominating-file default-directory ".ocamlformat")
|
|
|
|
(pcase (apheleia-formatters-extension-p "eliom" "eliomi")
|
|
|
|
("eliom" '("--impl"))
|
|
|
|
("eliomi" '("--intf")))
|
|
|
|
'("--profile=ocamlformat"))))
|
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
|
|
|
|
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
|
2022-08-12 20:29:19 +02:00
|
|
|
:when (modulep! :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
|
2022-08-12 20:29:19 +02:00
|
|
|
:unless (modulep! +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
|
2022-08-17 01:16:08 +01:00
|
|
|
:when (and (modulep! :checkers syntax)
|
|
|
|
(not (modulep! :checkers syntax +flymake)))
|
|
|
|
|
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
|
2022-08-12 20:29:19 +02:00
|
|
|
:when (modulep! :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
|
2022-08-12 20:29:19 +02:00
|
|
|
:when (modulep! :emacs imenu)
|
2019-07-08 21:58:05 +02:00
|
|
|
:hook (merlin-mode . merlin-use-merlin-imenu)))
|
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! ocp-indent
|
2024-08-13 16:32:59 -04:00
|
|
|
:hook (tuareg-mode-local-vars . ocp-setup-indent)
|
|
|
|
:hook (caml-mode-local-vars . ocp-indent-caml-mode-setup)
|
|
|
|
:init
|
|
|
|
(defadvice! +ocaml--init-ocp-indent-maybe-h (fn &rest args)
|
|
|
|
"Run `ocp-setup-indent' only if the ocp-indent binary is found."
|
|
|
|
:around #'ocp-setup-indent
|
|
|
|
(when (executable-find ocp-indent-path)
|
|
|
|
(apply fn args)))
|
2019-07-08 21:58:05 +02:00
|
|
|
:config
|
2024-08-13 16:32:59 -04:00
|
|
|
;; HACK: The package adds these hooks, but they're redundant (even
|
|
|
|
;; counter-productive) with the hooks I add above.
|
|
|
|
(remove-hook 'tuareg-mode-hook #'ocp-setup-indent)
|
|
|
|
(remove-hook 'caml-mode-hook #'ocp-indent-caml-mode-setup))
|
2019-07-08 21:58:05 +02:00
|
|
|
|
2021-10-19 01:54:17 +01:00
|
|
|
|
2024-04-10 17:50:14 +05:30
|
|
|
(use-package! opam-switch-mode
|
2024-08-13 16:32:59 -04:00
|
|
|
:hook (tuareg-mode-local-vars . opam-switch-mode)
|
|
|
|
:preface
|
|
|
|
(map! :after tuareg
|
|
|
|
:localleader
|
2024-04-10 17:50:14 +05:30
|
|
|
:map tuareg-mode-map
|
|
|
|
"w" #'opam-switch-set-switch)
|
2024-08-13 16:32:59 -04:00
|
|
|
:init
|
|
|
|
(defadvice! +ocaml--init-opam-switch-mode-maybe-h (fn &rest args)
|
2024-04-10 17:50:14 +05:30
|
|
|
"Activate `opam-switch-mode' if the opam executable exists."
|
2024-08-13 16:32:59 -04:00
|
|
|
:around #'opam-switch-mode
|
|
|
|
(when (executable-find opam-switch-program-name)
|
|
|
|
(apply fn args)))
|
2024-04-10 17:50:14 +05:30
|
|
|
:config
|
|
|
|
;; Use opam to set environment
|
|
|
|
(setq tuareg-opam-insinuate t)
|
|
|
|
(opam-switch-set-switch (tuareg-opam-current-compiler)))
|
|
|
|
|
2024-08-13 16:32:59 -04:00
|
|
|
|
2024-08-15 23:21:37 -04:00
|
|
|
(when (modulep! +tree-sitter)
|
2024-08-13 16:32:59 -04:00
|
|
|
(add-hook 'tuareg-mode-local-vars-hook #'tree-sitter!))
|