Sublime Forum

Creating an arbitrary folding region?

#1

I have a large block of repeating code in my html file. I have no need to wrap it with an html tag, but I’d like to be able to hide it by folding it.

I know I can select the whole thing and use the keyboard command for “fold”, but I have to do that every time. I’d like to know if there some sort of special comment syntax to define a foldable region.

0 Likes

Job: $20 for creating a really simple difinition syntax
#2

You can use the RegReplace plugin to find and fold/unfold your code blocks. You can use literal string searches or regex.

Your other alternative is to write a plugin that that allows you to mark regions (maybe with a faint outline). And then you can have a command that folds/unfolds all marked regions. If you change the code in those regions (make the region bigger or smaller), you would have to re-mark it though.

Basically you can fold any region if you are able to give the region end points. The problem is you have to be able to determine what those end points are, which is why I suggest RegReplace, which can find the regions by rules you set.

0 Likes

#3

Perhaps it can be made to work with some sort of comment syntax, such as

<!--- somename -->

<!---/somename -->

that’s 3 hyphens at the start, using the same name for each, plus the close /

In other words, have ST2 recognize a pair of these as folding markers. Possible?

Sort of how you can use pragma marks and ASDOC markers in Flex.

0 Likes

#4

@facelessuser. Hi.

How would this be done please? Presumably we replace the text with the same text of a certain scope…?

0 Likes

#5

[quote=“agibsonsw”]@facelessuser. Hi.

How would this be done please? Presumably we replace the text with the same text of a certain scope…?[/quote]

There is a fold and unfold API command. You just feed it a list of regions. RegReplace uses regular expression to find regions, and feeds them to the one of these API commands. To do a manual plugin, you would just have a command that adds the current selection region to the view as a region with a key name of your choice, and you simply specify if you want as an outline, hidden, etc.

Then when you want to fold or unfold, you request the list of regions from the view and fold or fold them.

0 Likes

#6

@facelessuser. Thank you. I recall now that, when I previously defined at outlined-scope, it appeared with an ugly highlight.

BTW I can’t leave Python.tmLanguage alone :open_mouth:. But I’m gaining control, and I’m quite pleased to have achieved colour-matched brackets () :smiley:

Regards, Andy.

0 Likes