Chapter 26. What tools provide what functions?
-
python-mode
works automatically when in python-mode
-
python-ts-mode
No difference apparent vs python-mode (over my body)
-
treesitter
In Emacs, with python file open (but cursor anywhere), type
C-c TAB s
Prerequisite
Requires python isort package.
poetry add --group=dev isort
This works, but the exact details conflict with ruff's linter and produce an
I1001
error. -
ruff
At the command line:
ruff check
filename
--fix
-
LSP and pylsp
Put cursor in symbol.
M-x lsp-rename
-
treesitter
To use treesitter, first change to the -ts- version of the current mode. For example,
python-ts-mode
instead ofpython-mode
. To make this automatic TK.If needed, install the grammar for that mode via
M-x treesit-install-language-grammar
and then following the prompts to let it download and compile and install the grammar. -
lsp
?
-
lsp + yasnippet
?
Installation
Add to
~/.emacs.d/init.el
:(usepackage yasnippet)
-
treesit + treesit-fold
stuck on this error:
Symbol’s function definition is void: treesit-fold-indicators-refresh Mark set
Note
Installed via Manual method:
git clone https://github.com/emacs-tree-sitter/treesit-fold /path/to/lib
and then putting this in
~/.emacs/init.el
:(use-package treesit-fold :load-path "/path/to/lib")
Raw notes
Completion Front-ends
helm
ivy
default
linting from flycheck (UI) + ruff
Installing tree-sitter python
up-----------------------------
(from 2024-11 Habamax https://gist.github.com/habamax/290cda0e0cdc6118eb9a06121b9bc0d7)
Make sure you have installed python treesitter grammar
Windows: download libtree-sitter-python.dll from https://corwin.bru.st/emacs-tree-sitter/ into ~/.emacs.d/tree-sitter/
GNU/Linux: run M-x treesit-install-language-grammar RET type python RET and do a couple of additional y for default options. You will need to have git and C/Cpp compiler available as it would download repo and build grammar library.
verify:
M-x ielm
(treesit-language-available-p 'python)
should return t
verify:
Open python file and do M-x python-ts-mode RET to activate treesitter python mode.
set treesit-font-lock-level to 4
Install ruff
------------
poetry add --group=dev ruff
poetry add --group=dev flycheck
Commands
--------
Things I want to do
* rename symbols
-
* replace tabs with spaces and switch to two spaces
* figure out what lens mode does
-
Functional Requirements
Code navigation
jump to definition
see usages
fold/unfold
move cursor by semantic increments
Reformatting
exact format (black)
module order (isort)
Refactoring
renaming symbols
-
What does what
Table 26.1. Front and back end providers by functionLSP Server Lint Type check autocomplete Navigate Reformat Test + Debug Refactor Doc python-lsp-server ◒ ruff server ◒ Front End flycheck ◓ ◓ eglot ◓ eglot-rename
lsp-mode ◓ eglot-rename
LSP ● ruff (as LSP) ● company ● black ◐ isort ◐
Note
◓: Provides UI
◒: Provides back end
◐: Provides some functions
⚫: Provides everything