Xojo IDE Reformat Code Script

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:@]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:

: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

Fix: Corrected Me.a+=b and Self.a+=b (and all variants there of)

Current features

-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, convert types as you type
-An error checking feature that will notify you if the line has: mismatched parentheses, missing opening parenthesis, missing closing parenthesis, mismatched quotes

Visit https://github.com//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 or later as there may be some issues with previous versions that have had bug fixes in later releases.

Still not working for you?

If the reformat code script doesn’t seem to activate for you, please follow these steps closely:

https://github.com//ReformatCode#getting-started

Make sure that the “ReformatCode.xojo_script” file is named exactly that and it’s inside the Script folder of the current version of Xojo that you’re using.

After restarting the IDE, if nothing happens make sure you have “Apply standardize format after ending line” turned on under Options->Coding in the IDE.

Failing all that, please post a message to this thread asking for some help.

has this been corrected in this update ?
https://forum.xojo.com/51048-bad-autocompletion-when-standardize-code-is-checked
thanks.

Unfortunately not, this is an issue with the IDE with regards to how it moves the text around during a Shift+Enter in conjunction with the reformat code script system, the fix is out of my control as it also happens with the simple script that xojo provide on the Custom Code Reformatting documentation page.

I brought this up in a private note on <https://xojo.com/issue/51228> in June 2018 but it wasn’t fixed. I’ll make another ticket with it in because its still not working correctly even in the upcoming 2019r1 release.

Thanks, Julian, for bringing us this reformat script.
who knows may be one day Xojo will correct this IDE bad behavior, and then it will be perfect !

if you give us teh feedback number, some of us might join it so it might raise high enough that someone sees the case.

In the latest beta, the first line of the macro’s (comment line) is not visible, therefor there isn’t any explanation to see while the list with the possible choises pops up. This is tried in Windows 10.

Still a very usefull addition to the IDE!

<https://xojo.com/issue/55398>

rank 550th … :frowning:

Seen and pushed to development team :slight_smile:

I’ve just updated the Reformat Code Script to include some useful new features.

Current features

-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, convert types as you type
-An error checking feature that will notify you if the line has: mismatched parentheses, missing opening parenthesis, missing closing parenthesis, mismatched quotes
New features
-Parentheses checking across line continuations in pasted code (less error message spam)
-Automatic conversion of hex values
-Automatic conversion of #define to const
-Automatic conversion of MSDN code blocks to declares

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

Original features video - https://youtu.be/IAVjh-xiO0w
Latest features update video - https://youtu.be/-JPjQ4Gn1bM

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 or later as there may be some issues with previous versions that have had bug fixes in later releases.

Still not working for you?

If the reformat code script doesn’t seem to activate for you, please follow these steps closely:

https://github.com//ReformatCode#getting-started

Make sure that the “ReformatCode.xojo_script” file is named exactly that and it’s inside the Script folder of the current version of Xojo that you’re using.

After restarting the IDE, if nothing happens make sure you have “Apply standardize format after ending line” turned on under Options->Coding in the IDE.

Failing all that, please post a message to this thread asking for some help.

1 Like

I tested the new script and for a line like this:

lines.Append log("test")

is changed like this

lines.AppendLog("test")

ugh!

Doh sorry! I missed out one line of code in my refactor, fixed and updated on git, thanks Massimo!

I’ve added that test to my long list.