mirror of
https://github.com/astral-sh/ruff
synced 2026-01-07 06:34:07 -05:00
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:
@@ -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:
|
||||
|
||||
```elisp
|
||||
(add-hook 'python-mode-hook 'eglot-ensure)
|
||||
(with-eval-after-load 'eglot
|
||||
(add-to-list 'eglot-server-programs
|
||||
'(python-mode . ("ruff" "server")))
|
||||
(add-hook 'after-save-hook 'eglot-format))
|
||||
'(python-base-mode . ("ruff" "server"))))
|
||||
(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:
|
||||
|
||||
Reference in New Issue
Block a user