How to get the ReformatCode.xojo_script working

Hi All,

  • Windows 11
  • Xojo 2025r1.1
  • Using the latest version of the script from here
  • Placed in the Scripts folder in my version of Xojo (only one installed)
  • File name = ReformatCode.xojo_script
  • Edit => Options => Coding => Apply standardize formatting after ending line is checked
  • App.RC_ConstStorageLocation = Settings
  • ReadPreference_ConstStorageLocation(“ConstantStorageLocation”, RC_ConstStorageLocation, “Settings”)
  • ReadPreference(“Prefix”, RC_Prefix, “RC_”) (set this way in the script and in the Settings module)
  • RC_DimVar = “Var” (both script and Settings Module)
  • etc…
    The script does not appear to be triggering.
    Anyone know what goofy thing(s) I am doing that would prevent this?

Thanks.

Here’s an example Xojo project that is setup to utilize the script. I made this a while ago for testing a script issue.

Note the App.ConstantStorageLocation constant and the module named ReformatSettings.

Although I made this on a Mac, it should run on Windows too.

Also note: after placing the ReformatCode.xojo_script file in the /Scripts folder, the Xojo IDE needs to be restarted.

Reformat Code Testing.xojo_binary_project.zip (5.4 KB)

Thanks. When I look at the App.ConstantStorageLocation the icon has some kind of read mark on it. What does that mean?

That does not seem to be working and I am using the plain script from github linked above.
Any thoughts?
(To be clear I opened your project and started moving around, but nothing happened.)

That’s an attribute indicator. In this case the attribute (click the gear icon) is “Hidden” from the autocomplete list, because strictly speaking, that particular constant is not for use in the execution of your project. It’s for use by the script only.

You mentioned in your first post that you edited the script. If so, line 11 should read as the following:

  ReadPreference_ConstStorageLocation("ConstantStorageLocation", RC_ConstStorageLocation, "App.")

Are you moving around inside the Window1.Opening event?

And have you restarted the Xojo IDE?

I have since recopied an unaltered version into the Xojo Scripts folder and restarted several times.
Yes, the “ConstantStorageLocation” line looks like that.
Yes, I am moving around inside the Window1.Opening event.
I am not seeing and reformatting or errors, like MISSING_PARENTHESES, showing up.

I just tried 2024r3.1 Windows, clean install, no plugins just the ReformatCode script and it still did not do anything using your sample project.

I have a maybe stupid question, please forgive me if I missed something: Are you aware that you have to trigger this type of script manually for it to work?

I think I only have one script installed and I have to trigger it on Windows with Ctrl+ALT+1 for it to work.

@Sascha_S of the many posts of yours that I have read I have never seen you ask a stupid question. :slight_smile:
I have used this script previously and because of setting the option in the Coding section anytime you move past a line of code it should trigger the ReformatCode script.
By “move past” I mean moving your cursor line by line through the code, like what you might have in a “Pressed” or “Opening” event.
I don’t recall having to use any particular key stroke(s) to invoke it.
I could be wrong and often times am. :man_shrugging:

2 Likes

@Sascha_S

ReformatCode.xojo_script is special. When read, it does not appear in the scripts menu. The script is run automatically at specific times, the documentation outlines when that is: Custom code reformatting — Xojo documentation


The behavior will depend on which version of the IDE you are using (reference). You can test the script is running for sure by selecting the block of code, right clicking, and choosing “Standardize Format”.

2 Likes

Thanks Tim. I will try that during my lunch break later today and report back here. :slight_smile:

I don’t know what to say Craig, on macOS, up to version 2025r1.1 this project and the original script is working by simply moving the up/down arrow keys through the lines of code.

Note: Not too long ago, it was discovered that the custom reformatting routines had briefly stopped working, but that was fixed. Maybe this is a new issue that affects Windows IDE’s?

As another suggestion, try enabling the debugging feature of the script to ensure the script is running. This is done by adding a DebugLevel constant to the ReformatSettings module (see left-side of my screen-shot), and give it a value of 2.

Thanks for the screenshots and detailed response. I will take a run at this approach as well and report back here later. :slight_smile:

1 Like

This was the changed behavior I was referring to. After my recent “that belongs in Testers” slip, I’m trying to be a little more well behaved. I’ve linked to the ticket / release note about this behavior changing.

Personally, I’m glad it’s being changed because I have clients that insist on committing the formatting changes. I just spent nine hours crafting my own ReformatCode.xojo_script because it was driving my OCD wild.

1 Like

Same. I very much want my own code to be “standardized”, capitalized, spaced, etc. in very particular ways.

But when reading code from others, e.g., macoslib, I want to preserve the original code as much as possible.

It’ll be a fine compromise, if a change in behaviour materializes in some future version.

I just confirmed that is not working for me: 2025r1.1 & 2024r3.1

I tried that @Scott_C and there was no output in the Message pane and none of the code got formatted.

Sorry, Craig, I tried.

I wonder if anyone else can confirm it’s not working in the Windows IDE?

No worries Scott. I really appreciate your time and everyone else’s.
It would be nice to get this working, but at the end of the day, for me, it is a “nice to have” and not critical functionality. :man_shrugging:
I will keep puttering around with this and if I get it working I will post more here.