diff --git a/modules/lang/ocaml/config.el b/modules/lang/ocaml/config.el index f25c6435b..9df9b6c2e 100644 --- a/modules/lang/ocaml/config.el +++ b/modules/lang/ocaml/config.el @@ -26,90 +26,88 @@ comment-line-break-function #'+ocaml/comment-indent-new-line) - (def-package! merlin - :unless (featurep! +lsp) - :defer t + (def-package! utop + :when (featurep! :tools eval) + :hook (tuareg-mode . +ocaml|init-utop) :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) + (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) + :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))) + + (after! tuareg (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! :localleader - :map tuareg-mode-map - "t" #'merlin-type-enclosing - "a" #'tuareg-find-alternate-file) - - (def-package! merlin-eldoc - :hook (merlin-mode . merlin-eldoc-setup)) - - (def-package! merlin-iedit - :when (featurep! :editor multiple-cursors) - :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))) + :documentation #'merlin-document)) + :config + (setq merlin-completion-with-doc t) + (map! :localleader + :map tuareg-mode-map + "t" #'merlin-type-enclosing + "a" #'tuareg-find-alternate-file) (def-package! flycheck-ocaml :when (featurep! :tools flycheck) - :init + :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))) - (add-hook 'merlin-mode-hook #'+ocaml|init-flycheck)) + (flycheck-ocaml-setup)))) + (def-package! merlin-eldoc + :hook (merlin-mode . merlin-eldoc-setup)) - (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 - ;; 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 + (def-package! merlin-iedit + :when (featurep! :editor multiple-cursors) :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)) + (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))) - (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))) +(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 + :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)))) + + +(def-package! ocamlformat + :when (featurep! :editor format) + :commands ocamlformat + :hook (tuareg-mode . +ocaml|init-ocamlformat) + :config + (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))))