Sublime Forum

► FOLDING OF SINGLE LINE BLOCK (why minimally two lines need?)

#1

For code folding at least 2 lines should be in indent block. But sometimes need 1 line folding.

Why its not realized? How to modify *.py files to achieve this effect?

Me have tried next actions:
1)me uncompressed next package file: “st3\Packages\Default.sublime-package”
2)inside me found next possibly folding related files: fold.py, indentation.py, detect_indentation.py
3)me placed copy of them to dir: “st3\Data\Packages\Default”. Now when modifying this files ST3 reacts on changes.
4)Later me stucked. Dont know how to change code logic. Dont see simple change condition ‘x<2’ to ‘x<1’.
Or maybe other *.py files need to edit?
Plz help.

5 Likes

Why can't I collapse/fold code with only one nested line?
On st folding problems
#2

##+ 1

 
I hadn’t noticed that, seems like an odd discrepancy in whatever code adds the fold marker.  However, if you run the fold_by_level {"level": 1} with ctrl+k, ctrl+1, you should get the effect you’re looking for. 

The only issue is that it affects all code, so you still aren’t able to manually fold individual single-line entries.
 



 
I’m guessing that whatever code adds fold markers should be in some kind of listener.  I did a quick search of the contents of all the default packages but didn’t see anything that looked like it might contain such code…  Maybe worth looking into if you have the time to check out each listener.
 



 

 
At which file + function did you find this code?

0 Likes

#3

It’s consistent. A folding marker is added if at least the following two lines have more indentation.

0 Likes

#4

 

Yes, but what’s odd is that fold_by_level does not follow the same rule, and will fold even single lines.

0 Likes

#5

Unsuccessfully tried to find problem inside *.py files.
I carefully watched through all *.py files and left only next possibly related to folding:
(‘Default’ package: fold.py, detect_indentation.py, indentation.py, block.py).
But the problem is probably hard-coded and compiled inside c++ sources of ‘sublimetext.exe’.
Code should have some text like that: ‘if lines>1’, ‘add fold button/mark’ to ‘gutter’.
I stucked and dont know what to do. SublimeText’s developers can easy answer on this question or at least give a hint what file/function to modify.

0 Likes

#6

You can not change this behavior. Folding arrows are hard-coded and it can not be modified by plugin code either.

0 Likes

#7

I hope this option will be added in the future. Need every day. Plz.

1 Like

#8

So… still no fix for this? :confused:

Also, the ability to select some text, then right click it and have a “fold selected text” option in the context menu is another dreadfully needed feature.

0 Likes

#9

so add it yourself then if you need it that much… :wink:

Create a file in Packages/User called Context.sublime-menu with the following contents:

[
    { "command": "fold", "caption": "Fold Selected Text" },
]
3 Likes

#10

Please consider fixing this. There’s no reason to make 2 lines the minimum rather than 1.

Because of this issue, I can’t fold functions with a 1-line body.

0 Likes

#11
0 Likes