necaris / conda.el

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

`pop-to-buffer` vs `switch-to-buffer` #93

Closed wtianyi closed 2 years ago

wtianyi commented 2 years ago

In dcd47f4bea34a85e2d0640824ffb1df3ed12a7cd, @dwa changed the buffer-switching function that conda--switch-buffer-auto-activate is used to advise for, from switch-to-buffer to pop-to-buffer without much explanation.

In my use case (latest Doom Emacs (27.1) with pretty much default settings), this change makes the auto-activation stop to work for most of the buffer-switching operations including evil-switch-to-windows-last-buffer and +ivy/switch-workspace-buffer, because they call switch-to-buffer to switch buffers while it seems that under the hood, pop-to-buffer is only used by switch-to-buffer for part of the cases.

Therefore I'm bringing up this discussion and definitely would like to learn more about this change.

dwa commented 2 years ago

Hi @wtianyi. Thanks, I believe you might be right. The problem I had with switch-to-buffer was that after opening a file, I had to jump to another buffer and then back again for the conda-env-autoactivate-mode to do its job. But now that you brought it up, I did some testing and noticed that conda-current-name gets the wrong value (with pop-to-buffer) when jumping between buffers that use different conda envs. This seem to work better with switch-to-buffer.

But what is the right solution to activating conda on the opening of a file?

As a workaround, I added conda-env-activate-for-buffer to find-file-hook:

(use-package conda
  :hook
  (find-file . conda-env-activate-for-buffer)
  :config
  (conda-env-initialize-eshell)
  (conda-env-autoactivate-mode t)
  :ensure t)

So maybe that commit should be reverted, neither solution seem perfect, but at least the problem with switch-to-buffer can be worked around.

wtianyi commented 2 years ago

Thanks for your detailed explanation and tests! @dwa

I do resonate with you on the problem that the environment is not auto-activated on the opening of a file, and I too don't have a satisfying solution.

I was thinking that maybe there is some way to make "conda.el" work with "projectile" so that the conda environment is consistent and set "per project". But I have not nearly enough knowledge about "projectile" to make any proposals.

Thanks for your workaround with find-file-hook too!

wtianyi commented 2 years ago

I'm closing the issue. Should I have a better idea about projectile I'll potentially open a new issue or pull request.

wtianyi commented 2 years ago

Referring related open issues #29 #64 #81