https://github.com/eddiebergman/nvim-treesitter-pyfold
Some sane Python folding with nvim-treesitter
https://github.com/eddiebergman/nvim-treesitter-pyfold
folding nvim python treesitter
Last synced: about 1 year ago
JSON representation
Some sane Python folding with nvim-treesitter
- Host: GitHub
- URL: https://github.com/eddiebergman/nvim-treesitter-pyfold
- Owner: eddiebergman
- Created: 2021-05-19T23:58:20.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-11T06:56:05.000Z (about 3 years ago)
- Last Synced: 2024-10-05T21:06:50.991Z (over 1 year ago)
- Topics: folding, nvim, python, treesitter
- Language: Lua
- Homepage:
- Size: 280 KB
- Stars: 33
- Watchers: 2
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nvim-treesitter-pyfold
Folding is a great way to declutter the screen from irrelevant context but
overfolding can be equally annoying.
Hence, a lua based module for nvim-treesitter, setting some sane folding
defaults and provides an optional foldtext.
## Installation
Using your favourite package manager
```lua
# vim-plug
Plug 'nvim-treesitter-pyfold'
# Packer
require('packer').setup {
...
use 'eddiebergman/nvim-treesitter-pyfold'
...
}
```
Once your package manager has installed the package, in your nvim-treesitter
setup, you simply enable the package with:
```lua
require('nvim-treesitter.configs').setup {
...
pyfold = {
enable = true
custom_foldtext = true -- Sets provided foldtext on window where module is active
}
...
}
```
If you havn't already, to use treesitter folding, you have to set the following two lines in your `.vimrc` at some point.
```
set foldmethod=expr
set foldexpr=nvim_treesitter#fold_expr()
```
For debuging issues, make these two lines are set using `set foldmethod` and `set foldexpr` to verify these are set.
## Example
#### Classes

#### Functions / Methods



#### Dicts, Lists, Tuples

### TODO
* Getting multiple imports to fold into one line.
```Python
# Code
import one
import two
import three
from x import y
import a as b
from z import (
alpha, beta, phi
)
# Desired
-- imports
```
The C part of the python tree-sitter parser doesn't want to fold any
'queryable' that only lives on one line, even if you group multiple of them
together in query. Please let me know if you know of any workaround for this!