wWA5RnA4n2P3w2WvfHq · 2022-02-14 18:24
Apparently there is a package called python. It's built-in, and also distributed through GNU ELPA: [https://elpa.gnu.org/packages/python.html](https://elpa.gnu.org/packages/python.html)
And there is *different one* called python-mode in MELPA: [https://melpa.org/#/python-mode](https://melpa.org/#/python-mode), with upstream at [https://gitlab.com/python-mode-devs/python-mode/](https://gitlab.com/python-mode-devs/python-mode/)
What is the difference between them?
The background of my question is that I tried to setup my Emacs 27 as a python environment with a language server like David Wilson (aka SystemCrafter) described in his tutorial. This is a codesnippet of it.
```lisp
(use-package lsp-mode
:commands (lsp lsp-deferred)
:init
(setq lsp-keymap-prefix "C-l")
:config
(lsp-enable-which-key-integration t)
)
(use-package python-mode
:ensure t
:hook
(python-mode . lsp-deferred)
:custom
(python-shell-interpreter "python3")
)
```
I am not sure but it looks like that the `python-mode` here cause the use of the MELPA version of `python-mode`. How can I setup the inbuild python mode of Emacs include the use of the language server?
wargxs · 2022-02-14 19:32
Can you try use-package python instead of use-package python-mode?
JDRiverRun · 2022-02-14 21:30
Yes, this is confusing. python.el (which implements `python-mode`, sigh) was created by Emacs users for python. The separate package python-mode.el *also* implements its own `python-mode`, but was written and is maintained by people connected to the python project. The former is shipped with Emacs. The latter includes a bunch of custom python modules to aid with completion and other things, which it does by interrogating a live python process (python.el also does this, but to a lesser extent).
To add yet more, there is elpy.el, which is a package that sits on top of python.el and adds lots of other features, like (Jedi-based) refactoring/renaming, syntax checking, venv support, etc.
But if you are using lsp-mode, most of the in-buffer "code awareness/actions" like completion, docstring, renaming and code lookup, etc. will come from the lsp server. So in that case, the differences I expect will not be that great, and come down to fontification, key bindings, code manipulation, navigation conveniences, and that type of thing.
wWA5RnA4n2P3w2WvfHq · 2022-02-15 08:36
Elpy is not an option. I still run this in a different configuration and have some problems with it. And it is to much for me. I only need code highlighting, linting and as a bonus some completion and documentation.
If I understood your right there is no big/relevant difference between the two python modes/packages? In that case I would go for the Emacs inbuild mode.
What confuses me is that I can not see any package in \`M-x list-packages\` named \`python\` or \`python-mode\`. How do I find out which one is installed or currently active?
JDRiverRun · 2022-02-15 18:00
*If* you use LSP, they will be pretty similar, for the stuff lsp-mode isn't already delivering. C-h f python-mode, click on the file name and you'll see whether it's in elpa or the distributed packages.
mickeyp · 2022-02-15 19:41
Sigh, yeah, the history around it is even more complex...
The present python mode that ships with Emacs is a wholesale, more or less, replacement for the _old_ one that used to ship with Emacs. The original was written by Dave Love, if I recall correctly. Both are annoyingly named `python.el`
The `python-mode.el` that OP refers to is indeed one by people associated with the python project.
One common difference -- back in the day anyway -- was that `python-mode.el` did a rather poor job of behaving like a proper Emacs major mode. Dumb things like not supporting `kill-sexp` & friends on triple-quoted docstrings, among other grievances. It did have a lot more features, in theory, but none of them worked well.
Dave Love's old mode behaved like an Emacs mode should, but had fewer overall features, and a couple of weird remnants from a bygone era, like support for "bicycle repair man", a refactoring tool that never really worked very well either.
The "new" mode that ships with Emacs is -- today -- pretty good. It wasn't in the beginning, and why nobody bothered to extend the existing one, and instead giving it the heave-ho I'll never understand. But meh, I digress. I lugged around the old one for about 5-6 years before I finally switched to the default one. I recommend OP stick to the built-in one, enable tree-sitter in it + lsp/eglot and not worry :)