Apply visual formatting to unformatted code
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Apply visual formatting to unformatted code
Hello all!
I am a (very) longtime reader of the forum (helpful!), but this is my first time posting a question.
Imagine that I paste an unformatted script in a regular field of my stack. Is there some way to colorize and indent this so it appears like it would when working in the Code Editor (but without having to manually select and copy the script in the Code Editor)?
In other words, can I put an unformatted script in a field and then click a button to paste a color/indent-formatted version into a second field?
I tried to set the script of an object using the unformatted code hoping that the Code Editor would format it, but could not find a way to use a script to copy a formatted version.
Thanks for any suggestions!
Eric R
I am a (very) longtime reader of the forum (helpful!), but this is my first time posting a question.
Imagine that I paste an unformatted script in a regular field of my stack. Is there some way to colorize and indent this so it appears like it would when working in the Code Editor (but without having to manually select and copy the script in the Code Editor)?
In other words, can I put an unformatted script in a field and then click a button to paste a color/indent-formatted version into a second field?
I tried to set the script of an object using the unformatted code hoping that the Code Editor would format it, but could not find a way to use a script to copy a formatted version.
Thanks for any suggestions!
Eric R
Re: Apply visual formatting to unformatted code
Hi Eric,
there is an undocumented feature of the engine that LC uses to colorize the scripts in the script editor.
Here the script in a mouseup handler, I had copied a script into that field (field 1) without formatting:
Tested and works. 
Best
Klaus
P.S.
I'm not sure if this will also work in a standalone.
there is an undocumented feature of the engine that LC uses to colorize the scripts in the script editor.
Here the script in a mouseup handler, I had copied a script into that field (field 1) without formatting:
Code: Select all
on mouseUp
_internal script colorize char 1 to (the number of chars of field 1) of field 1
end mouseUp

Best
Klaus
P.S.
I'm not sure if this will also work in a standalone.
Re: Apply visual formatting to unformatted code
Thank you, Klaus!! Very helpful (and impressively fast reply).
Is there an analogous function for indentation?
Is there an analogous function for indentation?
Re: Apply visual formatting to unformatted code
Hi Eric,
buried deep in the multiple LC IDE scripts and behaviors.
Best
Klaus
my pleasure and I kind of live here.



there is, however that is not a one-liner but a very long script which relies on many other handlers
buried deep in the multiple LC IDE scripts and behaviors.
Best
Klaus
Re: Apply visual formatting to unformatted code
Hi Eric,
try this
Code: Select all
on mouseUp
local tOrigText, tFormattedText
put the text of field "fInput" into tOrigText
send "scriptFormatSnippet tOrigText" to stack "com.livecode.scripteditor.behavior.editorcommon"
put the result into tFormattedText
put tFormattedText into field "fRes"
end mouseUp
Kind regards
Bernd
Re: Apply visual formatting to unformatted code
Thanks again everyone!
Re: Apply visual formatting to unformatted code
Ah, yes, Bernd is correct!
There are so many IDE stacks and scripts and behaviours, so I missed this one, sorry.
There are so many IDE stacks and scripts and behaviours, so I missed this one, sorry.
-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
Re: Apply visual formatting to unformatted code
This is marvellous.
I wonder how many other undocumented features of the engine there are, and if anyone has, err, documented them.
How, Klaus, did you discover that feature?
I wonder how many other undocumented features of the engine there are, and if anyone has, err, documented them.
How, Klaus, did you discover that feature?
Re: Apply visual formatting to unformatted code
I think this came up on the mailing list many, many years ago and I have a wonderful memory. 

-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
Re: Apply visual formatting to unformatted code
Good that you have that memory.
But that is like asking which came first: the hen or the egg.
Because, someone, somewhere, somewhen must have somehow had access to the innards of the engine to find that information out.
Unless, of course, LiveCode have their own, internal documentation.
But that is like asking which came first: the hen or the egg.
Because, someone, somewhere, somewhen must have somehow had access to the innards of the engine to find that information out.
Unless, of course, LiveCode have their own, internal documentation.
Re: Apply visual formatting to unformatted code
So, for the sake of completeness, and future readers, here's an all-in-one appliance of it:
Code: Select all
command formatAsScript pOutputFieldId,pSourceText
## pOutputFieldId has to be the long id of the output field
## pSourceText can optionally be used if the code to be formatted is not already in the output field
if pSourceText is empty then put the text of pOutputFieldId into pSourceText
dispatch "scriptFormatSnippet" to stack "com.livecode.scripteditor.behavior.editorcommon" with pSourceText
set the text of pOutputFieldId to the result
dispatch "revSEColorizeField" to stack "revseutilities" with pOutputFieldId,1,length(pOutputFieldId)
end formatAsScript
on mouseUp
## Example with the input and output field being the same
formatAsScript the long id of field "myOutputField"
## Example with the input source being another field than the output field
formatAsScript the long id of field "myOutputField",fld "myUnformattedCode"
end mouseUp
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Apply visual formatting to unformatted code
Most of us who've wanted to do things the IDE does learned how it does then by reading the scripts.richmond62 wrote: ↑Fri Dec 20, 2024 11:12 amBecause, someone, somewhere, somewhen must have somehow had access to the innards of the engine to find that information out.
That's one of the things I've loved about xTalks with scripted IDEs (SuperCard, Gain Momentum, MetaCard/RuneRev/LC) over those with IDE elements compiled into the engine (HyperCard, Oracle Media Objects, Spinnaker Plus): the ability to dive in as deep as you want to learn and tweak to your heart's content.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn