mirror of
https://github.com/SqrtMinusOne/micromamba.el.git
synced 2025-12-10 21:23:03 +03:00
Only activate if same env not active
This commit is contained in:
parent
359eb819c8
commit
497497537f
1 changed files with 10 additions and 5 deletions
|
|
@ -240,6 +240,11 @@ The parameters value is an alist as defined by
|
||||||
(setenv (car var) (cdr var)))
|
(setenv (car var) (cdr var)))
|
||||||
(setq eshell-path-env (getenv "PATH")))
|
(setq eshell-path-env (getenv "PATH")))
|
||||||
|
|
||||||
|
(defun micromamba--env-name-to-prefix (name)
|
||||||
|
"Get the prefix of an environment with NAME."
|
||||||
|
(let ((envs (micromamba-envs)))
|
||||||
|
(alist-get name envs nil nil #'equal)))
|
||||||
|
|
||||||
;; "public" functions
|
;; "public" functions
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun micromamba-activate (prefix)
|
(defun micromamba-activate (prefix)
|
||||||
|
|
@ -255,8 +260,7 @@ full paths."
|
||||||
envs nil nil #'equal))))
|
envs nil nil #'equal))))
|
||||||
;; To allow calling the function with env name as well
|
;; To allow calling the function with env name as well
|
||||||
(unless (string-match-p (rx bos "/") prefix)
|
(unless (string-match-p (rx bos "/") prefix)
|
||||||
(let ((envs (micromamba-envs)))
|
(setq prefix (micromamba--env-name-to-prefix prefix))
|
||||||
(setq prefix (alist-get prefix envs nil nil #'equal)))
|
|
||||||
(unless prefix
|
(unless prefix
|
||||||
(user-error "Environment %s not found" prefix)))
|
(user-error "Environment %s not found" prefix)))
|
||||||
(micromamba-deactivate)
|
(micromamba-deactivate)
|
||||||
|
|
@ -291,14 +295,15 @@ This can be set by a buffer-local or project-local variable (e.g. a
|
||||||
`environment.yml` or similar at the project level."
|
`environment.yml` or similar at the project level."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((inferred-env (micromamba--infer-env-from-buffer)))
|
(let ((inferred-env (micromamba--infer-env-from-buffer)))
|
||||||
(when inferred-env
|
(when (and inferred-env
|
||||||
|
(not (string= micromamba-env-current-prefix
|
||||||
|
(micromamba--env-name-to-prefix inferred-env))))
|
||||||
(micromamba-activate inferred-env))))
|
(micromamba-activate inferred-env))))
|
||||||
|
|
||||||
(defun micromamba--switch-buffer-auto-activate (&rest args)
|
(defun micromamba--switch-buffer-auto-activate (&rest args)
|
||||||
"Add Conda environment activation if a buffer has a file, handling ARGS."
|
"Add Conda environment activation if a buffer has a file, handling ARGS."
|
||||||
(let ((filename (buffer-file-name)))
|
(let ((filename (buffer-file-name)))
|
||||||
(when filename
|
(when filename
|
||||||
;; (message "switch-buffer auto-activating on <%s>" filename)
|
|
||||||
(with-demoted-errors "Error: %S"
|
(with-demoted-errors "Error: %S"
|
||||||
(micromamba-env-activate-for-buffer)))))
|
(micromamba-env-activate-for-buffer)))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue