Home Download Buy Blog Forum Support

C++ code folding stops with character in first column

C++ code folding stops with character in first column

Postby djczaski on Fri Nov 22, 2013 8:35 pm

Code folding stops when there is non-whitespace in the first column. I noticed this in ST2 and figured it was a bug that would get fixed in ST3. Anybody else notice this and know of a work around -- other than reindenting which isn't convenient for working with an existing code base.

Image
Last edited by djczaski on Sat Nov 23, 2013 4:40 am, edited 1 time in total.
djczaski
 
Posts: 11
Joined: Tue Mar 05, 2013 3:56 am

Re: C++ code folding stops with character in first column

Postby skuroda on Sat Nov 23, 2013 1:26 am

It's not a bug. The default folding is language agnostic, relying on tabs to determine where to fold. I believe there are some plugins that try to do this more intelligently, though I don't know any off the top of my head.
skuroda
 
Posts: 687
Joined: Fri Oct 05, 2012 8:11 am

Re: C++ code folding stops with character in first column

Postby adzenith on Sat Nov 23, 2013 3:05 am

I might call it a bug, considering that the .tmLanguage files have built in folding start and stop markers.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: C++ code folding stops with character in first column

Postby djczaski on Sat Nov 23, 2013 5:00 am

The folding markers are specified in the language file, so yes this is a bug.

The same happens with Lua syntax which is much simpler:

Code: Select all
   <key>foldingStartMarker</key>
   <string>^\s*\b(function|local\s+function|if|for)\b|{[ \t]*$|\[\[</string>
   <key>foldingStopMarker</key>
   <string>\bend\b|^\s*}|\]\]</string>


I don't see anything in either of those rules which would identify something in column 1 as a start or stop folding marker.
djczaski
 
Posts: 11
Joined: Tue Mar 05, 2013 3:56 am

Re: C++ code folding stops with character in first column

Postby qgates on Sat Nov 23, 2013 5:18 am

It's not a bug: Jon simply hasn't done it yet. I too wish for "proper" folding that uses the .tmLanguage definitions. It was high on my hope-list for ST3. The current folding works quite literally on the indent level: not great. It's also a PITA that it doesn't remember folds in your project, though I am aware that some plugins do circumvent this.
qgates
 
Posts: 230
Joined: Mon Nov 05, 2012 4:33 pm

Re: C++ code folding stops with character in first column

Postby Tuanglen on Sat Nov 23, 2013 5:36 am

I'm trying ST3 for the first time right now, and I'm a little confused about code folding. (Ironically, this thread was right at the top of the forum.)

I wrote a bit of Python:
def foo():
....larry()
....curly()
....moe()

(In the actual code, those four dots are a single tab). I placed the cursor in the header line (def foo():) and hit the keyboard shortcut for Fold (opt-cmd-[). It did nothing. So I selected the whole line, entered the keyboard cmd, and it folded the header, leaving the body---the exact opposite of what I wanted. So I dragged down the side and carefully selected the whole function, hit the keyboard cmd, and the whole thing folded up and disappeared, including the header line. So, now I can't see what I've folded. So I selected all the lines in the function body, avoiding the header line, hit the command, and all the selected lines folded up, leaving the header, as I wanted.

Is this really how Sublime Text code folding is supposed to work (I have to manually select all the lines to fold), or am I doing it wrong or missing a preference setting or something? Or is the idea with ST that you should uncomment or specify some sort of package specific to the syntax of the file whose code you want to fold, then the keyboard shortcut triggers the command from that package?

EDIT: I found my own answer, in case it's useful to others:
Instead of putting the cursor in the header line, put it on one of the indented lines in the group you want folded. You don't have to select them all, just put the cursor in one of them.
Tuanglen
 
Posts: 15
Joined: Wed Aug 22, 2012 8:17 am


Return to Technical Support

Who is online

Users browsing this forum: Majestic-12 [Bot], Yahoo [Bot] and 21 guests