refactor(ocaml): use apheleia instead of ocamlformat.el

The ocamlformat.el package reinvents what Apheleia is already doing, but
Apheleia's default definition for ocamlformat is a little simplistic.
This merges the efforts of both and allows us to cut down on an unneeded
dependency.
This commit is contained in:
Henrik Lissner 2024-08-13 16:31:12 -04:00
parent 95e0b43012
commit fa153d5b91
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 7 additions and 22 deletions

View file

@ -13,6 +13,13 @@
(after! tuareg (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 ;; tuareg-mode has the prettify symbols itself
(set-ligatures! 'tuareg-mode :alist (set-ligatures! 'tuareg-mode :alist
(append tuareg-prettify-symbols-basic-alist (append tuareg-prettify-symbols-basic-alist
@ -101,23 +108,6 @@
(ocp-setup-indent)))) (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 (use-package! opam-switch-mode
:hook (tuareg-mode-local-vars . +ocaml-init-opam-switch-h) :hook (tuareg-mode-local-vars . +ocaml-init-opam-switch-h)

View file

@ -18,11 +18,6 @@
(when (modulep! :tools eval) (when (modulep! :tools eval)
(package! utop :pin "384b3098c8c4a2e26b87167053952b753aa8a63a")) (package! utop :pin "384b3098c8c4a2e26b87167053952b753aa8a63a"))
(when (modulep! :editor format)
(package! ocamlformat
:recipe (:host github :repo "ocaml-ppx/ocamlformat" :files ("emacs/*.el"))
:pin "c43f89bc0ebd536009151814214320bdf3988c50"))
(package! dune (package! dune
:recipe (:host github :repo "ocaml/dune" :files ("editor-integration/emacs/*.el")) :recipe (:host github :repo "ocaml/dune" :files ("editor-integration/emacs/*.el"))
:pin "aac3d84f1d5abdf276d72be3dccac23bf99b3c7c") :pin "aac3d84f1d5abdf276d72be3dccac23bf99b3c7c")