emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/tuareg 481b42af1c 1/2: feat: Add support for opam-switch-m


From: ELPA Syncer
Subject: [nongnu] elpa/tuareg 481b42af1c 1/2: feat: Add support for opam-switch-mode (>= 1.6)
Date: Tue, 18 Jul 2023 16:03:10 -0400 (EDT)

branch: elpa/tuareg
commit 481b42af1ceba9b4018dc4cdfcb4051aeac4fbc7
Author: Erik Martin-Dorel <erik.martin-dorel@irit.fr>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    feat: Add support for opam-switch-mode (>= 1.6)
    
    * Add option `tuareg-kill-ocaml-on-opam-switch` (default: t)
      and related function `(tuareg-kill-ocaml-on-opam-switch)`
      that kills the ocaml toplevel just before we change the opam switch
      using the OPSW menu-bar or the OPSW mode-bar from opam-switch-mode.
    
    * See: https://github.com/ProofGeneral/opam-switch-mode,
      a package available in MELPA, MELPA Stable, NonGNU-devel, NonGNU
      that just requires (emacs "25.1").
    
    * This feature typically expects `tuareg-opam-insinuate` to be nil.
---
 CHANGES.md     |  5 +++++
 tuareg-opam.el |  9 +++++++--
 tuareg.el      | 30 ++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 9c8e27b01d..0ab6acc07b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,8 @@
+unreleased
+----------
+
+* Add support for 
[opam-switch-mode](https://github.com/ProofGeneral/opam-switch-mode): enable 
the mode with <kbd>M-x opam-switch-mode</kbd> or add an automatic hook 
`(add-hook 'tuareg-mode-hook #'opam-switch-mode)`.
+
 3.0.1 2022-09-29
 ----------------
 
diff --git a/tuareg-opam.el b/tuareg-opam.el
index 658e9f3f0c..b3bd0395b2 100644
--- a/tuareg-opam.el
+++ b/tuareg-opam.el
@@ -348,7 +348,8 @@ issue an \"opam switch\" in a shell.  If this variable is 
set to
 t, Tuareg will try to use opam to set the right environment for
 `compile', `run-ocaml' and `merlin-mode' based on the current
 opam switch at the time the command is run (provided opam is
-found).  You may also use `tuareg-opam-update-env' to set the
+found).  You may also use `tuareg-opam-update-env', or the menus
+from the ELPA package `opam-switch-mode', to set the
 environment for another compiler from within emacs (without
 changing the opam switch).  Beware that setting it to t causes
 problems if you compile under tramp."
@@ -382,7 +383,11 @@ error message as a string)."
 
 ;;;###autoload
 (defun tuareg-opam-update-env (switch)
-  "Update the environment to follow current OPAM switch configuration."
+  "Update the environment to follow current OPAM switch configuration.
+
+You may also be interested in the ELPA package `opam-switch-mode' that
+provides a similar feature, along with a menu-bar and a mode-bar menu
+`\"OPSW\"'; see https://github.com/ProofGeneral/opam-switch-mode.";
   (interactive
    (let* ((compl (tuareg-opam-installed-compilers))
           (current (tuareg-opam-current-compiler))
diff --git a/tuareg.el b/tuareg.el
index c71943700b..d9461e76a0 100644
--- a/tuareg.el
+++ b/tuareg.el
@@ -3924,6 +3924,36 @@ If the region is active, evaluate all phrases 
intersecting the region."
     (with-current-buffer tuareg-interactive-buffer-name
       (comint-kill-subjob))))
 
+(defcustom tuareg-kill-ocaml-on-opam-switch t
+  "If t, kill the OCaml toplevel before the opam switch changes.
+If the user changes the opam switch using `opam-switch-set-switch'
+or an `\"OPSW\"' menu from `opam-switch-mode', this option asks to
+kill the OCaml toplevel process, so that the next eval command
+starts a new process, typically with a different OCaml version
+from a different opam switch.
+
+See https://github.com/ProofGeneral/opam-switch-mode
+
+Note: `opam-switch-mode' triggers automatic changes for `exec-path'
+and `process-environment', which are useful to find the `\"ocaml\"'
+binary and that of its subprocesses, in the ambient opam switch.
+
+`opam-switch-mode' 1.6+ is compatible with `tuareg-mode' whatever
+is the value of `tuareg-opam-insinuate' (albeit the default value
+nil is recommended as it omits the `\"opam exec --\"' wrapper)."
+  :type 'boolean)
+
+(defun tuareg--kill-ocaml-on-opam-switch ()
+  "Kill the OCaml toplevel before the opam switch changes.
+This function is for the `opam-switch-mode' hook
+`opam-switch-before-change-opam-switch-hook', which runs just
+before the user changes the opam switch through `opam-switch-mode'."
+  (when tuareg-kill-ocaml-on-opam-switch
+    (tuareg-kill-ocaml)))
+
+(add-hook 'opam-switch-before-change-opam-switch-hook
+          #'tuareg--kill-ocaml-on-opam-switch t)
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;                               Menu support
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]