mirror of https://github.com/astral-sh/ruff
Limit `eglot-format` hook to eglot-managed Python buffers (#21459)
Running `eglot-format` in buffers not managed by Eglot causes a `jsonrpc-error` in Emacs 30. It may also display a `documentFormattingProvider` warning when the server does not support formatting. Add checks for both.
This commit is contained in:
parent
04a3ec3689
commit
c16ef709f6
|
|
@ -400,11 +400,13 @@ Ruff can be utilized as a language server via [`Eglot`](https://github.com/joaot
|
||||||
To enable Ruff with automatic formatting on save, use the following configuration:
|
To enable Ruff with automatic formatting on save, use the following configuration:
|
||||||
|
|
||||||
```elisp
|
```elisp
|
||||||
(add-hook 'python-mode-hook 'eglot-ensure)
|
|
||||||
(with-eval-after-load 'eglot
|
(with-eval-after-load 'eglot
|
||||||
(add-to-list 'eglot-server-programs
|
(add-to-list 'eglot-server-programs
|
||||||
'(python-mode . ("ruff" "server")))
|
'(python-base-mode . ("ruff" "server"))))
|
||||||
(add-hook 'after-save-hook 'eglot-format))
|
(add-hook 'python-base-mode-hook
|
||||||
|
(lambda ()
|
||||||
|
(eglot-ensure)
|
||||||
|
(add-hook 'after-save-hook 'eglot-format nil t)))
|
||||||
```
|
```
|
||||||
|
|
||||||
Ruff is available as [`flymake-ruff`](https://melpa.org/#/flymake-ruff) on MELPA:
|
Ruff is available as [`flymake-ruff`](https://melpa.org/#/flymake-ruff) on MELPA:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue