IDE removing () and starting spaces

Not sure if you’ve noticed, but

  1. If you type the two characters ‘()’ anywhere in a sentence in the IDE then move your cursor away, these two characters disappear
  2. You cannot type a space character at the start of a line, it just won’t happen

I am sure there are good reasons for this, but I thought you might find it fun. There may be other oddities too.

I don’t think so. Code with the parenthesis works just fine maybe they decide to delete them because are not necesary, but those actually improve the code readability.

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

I turned on Standardised Format recently, so thank you for the source.

Do you chaps know about https://github.com//ReformatCode ?

Can be used to append the empty parenthesis on a method call?

Is there a way to reformat ALL the code at once?

Alas not.

Not with the script I posted as that only runs when the cursor is moved off the line or when code is pasted into the IDE.

You might want to take a look at GitHub - jcowgar/xojo-format-code: Code formatter written in XojoScript for Xojo but its essentially the same as Cut+Pasting the code in the current view.

There might be some more xojo code “prettifiers” out there that people know of and can post links to?

No, but there’s a feature request for that :wink:
<https://xojo.com/issue/47517>

A quote from there:

I’d be interested to know how to do that… :slight_smile:

Mac 10.14.4
Xojo v2018 Relase 4

I know of it. But when I install it I am not sure what to expect. If I am in Xojo and go to the File>>IDE Scripts menu and run it, I get a message: IDE Script Compile Error
Compiler Error [11] Error found while compiling on line 365. Continue?

If I Continue I will get notifications of other lines with errors. 338 etc.

I have used cowgar script and that works for me if I call it from the Scripts menu. But if it is not going to do more than what would happen if I Cut and Paste back, then it is not too useful to me. It does things like capitalize

while … wend

if I do not have the Standardize format: Apply standardize format after ending line already set.

In the Xojo Preferences I do use Autocomplete >> Applies standard case and Shows Icons. Also Standardize format: Apply standardize format after ending line. This is a great boon.

Nonetheless, I remain quite frustrated at the state of formatting in Xojo. Take a Xojo function like round or abs or whatever. If I type rou then it will auto-complete to Round which I like with the capital “R” but I do not know how to convert all my [b]round/b to [b]Round/b in my code window. If I did not use autocomplete when typing round, I am stuck with the lower case “r”. If I paste in code from somewhere else, this situation applies as well.

Calling Standardize Format does not do it. I find this irritating.

Is there some method that I do not know of that will accomplish this task?

When I watch the YouTube video, it seems to imply that I place the script in the Scripts folder and it will somehow magically work without even calling it from the File>>IDE Scripts menu. I cannot understand how that could work. Does it conflict with the built-in formatting of Apply standardize format after ending line? Is it automatic because its name is “ReformatCode”?
Are my problems with manually calling it from File>>IDE Scripts menu simply because it is not intended to be used in this fashion?

When I try the test code of

if  a=2  then

nothing magical happens. It seems to imply that I have not installed it correctly.

If I type (after the preference in the IDE is set to Standardize format: Apply standardize format after ending line)

if a=2 then -> If a = 2 Then

On the other hand, if I type

hello()

The parenthesis do survive no matter whether or not I have Standardize format: Apply standardize format after ending line checked.

Typing

hello(world)

does not result in padding inside the parenthesis.

Further experimentation: (testing done with Standardize format: Apply standardize format after ending line off.)

I do have it installed as best I understood the directions in the YouTube video. The error I got when specifically calling if from
File>>IDE Scripts
convinces me that that is not what I am supposed to do.

So I test it assuming that it will work magically. It does seem to have some effect. When I type

put the dog () out

normally the () would disappear, but it does not. So I interpret this to mean that the code is doing something.

When I type

if a=2 then

Nothing happens. The YouTube video implies to me that it should transform to

[code]If a = 2 Then

End If[/code]

I then, as per the YouTube, set up the App Constant: ConstantStorageLocation = Settings
And a Module Settings
And a Constant in that Module: PadParInside = True
When I type

hello(world)

Nothing happens. There is no padding installed inside the ()
Similarly when creating another constant PadParOutside = True
No effect on

hello(world)

Similarly when creating another constant PadEmptyParInside = True
No effect on

hello()

So basically, the only hint that I have that the ReformatCode script is doing anything is that it seems to prevent () from disappearing when typed into the IDE.

Well, I think I misspoke here.

put the dog () out

The () are preserved if Standardize format: Apply standardize format after ending line is turned off as it was for my testing. So I have no evidence that the ReformateCode is doing anything on my system.

It is a shame, but a really nice advantage to have the option of a better Standardize Format

Thanks

[quote=431484:@Robert Livingston]I know of it. But when I install it I am not sure what to expect. If I am in Xojo and go to the File>>IDE Scripts menu and run it, I get a message: IDE Script Compile Error

So I test it assuming that it will work magically. It does seem to have some effect. When I type[/quote]

Well, there is a detailed description and instruction in the github page. there is also the video, and even a link to a forum thread where julian aswered the same question of some else that did not readed the instructions and expected to work magically.
I’m shure it is faster to see the video, read the instructions, read the forum thread, and even personalizing the script to avoid the use of constants in the IDE than runing it over and over doing tests and then writing a long post about not knowing how to use it.

[quote=431474:@Jürg Otter]A quote from there:

Norman Palardy: Just FYI you can actually implement this for yourself by iterating over all the project items, selecting all the text in a code item and then issuing the command “Standardize Format” which will now run whatever script you have for formatting

I’d be interested to know how to do that… :)[/quote]

That is easy, in the navigator, Click a item with code, pres Ctrl + A (on windows) to select code, Right click on the selection and click the “Standardize Format” item from the contextual menu, then “iterate over all the project items” repeating the steps. I think he means manually.

Yeap, doable, but, not realistic for big proyects.

I have to thank Ivan for his kind and helpful remarks.
With his cryptic guidance, I got things to work.
In summary, for others who might fall into this thread:

  1. Standardize format: Apply standardize format after ending line off This has to be checked on. It is in Xojo preferences.
  2. The name of the script (ReformatCode.xojo.script) is the key to why it “magically” works. Xojo apparently looks for this name and if present in the Scripts folder, it is used instead of the default behavior when (1) is checked on. It is an alternate code "“prettifier” to the default provided by Xojo.
  3. The “official” location for discussion of this product that kindly provided is:
    https://forum.xojo.com/47389-xojo-ide-reformat-code-script
  4. You do not attempt to access the script through File>>IDE Scripts
  5. As Ivan alluded to, another person managed to make some of the mistakes that I did and this all is discussed on the site (3). If I had gone there, I might have saved the rehash here.
  6. I thank for his contribution and apologize for screwing things up despite his extraordinarily rich documentation.

In defense of myself, the reason for my long-winded posts was related to the fact that when trying to answer other’s questions I generally find more information rather than less to be useful.

[quote=431507:@Ivan Tellez]It is a shame, but a really nice advantage to have the option of a better Standardize Format

Thanks[/quote]

If the feature was exposed for me by the IDE, I would implement it :slight_smile:

I just woke up to this. I’m glad you got it sorted Robert, thanks Ivan.

I’ll update the forum thread about it making it a little clearer and I’ll see if I can tweak the video too.

If you have any further issues with it, let me know on the thread posted above.

Cheers

[quote=431507:@Ivan Tellez]
That is easy, in the navigator, Click a item with code, pres Ctrl + A (on windows) to select code, Right click on the selection and click the “Standardize Format” item from the contextual menu, then “iterate over all the project items” repeating the steps. I think he means manually.[/quote]
IDE scripting can do this programmatically

The IDE should do the reformat automatically. Even 20 years ago the suboptimal VBA IDE could do this.

Just… how?
I guess something along these lines?

IDE Script:

[code]Dim processedItems() As String

Sub processProjectItem(projectItem As String)
processedItems.Append(projectItem)
'if this is a projectItem that contains code…
'…how to access all codeItems and apply StandardizeFormat?
'DoCommand(“StandardizeFormat”)

'recursive loop through all subitems of this projectItem
Dim subItemList As String = Sublocations(projectItem)
Dim subItems() As String = subItemList.Split(ChrB(9))

For Each subItem As String In subItems
processProjectItem(projectItem + “.” + subItem)
Next
End Sub

Dim rootItemList As String = Sublocations(“”)
Dim rootItems() As String = rootItemList.Split(ChrB(9))

For Each rootItem As String In rootItems
If (rootItem = “Build Automation”) Then Continue
processProjectItem(rootItem)
Next

Dim sAllProcessedItems As String = Join(processedItems, EndOfLine)
Clipboard = sAllProcessedItems[/code]

edit: script adds “.” for SubItems, in order to retrieve the whole project structure.
I really have no clue… and this example above doesn’t even iterate over “multiple subfolders”… E.g. in a project structure like this:
MainFolder1 → Subfolder1_1 → SubSubFolder1_1_1
MainFolder 1 → SubFolder1_1 → SubSubFolder1_1_2
And I don’t see how to iterate and access all “Methods” and other Items that may contain code - and how to apply “StandardizeFormat” to everything that contains code.

Can you please share with us a script that can do the StandardizeFormat in the whole proyect?