_internal script colorize [SOLVED]

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

_internal script colorize [SOLVED]

Post by stam » Fri Nov 25, 2022 10:34 am

Hi all,
I know this is not supported API and that it's a bit of a dark art...

I format/auto-indent fields that contain liveCodeScript using Mark Waddingham's advice here the code, which works seamlessly and always.

I colourise the script in a field using the code shown by James Hale James Hale's advice here.:

Code: Select all

 _internal script colorize char 1 to (the number of chars in field "x") of field "x"
Colorisation is great, but weirdly doesn't work all the time. Specifically once I get it to work then it always works until quitting LC. If I launch the stack directly (i.e. it's the first stack to be opened) it's just doesn't work through any script.

I finally realised that the simple action of opening the message box or the script editor actually fixes that so a clunky work around is to open/close the message box at preOpenStack, and then the colorisation works as expected.

Clearly there is some sort of initialisation that happens when opening the msg box but or script editor which doesn't happen when I just open my stack -- does anyone have any idea what this is and how I can include it in my stack so I don't have to use the clunky workaround of opening/closing msgBox?

Many thanks
Stam
Last edited by stam on Sat Nov 26, 2022 5:35 pm, edited 1 time in total.

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

Re: _internal script colorize

Post by bn » Fri Nov 25, 2022 11:11 am

Stam,

maybe you can try

Code: Select all

_internal script colorize char 1 to (the number of chars in field "x") the long id of field "x" of this stack
It could be that without the long id field "x" is not resolved properly somehow.

In tinyDictionary I use a different way by the intermediary of stack "revSEUtilities

Code: Select all

dispatch "revSEColorizeField" to stack "revSEUtilities" with the long id of field "fRes" of this stack, tStartChar, tEndChar
I have not seen this fail.

Kind regards
Bernd

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

Re: _internal script colorize

Post by AndyP » Fri Nov 25, 2022 12:33 pm

Nearly right.

Try this with xxxx being the id of the fld x

Code: Select all

 _internal script colorize line 1 to (the number of lines in fld "x") of fld id xxxx of this stack
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: _internal script colorize

Post by bn » Fri Nov 25, 2022 2:35 pm

Hi Andy,

OK, I goofed up in my sample code to pass the long id.

This code does not work!

Code: Select all

_internal script colorize char 1 to (the number of chars in field "x") the long id of field "x" of this stack


This code compiles and actually works and sends the long id instead of just the id of the field

Code: Select all

 put the long id of field "xField" into tLongID
 _internal script colorize char 1 to (the number of chars in field "xField") of tLongID
Of course field "xField" has to be unique.

Kind regards
Bernd

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

Re: _internal script colorize

Post by AndyP » Fri Nov 25, 2022 3:04 pm

Hi Bernd,

I like this variation, one for my scrapbook :)

Code: Select all

dispatch "revSEColorizeField" to stack "revSEUtilities" with the long id of field "fRes" of this stack, tStartChar, tEndChar
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

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: _internal script colorize

Post by LCMark » Fri Nov 25, 2022 3:59 pm

The internal colorize stuff needs to be configured before it will do anything useful. The code the SE (and message box uses) is in revseutilities... This doesn't get initialized until it is first used - the easiest thing to do is to use the utility handler Bernd suggested in there, as that ensures the current IDE's colorization theme is configured before it colorizes.

(Alternatively just prod around in that script a bit - basically you can configure keywords and classes - the former are specific colors/styles for different keyword tokens, the latter are the colors/styles for different kinds of token).

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

Re: _internal script colorize

Post by dunbarx » Fri Nov 25, 2022 5:48 pm

I have a plug-in that colorizes one or more portions of text in the SE. I place markers, say "XXX" at the beginning and end of the sections I want. I then just find the lines those two string live on, and (Abbreviated):

Code: Select all

set the backColor of line startLine to endLIne of fld 1 of stack "revScriptEditor1" to "yellow"
I am at my home computer, where I do not do this, so I am not quite sure I have the precise name of the SE at work correctly.

Anyway, I can leave one or more pairs of markers in the SE, and colorize whenever I want.

Craig

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

Re: _internal script colorize

Post by stam » Fri Nov 25, 2022 9:55 pm

Thanks Craig - to clarify this is regarding syntax colouring (as in the SE) but in a normal field...
My problem was that as Mark mentioned there is some initialisation required, but it's a bit dark-magic.

Not been able to yet, but I'll try the suggestions above and report back - thank you all!

S.

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

Re: _internal script colorize [SOLVED]

Post by stam » Sat Nov 26, 2022 5:38 pm

Thanks to LCMark, AndyP and Bernd - the solution that worked easiest is:
AndyP wrote:
Sat Nov 26, 2022 1:53 pm

Code: Select all

put the num of chars of fld "myField" of this stack into tEndChar 
dispatch "revSEColorizeField" to stack "revseutilities" with the long id of field "myField" of this stack, 1, tEndChar

Post Reply

Return to “Talking LiveCode”