Home Download Buy Blog Forum Support

Creating an arbitrary folding region?

Creating an arbitrary folding region?

Postby handycam on Wed Apr 04, 2012 1:37 pm

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.
Mac OS 10.9.3
ST 3 (3059)
handycam
 
Posts: 271
Joined: Tue Jan 03, 2012 2:42 pm

Re: Creating an arbitrary folding region?

Postby facelessuser on Wed Apr 04, 2012 2:34 pm

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.
facelessuser
 
Posts: 1549
Joined: Tue Apr 05, 2011 7:38 pm

Re: Creating an arbitrary folding region?

Postby handycam on Wed Apr 04, 2012 7:47 pm

Perhaps it can be made to work with some sort of comment syntax, such as
Code: Select all
<!--- 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.
Mac OS 10.9.3
ST 3 (3059)
handycam
 
Posts: 271
Joined: Tue Jan 03, 2012 2:42 pm

Re: Creating an arbitrary folding region?

Postby agibsonsw on Wed Apr 04, 2012 9:07 pm

@facelessuser. Hi.

write a plugin that allows you to mark regions (maybe with a faint outline)


How would this be done please? Presumably we replace the text with the same text of a certain scope..?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Creating an arbitrary folding region?

Postby facelessuser on Wed Apr 04, 2012 9:30 pm

agibsonsw wrote:@facelessuser. Hi.

write a plugin that allows you to mark regions (maybe with a faint outline)


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


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.
facelessuser
 
Posts: 1549
Joined: Tue Apr 05, 2011 7:38 pm

Re: Creating an arbitrary folding region?

Postby agibsonsw on Wed Apr 04, 2012 10:04 pm

@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 :shock:. But I'm gaining control, and I'm quite pleased to have achieved colour-matched brackets () :D

Regards, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot], pgrippi and 25 guests