Sublime Forum

Folding options?

#1

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?

0 Likes

Code folding
#2

No easy way to change that. Check this thread for short explation.
https://forum.sublimetext.com/t/confused-code-folding/7899/1
if you want to know more about folding internals and you dig python you can check the command inside Packages/Default/fold.py

0 Likes

#3

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.

0 Likes

#4

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.
https://forum.sublimetext.com/t/confused-code-folding/7899/1

0 Likes

#5

[quote=“vitaLee”]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.
https://forum.sublimetext.com/t/confused-code-folding/7899/1[/quote]

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:

if(true)
{
  a();
  b();
}

It folds to this:

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.

0 Likes

#6

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


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.

0 Likes

#7

Some ideas: 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() {
}

0 Likes

#8

Yes, tmLanguage files used by sublime have foldingStartMarker and foldingStopMarkerin 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: Folding is not as dynamic as it could be

S

0 Likes

#9

One solution to get folding like this:

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.

0 Likes