Skip to content

Smallscript-Corp/vscode-explicit-folding

 
 

Repository files navigation

Explicit Folding

License Visual Studio Marketplace Version Visual Studio Marketplace Installs License License License

Manually controls how and where to fold your code

Configuration

In your settings:

"explicitFolding.rules": {
    "*": {
        "begin": "{{{",
        "end": "}}}"
    },
    "javascriptreact": [
        {
            "begin": "{/*",
            "end": "*/}"
        },
        {
            "begin": "<",
            "end": "/>"
        }
    ]
}

Rules

The property explicitFolding.rules is defining how to fold the code.

Here the list of possible rules:

Global scope

When used in the global scope, the rules must be regrouped by language.

"explicitFolding.rules": {
    "cpp": [
        {
            "beginRegex": "#if(?:n?def)?",
            "middleRegex": "#el(?:se|if)",
            "endRegex": "#endif"
        }
    ]
}

Language scope

"[cpp]": {
    "explicitFolding.rules": [
        {
            "beginRegex": "#if(?:n?def)?",
            "middleRegex": "#el(?:se|if)",
            "endRegex": "#endif"
        }
    ]
}

Regex Syntax

Via VSCode's editor, the extension supports ES2018 regexes.

In addition, the following PCRE2 syntaxes are supported:

  • (?i)x: x becomes case insensitive
  • (?i:x)y: only x is case insensitive

Debugging

If the property explicitFolding.debug (false by default) is true, the extension will print out debug informations into the channel Folding of the panel Output (menu: View / Output).

Priority/Delay

VSCode is scoring each folding providers based on the scheme and language. When the scores are identicals, the providers which have been registered the latest have an higher priority. When starting up, VSCode loads the extensions. When reading a file, VSCode will load the folding provider of the file's language (only once per language).

The property explicitFolding.delay (in ms, 1000 by default) is used so that this extension's folding provider has a higher priority than the one of the language provider.

Notification

The property explicitFolding.notification (minor by default) indicates when to show the update notification.

Usages

Language Config
Emacs
"*": {
    "begin": "{{{",
    "end": "}}}"
}
C/C++
"cpp": [
    {
        "beginRegex": "#if(?:n?def)?",
        "middleRegex": "#el(?:se|if)",
        "endRegex": "#endif"
    },
    {
        "begin": "/*",
        "end": "*/",
        "nested": false
    },
    {
        "begin": "//",
        "continuation": "\\",
        "nested": false
    }
]
HTML
"html": {
   "beginRegex": "<(?!area|base|br|col|embed|hr|img|input|link|menuitem|meta|param|source|track|wbr)([a-zA-Z]+)[^>\\/]*>",
   "endRegex": "<\\/\\1>"
}
PHP
"php": [
    {
        "beginRegex": "(?:case|default)[^:]*:",
        "endRegex": "break;|(.)(?=case|default|\\})",
        "foldLastLine": [true, false]
    },
    {
        "beginRegex": "\\{",
        "middleRegex": "\\}[^}]+\\{",
        "endRegex": "\\}"
    }
]
Python
"python": {
    "beginRegex": "\"\"\"",
    "endRegex": "\"\"\""
}
SASS
"scss": {
    "beginRegex": " \\{\\s*$",
    "endRegex": "^\\s*\\}"
}

FAQ

Q: Why don't I see the foldings ?

A: Firstly, make sure you have the setting "editor.showFoldingControls": "always" and that you don't have "editor.foldingStrategy": "indentation". Then, verify your config 😉

Donations

Support this project by becoming a financial contributor.

Ko-fi ko-fi.com/daiyam
Liberapay liberapay.com/daiyam/donate
PayPal paypal.me/daiyam99

Editors support

VSCode/VSCodium

VSCode is using the folding ranges provided:

  • by the folding range provider defined by the setting editor.foldingStrategy (auto or indentation)
  • and, by the folding range provider defined by this extension if editor.foldingStrategy is set to auto

MrCode

MrCode is using the folding ranges provided:

  • by the folding range provider defined by the setting editor.foldingStrategy (auto or indentation)
  • or by the folding range provider defined by this extension if editor.foldingStrategy is set to explicit

The long-standing PR tries to bring this new behaviour to VSCode.

Enjoy!

About

Customize your Folding for Visual Studio Code

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • TypeScript 100.0%