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

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

Code folding for Livecode 9.6.9 and up

Post by bn » Mon Feb 12, 2024 9:12 pm

Dear Livecoder,

I post a stack that enables code folding in the (now) current versions of Livecode.
Tested from version 9.6.9 to 10.0.0 DP7.

partially collapsed_.jpg

Your see a collapsed structure marked by a black triangle pointing to the right indicating a collapsed struct and a outlined triangle pointint down indicating a collapseble struct (rect circles). Note the line numbers.

The attached stack will let you install folding onto the Script Editor of the above mentioned version.
This is a temporary install that will be gone when you close LC.
There is a read-me that explains a bit.
Code folding does not touch your actual code (the text) since it only operates on the appearance of the code.
Prior versions were used and tested without problems. The new installers seems to work as the previous versions.
But still, use with caution.

This is an old project that I finally got around to adapt to the current versions.

Would be interested in what you think

Kind regards
Bernd

Please note that a new version of Code Folding Installer is posted
https://forums.livecode.com/viewtopic.p ... 8e#p228244
Last edited by bn on Thu Feb 22, 2024 2:36 pm, edited 2 times in total.

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 Feb 12, 2024 9:42 pm

That looks amazing.
Can’t wait to try it out but on call at present…

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Code folding for Livecode 9.6.9 and up

Post by dunbarx » Mon Feb 12, 2024 9:50 pm

Bernd.

Cannot wait to try this.

It is similar to something I asked for 15 years ago, along the lines of the way Excel allows one to set the position of a horizontal or vertical line, and where each portion of the text on either side of that line may be independently scrolled.

Craig

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 Feb 12, 2024 10:16 pm

If you installed the patch to your Livecode version then when editing a script the Edit menu is appended by the option to turn code folding off and on on the fly. There are also option to collapse all or unfold all. (including the short cuts to do it via keyboard)

Bildschirmfoto 2024-02-12 um 21.50.42.png
Edit Menu in Edit Mode
Bildschirmfoto 2024-02-12 um 21.50.42.png (53.09 KiB) Viewed 1315 times

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 » Tue Feb 13, 2024 12:47 am

Bernd... Dude... this is amazing ;) You da man!

It works exactly as advertised and no crashes or data loss so far. Well, nearly. I had some script errors show up on installation and quit. Perhaps because I have strict compilation on - adding local definitions fixed the script errors. However even with the errors function seems exactly as expected.

Tested with a long script widget script - hugely helpful.
I've been missing this feature since I've started with LiveCode. The team really should have implemented this years ago.

I'm guessing the change in licensing means this won't be made part of the official build...

is there a way to make this permanent so I don't have to reinstall every restart?

Thanks once again for this Bernd, It's amazing!
As Craig says we just need split panes now...

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 » Tue Feb 13, 2024 1:11 am

stam wrote:
Tue Feb 13, 2024 12:47 am
Bernd... Dude... this is amazing ;) You're da man!
It works exactly as advertised and no crashes or data loss so far. Tested with a long script widget script - hugely helpful.
I've been missing this feature since I've started with LiveCode. The team really should have implemented this years ago.
I'm guessing the change in licensing means this won't be made part of the official build...
is there a way to make this permanent so I don't have to reinstall every restart?
Thanks once again, this is amazing!
Stam
Thanks Stam,

I am glad that you like it.
If you want to make colde folding permanent you would have to install Code Folding via the stack I posted above.

That stack makes changes to the following scripts:

revSEEditorBehavior.livecodescript
com.livecode.scripteditor.behavior.editorcommon.livecodescript
revSEGutterBehavior.livecodescript
revseutilities.livecodescript
revshortcutslibrary.livecodescript
revSEMenubarBehavior.livecodescript

Once you have installed the changes via the stack you can use the Project Browser with "Show IDE Stacks in Lists" and click on the respective stacks in the Project Browser to open them in the Script Editor. Then do a Save and remove the files from the Script Editor.

This will make the changes stick in the respective stacks inside the App Bundle. (I did not have permission problems but that might be different in other configurations. You would have the rights to make changes.) Since I do not have a Windows computer I can only assume that above technique will work on Windows too.

If you want to be super sure you could copy the original files from the app bundle into a backup folder so you could just swap those backup files back into the app bundle in case you had enough. Or you could install a fresh copy of the changed LC version from a download.

Once you have installed the patches you can still turn code folding on and off from the Edit Menu in edit mode.

There is a small overhead in using code folding but with faster computers less noticeable than formerly.

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 » Tue Feb 13, 2024 1:40 am

Thanks Bernd,
It's too late in the night to do "surgery" but I'll make this small project for the near future.

Regarding overhead - I haven't noticed any issues. Scrolling speed is the same or perhaps even slightly better paradoxically.

Great stuff...!

PS: This is exactly the kind of thing the IDE has needed for years. Better late than never I suppose. Pity it wasn't sooner!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Code folding for Livecode 9.6.9 and up

Post by jacque » Tue Feb 13, 2024 7:14 pm

Wow! Fantastic.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Code folding for Livecode 9.6.9 and up

Post by dunbarx » Tue Feb 13, 2024 9:30 pm

Bernd.

Really impressive. And seems rock solid.

A request for v.2

For me, to be able to fold any specified sequence of lines, say, 200 to 700, so that I can put together widely separated portions of a script. Right now I move handlers around to do that. That works fine, but is not ideal, and often I want to restore them to their original locations, but never remember where they started from.

Currently I colorize one or more blocks of a script so I can quickly navigate from one to the other. Works well, but a lot of traveling.

I declare all my local and global variables at the top of the script, so that is never an issue.

I can see that such a folding ought only to be allowed as you already do, that is, only full "handlers" can be folded. One would have to start at the first line of a handler or function and end at the bottom of a distant handler or function.

And for v.3, please implement what Stam and I want; he calls them "Split Panes", separately scrollable.

Scotland, are you seeing this?? Would make a terrific Christmas present. I would pay for it.

Craig

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 » Tue Feb 13, 2024 10:36 pm

Craig,

If I understand correctly you want to hide chunks of code to get it out of the way.

There is a feature at the request of Mike Kerner built-in

Code: Select all

#<

handler
handler
handler

#</
You do not have to place that pair: #< #</ outside of handlers. You can put it on any empty line (because LC thinks it is a comment)
But that does not nest. You can put as many of those special comments as you want, just not nested.

And command-K for 'collapse all' and command-U for 'unfold all' is your friend.

As far as split panes are concerned there is GLX2 Script Editor for LC maintained by Mark Wieder which has split panes. And also code folding.
https://github.com/mwieder/glx2ScriptEditor
And from contributing to that project I know that the split pane adds a lot of overhead. I never got used to 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 » Wed Feb 14, 2024 12:46 am

How to Make Code Folding permanent

Here is a stack with 1 button that makes the changes to the IDE for Code Folding permanent.

On a freshly started LC version supported by the Installer stack install Code Folding.
Then use the attached stack to makes the temporary changes permanent by saving the modified IDE stacks using the button.

You could copy the button to your Installer stack for future use.


Please note that a new version of Code Folding Installer is posted
https://forums.livecode.com/viewtopic.p ... 8e#p228244

Kind regards
Bernd
Last edited by bn on Thu Feb 22, 2024 2:30 pm, edited 1 time in total.

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 » Wed Feb 14, 2024 2:04 am

Hi Bernd,

One possible side effect I discovered after making this permanent:
On Mac the shortcuts cmd-shift-C for card script and cmd-shift-S for stack script have stopped working...

While not a complete showstopper, it is a pain.
Seems likely to be have happened during this process, but can't say for sure (sometimes I find LC randomly does not respond to shortcuts, but this has persisted over several restarts...)

Any one else have this issue or is it just me?
Any suggestions?

Stam

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Code folding for Livecode 9.6.9 and up

Post by dunbarx » Wed Feb 14, 2024 4:53 am

Bernd.

I have heard about Mark's offering for years. Looks like this is the time to check it out.

Craig

AndyP
Posts: 615
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Code folding for Livecode 9.6.9 and up

Post by AndyP » Wed Feb 14, 2024 10:57 am

Hi Bernd,

This is absolutely brilliant!

I've tested on a 2000 line card script and it does what it says on the tin.

Thank you for the time and effort you've put into this.

Note to LiveCode HQ. Please talk to Bernd about this, it should be a top of list new feature!
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

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 » Wed Feb 14, 2024 1:32 pm

Patch for shortcuts problems
stam wrote:
Wed Feb 14, 2024 2:04 am
Hi Bernd,
One possible side effect I discovered after making this permanent:
On Mac the shortcuts cmd-shift-C for card script and cmd-shift-S for stack script have stopped working...
Hi Stam,
Thank you for spotting the shortcut problem.
Here is a stack that lets you fix the problem.
It has the option to temporarily fix it in the currently open LC app or permanently in which case it will change the file of stack "revshortcutslibrary" in the app bundle/app.

A new version of code folding has bee posted that fixes the shortcut bug
https://forums.livecode.com/viewtopic.p ... 8e#p228244

I wait a while for more bug reports before posting a new version of the installer for code folding.

Kind regards
Bernd
Last edited by bn on Thu Feb 22, 2024 2:32 pm, edited 1 time in total.

Post Reply

Return to “Talking LiveCode”