Xojo IDE Reformat Code Script

-Fixed bug with no parentheses calls (thanks Massimo)
-Implemented a work around for a bug in the IDE regarding empty lines
-Now deal will hex values that include a trailing L

Thanks Julian, works now.

I am having an issue with this script and the DownTo keyword, where it is removing the space before it ie

for tempInt As Integer = myArray.Ubound DownTo 0 … next
becomes

for tempInt As Integer = myArray.UboundDownTo 0 … next

Can someone else confirm this?

I cannot find anywhere in the Script to disable this activity and I’m not sure if the Ubound or the DownTo is causing it.

I thought this might happen as I did a major refactor of one of the areas that caught all types of tokens.

To temporarily turn this off, uncheck reformatting in Options>Coding>Apply standardize format after ending line

Give me a few minutes and I’ll have a fix up on github.

Hmm it doesn’t happen here, are you sure you have the latest version?

If you download the latest version from git I’ve just added a way to view the version number of the currently installed script.

If you are on the latest version, typing this into the code

reformat_code_script_version

then moving onto the next line should show this message

Reformat Code Script Version v0.14

This means you’re using the latest version and the problem you mention above shouldn’t happen, could you let me know if it does/doesn’t as I can’t seem to replicate it?

Thanks

I was on version 12, so the issue is resolved now I have upgraded to version 14. Sorry for the inconvenience caused.

If I do not have the ReformatCode.xojo_script in place and am simply using the default formatting in place then it capitalizes functions like Mid

a=mid(b,4) --> a=Mid(b,4)

If I have the ReformatCode.xojo_script in place then this autocapitalization does not work.

Two questions:

  1. Is there a way to make ReformatCode display this same capitalization functionality with things like Mid, Left and the various Xojo commands?
  2. Is there a way, when ReformatCode.xojo_script is in place, to force an individual reformatting using the “standard” methodology at a particular time?

the script replaces the built in reformatter
so the script would have to have the keyword list and do the same thing as the built in one

[quote=453519:@Robert Livingston]Two questions:

Is there a way to make ReformatCode display this same capitalization functionality with things like Mid, Left and the various Xojo commands?
Is there a way, when ReformatCode.xojo_script is in place, to force an individual reformatting using the “standard” methodology at a particular time?[/quote]

  1. Yes. Near the top of the script there’s a section just under the comment 'TODO - reengineer this? that has a lots of commented lines. One of those lines 'Dim RC_Xojo_Core_MemoryBlock()... includes Left Mid Right etc. Uncomment that, then at the top of Sub InitWords() you’ll need to add that array into the list of concats.
RC_Words.Concat(RC_Xojo_Core_MemoryBlock)

Everything in RC_Xojo_Core_MemoryBlock will now be capitalised for you when you restart the IDE. You can uncomment other sections if you want more words corrected, just remember to add them to the block in InitWords.

  1. Not automatically I’m afraid, you can either alter the file as mentioned above and restart the IDE or you can add words at “runtime” so to speak if you do the following:

Create a string constant in App called ReplaceWords

In there enter your words in pairs separated by commas so to replace mid with Mid you would enter

mid,Mid

or to do mid and left, enter

mid,Mid,left,Left

etc.

This works instantly without requiring a restart and is project dependent because it reads the constant out of the project. A video demo of this can be seen here https://youtu.be/IAVjh-xiO0w?t=555

[quote=453525:@JulianS]2. Not automatically I’m afraid, you can either alter the file as mentioned above and restart the IDE or you can add words at “runtime” so to speak if you do the following:

Create a string constant in App called ReplaceWords

In there enter your words in pairs separated by commas so to replace mid with Mid you would enter

mid,Mid

or to do mid and left, enter

mid,Mid,left,Left

etc.

This works instantly without requiring a restart and is project dependent because it reads the constant out of the project. [/quote]

Thanks for that information. Actually, if you put the ReplaceWords constant in an external module referenced by the ConstantStorageLocation constant in the App section, it can propagate across all the projects that include the module. I’ve updated all of my apps and templates this way so I don’t have to do them all individually.

Yes perfect Dale, I didn’t want to confuse things with an advanced setting like that, but I’m glad someone is using the feature :slight_smile:

[quote]Create a string constant in App called ReplaceWords

In there enter your words in pairs separated by commas so to replace mid with Mid you would enter[/quote]

The video referenced by Samphire makes this clear, but I stumbled a bit here before seeing the video. I put the ReplaceWords constant at the level of App rather than in the module Settings. If you put the constant in App, it does not work. Just mention this for the benefit of others who might make the same mistake.

It does work in App.ReplaceWords but not if you have an App.ConstantStorageLocation that points somewhere else, you’d have to put it there instead :slight_smile:

Thanks for clarification.

  1. I wish that Xojo did all of this automatically. The other language I most commonly use (4D) makes all the capitalization patterns and space patterns the same, no matter what you type. So everyone’s code looks the same.
  2. You have done a great service for people like me with your formatting contribution.
  3. I am curious why the
Dim RC_Xojo_Core_MemoryBlock() As String = Array("LittleEndian", "Size", "Data", "Clone", "IndexOf", "Left"…

sits under the 'TODO - reengineer this? heading rather than just being a Preference to turn off and on like many other things in your formatter.
Is there something potentially wonky about this thing that you are considering reengineering?

  1. There’s such a diversity of people using xojo everyone likes their own way to do things. While the reformat code system isn’t perfect its much better than not having the feature there to work with so I’m thankful for that.
  2. You’re welcome, I really made it for myself, I’m just glad others find a use for it too :slight_smile:
  3. There’s a few reasons:
    a) There’s no way to easily differentiate between for example a variable name and a method name. This means that I need to maintain a list of everything that needs to be converted, This is where the commented block came from originally. I made sure Keywords were covered but quickly realised that the array concat list would end up being pretty extensive with around 700-750 classes/methods etc.

b) As there’s currently no way to maintain state/data between calls to the reformat script it is called from scratch every single time the cursor is moved to a new line. This means that those arrays are allocated and scanned over very often which was a bit concerning to me in terms of performance. While I have some options to tweak the way things work for extra performance I haven’t yet.

c) Because of a) if I were to cover all words used by the language it would start to cause issues with enforced capitalisation where people might not want it when using camel case for example with Width. If this was capitalised then you wouldn’t be able to have a variable called width with a lower case w and as Xojo allows you to call methods without parenthesis it gets even more difficult to ascertain what is a method vs what is a variable that shouldn’t be touched.

So I left it where it is at the moment with all keywords and a pretty standard set of words covered with the option for people to add more in themselves. If the reformat script is expanded to allow for detection of variables and some kind of persistence between calls then I would readdress this but at the moment I feel its almost at the right spot of picking up most things but not getting in the way but please let me know if you/anyone else has thoughts on this.

Ahh, that is a problem. Too bad.

The lack of enforced formatting in Xojo complicates version control because Diff analysis will identify differences in code versions that are not “real” but merely meaningless differences in capitalization and spacing.

@JulianS - I’ve been looking at this option for a couple of months, finally got around to trying it. Glad I did. I love it.
Great work!

This is my number one headache when dealing with Xojo version changes. One time, the value is “True” and the next it’s True (without the quotes). Then, numbers are numbers and the next time they are quoted strings … This is yet another reason for my locking all of my projects to 19r1.1.

I just Brought another project forward from 12r2.1 and am battling the yellow background in TextFields and TextAreas because of the shifted color codes.

I know that change is inevitable, but … I wish that Julian’s wonderful format script had super undo “update for change sake” power!!!

I’ve just updated the Reformat Code Script to v0.17 which includes 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
-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

New features

-Added support for Var
-Automatic conversion of Dim to Var and Var to Dim as desired
-Automatic conversion of Var to Dim when using API1 IDE’s (pre 2019r2)
-Added the ability to force case on anything except variables (uppercase, lowercase or xojo default)
-Updated Windows Declare list
-Made some hard coded tokens match your force case settings
-Moved the placement of defaults to the top of the script so they are easier to find and change
-Added a version check, type rc_version on a new line to display the current script version

Visit https://github.com/JulianSamphire/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/JulianSamphire/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.