wWA5RnA4n2P3w2WvfHq · 2022-03-18 14:28
I do use `use-package` but for a lot of packages there is not install and config instructions for it.
This is my working configuration which I have some questions about.
- The `eglot` start (via `eglot-ensure`) is configured in the `(use-package python-mode` block via a `:hook`. Python modes starts eglot. Is this a good solution?
- `company` start is configured via a `:hook` in `(use-package company` block and starts when `eglot` comes up.
```emacslisp
; ....
; language server (replacement for lsp-mode)
(use-package eglot)
(use-package python-mode
:ensure nil ; makes sure that Emacs in-build python-mode is used
:hook
(python-mode . eglot-ensure) ; connect to language server when py-file is opened
:custom
(python-shell-interpreter "python3")
)
(use-package company
:after eglot ; this line alone does not help to start company
:hook (eglot-managed-mode . company-mode) ; starts company when eglot is started
)
(use-package company-box
:hook (company-mode . company-box-mode))
; .....
```
I have some more examples; e.g. the [`ws-buttler`](https://github.com/lewang/ws-butler). Do I start it that way?
```
(use-package ws-butler
:init
(progn
(add-hock 'python-mode-hook 'ws-butler-mode)))
```
Or with a `:hook` where I do not know what I have to write there.
```
(use-package ws-butler
:hook ??????
```
Or should I use the `python-mode`?
```
(use-package python-mode
:ensure nil ; makes sure that Emacs in-build python-mode is used
:hook
(python-mode . ws-butler-mode)
```
On important point is that e.g. `ws-butler-mode` should not only start when a Python buffer is opened. It should only work in that Python buffers and not in others after it is started.
As a newbie it is very hard to decide which configuration ways I should use to start a mode. Should the mode install itself in via a hook to another mode (python)? Should the other mode (python) start it? etc etc
wargxs · 2022-03-18 19:38
I would recommend to use the build in python.el. If you use python-mode you may end up with this: https://gitlab.com/python-mode-devs/python-mode which is different from the build in one.
wWA5RnA4n2P3w2WvfHq · 2022-03-18 20:07
It is the inbuild python-mode; definitly. I had this problems with this two versions before. I double checked. The \`":ensure nil" takes care that use-package does not load any python package from (m)elpa, which in fact causes that it use the in build variant or it would throw an error if there wouldn't be any python mode in emacs.
doolio_ · 2022-03-19 22:29
If you want to use the built-in python mode then the feature name is python not python-mode. So it should be:
`use-package python` not `use-package python-mode`
wWA5RnA4n2P3w2WvfHq · 2022-03-20 12:35
As you said it works with `(use-package python)`, too. But also with my `(use-package python-mode :ensure nil)` nothing from elpa is installed and nothing from elpa is in my elpa folder.
I am not sure how to be more sure about this. Can I do a somehow do a diagnosis on that while a Python file is open in a buffer?
OK, I opened a py-file and then did `C-h m`. The help text told me this is "Python mode" definied in "python.el". I jumped into that file and did `M-: (buffer-file-name)` which told me this is `"/usr/share/emacs/27.1/lisp/progmodes/python.el.gz"`.
Is this Emacs own in-build python mode?
The result is the same when I do `(use-package python)`. Interesseting.
doolio_ · 2022-03-20 13:01
> Is this Emacs own in-build python mode?
Yes. I suspect it still works in your case as the built in python mode provided by python.el is called `python-mode`. In the same way org.el provides `org-mode`. I can't comment on whether that is the correct convention and concede different packages follow different conventions.
In any case, in your `use-package` form you write the feature name as the first argument. That is whatever symbol is written in the provide expression. In this case, `(provide 'python)`.
Edit: add missing word; grammar