[TxMt] Use comments to mark sections (and indented folding vs marker-based folding)

JiHO jo.lists at gmail.com
Thu Jan 21 11:37:10 UTC 2016

Hi everyone,

I want to fold the following 'code'

# Section 1 ----

for (i in  1:30) {
    y = i+1

# Section 2 ----

# a comment
x = y + 1
y = y^2

    if (foo) {
        a = b
        for (j in 1:3) {
            b = b + 1

# Section 3 ----

b = c

to fold in the following way:
- "sections" in the code are defined by #something----, everything
between two section titles should fold when the folding marker of the
title line is clicked
- blocks are defined with { (and a few other markers) and should fold
as expected.

With the following rules I can almost make it work

    foldingStartMarker = '\{';
    foldingStopMarker = '\}';
    foldingIndentedBlockStart = '^#(.*?)\-{4,}';
    foldingIndentedBlockIgnore = '^(?!#(.*?)\-{4,})';

the blocks fold, respecting nesting, the sections fold up to the next
section, *except* for section 1; there, the `for` block is not
indented and is at the same level as the section, therefore folding at
section 1 only folds until the start of the for block, not all the way
down to section 2.
It looks like I am searching for a way to the `foldingIndentedBlock`
rule to take precedence over the `foldingStartMarker` rule. Is it

To make it easy to take a stab at it, I created a new bundle and a
test file (the language is "testing") which you can get there:

PS: having comments which define sections in the code seems like a
general use case. The syntax is in that particular example is defined
in the R language by the RStudio IDE. This IDE is becoming common
enough that I am receiving code formatted this way a lot.

Thanks in advance for your help!

More information about the textmate mailing list