necaris / conda.el

Emacs helper library (and minor mode) to work with conda environments
MIT License
153 stars 49 forks source link

Multiple sessions at the same time #96

Open mankoff opened 2 years ago

mankoff commented 2 years ago

I seem to have conda.el working well for one Python session at a time. Is it possible to configure conda.el to support multiple sessions?

I'd like to open proj.py in folder proj that uses ENV1. Maybe start a Python session. Maybe not. Then also open proj.py (same file name?) in folder proj (same folder name? Different path?) that uses ENV2. Then from either proj.py start Python, and toggle between them, and have each running in their own inferior *Python-ENV* buffer.

Is this possible with conda.el?

benbovy commented 2 years ago

FWIW, I have a function in my config that auto-switches the activated conda environment at the workspace level (I'm using persp-mode):

(defun +workspaces-save-conda-env (&rest _args)
  ;; Save current conda environment to a persp parameter
  (set-persp-parameter 'conda-env conda-env-current-name)
  )

(defun +workspaces-activate-conda-env (&rest _)
  ;; Restore and activate conda environment
  (conda-env-deactivate)
  (when-let* ((state (persp-parameter 'conda-env)))
    (conda-env-activate (persp-parameter 'conda-env))
    ))

(add-hook 'persp-before-deactivate-functions #'+workspaces-save-conda-env)
(add-hook 'persp-activated-functions #'+workspaces-activate-conda-env)

I guess it would be possible to have something like that at the buffer level?

necaris commented 2 years ago

conda-env-autoactivate-mode should do this, but we don't handle the multiple Python sessions -- the inferior Python is handled separately and isn't conda env aware yet. Would love a PR or help making this happen, though!