From a9f8bd59b2ee491caf9c509f2e7e3d4e4b854a7a Mon Sep 17 00:00:00 2001 From: Pathompong Kwangtong Date: Tue, 23 Jul 2024 12:20:51 +0700 Subject: [PATCH] Add Eglot setup guide for Emacs editor (#12426) ## 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 https://github.com/astral-sh/ruff-lsp/issues/19#issuecomment-1435138828) ## 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 --- docs/editors/setup.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/editors/setup.md b/docs/editors/setup.md index 47a6e00bc4..45f2226081 100644 --- a/docs/editors/setup.md +++ b/docs/editors/setup.md @@ -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