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:
Thamer Mahmoud 2025-11-17 16:52:31 +03:00 committed by GitHub
parent 04a3ec3689
commit c16ef709f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 3 deletions

View File

@ -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: