Home Download Buy Blog Forum Support

Folding options?

Folding options?

Postby dorn on Sun Nov 18, 2012 9:38 am

Newbie to sublime here. I've tried searching for info on this but no luck. Most of my code is like:
function()
{
do stuff
}

When I go to fold this it folds to the following.
function()
{ ...
}

I'd really prefer:
function() { ... }

Or at least:
function()
{ ... }

Is there any way to change this simply?
dorn
 
Posts: 3
Joined: Sun Nov 18, 2012 9:30 am

Re: Folding options?

Postby vitaLee on Sun Nov 18, 2012 11:06 am

No easy way to change that. Check this thread for short explation.
http://www.sublimetext.com/forum/viewtopic.php?f=2&t=10005
if you want to know more about folding internals and you dig python you can check the command inside Packages/Default/fold.py
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: Folding options?

Postby dorn on Sun Nov 18, 2012 10:56 pm

I'm not having the problem listed in that thread. I get the fold markers in the correct places. It's that it won't fold them correctly. More simply it won't fold the end delimiter of a block. So all folded code takes up 2 lines instead of 1.
dorn
 
Posts: 3
Joined: Sun Nov 18, 2012 9:30 am

Re: Folding options?

Postby vitaLee on Sun Nov 18, 2012 11:16 pm

well if you cared to read my explanation in that thread you might have understood why it's behaving like that.
it has nothing to do with context blocks. Sublime doesnt fold contextual blocks of code. What it does is track indentation levels of consecutive lines and provide fold markers where following indented lines are greater than 1.
http://www.sublimetext.com/forum/viewtopic.php?f=2&t=10005
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: Folding options?

Postby dorn on Sun Nov 18, 2012 11:40 pm

vitaLee wrote:well if you cared to read my explanation in that thread you might have understood why it's behaving like that.
it has nothing to do with context blocks. Sublime doesnt fold contextual blocks of code. What it does is track indentation levels of consecutive lines and provide fold markers where following indented lines are greater than 1.
http://www.sublimetext.com/forum/viewtopic.php?f=2&t=10005


I did read it. Again I'm not having a problem with that. The fold markers are in the correct spot. All my code has at least 2 lines with indentation. I'll use one of your examples in fact:

Code: Select all
if(true)
{
  a();
  b();
}


It folds to this:

Code: Select all
if(true)
{ ...
}


Leaving the last line hanging instead of folding it. I understand what you're saying though. Essentially sublime can't fold ANY languages delimiter unless it's indented vs the starting marker of a code block? Should that be bug reported maybe? That pretty much breaks every readability rule I've ever heard of.
dorn
 
Posts: 3
Joined: Sun Nov 18, 2012 9:30 am

Re: Folding options?

Postby vitaLee on Mon Nov 19, 2012 9:31 am

Essentially sublime can't fold ANY languages delimiter unless it's indented vs the starting marker of a code block?

Essentially sublime doesn't AT ALL recognize syntactical blocks of code and add folding behaviour based on that. No block delimeters or keywords are considered.
It's way simple than that. Consider this example:
Syntax: Plain Text
Screen shot 2012-11-19 at 10.52.53.png
Screen shot 2012-11-19 at 10.52.53.png (10.44 KiB) Viewed 2923 times

Unless Sublime is aware of language block delimeters, there's no way to consistently handle folding of block in different languages, thus John resorted to this simple solution.
Which admittedly is not perfect and at times is even annoying.
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: Folding options?

Postby hsuh on Mon Nov 19, 2012 3:43 pm

Some ideas: http://emacswiki.org/emacs/OutlineMode

Having the possibility to add special comments meaning headings is very cool:

/// This becomes a first level heading

// This is a normal comment
void fn(){
}

//// This is a level 2 heading

void fn2() {
}
hsuh
 
Posts: 9
Joined: Fri Nov 16, 2012 12:40 pm

Re: Folding options?

Postby qgates on Tue Nov 20, 2012 5:17 am

Yes, tmLanguage files used by sublime have <key>foldingStartMarker</key> and <key>foldingStopMarker</key>in their XML which makes makes it surprising that Jon's opted for such a simple and limited approach to folding. I'd love to see this improve, together with sublime remembering folds between sessions and even within the project/workspace files.

There are also issues with folded section cut, copy and paste behaviour. Folding is messy and buggy at present, and could really do with a bit of an overhaul.

See here: viewtopic.php?f=3&t=7222

S
qgates
 
Posts: 205
Joined: Mon Nov 05, 2012 4:33 pm

Re: Folding options?

Postby vitaLee on Tue Nov 20, 2012 7:38 am

One solution to get folding like this:
Or at least:
function()
{ ... }

is to use BracketHighlighter 2 package http://www.sublimetext.com/forum/viewtopic.php?f=5&t=9756&start=0. which can fold content enclosed within brackets and much more. You'll need to take some time to research it and configure keybindings but it's worth it.
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 17 guests