Skip to content

Commit

Permalink
Add Eglot setup guide for Emacs editor (#12426)
Browse files Browse the repository at this point in the history
## Summary

The purpose of this change is to explain how to use ruff as a language
server in Eglot with automatic formatting because I've struggle to use
it with Eglot. I've search it online and found that there are some
people also struggle too. (See [this reddit
post](https://www.reddit.com/r/emacs/comments/118mo6w/eglot_automatic_formatting/)
and
astral-sh/ruff-lsp#19 (comment))


## Test Plan

I've use this setting myself. And I will continue maintain this part as
long as I use it.

---------

Co-authored-by: Dhruv Manilawala <[email protected]>
  • Loading branch information
foxmean and dhruvmanila authored Jul 23, 2024
1 parent 143e172 commit a9f8bd5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/editors/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,17 @@ IntelliJ Marketplace (maintained by [@koxudaxi](https://github.com/koxudaxi)).

## Emacs

Ruff can be utilized as a language server via [`Eglot`](https://github.com/joaotavora/eglot), which is in Emacs's core.
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))
```

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

```elisp
Expand Down

0 comments on commit a9f8bd5

Please sign in to comment.