Sublime Forum

Confused code folding

#1

Ok… So we’ve got a LOT of code that looks similar to the following pattern – which is required for some re-use we’re doing and this sort of thing really confuses Sublime’s code folding system to the point where you can’t fold up an entire function when it’s got one or more comment sections like this where comments go to the far left edge – Sublime assumes this indicates the start of a new function/method…

/////////////////////////////////////////////////////////////////////////////////////////
//
// Method: Initialize
//
/////////////////////////////////////////////////////////////////////////////////////////
void MyCoolClass::Initialize()
{
if (foo == Types::BAR)
{

////////////////////////// BEGIN CODE REPLACE ///////////////////
// AnOldLineOfCode();
ANewLineOfCode();
////////////////////////// END CODE REPLACE /////////////////////
… more statements…
}
… more statements…
}

So, Sublime puts a folding carat at the Initialize() method and another one as expected at the ‘if’… However, if you ask it to fold up the entire method, it will only fold up to the “BEGIN CODE REPLACE” and the rest remains unfolded. Would it be possible to have it be a bit smarter about the code content and not stop folding (in this case) until it sees the matching closing brace at the bottom? I realize we do things a bit different but this seems like a bug IMHO. Anyone else notice anything like this?

0 Likes

Folding options?
Folding options?
Folding options?
#2

sublime folds at indentation levels where the marker will show up only if the indentation spans more than 1 line.
example:
sublime wont show fold icon on “if” line for either of this cases.

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

it will show fold icon on the “if” line in this case

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

and again a fold icon on “opening brace” line in this case

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

Code Folding and PHP HEREDOC