This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
oeed's profile picture

Lua Beautifier/Formatter/Indenter?

Started by oeed, 06 March 2013 - 05:56 PM
oeed #1
Posted 06 March 2013 - 06:56 PM
Is there any (preferably online or Java) good tool I can use to fix up the formatting of a Lua file. The code is around 2150 lines so I want to avoid having to do it by myself. I tried Googling but I couldn't find anything which appears to do the job.

For example, jsbeautifier.org, essentially something to make your code look better.
GravityScore #2
Posted 06 March 2013 - 08:27 PM
Download Sublime Text 2.

It has a re-indent feature for Lua, but it's a bit broken (doesn't indent at elseifs). If you download my ComptuerCraft Sublime Text 2 package, and set the language to ComputerCraft (should appear once you've installed it), then run the reindent feature (select the whole document, remove any current tabbing using shift+tab, then do edit->line->re-indent).
Shnupbups #3
Posted 06 March 2013 - 08:32 PM
There is a CC program to do that here, but that might not be what you're looking for.
oeed #4
Posted 06 March 2013 - 08:41 PM
Download Sublime Text 2.

It has a re-indent feature for Lua, but it's a bit broken (doesn't indent at elseifs). If you download my ComptuerCraft Sublime Text 2 package, and set the language to ComputerCraft (should appear once you've installed it), then run the reindent feature (select the whole document, remove any current tabbing using shift+tab, then do edit->line->re-indent).

Thanks! Even better than I was asking for. I've been using BBEdit but this is even better.
GravityScore #5
Posted 06 March 2013 - 11:42 PM
Download Sublime Text 2.

It has a re-indent feature for Lua, but it's a bit broken (doesn't indent at elseifs). If you download my ComptuerCraft Sublime Text 2 package, and set the language to ComputerCraft (should appear once you've installed it), then run the reindent feature (select the whole document, remove any current tabbing using shift+tab, then do edit->line->re-indent).

Thanks! Even better than I was asking for. I've been using BBEdit but this is even better.

Glad to help :P/>

I use it for absolutely everything except for Objective-C (Xcode) and Java (Eclipse).
theoriginalbit #6
Posted 07 March 2013 - 02:28 AM
the ultimate solution!
SpoilerIndent it correctly right from the start, makes life so much better and easier, and makes debugging a DREAM!
GravityScore #7
Posted 07 March 2013 - 02:41 AM
the ultimate solution!
SpoilerIndent it correctly right from the start, makes life so much better and easier, and makes debugging a DREAM!

Debugging is never a dream unless it's a syntax error (cause they're easy to fix :P/>)
theoriginalbit #8
Posted 07 March 2013 - 03:00 AM
Debugging is never a dream unless it's a syntax error (cause they're easy to fix :P/>)
I never have a problem with debugging. there are a few annoying times. but for the most part. its not hard.
GravityScore #9
Posted 07 March 2013 - 03:18 AM
I never have a problem with debugging. there are a few annoying times. but for the most part. its not hard.

I agree, it's not always too hard, but some times is some randomly obscure thing that is impossible to find without logging everything you do. And for those times, I have 1lann to do it for me :P/>
theoriginalbit #10
Posted 07 March 2013 - 03:26 AM
but some times is some randomly obscure thing that is impossible to find
You should try C++ … compiler errors are useless and errors are hard to track down …
Mads #11
Posted 07 March 2013 - 04:50 AM
but some times is some randomly obscure thing that is impossible to find
You should try C++ … compiler errors are useless and errors are hard to track down …

Are you kidding me? They give you all the information you need.
Bubba #12
Posted 07 March 2013 - 08:13 AM
I must say that debugging lua became simple as soon as I tried out brainf**ck for the first time.

On topic though, indenting correctly from the start is really not that difficult unless you write the program in something that does not support indentation (I have a lua app on my tablet that doesn't). Sublime Text is the ultimate solution for this that I've found (Thanks GravityScore!)
oeed #13
Posted 07 March 2013 - 01:54 PM
the ultimate solution!
SpoilerIndent it correctly right from the start, makes life so much better and easier, and makes debugging a DREAM!

I agree, however, it can be a pain if you're adding and removing stuff lots.



Download Sublime Text 2.

It has a re-indent feature for Lua, but it's a bit broken (doesn't indent at elseifs). If you download my ComptuerCraft Sublime Text 2 package, and set the language to ComputerCraft (should appear once you've installed it), then run the reindent feature (select the whole document, remove any current tabbing using shift+tab, then do edit->line->re-indent).

The reindenting doesn't appear to work with tables, which is a shame.
Kingdaro #14
Posted 07 March 2013 - 06:17 PM
Someone made a patch for tables. I can't find it on google, so I just pastebinned my own.

http://pastebin.com/UVLRMDjn

Text goes in the file:
Windows: %APPDATA%/Sublime Text 2/Packages/Lua/Indent.tmPreferences
Linux: ~/.sublime-text-2/Packages/Lua/Indent.tmPreferences

I forget what it is for Mac.
oeed #15
Posted 07 March 2013 - 06:42 PM
Someone made a patch for tables. I can't find it on google, so I just pastebinned my own.

http://pastebin.com/UVLRMDjn

Text goes in the file:
Windows: %APPDATA%/Sublime Text 2/Packages/Lua/Indent.tmPreferences
Linux: ~/.sublime-text-2/Packages/Lua/Indent.tmPreferences

I forget what it is for Mac.

Thanks, it makes a lot better, still a few glitches but overall much better.

(Woot, 100th post)
GravityScore #16
Posted 07 March 2013 - 08:26 PM
Text goes in the file:
Windows: %APPDATA%/Sublime Text 2/Packages/Lua/Indent.tmPreferences
Linux: ~/.sublime-text-2/Packages/Lua/Indent.tmPreferences

I forget what it is for Mac.

Mac: ~/Library/Application Support/Sublime Text 2/Packages/Lua/Indent.tmPreferences
campicus #17
Posted 17 August 2013 - 07:24 AM
Anyone else found that this doesn't decrease the indent for "until" in repeat loops?
theoriginalbit #18
Posted 17 August 2013 - 07:37 AM
Anyone else found that this doesn't decrease the indent for "until" in repeat loops?
yeh it's a common problem with most indenters.