Auto-indenting generated scripts [SOLVED]
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Auto-indenting generated scripts [SOLVED]
Hi all,
is there an easy way to auto-indent scripts that are generated from a script? Or do i have to insert spaces/tabs?
I'm working on a helper app for my development that will produce moderately complex scripts i can use with my main app currently in development. The intention is that this will be a reusable tool (for me at least), so making an effort to make it more solid.
This works well so far - only the text produced is all left-aligned and doesn't look good/is less readable, unless i copy to the script editor and manually hit tab inside each generated handler.
The generated scripts are first copied to a field in the helper app for review prior to inserting into the app in development - is there a way to auto-indent the text inside a field (also not sure if colouring is easily achievable?), to simulate the view in the script editor? Just so it's easier to review...
Many thanks
Stam
is there an easy way to auto-indent scripts that are generated from a script? Or do i have to insert spaces/tabs?
I'm working on a helper app for my development that will produce moderately complex scripts i can use with my main app currently in development. The intention is that this will be a reusable tool (for me at least), so making an effort to make it more solid.
This works well so far - only the text produced is all left-aligned and doesn't look good/is less readable, unless i copy to the script editor and manually hit tab inside each generated handler.
The generated scripts are first copied to a field in the helper app for review prior to inserting into the app in development - is there a way to auto-indent the text inside a field (also not sure if colouring is easily achievable?), to simulate the view in the script editor? Just so it's easier to review...
Many thanks
Stam
Last edited by stam on Tue Jul 12, 2022 10:23 am, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Auto-indenting generated scripts
Stam.
If they are already "generated from a script", they already have the spaces built into the text.
What am I missing?
Craig
If they are already "generated from a script", they already have the spaces built into the text.
What am I missing?
Craig
Re: Auto-indenting generated scripts
The script is generated on the fly based on data in fields and variables. This creates the text for the scripts in their entirety, either to be saved as script only stacks or where needed to be inserted into other scripts.
So typically something like “put xyz && field abc & return after tScript”.
So no, no “spaces” included.
I mean I could add spaces programmatically, but I was wondering if there is an IDE level handler I could hook into…
So typically something like “put xyz && field abc & return after tScript”.
So no, no “spaces” included.
I mean I could add spaces programmatically, but I was wondering if there is an IDE level handler I could hook into…
Re: Auto-indenting generated scripts
@stam: There isn't an 'official' IDE API for this - although if you post a request to the RQCC about it we can probably add one pretty easily as the code which does the indentation in the SE was exposed to work for the snippet manager we added in LiveCode 8 (?) [ and also so we could write unit tests for said indenter! ].
However, you could try doing this:
The indented text is then returned in `the result`.
Hope this helps!
However, you could try doing this:
Code: Select all
dispatch "scriptFormatSnippet" to stack "com.livecode.scripteditor.behavior.editorcommon" with tTextToIndent
Hope this helps!
Last edited by LCMark on Tue Jul 12, 2022 6:43 am, edited 1 time in total.
Re: Auto-indenting generated scripts
Dear Mark, thank you for the tip - that's very interesting but can't get it to work (i'm probably doing it wrong!).LCMark wrote: ↑Mon Jul 11, 2022 6:02 pmHowever, you could try doing this:The indented text is then returned in `the result`.Code: Select all
dispatch "scriptFormatSnippet" to "com.livecode.scripteditor.behavior.editorcommon" with tTextToIndent
I keep getting a chunk error (error in object expression). Perhaps i misunderstood - will this work in a normal text field?
As a test i created a button:
Code: Select all
on mouseUp
local tTextToIndent
put field "pathsScript" into tTextToIndent
dispatch "scriptFormatSnippet" to "com.livecode.scripteditor.behavior.editorcommon" with tTextToIndent
get the result -- to inspect it in 'it'
end mouseUp
Code: Select all
script "lib.paths"
global gSettings
function projectLibPath
if the environment is "development" then
return libPath()
else
return specialFolderPath("documents") & "/MDM Assistant/" & gSettings["meetingShortName"] & "/Libraries"
end if
end projectLibPath
function canelaPath
if the environment is "development" then
return libPath() & "/canelaDB/Libraries/"
else
return specialFolderPath("documents") & "/MDM Assistant/" & gSettings["meetingShortName"] & "/canelaDB/Libraries/"
end if
end canelaPath
function libPath
if the environment is "development" then
return "/Users/stam/Documents/Developer/MDMA6/Libraries"
else
return specialFolderPath("resources") & "/Libraries"
end if
end libPath
Any tips? Do I need to assign a behaviour to the field?
It's not critical by any means (the code works!), but would be nice to produce correctly indented text...
Many thanks once again,
Stam
Re: Auto-indenting generated scripts
@stam: Sorry - I made a mistake in my code example - it should be `stack "com.livecode....". The handler sits in one of the behavior scripts which make up the Script Editor - the actual code itself isn't specific to an SE instance or anything so it can be used by other things, its just that to call it you need to dispatch to that behavior stack, rather than call the handler directly. I've corrected my code example in my previous post.
Re: Auto-indenting generated scripts
Amazing! Works perfectlyLCMark wrote: ↑Tue Jul 12, 2022 6:45 am@stam: Sorry - I made a mistake in my code example - it should be `stack "com.livecode....". The handler sits in one of the behavior scripts which make up the Script Editor - the actual code itself isn't specific to an SE instance or anything so it can be used by other things, its just that to call it you need to dispatch to that behavior stack, rather than call the handler directly. I've corrected my code example in my previous post.
Thank you Mark!