Find Replace in Script Editor with cr

Alex Tweedly alex at tweedly.net
Wed Apr 7 10:07:08 EDT 2021


Hi Sean,

I'm struggling a bit to understand how you intend to use this.

You give an example of

> *if*  field "Level" begins with "Director" and field "UserDisplay" is not
> empty and field "UserDisplay" is not "All Agents" and the label of button
> "Status" is "All Sales"*then*
> *put*  pidbQueryDatabase( "SELECT * FROM QGNew where UserID = '" & (fld
> "UserID" of card 17 stack "QGv3") \
> & "' AND DealerID = '" & (fld "DealerID" of card 1 stack "QGv3") \
> & "' AND Status LIKE '%" & ("Sale") \
> & "%' OR UserID = '" & (fld "UserID" of card 17 stack "QGv3") \
> & "' AND DealerID = '" & (fld "DealerID" of card 1 stack "QGv3") \
> & "' AND Status LIKE '%" & ("Connect") \
> & "%'") into tMsg
BUT - that's no longer correct code; you need to add the "end if" after it.

I don't see how any find/replace is going to do that successfully.

You could tweak the script editor to allow some token to imply inserting 
a linefeed - but you'd still need to find the relevant end of statement 
and insert the 'end if' that you need.


So (unless I'm missing something) you will finish up doing a scripted 
solution. Also, I do believe you will want to have the ease of use of 
using the find/replace panel to select only those lines which are to be 
modified (otherwise you are likely to pull in a number of cases you 
don't want).

If it were me, I'd follow a process like :

1. identify the lines to be changed (parentheses for readability)

find/replace   (put then) --->  (put /*change*/ then)

2. use a plugin / frontscript to allow some weird key to trigger the 
changes.

Sample plugin (with thanks to Jacque for the outline)

> on preOpenStack
>    if the long name of this stack is among the lines of the 
> frontscripts then
>       put "---> passing" after msg
>       pass preOpenStack
>    else
>       insert the script of this stack onto front
>    end if
> end preOpenStack
>
> on commandKeyDown whichKey ---- from Jacqueline Landman Gay
>    if ("editor field" is not in the name of the target and "script" is 
> not in the name of the target) \
>          or the shiftkey is not down
>    then pass commandKeyDown
>
>    local tSel, tNewSel
>    if whichKey = "+" then
>       select text of the target
>       put the selection into tSel
>       repeat for each line L in tSel
>          if L contains "then /*change*/ put" then
>             replace "then /*change*/ put" with "then " & CR & "put" in L
>             replace ("& " & quote) with ("\" & CR & "   & " & quote) in L
>             put CR & "end if" after L
>          end if
>          put L &CR after tNewSel
>       end repeat
>       set the text of the target to tNewSel
>       select empty
>    else
>       pass commandKeyDown
>    end if
>    setEditorDirty
> end commandKeyDown
>
> private command setEditorDirty
>    type space
>    delete char (word 4 of the selectedchunk) of the target
> end setEditorDirty
>


3. ??? the srcipt editor has lost the "coloization" of the script. There 
is (or used to be) some way to restore that for the entire script - but 
I can't remember it. Hitting 'TAB' does it for the current handler but 
not for the whole script.


So, I apologize - I've got carried away and provided a "creative" 
solution that is outside the remit of your question. So sue me :-)

But since I had just finished reading Andre's book on plugins and 
development tools, this seemed like a good opportunity to try out 
creating a plugin.

Alex.

On 07/04/2021 06:16, Sean Cole (Pi) via use-livecode wrote:
> Hi all,
> So, the semicolon example was only given as an oversimplification because
> most of you didn't read the original post properly, jumped to the
> wrong conclusion and then offered irrelevant answers. But then, the
> oversimplification gathered the same results of people jumping to the wrong
> conclusion by not reading the posts correctly. (It wasn't helped by my /n
> \n typo that was jumped on and assumed to be where I was going wrong. It is
> the paradox of this forum. Make it comprehensive, people get lost and lose
> the point and give the wrong answer. Make it simple and they read more into
> it and then equally get it wrong.
>
> The code I deal with on a daily basis is infinitely more complex than a
> simple - put the script of someThing into tscript; replace “;” with “;” &
> cr in script; Set the script of someThing to tscript - and can do that kind
> of thing in my sleep (as I often do, but infinitely more complex).
>
> So, I KNOW all of these SCRIPTING techniques. I'm not interested! I can do
> that. NOT A PROBLEM :)
>
> BUT IN THE FIND/REPLACE PANEL !!!??
>
> Can I use a return character (or a wildcard, escaped, coded form) in the
> REPLACE field OF THE PANEL. - A simple question.
>
> You CAN use RegEx in the FIND Field. In there you can SEARCH for \n ((I got
> it right this time)) which refers to a line feed (or new line). BUT, you
> CANNOT, it seems, as best I can find or from the comments made, use \n to
> replace or insert a line feed.
>
> In my scripts (the several thousands of them) there are NO (zero, none)
> semicolons used to separate commands. It was used ONLY to help give you a
> simpler idea of what I was trying to achieve without having to use too much
> detail. But this kind of dialogue on a forum filled with 'clever' people
> trying to demonstrate how clever they are means they often miss the point
> and give answers that do not fulfil the remit! Or just answer a simple
> ruddy question.
>
> Here, then, is a 'Real World' example of what I am facing. There are many
> variants and not my only issue, but a useful example, sample, demonstration.
>
>
> *[code]if* field "Level" begins with "Director" and field "UserDisplay" is
> not empty and field "UserDisplay" is not "All Agents" and the label of
> button "Status" is "All Sales" *then* *put* pidbQueryDatabase( "SELECT *
> FROM QGNew where UserID = '" & (fld "UserID" of card 17 stack "QGv3") & "'
> AND DealerID = '" & (fld "DealerID" of card 1 stack "QGv3") & "' AND Status
> LIKE '%" & ("Sale") & "%' OR UserID = '" & (fld "UserID" of card 17 stack
> "QGv3") & "' AND DealerID = '" & (fld "DealerID" of card 1 stack "QGv3") & "'
> AND Status LIKE '%" & ("Connect") & "%'") into tMsg
> [/code]
> That is all on a single line of a script in one of many thousand buttons.
> In and of itself is not so much a problem as it is just difficult for me to
> plough through when working out what the script is doing. In this button
> alone there are 32 lines similar in nature to this.
>
> To make it easier for me to go through, as I arrive at each button to
> simplify and correlate and combine into much more elegant code in the card
> script, I would like to be able, IN THE FIND REPLACE PANEL, not by code or
> porting or anything else, just to search and replace (& ") with (\ cr & ")
> (parenthesis used here just to wrap the strings), and (then put) with (then
> cr put). Hence, it will look a bit more like this:
>
> [code]
> *if* field "Level" begins with "Director" and field "UserDisplay" is not
> empty and field "UserDisplay" is not "All Agents" and the label of button
> "Status" is "All Sales" *then*
> *put* pidbQueryDatabase( "SELECT * FROM QGNew where UserID = '" & (fld
> "UserID" of card 17 stack "QGv3") \
> & "' AND DealerID = '" & (fld "DealerID" of card 1 stack "QGv3") \
> & "' AND Status LIKE '%" & ("Sale") \
> & "%' OR UserID = '" & (fld "UserID" of card 17 stack "QGv3") \
> & "' AND DealerID = '" & (fld "DealerID" of card 1 stack "QGv3") \
> & "' AND Status LIKE '%" & ("Connect") \
> & "%'") into tMsg
> [/code]
>
> Ideally I'd want it even better than this eventually. But key to doing just
> this for now was being able to use a return character in the replace field
> of the find/replace panel.
>
> My original question was 'Just wondering if there is a way of replacing
> using cr in the find/replace panel of the script editor.'
>
> A simple Yes or No would have been sufficient. Even better, a yes with a
> 'just use this form : x,y,z' as a sample. I just hoped someone had found a
> simple method, especially as the guides and documentation are so woefully
> out of date and incomplete. Something more than 'the meaning of life = 42'
> and less than 'measuring gravity = the complete works of Sir Isaac Newton',
> as long as it actually answers the question asked :)
>
> (And please don't go into the simplification of the SQL requests, the 'if'
> condition or any other poop. I'm FULLY aware of this to the nth degree and
> is why I'm going through this poop-show of a stack. Over 10 years of
> poor/bad/dirty coding that now needs cleaning and refactoring without
> rebuilding from the ground up. I'm just working my way through and have
> managed 6 of the 801 cards)
>
> Stats for this behemoth:
> Number of stacks = 109
>     Total number of cards = 801
>        Total number of controls = 82579
>           Total number of buttons = 19124
>           Total Number of fields = 33484
>           Total number of groups = 12152
>           Total number of graphics = 14359
>           Total number of images = 3282
> Total Lines of code = 360036
>
> :-)
> Sean
>
> On Tue, 6 Apr 2021 at 23:42, doc hawk via use-livecode <
> use-livecode at lists.runrev.com> wrote:
>
>> sean slipped
>>
>>> For instance, suppose I have multiple commands on one line separated by ;
>>> and I want to search for semicolon and replace with semicolon followed by
>>> return character to drop the remaining script onto a new line.
>> put the script of someThing into tscript
>> replace “;” with “;” & cr in script
>> Set the script of someTHing to tscript
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the use-livecode mailing list