necaris / conda.el

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

once conda-env-autoactivate-mode is called for one buffer, it activates for everyfile #152

Open dadinn opened 10 months ago

dadinn commented 10 months ago

expected behaviour

I would like to automatically enable conda bode for eveny Python file I open. In particular, I would like the environment to be activated according to the first environment.yaml file found by traversing upward on the parent directories.

experienced behaviour

I tried to add conda-env-autoactivate-mood function to elpy-mode-book, assuming that this only applies for the current python buffer only. The docs actually say this: "This mode automatically tries to activate a conda environment for the current buffer."

The mode gets activated, and loads the correct environment automatically. I am not exactly sure why, but sometimes there is a glitch, and I don't get the message to notify that the correct environment has been activated, but when I open another file in the same project, I do get the message. From then on switching back to the original file will also display the message again, that the correct environment has been activated.

A more serious problem is that once hook is called and the mode is activated, then on every other file will activate a conda environment too (e.g. even org-mode files). In such case, when the project has no environment.yaml file, then the base environment gets activated.

This is not the behaviour I expect.

I found there is another function conda-env-activate-for-buffer. When using this function in the elpy-mode-hook, then when opening a python file the environment does not get activated.

Interestingly, I noticed there is also a variable named conda-env-autoactivate-mode. Surprisingly, the documentation for this variable says that it is defined in init.el, but then opening the link leads to nowhere (unsurprisingly, as there is no such variable defined in my init.el config).

environment

OS: Debian 12 Emacs: 27.1 conda.el commit hash: 6a6a27dad7ab696b41b54a1cb7591ca489133fec