lang/ocaml: refactor & reformat

This ensures that users' after! blocks have precendence over ocaml
packages.
This commit is contained in:
Henrik Lissner 2019-07-08 21:58:05 +02:00
parent 56393420e5
commit 52dc5001bc
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -26,21 +26,32 @@
comment-line-break-function #'+ocaml/comment-indent-new-line)
(def-package! merlin
(def-package! utop
:when (featurep! :tools eval)
:hook (tuareg-mode . +ocaml|init-utop)
: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)))))
(def-package! merlin
:unless (featurep! +lsp)
:defer t
:hook (tuareg-mode . +ocaml|init-merlin)
:init
(defun +ocaml|init-merlin ()
"Activate `merlin-mode' if the ocamlmerlin executable exists."
(when (executable-find "ocamlmerlin")
(merlin-mode)))
(add-hook 'tuareg-mode-hook #'+ocaml|init-merlin)
(after! tuareg
(set-company-backend! 'tuareg-mode 'merlin-company-backend)
(set-lookup-handlers! 'tuareg-mode
:definition #'merlin-locate
:references #'merlin-occurrences
:documentation #'merlin-document)
:documentation #'merlin-document))
:config
(setq merlin-completion-with-doc t)
@ -49,12 +60,25 @@
"t" #'merlin-type-enclosing
"a" #'tuareg-find-alternate-file)
(def-package! flycheck-ocaml
:when (featurep! :tools flycheck)
:hook (merlin-mode . +ocaml|init-flycheck)
:config
(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))))
(def-package! merlin-eldoc
:hook (merlin-mode . merlin-eldoc-setup))
(def-package! merlin-iedit
:when (featurep! :editor multiple-cursors)
:config
:defer t
:init
(map! :map tuareg-mode-map
:v "R" #'merlin-iedit-occurrences))
@ -63,47 +87,22 @@
:hook (merlin-mode . merlin-use-merlin-imenu)))
(def-package! flycheck-ocaml
:when (featurep! :tools flycheck)
: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))
(def-package! utop
:when (featurep! :tools 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))
(def-package! ocp-indent
(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
:hook (tuareg-mode . +ocaml|init-ocp-indent)
:config
(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))
(ocp-setup-indent))))
(def-package! ocamlformat
(def-package! ocamlformat
:when (featurep! :editor format)
:commands ocamlformat
:init
:hook (tuareg-mode . +ocaml|init-ocamlformat)
:config
(set-formatter! 'ocamlformat #'ocamlformat
:modes '(caml-mode tuareg-mode))
;; TODO Fix region-based formatting support
@ -111,5 +110,4 @@
(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)))
(setq +format-with 'ocamlformat))))