zokugun / vscode-explicit-folding

Customize your Folding for Visual Studio Code
MIT License
99 stars 14 forks source link

Allow "endRegex" to reference capture groups from "beginRegex" #14

Closed HolyBlackCat closed 4 years ago

HolyBlackCat commented 4 years ago

First of all, thanks a lot for fixing #4! Now I can use your extension instead of the silly indentation-based folding, yay!

I'm writing folding rules for C++ now, and I have a rather obscure feature request for you.

In short, I propose this syntax:

{
    "beginRegex": "^begin ([a-z]+)",
    "endRegex": "^end \\1",
    //                ^~~ this thing
},

Here, \\1 would expand to the value of the capture group ([a-z]+) in beginRegex.

So, for example:

begin foo   // beginRegex matches this line
blah blah
end         // endRegex does not match this line
end foo     // endRegex matches this line

VSC supports this feature in language grammars, so I think it would be nice to have it in this extension too.

The reason I want this feature is to be able to fold so-called raw strings in C++:

string s = R"foo( // the string starts here, folding begins here
aaa               // this part is folded
)"                // this is a part of the string, doesn't affect folding
bbb               // this part is still folded
)foo"             // the string ends here, folding ends here
daiyam commented 4 years ago

The newest version should fix your problem.

HolyBlackCat commented 4 years ago

Works great, thanks!