New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update README.md for better folding settings #5274
base: master
Are you sure you want to change the base?
Update README.md for better folding settings #5274
Conversation
I think that the README's settings for enabling treesitter's folding capabilities do not reflect how most people probably want their folds to behave. The current settings make it so that when a single section of code is folded, everything folds (due to how `foldlevel` works)... most people probably want the folds to be created for them automatically, sit in the background invisibly, and then only activate when they manually toggle them. By setting `foldlevelstart`, this is achieved, and the user can still use `:set foldlevel` to batch fold if desired.
README.md
Outdated
vim.wo.foldmethod = "expr" | ||
vim.wo.foldexpr = "nvim_treesitter#foldexpr()" | ||
vim.go.foldlevelstart = 99 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that vim.{wo,go}
is any wrong, just maybe not intended since set ...
can also be global, so I'd say maybe use vim.o
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right... it would be preferred to set the options globally with vim.o
so that if a user wanted to change them locally and then revert to global settings with :set option<
they would be able to do so. I'll make that change. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If anything, can you also change the foldexpr
to vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
, as nvim_treesitter#foldexpr()
is already deprecated/planned to remove.
See https://github.com/nvim-treesitter/nvim-treesitter/tree/main#folds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I was looking for a more lua way to do that but gave up on it. I'll add that as well... and a comment about setting the fold options per-filetype.
Suggest `vim.o` instead of `vim.{wo,go}` to set fold options
Use newer foldexpr function
```vim | ||
set foldmethod=expr | ||
set foldexpr=nvim_treesitter#foldexpr() | ||
set nofoldenable " Disable folding at startup. | ||
set foldexpr=v:lua.vim.treesitter.foldexpr() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Built-in foldexpr seems available from neovim 0.9+ and ported from this repo (neovim/neovim#22299). Does this mean that nvim_treesitter#foldexpr()
is deprecated and no longer used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. (I mentioned that the README is a mess, didn't I?)
I wanted to propose the same changes for README. And maybe add this options as well? vim.opt.foldtext = '' -- "transparent folds - just text with syntax highlighting" Is there anything else needed for this PR to be merged? |
The problem is that folding has changed significantly in Nvim 0.10, so I want to wait for that to be released and (official) support for Nvim 0.9 can be dropped so we don't need to document for multiple versions in the README. |
I think that the README's recommended settings for enabling treesitter's folding capabilities do not reflect how most people probably want their folds to behave. The current settings make it so that when a single section of code is folded, everything folds (due to how
foldlevel
works)... most people probably want the folds to be created for them automatically, sit in the background invisibly, and then only activate when they manually toggle them. By settingfoldlevelstart
, this is achieved, and the user can still use:set foldlevel
to batch fold if desired. Most people probably do not already have this option set, so including it in the README rather thannofoldenable
seems like it would be a desirable change to me.