Sublime Forum

Correct bracket indent in C but not Lua

#1

Hello,

I’ve been messing around trying to fix this but not had much luck

In C I can write the following - imagine my cursor is |

{
    {|}

I press enter and I get

{
    {
        |
    }

Great! That’s doing the correct indenting.

In Lua the closing brace goes like this:

{
    {
    |
}

It would be nice if it behaved like the C version.
Actually while writing this post I think I figured it out by taking some bits from the C indent file. I’ll post this anyway in case it helps anyone else searching for an answer.

Packages\Lua\Indent.tmPreferences

Here’s the code or I have my version on github here: https://github.com/balaam/sublime-settings/blob/master/lua/Indent.tmPreferences

[code]

<?xml version="1.0" encoding="UTF-8"?> name Indent scope source.lua settings increaseIndentPattern (?x) ^ .* \{ ^}"']* $ | ^ \s*(do|else|elseif|for|(local\s+|local\s+\w\s*=\s*)?function|if|repeat|until|while)\b((?!end).)*$ decreaseIndentPattern (?x) ^ (.*\*/)? \s* \} .* $ | ^ \s*(elseif|else|end)\s*$
</dict>
<key>uuid</key>
<string>411468A8-E0AC-415A-9E71-E2BD091EB571</string>
[/code]
0 Likes