Xojo IDE Reformat Code Script

Heh, doh! No it’ll only happen when you move off the line.

The reformatting stuff doesn’t thrill me much, but the macro facility - heck yes!!! Must check it out asap, thanks!

So it’s not currently possible to do multi-line macros? That is heartbreaking. Is there a feature request in Feedback I can vote for?

Quite impressive.

I just had a look at the script and have a few questions about it out of pure curiousity:

What makes this script work, i.e. what are the conditions under which it gets invoked? I could not find code that “inits” it, i.e. tell the IDE to invoke “CleanBlock” whenever the editor leaves a code line. Also, where does the tokenizer come from? Is there a doc on all this behavior by the IDE?

Xojo Dev Center: Custom Code Reformatting

Nope :frowning:

I just noticed that its visible to only me and Xojo, I’ve asked for it to be made public.

<https://xojo.com/issue/51365> all my comments in there are marked as private due to a bug in feedback so the ticket looks one sided and Norman is talking to himself :wink:

Norman/Xojo is aware of it and a little birdy tells me that they hope to get it into 2018r2 so fingers crossed.

Thanks for posting the link Jurg, let me know if anyone has any further questions.

Well its done but I’ve just found out that it will trigger mismatched parenthesis when a line is split using a continuation _ so you end up with:


and as I can’t navigate around the code in the script and I’m not able to work back and count the parenthesis. I can’t even check if the current line is a portion of a continuation and ignore the check.

This would mean that your code would end up with //MISMATCHED PARENTHESIS around the place when you split a line that contains parenthesis.

Not ideal but do you think its still worth doing?

New Feature

Checks the line for mismatched parentheses and notifies you


a = ((1+2)/3



when you move the cursor off the line.

Additional preferences

   CheckMismatchedPar (true)

If you set this value to true it will check if there are matching parentheses on the line. If not it will add a comment to the end of the line notifying you of the fact.

   MismatchedParComment (')
This is the comment type used for the mismatched parentheses notification.
   MismatchedParMessage ("MISMATCHED PARENTHESES")
This is the message that is shown to notify you if there are mismatched parentheses on the line.


Get the latest update here

Julian, thanks for this fantastic tool, works like a charm.

As always there are edge cases such as this:

Dim a, b As String a = "hhah" b = mid(a, 3 ' MISMATCHED PARENTHESES b = mid a, 3)(
The last line should IMHO been marked as MISMATCHED PERENTHESES and the line before that one should show “MISSING CLOSING PARENTHESE”.
But that, i think, is very hard to implement.

Something along these lines could maybe useable for single / double quotes especially in JS code blocks.
Add to the wishlist???

After all i think the tool makes the code in the editor much and MUCH better readable.
Again MANY THANKS !!! :smiley:

Great idea Andre, checking single quotes is a little harder as they are considered comments if they are outside of quotes and I don’t really want to get into parsing javascript inside comments. If you want to have a go at this please do, the source is on the git and I’ll happily merge it in.

I’ve just added this and tweaked some of the settings. Let me know if you find any problems with this update.


An error checking feature that will notify you if the line has:
- mismatched parentheses
- missing opening parenthesis
- missing closing parenthesis
- mismatched quotes


These error messages will automatically be removed when you move off the line if the error is corrected without altering the format or spacing of the error message.

   MessageComment (')

This is the comment type used for error message notifications. This setting can either be ', // or Rem.

   MessageParMismatched (MISMATCHED PARENTHESES)

This is the message that is shown to notify you if there are mismatched parentheses on the line. Setting this to _ (underscore) will turn off checks for this setting and the error message will not be shown.


This is the message that is shown to notify you if there is a missing opening parenthesis on the line. Setting this to _ (underscore) will turn off checks for this setting and the error message will not be shown.


This is the message that is shown to notify you if there is a missing closing parenthesis on the line. Setting this to _ (underscore) will turn off checks for this setting and the error message will not be shown.

   MessageQuoteMismatched (MISMATCHED QUOTES)

This is the message that is shown to notify you if there are mismatched quotes on the line. Setting this to _ (underscore) will turn off checks for this setting and the error message will not be shown.


Get the latest update here

Julian, you are a miracle, in a short test the new version works just fine, even the opening and closing error message for parenthesis work as i meant. Great job!

Thinking further about the single quote balancing i think indead that that is realy hard to implement, think about one single quote within a quoted text, how should you decide if that single quote is meant as such and no balancing should take place. IMHO that is almost impossible.

Oh, and i like the automatic removal of the error message after correcting the bug. A real masterpiece you made!

Glad you like it Andre.

Yes the single quotes thing is a bit tricky and I don’t really feel like writing a javascript parser at the moment but I can think of a way of doing it if someone has a javascript validator/parser.

I get an error when I try to copy in some obfuscated code on MISSING CLOSING PARENTHESIS on a continuation line:

Return DecodeBase64(c(97) + c(23) + c(61) + c(66) + c(119) + _'MISSING CLOSING PARENTHESIS
c(116) + c(37) + c(69) + c(79) + c(65) + _
c(9) + c(114) + c(58) + c(27) + c(100) + _
c(34) + c(3) + c(72) + c(2) + c(56) + _
c(77) + c(90) + c(83) + c(86) + c(91) + _
c(5) + c(76) + c(113) + c(45) + c(107) + _
c(17) + c(70) + c(38) + c(7) + c(31) + _
c(36) + c(10) + c(39) + c(73) + c(51) + _
c(50) + c(25) + c(11) + c(42) + c(117) + _
c(21) + c(81) + c(46) + c(57) + c(99) + _
c(32) + c(103) + c(40) + c(41) + c(22) + _
c(71) + c(68) + c(16) + c(35) + c(80) + _
c(1) + c(19) + c(96) + c(18) + c(8) + _
c(28) + c(20) + c(88) + c(98) + c(12) + _
c(78) + c(4) + c(59) + c(84) + c(24) + _
c(54) + c(33) + c(85) + c(63) + c(95) + _
c(111) + c(67) + c(94) + c(29) + c(101) + _
c(0) + c(110) + c(44) + c(52) + c(62) + _
c(105) + c(6) + c(75) + c(104) + c(49) + _
c(106) + c(118) + c(89) + c(64) + c(43) + _
c(92) + c(48) + c(74) + c(14) + c(13) + _
c(47) + c(15) + c(26) + c(115) + c(87) + _
c(93) + c(102) + c(53) + c(108) + c(55) + _
c(112) + c(82) + c(60) + c(30) + c(109))'MISSING OPENING PARENTHESIS

I mentioned this about a week ago, there’s not really anything I can do about messages around continuation marks because the IDE doesn’t give me the ability to navigate the code to check where the marks start/end. I have a feature request in for this <https://xojo.com/issue/52241>

I’ll have a look at sorting them for a multi-line paste like above as I think I can navigate around the multi-lines being pasted in, however you would need to paste the above with a spare line at the bottom so your cursor is off the last line, otherwise when you moved off the line it would just check it and place the message back there as I wouldn’t be able to navigate to the top to check.

Personally I’m happy with them in my code for now until the feature request is looked at, how about you? Please chip in if you’re using it at the moment.

I just went to implement part of this where it would check parentheses across a multiline paste with continuation and came up against a bug so I’ll have to put it on hold for the moment. <https://xojo.com/issue/52343>. I’ll look into this again when/if this is remedied.

[quote=388105:@JulianS]It would insert itself before any other comment on the line so you’d have the most change of seeing it if you had a long line, or I could insert it at the start of the line and comment the whole line out to make it more obvious?

Good idea? Bad Idea? Want is displayed differently? Thoughts?[/quote]

PLEASE PLEASE PLEASE do NOT ever comment out an entire line (your second alternative above) as that would potentially allow the code to compile with the coding error unnoticed.

Many of us put lots of comments into our code, so having an entire line turn into a comment makes it less visible–not more.

If there’s a syntax error in the code that gets overlooked, it’s VITAL that the coder gets notified by the error when they try to compile.

Commenting out an entire line of code due to a syntax error potentially allows a successful compile that could have subtle, catastrophic impact on the behavior of the project.

No worries Seth, I implemented it by putting the error message a the end, but before any other comment on the line so it had the most chance of being seen :slight_smile:


Fix: Added a space between )To e.g. For (a-1) To b

Fix: Removed the space between - and 1 in Return -1 or Return -a