Home Download Buy Blog Forum Support

Code Folding

Code Folding

Postby adzenith on Mon Feb 21, 2011 4:50 pm

I coded a little plugin this weekend that lets you do code folding. The way it works is you select some text and hit the "fold" shortcut, and the text gets grabbed from the buffer and replaced with a fold marker. If you select some or all of the fold marker and hit "unfold", the fold marker gets replaced with the text in the buffer. It's actually kind of cool, if I do say so myself.
It also works nice with saving: whenever you save, the fold markers all get replaced with the original text, and then get folded back again after the save. The file on the disk will always have the full text.
Anyway, check it out here:
https://github.com/adzenith/Sublime-plu ... folding.py

The one known bug is that whenever you save a view, it seems to scroll down about 1 line—it turns out that view.show(view.visible_region(),False) moves the view.

Also, if you're doing some hacking at home, keep in mind that if you ever save code_folding.py from within Sublime Text, the plugin will be reloaded and it will forget all the text that it's grabbed from buffers, making it impossible to unfold text.

As always, feedback and comments are appreciated.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: Code Folding

Postby theblacklion on Tue Feb 22, 2011 10:42 am

What about using something like sqlite or pickle for persistency?
theblacklion
 
Posts: 67
Joined: Sat Feb 05, 2011 10:07 pm
Location: Hannover, Germany

Re: Code Folding

Postby lunixbochs on Tue Feb 22, 2011 3:11 pm

you don't need to pickle externally

a reloaded python module keeps old variables, it just happens to execute the module again... which usually rewrites all of the variables

I had an issue in sublime lint - a thread was started every time the module was reloaded, which caused things to get pretty slow after a while. now I detect reload using a variable and it's way nicer to work on.
check this out: https://github.com/lunixbochs/sublimeli ... in.py#L142
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Re: Code Folding

Postby adzenith on Tue Feb 22, 2011 6:26 pm

sublimator wrote:Creative but seems like a pretty fragile way to implement folding.

Aren't you supposed to be able to find / replace/ copy etc in folded areas?

Yeah, but I can't think of a way to make that work without reimplementing them in the code folding plugin.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: Code Folding

Postby ViViDboarder on Wed Mar 23, 2011 2:57 pm

It sounds like this plugin actually removes the folded lines and replaces them when you save. Is this true?

If so it'd be great if the Sublime developer implemented even a basic, programmable folding feature like Hide Lines that could be scripted. Then plugin developers could just specify what lines they want folded.
ViViDboarder
 
Posts: 4
Joined: Wed Mar 23, 2011 2:55 pm

Re: Code Folding

Postby adzenith on Wed Mar 23, 2011 4:38 pm

That is true. The editor currently does not support hiding text.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: Code Folding

Postby Qard on Tue Jun 07, 2011 3:55 am

Rather than just line folding, it would be handy to be able to do index folding. That way you can fold everything between braces, for example. Folding is the only feature I miss from other editors.
Qard
 
Posts: 3
Joined: Tue Jun 07, 2011 3:50 am

Re: Code Folding

Postby alexrussell on Mon Aug 08, 2011 1:19 pm

sublimator wrote:As well as code folding, I'd like to be able to have composable views, made up of various sections of various files.

That sounds like a really good idea, although I can't think of many uses for it (if that makes any sense). One example I can think of is as a cheat sheet for a helper class/file with the method signatures easily accessible (then again, regular code folding would do this too for the most part).

What uses did you have in mind for these "composable views", sublimator?
alexrussell
 
Posts: 74
Joined: Fri Jul 15, 2011 9:06 am

Re: Code Folding

Postby alexrussell on Wed Aug 10, 2011 8:40 am

You're a passionate man!

Yes, some good ideas here.
alexrussell
 
Posts: 74
Joined: Fri Jul 15, 2011 9:06 am

Re: Code Folding

Postby dannoffs on Fri May 11, 2012 6:47 pm

https://github.com/adzenith/Sublime-plu ... folding.py

no longer working, is there any chance anyone can host it again? need code folding that saves on exit ;p
dannoffs
 
Posts: 6
Joined: Mon Dec 05, 2011 11:27 am

Next

Return to Plugin Announcements

Who is online

Users browsing this forum: Yahoo [Bot] and 12 guests