diff --git a/modules/lang/ocaml/config.el b/modules/lang/ocaml/config.el index 27a57ac21..de338bcdd 100644 --- a/modules/lang/ocaml/config.el +++ b/modules/lang/ocaml/config.el @@ -13,6 +13,13 @@ (after! tuareg + (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")))) ;; tuareg-mode has the prettify symbols itself (set-ligatures! 'tuareg-mode :alist (append tuareg-prettify-symbols-basic-alist @@ -101,23 +108,6 @@ (ocp-setup-indent)))) -(use-package! ocamlformat - :when (modulep! :editor format) - :commands ocamlformat - :hook (tuareg-mode-local-vars . +ocaml-init-ocamlformat-h) - :config - ;; TODO Fix region-based formatting support - (defun +ocaml-init-ocamlformat-h () - (setq-local +format-with 'ocp-indent) - (when (and (executable-find "ocamlformat") - (locate-dominating-file default-directory ".ocamlformat")) - (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))))) - (setq-local +format-with 'ocamlformat)))) (use-package! opam-switch-mode :hook (tuareg-mode-local-vars . +ocaml-init-opam-switch-h) diff --git a/modules/lang/ocaml/packages.el b/modules/lang/ocaml/packages.el index bf64fb7e4..6bb5a5a20 100644 --- a/modules/lang/ocaml/packages.el +++ b/modules/lang/ocaml/packages.el @@ -18,11 +18,6 @@ (when (modulep! :tools eval) (package! utop :pin "384b3098c8c4a2e26b87167053952b753aa8a63a")) -(when (modulep! :editor format) - (package! ocamlformat - :recipe (:host github :repo "ocaml-ppx/ocamlformat" :files ("emacs/*.el")) - :pin "c43f89bc0ebd536009151814214320bdf3988c50")) - (package! dune :recipe (:host github :repo "ocaml/dune" :files ("editor-integration/emacs/*.el")) :pin "aac3d84f1d5abdf276d72be3dccac23bf99b3c7c")