Skip to content

Commit c16ef70

Browse files
authored
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.
1 parent 04a3ec3 commit c16ef70

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/editors/setup.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,13 @@ Ruff can be utilized as a language server via [`Eglot`](https://github.com/joaot
400400
To enable Ruff with automatic formatting on save, use the following configuration:
401401

402402
```elisp
403-
(add-hook 'python-mode-hook 'eglot-ensure)
404403
(with-eval-after-load 'eglot
405404
(add-to-list 'eglot-server-programs
406-
'(python-mode . ("ruff" "server")))
407-
(add-hook 'after-save-hook 'eglot-format))
405+
'(python-base-mode . ("ruff" "server"))))
406+
(add-hook 'python-base-mode-hook
407+
(lambda ()
408+
(eglot-ensure)
409+
(add-hook 'after-save-hook 'eglot-format nil t)))
408410
```
409411

410412
Ruff is available as [`flymake-ruff`](https://melpa.org/#/flymake-ruff) on MELPA:

0 commit comments

Comments
 (0)