sublimehq / Packages

Syntax highlighting files shipped with Sublime Text and Sublime Merge
https://sublimetext.com
Other
2.95k stars 586 forks source link

[Lua] initializing two functions in a row messes up indentation #1921

Open RheingoldRiver opened 5 years ago

RheingoldRiver commented 5 years ago

screenshot - image

code from screenshot -

end

function p._main(args)

end

function p.test(args)

    end

function p.getUrl( spritesheet, query )

Or to recreate, type this at the start of an empty document:

function h.asd(frame)

end

function h.asd2(frame)

    end

I think the 2nd end should also be returned to the start of the line in this case

keith-hall commented 5 years ago

most likely you are running into https://github.com/SublimeTextIssues/Core/issues/1262 as opposed to a problem in the Lua indentation rules

RheingoldRiver commented 5 years ago

Ah yeah sounds like that

deathaxe commented 5 years ago

As end keyword is a custom one, which needs to be handled via tmPreferences I rather think it's a bug in the Indent.tmPreference

A very quick and lazy check revealed the following changed file (removed some \b) to fix the issue for end

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
    <dict>
        <key>name</key>
        <string>Indent</string>
        <key>scope</key>
        <string>source.lua</string>
        <key>settings</key>
        <dict>
            <key>decreaseIndentPattern</key>
            <string>(^\s*(elsei|elseif|else|end|until)\b.*$|^((?!\{).)*\}\;?.*$)</string>
            <key>increaseIndentPattern</key>
            <string>(^\s*((local[\s\w=]+)?function|repeat|else|elseif|if|while)\b((?!\bend\b).)*$|^.*\b(do|then)\b((?!\bend\b).)*$|^.*\{((?!\}).)*$)</string>
        </dict>
    </dict>
</plist>

... but there may be more.

SublimeTextIssues/Core#1262 is just about the "hardcoded" indention rules applied to { and }.

deathaxe commented 5 years ago

Interesting ... maybe indeed triggering the core issue sometimes.

See how dedenting the keyword end works or fails depending on whether an end was added to the function declaration line before or not.

Animation

Content of Packages/Lua/Indent.tmPreferences

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
    <dict>
        <key>name</key>
        <string>Indent</string>
        <key>scope</key>
        <string>source.lua</string>
        <key>settings</key>
        <dict>
            <key>decreaseIndentPattern</key>
            <string>(?x:
                ^\s*(
                    (elsei|elseif|else|end|until)\b
                    |
                    ((?!\{).)??\}\;?
                ).*?$
            )</string>
            <key>increaseIndentPattern</key>
            <string>(?x:
                ^\s*(
                    ((local[\s\w=]+)?function|repeat|else|elseif|if|while)\b((?!\bend\b).)*?
                    |
                    .*?\b(do|then)\b((?!\bend\b).)*?
                    |
                    .*?\{((?!\}).)*?
                )$
            )</string>
        </dict>
    </dict>
</plist>