LUA code beautifier wanted!

I worked a lot with flash actionscript and one of the most helpful IDE-function is the auto-indent button. One click and the code is parsed for syntax errors and formatted by an editable set of rules.

so this line:

if (foo==bar){ foo=1; bar=2;}else{trace("WTF?!")}  

would end up like this:

if (foo == bar){   
 foo = 1;   
 bar = 2;  
} else {  
 trace( "WTF?!" )  
}  

I need this for LUA code!
Especially indenting in complex code can be very confusing:
“now, where does this ‘end’ belong to?!”

This afternoon I tried a lot of stuff* but nothing worked satisfyingly.
any suggestions?

thanks
-finefin
*

  • Imagine PPGUI
  • Notepad++
  • UniversalIndentGUI
  • LUAEclipse
  • prettydoclua
  • …?
    [import]uid: 70635 topic_id: 21411 reply_id: 321411[/import]

Your looking to convert that line to lua ?

if (foo==bar){ foo=1; bar=2;}else{trace(“WTF?!”)}

[code]

if foo == bar then foo, bar = 1,2 else trace(“WTF?!”) end

? [import]uid: 84637 topic_id: 21411 reply_id: 84795[/import]

no… uhm, I’m looking for a tool that can auto-indent lua code
something that can turn this

function foo (bar) if bar == 0 then foobar = 1 end end  

to this

function foo (bar)   
 if bar == 0 then   
 foobar = 1   
 end   
end  

automatically by a set of rules.
I wish Corona Project Manager CPM could do this, but the indenting there is not optimal - autocomplete rocks, tho!
-finefin

[import]uid: 70635 topic_id: 21411 reply_id: 84803[/import]

Oh my bad :slight_smile:

Sorry I don’t know of one personally :confused: [import]uid: 84637 topic_id: 21411 reply_id: 84806[/import]

The best editor I’ve found available for free is IntelliJ IDEA editor with the LUA plugin. http://www.jetbrains.com/idea/
It has many great features including a ‘code reformat’ function that makes your code look great.

Jeff
[import]uid: 14119 topic_id: 21411 reply_id: 84838[/import]

One more thing, I tried your code with the IntelliJ IDEA editor

function foo (bar) if bar == 0 then foobar = 1 end end  

but it did not expand into multiple lines. It mainly cleans up the spacing.

Jeff
[import]uid: 14119 topic_id: 21411 reply_id: 84840[/import]

@Danny: no problemo :slight_smile:

@HabitatSoftware: looks promising. will take a look. thanks!
-finefin
EDIT: OH YEAH! IntelliJ IDEA is a nice one!
by copy/pasting chunks of code, my functions become nicely indented. it doesn’t split up my one-line-code, but at least it indents beautifully. thanks again! [import]uid: 70635 topic_id: 21411 reply_id: 84909[/import]