sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
804 stars 39 forks source link

Code Folding should be based on syntax, not on indentation level #101

Closed iamntz closed 2 years ago

iamntz commented 11 years ago

Just to prevent things like #100

datainadequate commented 3 years ago

This really rules out Sublime Text as a useful editor for XML. This is a shame because XML is horrible to edit and it would be much nicer to do it in Sublime Text than in Visual Studio. But you cannot work sensibly with XML unless you have folding based on XML syntax.

santoshsrinivas commented 2 years ago

I am not sure what incentive you guys need to prioritize this.
Help in coding? Please ask. I am sure there are extremely smart people in the community who can volunteer. Money? I am happy to pay. I have already purchased a license, I don't mind a few extra bucks.

I am disappointed that I couldn't use the product I bought. I am currently using other editors due to lack of this feature.

Please. Do something. :( :(

jokoon commented 2 years ago

I'm suspecting the dev responsible for the code that handles this has left the company with messy code that can't be maintained, which might be one reason they can't fix this.

On Mon, Jan 31, 2022 at 10:17 AM Santosh Srinivas Pulavarthi < @.***> wrote:

I am not sure what incentive you guys need to prioritize this. Dev support? Please ask. I am sure there are extremely smart people in the community who can volunteer. Money? I am happy to pay. I have already purchased a license, I don't mind a few extra bucks.

I am disappointed that I couldn't use the product I bought. I am currently using other editors due to lack of this feature.

Please. Do something. :( :(

— Reply to this email directly, view it on GitHub https://github.com/sublimehq/sublime_text/issues/101#issuecomment-1025526937, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAECK3MGPKN3ZUX6AXQJWC3UYZHRJANCNFSM4AGQWZWA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

idzikovsky commented 2 years ago

@jokoon yeah, so they haven't touched that part of code for eight years now... On the other hand, by looking at @wbond comments on this issue I assume that the more real reason is that developers simply don't find this problem important enough.

TWiStErRob commented 2 years ago

Issue is top 5, so it's hard to say it's not on their radar.

jokoon commented 2 years ago

Oh, did not know that.

it's also fighting with very old other issues, too.

On Mon, Jan 31, 2022 at 10:28 PM Róbert Papp @.***> wrote:

Issue is top 5, so it's hard to say it's not on their radar.

https://user-images.githubusercontent.com/2906988/151875924-9a8bab33-45da-4d54-b300-ea912ce3c28f.png

— Reply to this email directly, view it on GitHub https://github.com/sublimehq/sublime_text/issues/101#issuecomment-1026229190, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAECK3PUNQ3ABMPH2MN4X63UY35IXANCNFSM4AGQWZWA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

BenjaminSchaaf commented 2 years ago

Build 4130 introduces a configuration for syntax definitions to base folding on scopes. When configured this extends to the gutter and all the folding shortcuts. Note that no default syntax have such a configuration yet.

See the following example:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
    <key>scope</key>
    <string>source.c, source.c++, source.objc, source.objc++</string>
    <key>settings</key>
    <dict>
        <key>indentationFoldingEnabled</key>
        <false/>
        <key>scopeFoldingEnabled</key>
        <true/>
        <key>foldScopes</key>
        <array>
            <dict>
                <key>begin</key>
                <string>punctuation.section.block.begin</string>
                <key>end</key>
                <string>punctuation.section.block.end</string>
            </dict>
        </array>
    </dict>
</dict>
</plist>
Sayayaya commented 2 years ago

Is there somewhere the foldScopes syntax is documented... for example how would I get it to fold on //region //endregion etc. The example provided is not very clear to me.

deathaxe commented 2 years ago

There's no "foldScopes syntax".

Folding is based on scopes.

The TextMate preference file above, shows how to define fold begin and end selectors.

All tokens scoped punctuation.section.block.begin are used as starting point and punctuation.section.block.end as termination of a folding region in C/C++/Obj-C/Obj-C++.

If you want to use //region as beginning and //endregion as termination, you'd want to either look for the scope they have assigned by desired syntax definition. The scope name is displayed via ctrl+shift+alt+P.

You may probably need to modify syntax definition to assign a proper scope.

Example

A Fold.sublime-syntax specifies scopes (e.g. keyword.other.region.[begin|end]).

%YAML 1.2
---
# See http://www.sublimetext.com/docs/syntax.html
scope: source.fold
file_extensions:
  - fold

contexts:
  main:
    - match: (\\)region\b
      scope: keyword.other.region.begin
      captures:
        1: punctuation.definition.region
    - match: (\\)endregion\b
      scope: keyword.other.region.end
      captures:
        1: punctuation.definition.region

A Fold.tmPreferences file declares those scopes as begin and end of a folding region.

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
    <key>scope</key>
    <string>source.fold</string>
    <key>settings</key>
    <dict>
        <key>scopeFoldingEnabled</key>
        <true/>
        <key>foldScopes</key>
        <array>
            <dict>
                <key>begin</key>
                <string>keyword.other.region.begin</string>
                <key>end</key>
                <string>keyword.other.region.end</string>
                <key>excludeTrailingNewlines</key>
                <true/>                
            </dict>
        </array>
    </dict>
</dict>
</plist>

ST has then learned to define fold regions beginning with //region and ending with //endregion.

mnemnion commented 2 years ago

I'm having trouble getting this to work with telescoping scopes. I feel sure I'm doing something wrong, the indentation scopes fold.

The goal is to take this sort of todo:

** H2

...text

*** H3

**** H4

** H2

So that folding the first H2 folds everything between it and the next H2.

The dicts look like this:

            <dict>
                <key>begin</key>
                <string>markup.section.4.begin</string>
                <key>end</key>
                <string>markup.section.4.end</string>
                <key>excludeTrailingNewlines</key>
                <true/>
            </dict>
            <dict>
                <key>begin</key>
                <string>markup.section.3.begin</string>
                <key>end</key>
                <string>markup.section.3.end</string>
                <key>excludeTrailingNewlines</key>
                <true/>
            </dict>

Grammar has rules like

    - match: '{{h5}}'
      push:
      - meta_scope: markup.section.5.begin
      - match: '\s?(\*{5})'
        captures:
          1: markup.heading.section.level
        scope:
          markup.section.6.end
          markup.section.5.end
      - match: '(.*$)'
        captures:
          1: markup.entity.section.line
        pop: true

    - match: '{{h4}}'
      push:
      - meta_scope: markup.section.4.begin
      - match: '\s?(\*{4})'
        captures:
          1: markup.heading.section.level
        scope:
          markup.section.6.end
          markup.section.5.end
          markup.section.4.end
      - match: '(.*$)'
        captures:
          1: markup.entity.section.line
        pop: true

And so one: higher sections get a section close tag for every lower sort.

The problem is that: it works between peers (H3 won't gobble up H3), and an H3 won't fold an H2, but the sequence H3 H4 H2 gets the H2 and I can't for the life of me figure out why.

I know this is a work in progress, I'm exceedingly keen to see this feature, but I'm kinda stumped at this point.

FichteFoll commented 2 years ago

but the sequence H3 H4 H2 gets the H2 and I can't for the life of me figure out why.

What do you mean by that?

mnemnion commented 2 years ago

It's the same behavior described in #5423.

If you have in markdown:


### H3

text

#### H4

text

## H2 

text

then folding H3 will fold the H2.

jokoon commented 11 months ago

<?xml version="1.0" encoding="UTF-8"?>

scope source.c, source.c++, source.objc, source.objc++ settings indentationFoldingEnabled scopeFoldingEnabled foldScopes begin punctuation.section.block.begin end punctuation.section.block.end

Thanks, could you be more specific as to which file this should pasted into?

EDIT: I created a C++ folder in the Packages folder, and pasted this into the Fold.tmPreferences file... doesn't seem to fold curly braces in a single line.