Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

carschandler
Copy link

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 setting foldlevelstart, 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 than nofoldenable seems like it would be a desirable change to me.

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
Comment on lines 477 to 479
vim.wo.foldmethod = "expr"
vim.wo.foldexpr = "nvim_treesitter#foldexpr()"
vim.go.foldlevelstart = 99
Copy link
Member

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

Copy link
Author

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!

Copy link
Member

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

Copy link
Author

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()
Copy link
Member

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?

Copy link
Contributor

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

@DanilaMihailov
Copy link

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?

@clason
Copy link
Contributor

clason commented May 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants