lang/ocaml: refactor & reformat
This ensures that users' after! blocks have precendence over ocaml packages.
This commit is contained in:
parent
56393420e5
commit
52dc5001bc
1 changed files with 63 additions and 65 deletions
|
@ -26,21 +26,32 @@
|
||||||
comment-line-break-function #'+ocaml/comment-indent-new-line)
|
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)
|
:unless (featurep! +lsp)
|
||||||
:defer t
|
:hook (tuareg-mode . +ocaml|init-merlin)
|
||||||
:init
|
:init
|
||||||
(defun +ocaml|init-merlin ()
|
(defun +ocaml|init-merlin ()
|
||||||
"Activate `merlin-mode' if the ocamlmerlin executable exists."
|
"Activate `merlin-mode' if the ocamlmerlin executable exists."
|
||||||
(when (executable-find "ocamlmerlin")
|
(when (executable-find "ocamlmerlin")
|
||||||
(merlin-mode)))
|
(merlin-mode)))
|
||||||
(add-hook 'tuareg-mode-hook #'+ocaml|init-merlin)
|
|
||||||
|
|
||||||
|
(after! tuareg
|
||||||
(set-company-backend! 'tuareg-mode 'merlin-company-backend)
|
(set-company-backend! 'tuareg-mode 'merlin-company-backend)
|
||||||
(set-lookup-handlers! 'tuareg-mode
|
(set-lookup-handlers! 'tuareg-mode
|
||||||
:definition #'merlin-locate
|
:definition #'merlin-locate
|
||||||
:references #'merlin-occurrences
|
:references #'merlin-occurrences
|
||||||
:documentation #'merlin-document)
|
:documentation #'merlin-document))
|
||||||
:config
|
:config
|
||||||
(setq merlin-completion-with-doc t)
|
(setq merlin-completion-with-doc t)
|
||||||
|
|
||||||
|
@ -49,12 +60,25 @@
|
||||||
"t" #'merlin-type-enclosing
|
"t" #'merlin-type-enclosing
|
||||||
"a" #'tuareg-find-alternate-file)
|
"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
|
(def-package! merlin-eldoc
|
||||||
:hook (merlin-mode . merlin-eldoc-setup))
|
:hook (merlin-mode . merlin-eldoc-setup))
|
||||||
|
|
||||||
(def-package! merlin-iedit
|
(def-package! merlin-iedit
|
||||||
:when (featurep! :editor multiple-cursors)
|
:when (featurep! :editor multiple-cursors)
|
||||||
:config
|
:defer t
|
||||||
|
:init
|
||||||
(map! :map tuareg-mode-map
|
(map! :map tuareg-mode-map
|
||||||
:v "R" #'merlin-iedit-occurrences))
|
:v "R" #'merlin-iedit-occurrences))
|
||||||
|
|
||||||
|
@ -63,47 +87,22 @@
|
||||||
:hook (merlin-mode . merlin-use-merlin-imenu)))
|
:hook (merlin-mode . merlin-use-merlin-imenu)))
|
||||||
|
|
||||||
|
|
||||||
(def-package! flycheck-ocaml
|
(def-package! ocp-indent
|
||||||
: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
|
|
||||||
;; must be careful to always defer this, it has autoloads that adds hooks
|
;; 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
|
;; which we do not want if the executable can't be found
|
||||||
:defer t
|
:hook (tuareg-mode . +ocaml|init-ocp-indent)
|
||||||
:init
|
:config
|
||||||
(defun +ocaml|init-ocp-indent ()
|
(defun +ocaml|init-ocp-indent ()
|
||||||
"Run `ocp-setup-indent', so long as the ocp-indent binary exists."
|
"Run `ocp-setup-indent', so long as the ocp-indent binary exists."
|
||||||
(when (executable-find "ocp-indent")
|
(when (executable-find "ocp-indent")
|
||||||
(ocp-setup-indent)))
|
(ocp-setup-indent))))
|
||||||
(add-hook 'tuareg-mode-hook #'+ocaml|init-ocp-indent))
|
|
||||||
|
|
||||||
|
|
||||||
(def-package! ocamlformat
|
(def-package! ocamlformat
|
||||||
:when (featurep! :editor format)
|
:when (featurep! :editor format)
|
||||||
:commands ocamlformat
|
:commands ocamlformat
|
||||||
:init
|
:hook (tuareg-mode . +ocaml|init-ocamlformat)
|
||||||
|
:config
|
||||||
(set-formatter! 'ocamlformat #'ocamlformat
|
(set-formatter! 'ocamlformat #'ocamlformat
|
||||||
:modes '(caml-mode tuareg-mode))
|
:modes '(caml-mode tuareg-mode))
|
||||||
;; TODO Fix region-based formatting support
|
;; TODO Fix region-based formatting support
|
||||||
|
@ -111,5 +110,4 @@
|
||||||
(setq +format-with 'ocp-indent)
|
(setq +format-with 'ocp-indent)
|
||||||
(when (and (executable-find "ocamlformat")
|
(when (and (executable-find "ocamlformat")
|
||||||
(locate-dominating-file default-directory ".ocamlformat"))
|
(locate-dominating-file default-directory ".ocamlformat"))
|
||||||
(setq +format-with 'ocamlformat)))
|
(setq +format-with 'ocamlformat))))
|
||||||
(add-hook 'tuareg-mode-hook #'+ocaml|init-ocamlformat)))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue