An effective way to beautify the code in the Sublime editor

Hello Guys

Do you like to organize your codes, especially when you reach many lines?

Search LuaFormat via Package Control: Install Package

How To Use

Through shortcuts Ctrl + Alt + F to format the code within the current view.

I try to write shorter modules and then browse between them.  Are you a new user?  Have you used modules?

I do very agressively split up my code into smaller modules. In fact, if there is any way to interpret an object on three levels, I will split it into three different modules.

An example:

  1. My enemies are controlled by a separate “enemiesManager” module

  2. Then my tank, for example, will be a separate module

  3. My tank will have a separate “bulletManager” module as a child, taking care of firing, managing and cleaning up bullets fired by the tank

  4. And of course my “bullet” module will be separate as well.

This is my first step in organizing my code.

Another thing I do is always comment my “end” statements for functions, and often for loops and branches as well.

For example:

local createBunnies = function() for i = 1,10 do if weatherIsGood == true then putExtraBunnyInGarden() end -- if weatherIsGood end -- for 10 loop end -- createBunnies() 

This makes it a lot easier to navigate my code blocks, especially when scrolling up.

What sort of bugs me is that Sublime after all this time still has not implemented CodeWrangler’s “function dropdown menu”, in spite of many requests by users.

Adding that function would make Sublime the de facto best code editor out there for me.

@thomas6 -  I like your tagging the “end” statements as a rule.  I’m might try to be more systematic about that.  I add objects to lists (for tracking) at the end of functions so I have a visual cue but systematically tagging the "end"s will be more thorough.  I’ll see how it works for me visually - thanks.

You’re welcome! The color coding for commenting in Sublime works much better than the color coding shown above, I can tell you.

I try to write shorter modules and then browse between them.  Are you a new user?  Have you used modules?

I do very agressively split up my code into smaller modules. In fact, if there is any way to interpret an object on three levels, I will split it into three different modules.

An example:

  1. My enemies are controlled by a separate “enemiesManager” module

  2. Then my tank, for example, will be a separate module

  3. My tank will have a separate “bulletManager” module as a child, taking care of firing, managing and cleaning up bullets fired by the tank

  4. And of course my “bullet” module will be separate as well.

This is my first step in organizing my code.

Another thing I do is always comment my “end” statements for functions, and often for loops and branches as well.

For example:

local createBunnies = function() for i = 1,10 do if weatherIsGood == true then putExtraBunnyInGarden() end -- if weatherIsGood end -- for 10 loop end -- createBunnies() 

This makes it a lot easier to navigate my code blocks, especially when scrolling up.

What sort of bugs me is that Sublime after all this time still has not implemented CodeWrangler’s “function dropdown menu”, in spite of many requests by users.

Adding that function would make Sublime the de facto best code editor out there for me.

@thomas6 -  I like your tagging the “end” statements as a rule.  I’m might try to be more systematic about that.  I add objects to lists (for tracking) at the end of functions so I have a visual cue but systematically tagging the "end"s will be more thorough.  I’ll see how it works for me visually - thanks.

You’re welcome! The color coding for commenting in Sublime works much better than the color coding shown above, I can tell you.