Function: tuareg-opam-update-env

tuareg-opam-update-env is an interactive and natively compiled function defined in tuareg-opam.el.

This command is obsolete since 2023-07; use opam-switch-set-switch instead.

Signature

(tuareg-opam-update-env SWITCH)

Documentation

Update the environment to follow current OPAM switch configuration.

Delegate the task to opam-switch-set-switch if the minor mode opam-switch-mode (https://github.com/ProofGeneral/opam-switch-mode) is installed. This ELPA package also provides a menu-bar and a mode-bar menu "OPSW".

Key Bindings

tuareg-mode-map C-c C-w

Source Code

;; Defined in /nix/store/6mbh851dhnag8f92qfrlh9ckldzwf6c6-emacs-packages-deps/share/emacs/site-lisp/elpa/tuareg-20260626.936/tuareg-opam.el
;;;###autoload
(defun tuareg-opam-update-env (switch)
  "Update the environment to follow current OPAM switch configuration.

Delegate the task to `opam-switch-set-switch' if the minor mode
`opam-switch-mode' (https://github.com/ProofGeneral/opam-switch-mode)
is installed. This ELPA package also provides a menu-bar and a
mode-bar menu `\"OPSW\"'."
  (declare (obsolete opam-switch-set-switch "2023-07"))
  (interactive
   (let* ((compl (tuareg-opam-installed-compilers))
          (current (tuareg-opam-current-compiler))
          (default (if current current "current"))
          (prompt (format "opam switch (default: %s): " default)))
     (if (fboundp 'opam-switch-set-switch)
         '(use-opam-switch-interactively)
       (list (completing-read prompt compl)))))
  (if (fboundp 'opam-switch-set-switch)
      (if (eq switch 'use-opam-switch-interactively)
          (call-interactively #'opam-switch-set-switch)
        (opam-switch-set-switch switch))
    (let* ((switch (if (string= switch "") nil switch))
           (env (tuareg-opam-config-env switch)))
      (if env
          (dolist (v env)
            (setenv (car v) (cadr v))
            (when (string= (car v) "PATH")
              (setq exec-path (split-string (cadr v) path-separator))))
        (message "Switch %s does not exist (or opam not found)" switch)))))