Code folding for Livecode 9.6.9 and up

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Code folding for Livecode 9.6.9 and up

Post by stam » Sat Mar 23, 2024 3:39 pm

The more I use this the more it seems so essential as to be insane this isn't part of the standard IDE right now...

One feature I always liked in the glx2 script editor was the ability to organise handlers of a script into 'folders' - but frankly Bernd's solution can organise code in a similar way, without having to leave the standard SE:

Screenshot 2024-03-23 at 14.13.11.png

This really needs to be added to the standard IDE - or at least is worth of a blog post on the mothership's website I would have thought.
I mean outside of the small number of forum readers who've seen this here, there will be no awareness of this essential addition to the IDE (also remembering that IDEs like XOJO made a bit song and dance on their website when they added code-folding).

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Code folding for Livecode 9.6.9 and up

Post by bn » Sat Mar 23, 2024 10:51 pm

stam wrote:
Sat Mar 23, 2024 3:39 pm
The more I use this the more it seems so essential as to be insane this isn't part of the standard IDE right now...
One feature I always liked in the glx2 script editor was the ability to organise handlers of a script into 'folders' - but frankly Bernd's solution can organise code in a similar way, without having to leave the standard SE:
Stam,

I really like your use of the special folding characters "#<" and "#</".
That way you can mark as well as collapse sections of the script.

I am currently doing some minor bug fixes for the folding stack I posted on the previous page. Including a small speed increase when changing tabs in the Script Editor. I am waiting for a new release from LC to test that folding version against. If anyone finds anything that is annoying or not working as expected please raise the issue here.

And thanks for your kind words in Quality Control Center.

Kind regards
Bernd

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Code folding for Livecode 9.6.9 and up

Post by stam » Sun Mar 24, 2024 6:38 pm

Dear Bernd,
I discovered a bit of a problematic issue with your otherwise wonderful solution.

I sometimes refactor code and will change variable names to more appropriate ones (in the example below change 'control x of me' to 'the control id <id>' and to avoid issue I search/replace all occurrences.

Doing this with code folding on, it completely destroys location of folding arrows. Note - there is no new code, only replacement of variable names.

For example, this is what happens going from perfectly good code folding, replacing a variable name with another and then seeing this:
Screenshot 2024-03-24 at 17.25.40.png

I can't see a way to reset the code folding - perhaps your code could account for the search/replace?
I should note that (as I've had to do in this case) replacing individual variable names 1 at a time is fine... this only happens when replacing all occurrences

BW
Stam

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Code folding for Livecode 9.6.9 and up

Post by bn » Sun Mar 24, 2024 9:19 pm

Hi Stam,

Could you try "unfold All" either from the "Edit Menu" or via command-U.

Other than that try to close the tab and reopen it.

I am not surprised that this happens since I never tested this and it should be taken care of.
I am just wondering if any text is lost which should not happen. I am currently investigating this.

In my testing I see the "disappearance" of text but command-U shows it all with markers at the correct place and the replacements applied.
If you happen to see loss of text then I would be interested in a snippet of that code to test it.

Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Code folding for Livecode 9.6.9 and up

Post by bn » Sun Mar 24, 2024 9:38 pm

Stam,

I should add that for command-U to work the script field has to have focus. Click anywhere in the field.
What also could help is to go to another tab and go back to the script tab where "Code Folding has eaten your homework"

Kind regards
Bernd

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Code folding for Livecode 9.6.9 and up

Post by stam » Mon Mar 25, 2024 12:11 am

Thanks for looking into this so quickly Bernd.

When this first happened I did appear to lose text (I was randomly hitting the disclose triangles in a mild panic ;) )
Luckily I had just saved before doing the find/replace, so recovered fully. On subsequent attempts to reproduce this, I just quit and re-opened. But the script did appear to reduce from about 360 lines to about 30 the first time this happened.

I cannot now reproduce loss of text, and I'm unsure what I did when this first happened.

As you suggest:
- This does not occur if everything is expanded fully (i.e. cmd-U before find/replace).
- Using cmd-U reverts the issue and all disclose triangles appears correctly positioned.

Looking forward to a fix, but know how to work around for now, thank you!
Best regards
Stam

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Code folding for Livecode 9.6.9 and up

Post by bn » Mon Mar 25, 2024 12:39 pm

Stam,

I have sent you the current version of code folding to your .mac address. It should fix the problem. Could you try that version?

Kind regards
Bernd

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Code folding for Livecode 9.6.9 and up

Post by stam » Mon Mar 25, 2024 2:30 pm

bn wrote:
Mon Mar 25, 2024 12:39 pm
Stam,

I have sent you the current version of code folding to your .mac address. It should fix the problem. Could you try that version?

Kind regards
Bernd
Hi Bernd,
I can confirm the issue has been fixed, and I've not encountered any other issues at present - I'll report back if I do, but as this was the only issue I had encountered since the previous version, I do not really expect to...

Thank you for making this even more bullet proof!
Stam

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Code folding for Livecode 9.6.9 and up

Post by bn » Mon Mar 25, 2024 3:07 pm

Hi Stam,
Thanks for testing and confirming that it works.
I will probably upload the new version soon,

Kind regards
Bernd

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Code folding for Livecode 9.6.9 and up

Post by stam » Fri Mar 29, 2024 12:45 pm

Hi Bernd,

1 further reproducible issue:

If part of the script is folded and you paste in text (in my case, a small handler), all the text from the insertion point and below (including what was pasted) becomes invisible.

Specifically I have partitioned off sections of the script with the #< and #</ markers and the entire script is collapsed so only these section headers show; I expanded the top one to paste in the handler in the correct location. All text vanishes from the insertion point and below (including the pasted handler).

Unfolding all (cmd-U) fixes the issue and it works normally thereafter...

BW
Stam

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Code folding for Livecode 9.6.9 and up

Post by stam » Fri Mar 29, 2024 3:47 pm

Hi Bernd,

One further observation: Your solution recognises multi-line comments (/*...*/) and assigns disclosure triangles correctly, but these are not collapsed with the Collapse All (cmd-K) command.
Even when within a code block collapsed within #<...#</, these are still fully expanded:

Screenshot 2024-03-29 at 14.41.21.png

Stam

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Code folding for Livecode 9.6.9 and up

Post by bn » Fri Mar 29, 2024 3:56 pm

Hi Stam,

Thank you for reporting, I am currently looking into the first issue you reported and will look into the second issue you found.
For the first issue I might have a solution that needs more testing.

Kind regards
Bernd

Post Reply

Return to “Talking LiveCode”