[Python] Run Ruff in Emacs

Discussão em 'Python' iniciado por Stack, Abril 4, 2025.

  1. Stack

    Stack Membro Participativo

    How can I run Ruff in Emacs? I need to enable 2 commands on the current buffer:

    • ruff check --select ALL current_buffer → bind to M-x ruff-check
    • ruff check --select ALL --fix current_buffer → bind to M-x ruff-fix

    I can run each of these commands with a file argument on the command line, and ruff is in my $PATH.

    I tried the solutions from here: Setup | Ruff, and have the following lines in ~/.emacs, but they are not running ruff on save as expected. Besides, I really want to enable the two distinct commands above, rather than running ruff on save.

    (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))

    (require 'ruff-format)
    (add-hook 'python-mode-hook 'ruff-format-on-save-mode)

    Continue reading...

Compartilhe esta Página