From 6813db6d54c8f219724fb22d3d7b4a74a9a63772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Thibault?= Date: Thu, 31 Oct 2024 15:21:05 +0100 Subject: [PATCH 1/5] fix(ocaml): wrap `opam-switch-set-switch` in `after! tuareg` block This fixes an issue where `tuareg-opam-current-compiler` would be undefined if `opam-switch-mode` was loaded before `tuareg`. --- modules/lang/ocaml/config.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/lang/ocaml/config.el b/modules/lang/ocaml/config.el index 4ca5805d555..2a39d5ad8f0 100644 --- a/modules/lang/ocaml/config.el +++ b/modules/lang/ocaml/config.el @@ -125,10 +125,10 @@ (when (executable-find opam-switch-program-name) (apply fn args))) :config - ;; Use opam to set environment - (setq tuareg-opam-insinuate t) - (opam-switch-set-switch (tuareg-opam-current-compiler))) - + (after! tuareg + ;; Use opam to set environment + (setq tuareg-opam-insinuate t) + (opam-switch-set-switch (tuareg-opam-current-compiler)))) (when (modulep! +tree-sitter) (add-hook 'tuareg-mode-local-vars-hook #'tree-sitter!)) From 1cf2bd481bfd0facd012d7dfef4cd4e4da2ef0f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Thibault?= Date: Thu, 31 Oct 2024 15:23:08 +0100 Subject: [PATCH 2/5] feat(coq): add `opam-switch-mode` --- modules/lang/coq/config.el | 14 ++++++++++++++ modules/lang/coq/packages.el | 2 ++ 2 files changed, 16 insertions(+) diff --git a/modules/lang/coq/config.el b/modules/lang/coq/config.el index 8427e2cf817..71f26fe2a83 100644 --- a/modules/lang/coq/config.el +++ b/modules/lang/coq/config.el @@ -93,3 +93,17 @@ "e" #'company-coq-document-error "E" #'company-coq-browse-error-messages "h" #'company-coq-doc))) + +(use-package! opam-switch-mode + :hook (coq-mode . opam-switch-mode) + :preface + (map! :after coq + :localleader + :map coq-mode-map + "w" #'opam-switch-set-switch) + :init + (defadvice! +coq--init-opam-switch-mode-maybe-h (fn &rest args) + "Activate `opam-switch-mode' if the opam executable exists." + :around #'opam-switch-mode + (when (executable-find opam-switch-program-name) + (apply fn args)))) diff --git a/modules/lang/coq/packages.el b/modules/lang/coq/packages.el index f31d1f03937..790dac3622a 100644 --- a/modules/lang/coq/packages.el +++ b/modules/lang/coq/packages.el @@ -3,3 +3,5 @@ (package! proof-general :pin "3a99da275523c8f844fdfa3dd073295eece939f3") (package! company-coq :pin "5affe7a96a25df9101f9e44bac8a828d8292c2fa") + +(package! opam-switch-mode :pin "1069e56a662f23ea09d4e05611bdedeb99257012") From 03e545592130aa1370049b0953049ec971390ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Thibault?= Date: Thu, 31 Oct 2024 15:23:08 +0100 Subject: [PATCH 3/5] fix(coq): add `+no-opam` flag Some Rocq users don't use OPAM, so I add a new flag that can be used to turn off loading features that depend on `opam`, such as `opam-switch-mode`. --- modules/lang/coq/README.org | 6 +++++- modules/lang/coq/config.el | 27 ++++++++++++++------------- modules/lang/coq/doctor.el | 6 ++++++ modules/lang/coq/packages.el | 3 ++- 4 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 modules/lang/coq/doctor.el diff --git a/modules/lang/coq/README.org b/modules/lang/coq/README.org index d2000e8db52..8019c0a004b 100644 --- a/modules/lang/coq/README.org +++ b/modules/lang/coq/README.org @@ -13,11 +13,15 @@ This module adds [[https://coq.inria.fr][coq]] support, powered by [[https://pro /This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]] ** Module flags -/This module has no flags./ +- +opam-switch :: + Enable ~opam-switch-mode~ integration. Allows for switching OPAM switch. + Requires OPAM to be installed. ** Packages - [[doom-package:proof-general]] - [[doom-package:company-coq]] +- [[doom-package:opam-switch-mode]] if [[doom-module:+opam-switch]] + ** Hacks + Replaces coq-mode abbrevs with yasnippet snippets from doom's snippet library diff --git a/modules/lang/coq/config.el b/modules/lang/coq/config.el index 71f26fe2a83..3acc68a29ff 100644 --- a/modules/lang/coq/config.el +++ b/modules/lang/coq/config.el @@ -94,16 +94,17 @@ "E" #'company-coq-browse-error-messages "h" #'company-coq-doc))) -(use-package! opam-switch-mode - :hook (coq-mode . opam-switch-mode) - :preface - (map! :after coq - :localleader - :map coq-mode-map - "w" #'opam-switch-set-switch) - :init - (defadvice! +coq--init-opam-switch-mode-maybe-h (fn &rest args) - "Activate `opam-switch-mode' if the opam executable exists." - :around #'opam-switch-mode - (when (executable-find opam-switch-program-name) - (apply fn args)))) +(unless (modulep! +no-opam) + (use-package! opam-switch-mode + :hook (coq-mode . opam-switch-mode) + :preface + (map! :after coq + :localleader + :map coq-mode-map + "w" #'opam-switch-set-switch) + :init + (defadvice! +coq--init-opam-switch-mode-maybe-h (fn &rest args) + "Activate `opam-switch-mode' if the opam executable exists." + :around #'opam-switch-mode + (when (executable-find opam-switch-program-name) + (apply fn args))))) diff --git a/modules/lang/coq/doctor.el b/modules/lang/coq/doctor.el new file mode 100644 index 00000000000..3395df797c1 --- /dev/null +++ b/modules/lang/coq/doctor.el @@ -0,0 +1,6 @@ +;; -*- lexical-binding: t; no-byte-compile: t; -*- +;;; lang/coq/doctor.el + +(unless (modulep! +no-opam) + (unless (executable-find "opam") + (warn! "Couldn't find OPAM"))) diff --git a/modules/lang/coq/packages.el b/modules/lang/coq/packages.el index 790dac3622a..2fc8849c35a 100644 --- a/modules/lang/coq/packages.el +++ b/modules/lang/coq/packages.el @@ -4,4 +4,5 @@ (package! proof-general :pin "3a99da275523c8f844fdfa3dd073295eece939f3") (package! company-coq :pin "5affe7a96a25df9101f9e44bac8a828d8292c2fa") -(package! opam-switch-mode :pin "1069e56a662f23ea09d4e05611bdedeb99257012") +(unless (modulep! +no-opam) + (package! opam-switch-mode :pin "1069e56a662f23ea09d4e05611bdedeb99257012")) From a22539a849f813fd244fa6cac0433edde6962b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Thibault?= Date: Wed, 4 Jun 2025 16:56:25 +0200 Subject: [PATCH 4/5] fix(ocaml): add `+no-opam` flag Some OCaml users don't use OPAM, so I add a new flag that can be used to turn off loading features that depend on `opam`, such as `opam-switch-mode`. --- modules/lang/ocaml/config.el | 38 +++++++++++++++++----------------- modules/lang/ocaml/packages.el | 3 ++- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/modules/lang/ocaml/config.el b/modules/lang/ocaml/config.el index 2a39d5ad8f0..9328f17173c 100644 --- a/modules/lang/ocaml/config.el +++ b/modules/lang/ocaml/config.el @@ -111,29 +111,29 @@ (remove-hook 'caml-mode-hook #'ocp-indent-caml-mode-setup)) -(use-package! opam-switch-mode - :hook (tuareg-mode-local-vars . opam-switch-mode) - :preface - (map! :after tuareg - :localleader - :map tuareg-mode-map - "w" #'opam-switch-set-switch) - :init - (defadvice! +ocaml--init-opam-switch-mode-maybe-h (fn &rest args) - "Activate `opam-switch-mode' if the opam executable exists." - :around #'opam-switch-mode - (when (executable-find opam-switch-program-name) - (apply fn args))) - :config - (after! tuareg - ;; Use opam to set environment - (setq tuareg-opam-insinuate t) - (opam-switch-set-switch (tuareg-opam-current-compiler)))) +(unless (modulep! +no-opam) + (use-package! opam-switch-mode + :hook (tuareg-mode-local-vars . opam-switch-mode) + :preface + (map! :after tuareg + :localleader + :map tuareg-mode-map + "w" #'opam-switch-set-switch) + :init + (defadvice! +ocaml--init-opam-switch-mode-maybe-h (fn &rest args) + "Activate `opam-switch-mode' if the opam executable exists." + :around #'opam-switch-mode + (when (executable-find opam-switch-program-name) + (apply fn args))) + :config + (after! tuareg + ;; Use opam to set environment + (setq tuareg-opam-insinuate t) + (opam-switch-set-switch (tuareg-opam-current-compiler))))) (when (modulep! +tree-sitter) (add-hook 'tuareg-mode-local-vars-hook #'tree-sitter!)) - (use-package! dune :defer t :config diff --git a/modules/lang/ocaml/packages.el b/modules/lang/ocaml/packages.el index 09fa4c871d7..26f88a145a6 100644 --- a/modules/lang/ocaml/packages.el +++ b/modules/lang/ocaml/packages.el @@ -2,7 +2,8 @@ ;;; lang/ocaml/packages.el (package! tuareg :pin "1d53723e39f22ab4ab76d31f2b188a2879305092") -(package! opam-switch-mode :pin "1069e56a662f23ea09d4e05611bdedeb99257012") +(unless (modulep! +no-opam) + (package! opam-switch-mode :pin "1069e56a662f23ea09d4e05611bdedeb99257012")) (package! ocp-indent :pin "f38578c25d62701847b1bcb45099a9020e2032fe") (package! dune :recipe (:host github :repo "ocaml/dune" :files ("editor-integration/emacs/*.el")) From 93d21466792db3bb42a2e9531322337f36932c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Thibault?= Date: Wed, 4 Jun 2025 17:04:37 +0200 Subject: [PATCH 5/5] docs(coq,ocaml): document `+no-opam` flag --- modules/lang/coq/README.org | 7 +++---- modules/lang/ocaml/README.org | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/lang/coq/README.org b/modules/lang/coq/README.org index 8019c0a004b..7e57b5e16a7 100644 --- a/modules/lang/coq/README.org +++ b/modules/lang/coq/README.org @@ -13,14 +13,13 @@ This module adds [[https://coq.inria.fr][coq]] support, powered by [[https://pro /This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]] ** Module flags -- +opam-switch :: - Enable ~opam-switch-mode~ integration. Allows for switching OPAM switch. - Requires OPAM to be installed. +- +no-opam :: + Disable features depending on OPAM. As of now, it only disables ~opam-switch-mode~ integration. ** Packages - [[doom-package:proof-general]] - [[doom-package:company-coq]] -- [[doom-package:opam-switch-mode]] if [[doom-module:+opam-switch]] +- [[doom-package:opam-switch-mode]] unless [[doom-module:+no-opam]] ** Hacks diff --git a/modules/lang/ocaml/README.org b/modules/lang/ocaml/README.org index c062f1aecf5..be4c37dd8e5 100644 --- a/modules/lang/ocaml/README.org +++ b/modules/lang/ocaml/README.org @@ -26,13 +26,15 @@ This module adds [[https://ocaml.org/][OCaml]] support to Doom Emacs, powered by - +tree-sitter :: Leverages tree-sitter for better syntax highlighting and structural text editing. Requires [[doom-module::tools tree-sitter]]. +- +no-opam :: + Disable features depending on OPAM. As of now, it only disables ~opam-switch-mode~ integration. ** Packages - [[doom-package:dune]] - [[doom-package:ocamlformat]] if [[doom-module::editor format]] - [[doom-package:ocp-indent]] - [[doom-package:tuareg]] -- [[doom-package:opam-switch-mode]] +- [[doom-package:opam-switch-mode]] unless [[doom-module::+no-opam]] - [[doom-package:utop]] if [[doom-module::tools eval]] - unless [[doom-module:+lsp]] - [[doom-package:flycheck-ocaml]] if [[doom-module::checkers syntax]]