Hello,
although on a daily basis I use a real IDE for work, I decided to give another try to Corona Editor, especially since it now supports debugging I’ve been asking for in one of my discussions.
Anyway… Apart from work I work on some new ideas and test stuff and I use Corona Editor for it now, but I’m struggling with something most basic… code indentation.
When I reformat my code, there are two issues I have to manually fix: formatting of ‘elseif’ (everywhere) and ‘end’ (of an anonymous function passed to onComplete/timer/event).
Here are two samples:
transition.to(signal, {alpha = 0, xScale = 2, yScale = 2, time = 400, transition = easing.inOutQuad, onComplete = function(target) target:removeSelf() end})
if event.target == boardTop then spots = topSpots elseif event.target == boardBottom then spots = bottomSpots else assert(false, "unknown board") end
I’m not that fluent with Sublime to fix it myself. I’ve looked at the Lua code template, and the increaseIndentPattern looks ok.
Any ideas on how to fix this?
EDIT:
Ok… now that I wrote all of this, I have found the _decreaseIndentPattern _option, and it seems it lacks handling of this situation. I’m not sure it won’t screw things up in other cases, but now reformatting my file works as expected. I’ve added .* at the end of the pattern.
\<string\>^\s\*(elseif|else|end|\}).\*\s\*$\</string\>
BTW.
If you want your code formatting to work like in IntelliJ IDEA, you can add this to your user’s keybinding:
{ "keys": ["command+alt+l"], "command": "reindent", "args": {"single\_line": false} }
Happy coding!
EDIT2:
And to all of you who prefer syntax:
local table = { blah = 2 }
over:
local table = { blah = 2 }
here’s add .* into your increaseIndentPattern before the {
\<string\>^\s\*(else|elseif|for|(local\s+)?function|if|repeat|until|while)\b((?!end).)\*$|.\*\{\s\*$\</string\>