vscode-explicit-folding
vscode-explicit-folding copied to clipboard
F.A.Q. section in `README.md` is unclear about multi-line `regex`
The suggested answer regarding why \n does not work, mentions that $ must be used, but provides no example of how to do that using the Mozilla regex syntax. Likewise, Mozilla-provided documentation is unclear to me regarding this use case.
Since The document parser is line-based., multi-lines regexes won't work.
I know you are trying to fold Lua but can you give me an example of what you want to fold (function, if, for, comment or ???)
You can look at the discussions to see how some users have successfully used the extension.
Examples for Lua
I have prepared these code-folding examples at your request. π
(And much gratitude for how you are matching my style of keyword highlighting.)
π‘ Main idea: When folded, I want to hide the end statements as well as the contents of the blocks they end.
Single-Level Blocks
The simple case is a single, top-level block with an end statement.
The block:
β if conditions then
ββ actions
β end
Should fold to:
β if conditions then
Blocks Implied by Indentation
Though Lua is not a language with whitespace-defined blocks the way, e.g. Python is, for managing complex code constructs, it his highly advantageous to offer the developer an opportunity to fold the trailing lines.
A typical example for where this would be needed, is within multi-line comments.
The statement:
β --[[ some header description
βββsome list item
βββsome list item
βββsome list item
ββ]]
Folds to:
β --[[ some header description
Multi-Level Blocks
Blocks with other blocks defined as nested within them must allow the nested blocks to be folded without having to fold the parent block(s).
The blocks:
β for conditions do
ββ if conditions then
βββ actions
ββ else
βββ actions
ββ end
β end
Sould fold to:
β for conditions do
ββ if conditions then
βββ actions
ββ else
ββ end
β end
β οΈ NOTICE: A nested block which is folded should not hide the end statement for its parent block, even if the nested block has no end statement of its own according to Lua syntax.
And then to:
β for conditions do
ββ if conditions then
β end
And finaly:
β for conditions do
Blocks Defined on Multiple Lines
When dealing with blocks where the opening statements span multiple lines, place the folding toggle on the first line.
The block:
β if conditions
β then
ββ actions
β end
Should fold to:
β if conditions
π‘ Or consider the typical case from C-like languages:
The block:
public static void main()
{
β continue;
}
Should not appear as:
β public static void main()
β {
ββ continue;
β }
But rather:
β public static void main()
β {
ββ continue;
β }
And folds to:
β public static void main()
Bonus Feature
Some of the currently-supported languages already hide trailing blank lines when folding blocks, and this is greatly appreciated! π― In so doing, the debate over whether to use blank lines is rendered moot. π
I will use https://github.com/lcpz/lain/blob/master/layout/termfair.lua as my test file since it contains most of the cases.
For Lua, here the config that I used:
"[lua]": {
"explicitFolding.debug": true,
"explicitFolding.rules": [
{
"begin": "--[[",
"end": "--]]",
"nested": false,
"kind": "comment",
},
{
"begin": "--",
"continuation": "\\",
"nested": false,
"kind": "comment",
},
{
"begin": "\"",
"end": "\"",
"nested": false,
},
{
"beginRegex": "\\b(?:for|function|if)\\b",
"middleRegex": "\\belse(?:if)?\\b",
"endRegex": "\\bend\\b",
},
],
},
For C, you should look at https://github.com/zokugun/vscode-explicit-folding/discussions/44
Were the configs helpful?