Skip to content

Emacs Usage

Brendan Maginnis edited this page Mar 26, 2021 · 1 revision

Installation

  1. Install the lsp-mode LSP client for Emacs.
  2. Install the sourcery-cli pypi package pip install --user sourcery-cli. Note down the full command path with
    which sourcery.
  3. Sign up for Sourcery on the website and get your token.
  4. Add the following code to your emacs config:
(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection '("<Command to run Sourcery>" "lsp"))
                  :initialization-options '((token . "<your_token_here>")
                                            (extension_version . "emacs-lsp")
                                            (editor_version . "emacs"))
                  :activation-fn (lsp-activate-on "python")
                  :server-id 'sourcery
                  :add-on? t
                  :priority 2))

How does it work?

Sourcery scans the currently open Python file. If lsp-modeline-diagnostics-mode is enabled it highlights the relevant lines of code with improvements.

When on a suggestion line, you can hover to see the suggestion, and run the code action to refactor that code.

See the Sourcery Tutorial for more detailed info.

How do I configure Sourcery?

Please see the Sourcery configuration section for details.

Clone this wiki locally