Xojo Code Formatter - Written in XojoScript for IDE access

[quote=14086:@Tobias Bußmann]two little fixes:
[/quote]

Do you have a github account? Could you issue a pull request?

not yet, but I have it on my list…

Oh, and you could add the intristic Types like Integer, Sting, … to the KeywordsToCapitalize Array.

yes, me too as it also manages whitespace. but there are plenty of different styles the different devs out there prefer. so some settings would be great. To me the Code Format Script is a nice workaround but this is a functionality that should be handled and maintained by Xojo officially.

as we are on the topic, some more feedback cases on the same topic. I’ve already sent merge requests (did that in the past also, but in my impression, merge requests are just delivered to /dev/null at RS…)

<https://xojo.com/issue/26429> - Make Option For AutoComplete Run On Every Line Edit
<https://xojo.com/issue/11478> - Put Standardize Format icon button on the IDE Code Editor toolbar
<https://xojo.com/issue/4155> - Preference for Standardize Format
<https://xojo.com/issue/2170> - Standardize Format needs a shortkey key

Maybe we should create 4 single-topic new cases: “easier access of functionality”, “automatic run after leaving row”, “take care of whitespace” and “take care of identifiers” and try to get the others merged on these.

[quote=14090:@Tobias Bußmann]not yet, but I have it on my list…

Oh, and you could add the intristic Types like Integer, Sting, … to the KeywordsToCapitalize Array.
[/quote]

If it is not on your short list, I’ll make the changes, but it would be nice to have pull requests, that way what is done is exactly what was expected and it is already tested and works in the scenarios that prompted the changes. It’s also easy and nice to see contributors as well as giving credit.

Works fine now.
:thumbs up:

OK, I fixed the trailing space problem, comma space problem and formatting of // comments. From here on out, if you have an issue please contact me directly or file a bug on github as I do not think the forums are the proper place to support a 3rd party script/app. Thanks for all the input, I hope the script is of help to someone, and please, file bug reports, suggest features, submit features, submit bug fixed!

How does this work??

I placed the Format Code Script.xojo_script file into Xojo’s Scripts folder.
I then restarted Xojo, opened my project file, then compiled it - but nothing changes?

I was under the impression that the Keywords in my code would be automatically changed to TitleCase etc.
Have I totally misunderstood the concept of this?

Thanks.

[quote=115296:@Richard Summers]How does this work??

I placed the Format Code Script.xojo_script file into Xojo’s Scripts folder.
I then restarted Xojo, opened my project file, then compiled it - but nothing changes?
[/quote]
You’ve successfully installed the IDE script but you haven’t yet run it. To do this, select the script from the File > IDE Scripts menu.

Format Code is a more advanced “Standardize Format.” Both must be ran manually when you want to format your source. Both will only execute on your current method. As Gavin said, you must choose File > IDE Scripts > Format Code. I am on a Mac, and I added a shortcut for Ctrl-F, so I tend to code, format code and save, code, format save, etc…

In the meantime I’ve tried many times to make the shortcut work with the Format Code Script, but it fails every time.
I defined the shortcut in Keyboard > Shortcuts > App Shortcuts.

When I press this shortcut in Xojo, the Script Editor is started.

Very frustrating! :frowning:

Paul,

I have run into the same thing, and yes, drives me nuts. I am not sure how I first discovered this, but try changing the name of the script to “Format Code.xojo_script” and update your menu shortcut accordingly. See if that works.

That fixes it for me, but it may be a few weeks and then it starts opening in the editor again… A file rename will make it work again. Some others have not had that issue at all. I am unsure where the actual bug exists at, but annoying for sure.

Out of interest, does selecting the menu item with your mouse cause the script to run or the Script Editor to open?

It always executes for me when manually clicking even when the shortcut messes up. You can, however, Option click a script from the IDE Scripts menu and that will cause it to open in the script editor instead of running.

Yeah, I see the same problem myself sometimes, was just checking the symptoms were exactly the same. Didn’t know about the renaming trick, will try that.

@Gavin Smith
When I select the menu item, the script is run, no Script Editor.

@Jeremy Cowgar
I’ve changed the name to FormatCode (and without the xojo_script extension) and it works now with ^F.
(Why haven’t I thought of this before). :wink:

Paul, my gut feeling (no evidence though) is that the bug is in Xojo. Chances are in a few weeks you’ll have to rename it again. It doesn’t have anything to do with the actual filename, that I can tell. I have no idea what is triggering it.

I have the same feeling too.
Shortcuts I’ve made to other programs work fine.

Scripts are no programs - they are just another document type that Xojo can open

I don’t understand what you mean? The issue at hand here is that when you assign a shortcut to an item in the File > IDE Scripts menu such as “Format Code”, for a while it’ll work OK. i.e. hit the shortcut and the script will execute. Then it begins instead of executing, it opens in the Script Editor, as if you clicked the menu entry with the Option key.

The menu does get rebuilt at IDE start time & when you open a project (depending on where you have the script)
Thats the only thing I can imagine has any impact

[quote=119954:@Norman Palardy]The menu does get rebuilt at IDE start time & when you open a project (depending on where you have the script)
Thats the only thing I can imagine has any impact[/quote]

It’s interesting though that it always selects the right item, just sometimes it executes the right item and other times it opens the right item in the Script Editor. Shrug.