Beautify your code!

Previous topic - Next topic

Moru

This program parses your code and indent each line properly. The comments at the end of lines are nicely aligned to improve readability and comments that start too far to the right are places alone on the previous line instead. All you need to do is call the program with the filename(s) in the parameters.

Examplecode for the macro system in GLBasic v7 is included. It won't destroy your original file, it just creates two more files, one called "filename.gbas.new" and the second called "filename.gbas.rem". The first one is the first pass, only indenting each line correctly. The second has also aligned the comments on the end of all lines. (you do comment your code, right? :-)

If you run the macro it will open up both files in notepad, one after the other, just edit the macro so you get the file you want. Copy/paste into your original file if you feel happy with what he did.

Please try this and leave comments here, it is not fully tested yet so please don't paste over your original code before reviewing it with some program that can compare lines for similarities. PSPad is great for this, it doesn't complain on indentation differences, only real characters so you can be sure that the code is intact.

I also try to leave INLINE/ENDINLINE blocks untouched since I can't be bothered to figure all different ways of indenting c++ code...

Beautify your code!
Have fun!

Quentin

#1
a "Pretty Printer"!!

Great job! Could be very useful!  :good:

could be a galactic tool, if it was possible to format marked code blocks, not only the whole file (like block comment function) :) Gernot?


[edit]
some small suggestions:

  • tab size and commend positions as command line arguments?
  • ignore all // between quote signs " "
  • go on with it, its a really good and useful tool :)

Moru

Quote from: Quentin on 2009-Jul-31
some small suggestions:

  • tab size and commend positions as command line arguments?
  • ignore all // between quote signs " "
  • go on with it, its a really good and useful tool :)

Those are already planned for when I have the time :-)
Ignoring // is a problem because I'm using the built-in functions for searching and splitting strings. I need to write my own functions for it. Comment position is different from function to function depending on where you place the rightmost comment. Some functions can have long rows, others have short rows.

Btw, the readme file shows you how to extend for new commands or change it for some other language.