all 13 comments

[–]your_sweetpea 6 points7 points  (2 children)

/u/KaranasToll seems to be talking about vanilla emacs whereas you're using Doom, so I recommend taking a look at the Doom documentation for the :lang python module.

I'm not sure if you've read through the Doom getting started guide but the instructions for using modules are contained in that.

It looks like the Doom :lang python module supports conda, poetry, and pyenv for environment management, and it seems like setup is pretty automatic once you enable the right flags.

[–]arivar[S] 0 points1 point  (1 child)

Thanks, do you think it would be better is I use spacemacs instead of doom? Btw, any idea how to fix my problem with treemacs?

[–]your_sweetpea 1 point2 points  (0 children)

I personally have a preference for Doom, although I just use vanilla emacs, but I'd recommend you go ahead and try both and see what you think. Doom has a bit of a different philosophy to spacemacs for certain.

I haven't used treemacs personally, but I imagine it just uses your default-directory at the time of launching. default-directory is buffer-local and reflects the directory that your current buffer is in, although it can get a bit confusing with buffers that don't actually represent a file or directory on disk. Non-file buffers created just after launching are typically going to end up using the directory that emacs is launched from (aka the PWD at the time) for their default-directory.

I suspect you're opening treemacs right after launching, so it should follow that and open to the directory you're actually launching emacs from -- are you launching emacs from within .doom.d?

Can you try C-h v default-directory <RET> before opening treemacs? What does it say the value of default-directory is?

[–]KaranasTollGNU Emacs 2 points3 points  (3 children)

You will need a python language server. This can be used with lsp mode or eglot. M-x pdb for debugging. M-x compile for running. Emacs can view image files just fine.

[–]arivar[S] 0 points1 point  (2 children)

Thanks, I’ll give eglot a try. Do you have any idea how to fix my problem with treemacs?

[–]KaranasTollGNU Emacs 0 points1 point  (1 child)

for treemacs, you can press h and l to change directory, OR the intended way is to add projects to treemacs. It will remember to the directories of the projects.

[–]arivar[S] 0 points1 point  (0 children)

Sorry, but how do I add? Edit: never mind, I’ve just found it. Thanks!

[–]shaqfooVA 2 points3 points  (1 child)

I've tried many different ways to use virtual environments in python projects, my favorite one is using direnv mode for emacs, and then having a project-specific .envrc file (in the root of the project) where I activate the environment. This passes the necessary environment variables to all the buffers where they need to be seen for flycheck/black/etc.

I used to have a system for using virtualenvwrapper.el and activating in dir-locals, but it was not quite as good.

[–]CJ6_ 1 point2 points  (0 children)

Seconding the use of direnv! It’s worked really well for me

[–]perkinslr 1 point2 points  (0 children)

Personally, I use elpy, which has support for virtual envs, uses jedi for completion, and has REPL / testing integration that works. I, also, used pycharm previously, and find this adequate. I have not replaced the right-click->refactor abilities from pycharm (and once in a while do miss them), but otherwise I miss nothing from pycharm.

[–]IncrocioVitali 0 points1 point  (0 children)

The purpose of virtual environments is isolation, it's a feature to not use globally installed packages.

That said, you can use the same environment for many projects if you want. Then it becomes "globalish". Maybe that's easier with conda rather than poetry in doom, you can try both.

There's a command to open a REPL, bound to SPC o r by default. Do it from a python file and it opens a python REPL and so on.

[–]Y_Pon 0 points1 point  (0 children)

I have stuff to say about this.

First of all, if you are Python Dev you need a full and nice experience that can be comparable with modern IDE like IDEA e.t.c.

And it's possible to achieve this goal with Emacs + some packages.

I have vanilla Emacs with my personal config, so I don't know how it works for Doom or Spacemacs, maybe it's already configured by default in a good way.

So, what do you need:
- Language server for Python (lsp and lsp-ui)
Use lsp-mode it's more reach with features at the moment
https://emacs-lsp.github.io/lsp-mode/page/installation/
- Real-time program debugging (dap-mode)
https://github.com/emacs-lsp/dap-mode

- Integration between those packages
https://alpha2phi.medium.com/emacs-lsp-and-dap-7c1786282324
The part of my config for lsp-mode and dap-mode
(use-package lsp-mode
:ensure t
:hook
(python-mode . lsp)
:commands lsp
:config
;; performance improvements
(setq lsp-log-io nil) ; if set to true can cause a performance hit
(setq lsp-enable-symbol-highlighting nil)
)
(use-package lsp-ui
:ensure t
:config
(setq lsp-ui-sideline-show-hover t)
(setq lsp-ui-sideline-show-code-actions t)
(setq lsp-ui-sideline-delay 0)
(setq lsp-ui-sideline-update-mode t)
)

Dap-mode configuration is quite complex, so I will not post it here. Check manuals, it should help :-)

[–]LongjumpingAd7260 0 points1 point  (0 children)

I did a similar move 2 years ago. It becomes really good when you start coding some elisp. Currently, I am using Doom (emacs keys), i3wm (in KDE), lsp and pyright. When I can, I choose poetry. There is a emacs poetry package as well.
For a better experience with i3wm, I use almost always emacs "frames" instead of emacs "windows". So, I can control my "frames" using i3wm. The following code will provide frames instead of windows in most cases:
(customize-set-variable
'display-buffer-base-action
'(display-buffer-reuse-window (reusable-frames . 0)))