Xojo IDE Reformat Code Script

  1. ‹ Older
  2. 2 weeks ago

    Wes W

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

    @Julian S Wes, put some votes into Feedback Case #50560 if you want to give Norman more work fix the problem you mentioned (which was introduced in 2017r1) :)

    Thanks Julian, I've added case 50560 to the "My Top Cases" category in the Feedback application. Is that how you 'put some votes into' it?

    I get that the Select Case/End Select is a bit odd in that it has an opening (Select Case) and a closing (End Select) but the Case clauses only have an opening (there's no End Case.) But still, the Case clauses are children of the Select Case and should be indented. I really wish the IDE would allow a little latitude when it comes to indenting in this particular situation.

  3. Julian S

    May 16 Pre-Release Testers, Xojo Pro UK

    @Wes W Thanks Julian, I've added case 50560 to the "My Top Cases" category in the Feedback application. Is that how you 'put some votes into' it?

    Spot on

    Select certainly is an odd one (trying to tactfully keep this thread on track :D)

  4. Julian S

    May 16 Pre-Release Testers, Xojo Pro UK

    I read a comment on here (I can't remember where or who) that mentioned their project can take a number of minutes to compile when something as trivial as a mismatched parenthesis ( ) could cause a compilation failure and a waste of time,

    I'm thinking about putting in mismatched parenthesis detection into the script. As I'm not able to do anything fancy like highlight the line or place a warning symbol in the gutter from the script (feature request?) I'm thinking about adding a comment to the end of the line that looks something like:

    if a = ( a + 1 then // MISMATCHED PARENTHESIS

    It would insert itself before any other comment on the line so you'd have the most change of seeing it if you had a long line, or I could insert it at the start of the line and comment the whole line out to make it more obvious?

    Good idea? Bad Idea? Want is displayed differently? Thoughts?

  5. Jens K

    May 16 Pre-Release Testers, Xojo Pro Europe (Germany)

    Good idea!

  6. Julia T

    May 16 Sandy Hook, Connecticut

    As long as it doesn't flag the mismatch in real time. I have an editor that does that, and it's maddening - every time I enter a left parenthesis it throws up a startling warning, and I'm like, "jeez, let me finish!"

  7. Julian S

    May 16 Pre-Release Testers, Xojo Pro UK

    Heh, doh! No it'll only happen when you move off the line.

  8. Julia T

    May 16 Sandy Hook, Connecticut

    The reformatting stuff doesn't thrill me much, but the macro facility - heck yes!!!! Must check it out asap, thanks!

  9. Julia T

    May 16 Sandy Hook, Connecticut
    Edited 2 weeks ago

    @Julian S 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.

    So it's not currently possible to do multi-line macros? That is heartbreaking. Is there a feature request in Feedback I can vote for?

  10. Thomas T

    May 16 Pre-Release Testers, Xojo Pro Europe (Germany, Munich)
    Edited 2 weeks ago

    Quite impressive.

    I just had a look at the script and have a few questions about it out of pure curiousity:

    What makes this script work, i.e. what are the conditions under which it gets invoked? I could not find code that "inits" it, i.e. tell the IDE to invoke "CleanBlock" whenever the editor leaves a code line. Also, where does the tokenizer come from? Is there a doc on all this behavior by the IDE?

  11. Jürg O

    May 16 Pre-Release Testers, Xojo Pro

    @ThomasTempelmann Is there a doc on all this behavior by the IDE?

    Xojo Dev Center: Custom Code Reformatting

  12. Julian S

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

    @Julia T So it's not currently possible to do multi-line macros? That is heartbreaking. Is there a feature request in Feedback I can vote for?

    Nope :(

    I just noticed that its visible to only me and Xojo, I've asked for it to be made public.

    Feedback Case #51365 all my comments in there are marked as private due to a bug in feedback so the ticket looks one sided and Norman is talking to himself ;)

    Norman/Xojo is aware of it and a little birdy tells me that they hope to get it into 2018r2 so fingers crossed.

    Thanks for posting the link Jurg, let me know if anyone has any further questions.

  13. Julian S

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

    Well its done but I've just found out that it will trigger mismatched parenthesis when a line is split using a continuation _ so you end up with:

    a = (1 + _//MISMATCHED PARENTHESIS
    a)//MISMATCHED PARENTHESIS

    and as I can't navigate around the code in the script and I'm not able to work back and count the parenthesis. I can't even check if the current line is a portion of a continuation and ignore the check.

    This would mean that your code would end up with //MISMATCHED PARENTHESIS around the place when you split a line that contains parenthesis.

    Not ideal but do you think its still worth doing?

  14. Julian S

    May 16 Pre-Release Testers, Xojo Pro UK

    New Feature

    Checks the line for mismatched parentheses and notifies you

    Example

    a = ((1+2)/3

    becomes

    a = ((1+2)/3'MISMATCHED PARENTHESES

    when you move the cursor off the line.

    Additional preferences

       CheckMismatchedPar (true)

    If you set this value to true it will check if there are matching parentheses on the line. If not it will add a comment to the end of the line notifying you of the fact.

       MismatchedParComment (')

    This is the comment type used for the mismatched parentheses notification.

       MismatchedParMessage ("MISMATCHED PARENTHESES")

    This is the message that is shown to notify you if there are mismatched parentheses on the line.

    Download

    Get the latest update here

  15. Andre K

    May 17 Pre-Release Testers

    Julian, thanks for this fantastic tool, works like a charm.

    As always there are edge cases such as this:

    Dim a, b As String
    a = "hhah"
    b = mid(a, 3 ' MISMATCHED PARENTHESES
    b = mid a, 3)(

    The last line should IMHO been marked as MISMATCHED PERENTHESES and the line before that one should show "MISSING CLOSING PARENTHESE".
    But that, i think, is very hard to implement.

    Something along these lines could maybe useable for single / double quotes especially in JS code blocks.
    Add to the wishlist???

    After all i think the tool makes the code in the editor much and MUCH better readable.
    Again MANY THANKS !!! :D

  16. last week

    Julian S

    May 19 Pre-Release Testers, Xojo Pro UK
    Edited last week

    Great idea Andre, checking single quotes is a little harder as they are considered comments if they are outside of quotes and I don't really want to get into parsing javascript inside comments. If you want to have a go at this please do, the source is on the git and I'll happily merge it in.

    I've just added this and tweaked some of the settings. Let me know if you find any problems with this update.

    Updates

    An error checking feature that will notify you if the line has:

    • mismatched parentheses
    • missing opening parenthesis
    • missing closing parenthesis
    • mismatched quotes

    Settings

    These error messages will automatically be removed when you move off the line if the error is corrected without altering the format or spacing of the error message.

       MessageComment (')

    This is the comment type used for error message notifications. This setting can either be `'`, `//` or `Rem`.

       MessageParMismatched (MISMATCHED PARENTHESES)

    This is the message that is shown to notify you if there are mismatched parentheses on the line. Setting this to `_` (underscore) will turn off checks for this setting and the error message will not be shown.

       MessageParOpening (MISSING OPENING PARENTHESIS)

    This is the message that is shown to notify you if there is a missing opening parenthesis on the line. Setting this to `_` (underscore) will turn off checks for this setting and the error message will not be shown.

       MessageParClosing (MISSING CLOSING PARENTHESIS)

    This is the message that is shown to notify you if there is a missing closing parenthesis on the line. Setting this to `_` (underscore) will turn off checks for this setting and the error message will not be shown.

       MessageQuoteMismatched (MISMATCHED QUOTES)

    This is the message that is shown to notify you if there are mismatched quotes on the line. Setting this to `_` (underscore) will turn off checks for this setting and the error message will not be shown.

    Download

    Get the latest update here

  17. Andre K

    May 19 Pre-Release Testers
    Edited last week

    Julian, you are a miracle, in a short test the new version works just fine, even the opening and closing error message for parenthesis work as i meant. Great job!

    Thinking further about the single quote balancing i think indead that that is realy hard to implement, think about one single quote within a quoted text, how should you decide if that single quote is meant as such and no balancing should take place. IMHO that is almost impossible.

    Oh, and i like the automatic removal of the error message after correcting the bug. A real masterpiece you made!

  18. Julian S

    May 19 Pre-Release Testers, Xojo Pro UK

    Glad you like it Andre.

    Yes the single quotes thing is a bit tricky and I don't really feel like writing a javascript parser at the moment but I can think of a way of doing it if someone has a javascript validator/parser.

  19. 6 days ago

    LANCE D

    May 22 Pre-Release Testers, Xojo Pro

    I get an error when I try to copy in some obfuscated code on MISSING CLOSING PARENTHESIS on a continuation line:

    Return DecodeBase64(c(97) + c(23) + c(61) + c(66) + c(119) + _'MISSING CLOSING PARENTHESIS
    c(116) + c(37) + c(69) + c(79) + c(65) + _
    c(9) + c(114) + c(58) + c(27) + c(100) + _
    c(34) + c(3) + c(72) + c(2) + c(56) + _
    c(77) + c(90) + c(83) + c(86) + c(91) + _
    c(5) + c(76) + c(113) + c(45) + c(107) + _
    c(17) + c(70) + c(38) + c(7) + c(31) + _
    c(36) + c(10) + c(39) + c(73) + c(51) + _
    c(50) + c(25) + c(11) + c(42) + c(117) + _
    c(21) + c(81) + c(46) + c(57) + c(99) + _
    c(32) + c(103) + c(40) + c(41) + c(22) + _
    c(71) + c(68) + c(16) + c(35) + c(80) + _
    c(1) + c(19) + c(96) + c(18) + c(8) + _
    c(28) + c(20) + c(88) + c(98) + c(12) + _
    c(78) + c(4) + c(59) + c(84) + c(24) + _
    c(54) + c(33) + c(85) + c(63) + c(95) + _
    c(111) + c(67) + c(94) + c(29) + c(101) + _
    c(0) + c(110) + c(44) + c(52) + c(62) + _
    c(105) + c(6) + c(75) + c(104) + c(49) + _
    c(106) + c(118) + c(89) + c(64) + c(43) + _
    c(92) + c(48) + c(74) + c(14) + c(13) + _
    c(47) + c(15) + c(26) + c(115) + c(87) + _
    c(93) + c(102) + c(53) + c(108) + c(55) + _
    c(112) + c(82) + c(60) + c(30) + c(109))'MISSING OPENING PARENTHESIS

  20. 5 days ago

    Julian S

    May 22 Pre-Release Testers, Xojo Pro UK
    Edited 5 days ago

    I mentioned this about a week ago, there's not really anything I can do about messages around continuation marks because the IDE doesn't give me the ability to navigate the code to check where the marks start/end. I have a feature request in for this Feedback Case #52241

    I'll have a look at sorting them for a multi-line paste like above as I think I can navigate around the multi-lines being pasted in, however you would need to paste the above with a spare line at the bottom so your cursor is off the last line, otherwise when you moved off the line it would just check it and place the message back there as I wouldn't be able to navigate to the top to check.

    Personally I'm happy with them in my code for now until the feature request is looked at, how about you? Please chip in if you're using it at the moment.

or Sign Up to reply!