Xojo IDE Reformat Code Script

I’ve put together a little reformat code script that adds some extra functionality to the IDE.

I’ve been working on the script on and off ever since I asked Norman for an option to turn off the automatic removal of empty parenthesis. Norman kindly reminded me about the ReformatCode system and gave me some initial pointers and ideas to get me started. He has also kindly fixed most of the bugs I’ve found.

The current feature list includes:

-Pad the inside of parentheses with a space. So a(b,c) will become a( b,c )
-Pad the outside of parentheses with a space. So a(b,c) will become a (b,c)
-Pad empty parentheses with a space. So a() will become a( )
-Remove empty parentheses. So a() will become a
-Pad commas. So a(b,c) will become a(b, c)
-Pad operators. So a=b+c will become a = b + c
-Pad inline ifs so a=if(b=1,0,1) will become a=if (b=1,0,1)
-Pad before a line continuation mark (underscore)
-Aid with some common transpositions i.e. endif will become End If
-Comment replacement e.g. ’ will become // or vice versa
-Pad comments before and after the comment mark
-Code replacement, a++ (a=a+1), a+=1 (a=a+1), if a!=1 (if a<>1) etc.
-Macros, quickly insert pre-defined text with autocomplete description
-Automatic calculation of windows declare types

Visit https://github.com/JulianSamphire/ReformatCode to download and/or watch the video for more information.

If you have any questions, feature requests or bug reports please post them below.

If something is formatting incorrectly for you, please post what you typed and what you expected to see on separate lines, thanks.

I would only suggest using this in version 2018r1 as there may be some issues with previous versions that have had bug fixes in the latest release. If you would like to know what these are because you’d like to us this on your current version then let me know and I’ll dig out the bug reports and let you know what you need to void.

I downloaded and added to the scripts folder of 2018r1.1, runnning the script gave me a lot of script errors.

[quote]Compiler error [11] Error found while compiling on line 311. Continue?
Compiler error [11] Error found while compiling on line 312. Continue?
Compiler error [2] Error found while compiling on line 312. Continue?
Compiler error [201] Error found while compiling on line 312. Continue?
Compiler error [11] Error found while compiling on line 320. Continue?


Am i missing something?

I think this will be awesome for me as well. Really miss i++ syntax. Add adding declares will be nice and easy

Oh, you dont run the script, you just put it in the Scripts folder and restart the IDE, it will then load and run from then on while you move around your code.

I put it in the folder and started Xojo, added

[code]dim i as integer

i++ [/code]

to a test app and nothing happened. thus i thought you had to run it yourself.

What do you mean “while you move around your code?”
Also running on macOS 10.12.6, also no random html at the top

Found it, you need preferences - Coding - Apply standardize format after ending line checked on

Ahha, I’ll add that one to the document, thanks Graham :slight_smile:

Updated: Remove trailing space if () are removed

Very interesting and excellent work, Julian.

Glad Norman “reminded” you of this feature. As for me, I had no idea such a capability existed.

I’ve had this request (feedback://showreport?report_id=40097) in since 2015 (and a similar request dating back to fogbugz era). Seem that the hooks were already there.

Me too :slight_smile:

The macro idea was a bit of an ahha moment for me when playing with the reformat code system. It was working very well inserting multi line macros and it was a bit heartbreaking having to limit it to a single line when the bug was found.

Norman knows about the feature request so hopefully it will come out soon.

I’m sure a community driven library of useful code snippets will follow as soon as its implemented :slight_smile:

I’ve got so many “C/C++” to “Xojo” macros sitting in Paul’s CodeVue. It will be really nice to remove the find / copy / paste operations.

BTW - who do you use to do your animated GIF conversions?

SnagIt I should be on commission :wink:

Mac & Windows too!

Ah - the Camtasia folks.

It turns out that I’m kind of asleep this morning - I use Screenflow on the Mac, and do my Windows and Linux screen recordings in VMs, so I already have Animated GIF output - D’oh!

More caffeine input required! I used Screenflow when I tried to move to macOS, shame it doesn’t have a windows version.

Really liking the scripting plugin. Nice work!

Thanks for the bug report in git Jeremie, I’ve added email notification to the repository so I’ll be notified next time :wink:

Fixed an issue where unicode literals (&u) were being treated as strings so they were being surrounded by quotes


In the last year Xojo changed the way they format Select Case constructs. It used to be that Xojo would allow you to indent each Case clause. Like this:

Select Case RetCode

  Case 1

  Case 2
  Case 3
End Select

Now Xojo forces the Case clauses to be at the same indent level as the Select Case/End Select.

Select Case RetCode

Case 1

Case 2
Case 3
End Select

This makes no sense to me because the Case clauses are children of the Select Case/End Select. Is this something that your code reformatter could be enhanced to handle?


Unfortunately not Wes, indentation is out of the control of the ReformatCode script :frowning: