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

[Feature Request] Un/Folding comments #499

Open
tkapias opened this issue Sep 20, 2022 · 2 comments
Open

[Feature Request] Un/Folding comments #499

tkapias opened this issue Sep 20, 2022 · 2 comments
Labels

Comments

@tkapias
Copy link

tkapias commented Sep 20, 2022

Apparently, there is no plugin that supports comments folding for major filetypes. Those that I found are deprecated, or really limited.
Most of the plugins dedicated to syntax and filetypes don't offer it either.

I currently use custom fold expressions for Unix-like comments, like the one found here:

set fdm=expr
set fde=getline(v:lnum)=~'^\\s#'?1:getline(prevnonblank(v:lnum))=~'^\\s#'?1:getline(nextnonblank(v:lnum))=~'^\\s*#'?1:0

Would nerdcommenter be a good place to add such a functionality?

@tkapias
Copy link
Author

tkapias commented Sep 20, 2022

For now I use this setup:

autocmd FileType sh,toml,yaml,python noremap <buffer><silent> <Leader>fc :set foldmethod=expr<CR>
    \:set foldexpr=getline(v:lnum)=~'^\\s#'?1
    \:getline(prevnonblank(v:lnum))=~'^\\s#'?1
    \:getline(nextnonblank(v:lnum))=~'^\\s*#'?1
    \:0<CR>
autocmd FileType vim noremap <buffer><silent> <Leader>fc :set foldmethod=expr<CR>
    \:set foldexpr=getline(v:lnum)=~'^\\s\"'?1
    \:getline(prevnonblank(v:lnum))=~'^\\s\"'?1
    \:getline(nextnonblank(v:lnum))=~'^\\s*\"'?1
    \:0<CR>

@alerque
Copy link
Member

alerque commented Sep 27, 2022

I would help facilitate a PR if somebody wanted to contribute this as a new feature. I would suggest in needs to be behind a default-off feature flag so as to not mess up other fold expression enabled plugins, and we need some way to derive the expression to use for all block/multiline comments. Preferably we wouldn't be matching inline or even single line comments.

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

No branches or pull requests

2 participants