ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Syntax​Fold

by jamalsenouci ST3

Sublime Text Plugin that provides a configurable command and popup for folding code based on syntax

Details

Installs

  • Total 10K
  • Win 6K
  • OS X 3K
  • Linux 2K
Jun 17 Jun 16 Jun 15 Jun 14 Jun 13 Jun 12 Jun 11 Jun 10 Jun 9 Jun 8 Jun 7 Jun 6 Jun 5 Jun 4 Jun 3 Jun 2 Jun 1 May 31 May 30 May 29 May 28 May 27 May 26 May 25 May 24 May 23 May 22 May 21 May 20 May 19 May 18 May 17 May 16 May 15 May 14 May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3
Windows 2 5 1 2 1 2 1 2 0 1 3 3 0 6 5 1 2 4 2 7 5 4 1 1 1 3 4 3 2 3 5 3 11 2 5 4 2 4 0 5 5 5 3 3 1 2
OS X 2 0 0 4 2 2 1 1 1 1 3 3 4 3 3 1 0 4 2 3 3 4 3 1 3 1 5 4 3 4 1 7 1 3 1 1 0 0 1 2 2 1 1 0 2 3
Linux 0 0 0 2 2 3 0 2 0 0 0 1 0 5 4 2 2 2 0 0 2 1 0 1 2 1 1 1 2 0 0 1 2 4 1 2 0 0 2 1 0 1 3 0 0 2

Readme

Source
raw.​githubusercontent.​com

SyntaxFold - Sublime Text Plugin

A plugin for Sublime Text 3 that folds/collapses or unfolds/expands code blocks based on specific syntax defined by the User rather than indent.

Note: This plugin does not create folding markers (the functionality for creating these markers is not exposed within the Sublime Text API). The folding functionality provided by this plugin relies on using keyboard shortcuts assigned by the User or by invoking fold commands through the command panel.

Background

This plugin was created for any language that uses named regions similar to languages like VB, C++ and C# (see here). Where possible, use a plugin created specifically for your syntax.

Expanding and collapsing areas is also supported in non-source files, such as text files (Sublime Text regards HTML as belonging to a text scope name).

Installation

  • Use Sublime Package Control
  • Ctrl+Shift+P then select Package Control: Install Package
  • Type SyntaxFold and press ENTER

Alternatively Clone this repository to your Sublime Text packages directory.

Setup

The settings file can be accessed through Preferences -> Package Settings -> Settings - User. It will be initially populated with the following settings.

{
    "config":[
        {
            "scope": "source.java, source.js, embedding.php",
            "startMarker": "//region",
            "endMarker":"//endregion"
        },
        {
            "scope": "source.cs",
            "startMarker":"#region",
            "endMarker":"#endregion"
        },
        {
            "scope": "source.c++, source.c",
            "startMarker":"#pragma region",
            "endMarker":"#pragma endregion"
        },
        {
            "scope": "text.html.basic",
            "startMarker":"",
            "endMarker":""
        },
        {
            "scope": "text.plain",
            "startMarker":"---region---",
            "endMarker":"---endregion---"
        }
    ]
}

Add or remove fold region objects to meet your needs. Note the scope key. Utilize this key to filter which source file types for which the start and end markers are active. To determine the scope name for a file type use Tools -> Developer -> Show Scope Name or Ctrl+Alt+Shift+P.

The scope key may contain a comma separated list of scopes for which the markers should be active. The settings file above supports, for example, Java, Javascript and PHP files folding through the same //region and //endregion markers since the defined scope is "source.java, source.js, embedding.php".

Usage

Use the keybindings to fold/unfold your code

Key Bindings

The following is an excerpt of the default key bindings:

[
//Fold all code blocks
  { "keys": ["alt+0", "alt+0"],
    "command": "fold_all" },

// Unfold all code blocks
  { "keys": ["alt+shift+0", "alt+shift+0"],
    "command": "unfold_all"},

// Toggle fold current code block
  { "keys": ["alt+1", "alt+1"],
    "command": "toggle_fold_current"},
]

Command Reference

A list of commands have been added to the command palette and can be accessed using Ctrl+Shift+P. All commands start with “SyntaxFold : [command name]”.

Fold All: Fold/collapse all syntax delimited blocks in the current document.

Unfold all: Unfold/expand all syntax delimited blocks in the current document.

Toggle Fold Current: Folds/collapses or Unfolds/expands the syntax delimited block where the cursor is placed on.

Open README: Open this readme file.

Saving fold state

This package doesn't support saving the folded state of a file (remembering which blocks you have folded) but there is a package called BufferScroll perfectly suited to that https://packagecontrol.io/packages/BufferScroll