Xojo IDE Reformat Code Script

  1. 5 weeks ago

    Julian S

    Apr 25 Pre-Release Testers, Xojo Pro UK

    I've put together a little reformat code script that adds some extra functionality to the IDE.

    I've been working on the script on and off ever since I asked Norman for an option to turn off the automatic removal of empty parenthesis. Norman kindly reminded me about the ReformatCode system and gave me some initial pointers and ideas to get me started. He has also kindly fixed most of the bugs I've found.

    The current feature list includes:

    • 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

    Visit https://github.com/JulianSamphire/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 as there may be some issues with previous versions that have had bug fixes in the latest release. If you would like to know what these are because you'd like to us this on your current version then let me know and I'll dig out the bug reports and let you know what you need to void.

  2. Julian S

    Apr 25 Pre-Release Testers, Xojo Pro Answer UK
    Edited 5 weeks ago

    The current feature list includes:

    • 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

    Visit https://github.com/JulianSamphire/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 as there may be some issues with previous versions that have had bug fixes in the latest release. If you would like to know what these are because you'd like to us this on your current version then let me know and I'll dig out the bug reports and let you know what you need to void.

  3. Graham B

    Apr 25 Pre-Release Testers, Xojo Pro The Canada's
    Edited 5 weeks ago

    I downloaded and added to the scripts folder of 2018r1.1, runnning the script gave me a lot of script errors.

    Compiler error [11] Error found while compiling on line 311. Continue?
    Compiler error [11] Error found while compiling on line 312. Continue?
    Compiler error [2] Error found while compiling on line 312. Continue?
    Compiler error [201] Error found while compiling on line 312. Continue?
    Compiler error [11] Error found while compiling on line 320. Continue?
    ....

    Am i missing something?

    I think this will be awesome for me as well. Really miss i++ syntax. Add adding declares will be nice and easy

  4. Julian S

    Apr 25 Pre-Release Testers, Xojo Pro UK
    Edited 5 weeks ago

    Oh, you dont run the script, you just put it in the Scripts folder and restart the IDE, it will then load and run from then on while you move around your code.

  5. Graham B

    Apr 25 Pre-Release Testers, Xojo Pro The Canada's
    Edited 5 weeks ago

    I put it in the folder and started Xojo, added
    dim i as integer i++

    to a test app and nothing happened. thus i thought you had to run it yourself.

    What do you mean "while you move around your code?"
    Also running on macOS 10.12.6, also no random html at the top

  6. Graham B

    Apr 25 Pre-Release Testers, Xojo Pro The Canada's

    Found it, you need preferences - Coding - Apply standardize format after ending line checked on

  7. Julian S

    Apr 25 Pre-Release Testers, Xojo Pro UK

    @Graham B Found it, you need preferences - Coding - Apply standardize format after ending line checked on

    Ahha, I'll add that one to the document, thanks Graham :)

  8. Julian S

    Apr 26 Pre-Release Testers, Xojo Pro UK

    Updated: Remove trailing space if () are removed

  9. Tim J

    Apr 26 Pre-Release Testers, Xojo Pro Phoenix, AZ USA (desication ce...

    Very interesting and excellent work, Julian.

    Glad Norman "reminded" you of this feature. As for me, I had no idea such a capability existed.

    I've had this request (Feedback Case #40097) in since 2015 (and a similar request dating back to fogbugz era). Seem that the hooks were already there.

  10. Julian S

    Apr 26 Pre-Release Testers, Xojo Pro UK

    @Tim J Glad Norman "reminded" you of this feature

    Me too :)

    The macro idea was a bit of an ahha moment for me when playing with the reformat code system. It was working very well inserting multi line macros and it was a bit heartbreaking having to limit it to a single line when the bug was found.

    -image-

    Norman knows about the feature request so hopefully it will come out soon.

    I'm sure a community driven library of useful code snippets will follow as soon as its implemented :)

  11. Tim J

    Apr 26 Pre-Release Testers, Xojo Pro Phoenix, AZ USA (desication ce...

    I've got so many "C/C++" to "Xojo" macros sitting in Paul's CodeVue . It will be really nice to remove the find / copy / paste operations.

  12. Tim J

    Apr 26 Pre-Release Testers, Xojo Pro Phoenix, AZ USA (desication ce...

    BTW - who do you use to do your animated GIF conversions?

  13. Julian S

    Apr 26 Pre-Release Testers, Xojo Pro UK

    @Tim J BTW - who do you use to do your animated GIF conversions?

    SnagIt I should be on commission ;)

    Mac & Windows too!

  14. Tim J

    Apr 26 Pre-Release Testers, Xojo Pro Phoenix, AZ USA (desication ce...

    Ah - the Camtasia folks.

  15. Tim J

    Apr 26 Pre-Release Testers, Xojo Pro Phoenix, AZ USA (desication ce...

    It turns out that I'm kind of asleep this morning - I use Screenflow on the Mac, and do my Windows and Linux screen recordings in VMs, so I already have Animated GIF output - D'oh!

  16. Julian S

    Apr 26 Pre-Release Testers, Xojo Pro UK

    More caffeine input required! I used Screenflow when I tried to move to macOS, shame it doesn't have a windows version.

  17. 4 weeks ago

    Graham B

    Apr 27 Pre-Release Testers, Xojo Pro The Canada's

    Really liking the scripting plugin. Nice work!

  18. 2 weeks ago

    Julian S

    May 15 Pre-Release Testers, Xojo Pro UK
    Edited 2 weeks ago

    Thanks for the bug report in git Jeremie, I've added email notification to the repository so I'll be notified next time ;)

    Fixed an issue where unicode literals (&u) were being treated as strings so they were being surrounded by quotes

  19. Wes W

    May 15 Pre-Release Testers, Xojo Pro MD, Columbia USA
    Edited 2 weeks ago

    Julian,

    In the last year Xojo changed the way they format Select Case constructs. It used to be that Xojo would allow you to indent each Case clause. Like this:

    Select Case RetCode
    
      Case 1
        MsgBox("A")
    
      Case 2
        MsgBox("B")
      
      Case 3
        MsgBox("C")
      
    End Select

    Now Xojo forces the Case clauses to be at the same indent level as the Select Case/End Select.

    Select Case RetCode
    
    Case 1
      MsgBox("A")
    
    Case 2
      MsgBox("B")
      
    Case 3
      MsgBox("C")
      
    End Select

    This makes no sense to me because the Case clauses are children of the Select Case/End Select. Is this something that your code reformatter could be enhanced to handle?

    -Wes

  20. Newer ›

or Sign Up to reply!