Jump to content

SciTE + LUA = tool to make string variable from selected text


Go to solution Solved by Jos,

Recommended Posts

Posted

I just asking

do anybody make a lua script / tool which do somethnig like that

 

in SciTE i write some text

  Quote

 

first test line

second test line

third test line

 

now I select this text

and run LUA script which change selected text to that form

  Quote
$s = "first test line" & @CRLF
$s &= "second test line" & @CRLF
$s &= "third test line" & @CRLF
 

 

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Regexp?

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

Yes i know

I do this with my own au3 script

but I asking for LUA solution which can be embended to SciTE

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

What does your regular expression look like? I could consider temporarily adding to SciTE Jump.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Func _Text_to_Au3_Variable($sStringToConvert)
    Local $sVariableName = '$s' & InputBox('Variable Name', 'If variable name must be like $sMyName then input only "MyName"')
    Local $sStringToReturn = ''
    $sStringToReturn &= StringRegExpReplace($sStringToConvert, '(?i)(.*)(?:\r\s)', $sVariableName & ' &= "$1" & @CRLF' & @CRLF)
    $sStringToReturn &= @CRLF
    Return $sStringToReturn
EndFunc   ;==>_Text_to_Au3_Variable

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Developers
Posted

Just in case you like to play with the LUA option,Something like this should work:

--------------------------------------------------------------------------------
-- demo()
--------------------------------------------------------------------------------
function AutoItTools:Demo()
    editor:BeginUndoAction()
    local FirstLine = editor:LineFromPosition(editor.SelectionStart)
    local LastLine = editor:LineFromPosition(editor.SelectionEnd)
    local CurrentLine = FirstLine
    editor:GotoLine(FirstLine)
    while (CurrentLine <= LastLine) do
        editor:Home()
        if CurrentLine == FirstLine then
            editor:AddText("$s = '" )
        else
            editor:AddText("$s &= '" )
        end
        editor:LineEnd()
        editor:AddText("' & @CRLF" )
        CurrentLine = CurrentLine + 1
        editor:LineDown()
    end
    editor:EndUndoAction()
end
#x lua test func
command.name.41.$(au3)=Test
command.mode.41.$(au3)=subsystem:lua,savebefore:no
command.shortcut.41.$(au3)=Ctrl+Shift+F
command.41.$(au3)=InvokeTool AutoItTools.Demo

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

this is awesome

exacly what I need

BIG thanks Jos

 

@Jos and @guinness

What You think about that

@Jos

How You think. Can this be added as a standard functionality to SciTE4AutoIt3.exe  ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

SciTE4AutoIt3 is Jos' baby, up to Jos really.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • Developers
Posted
  On 7/27/2013 at 9:58 AM, mlipok said:
@Jos

How You think. Can this be added as a standard functionality to SciTE4AutoIt3.exe  ?

 

Adding it is easy but am not so sure this would be an option that people have a real general use for.

These are things that really should be in a separate personal LUA file containing these personal nice-to-have's in my opinion.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

@guiness

Yes I know

But You take an attention on that and You want to add this to SciTE Jump

in that case You are the right person to say "What You think about that"

EDIT:

@guiness

@guinness

Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@Jos

Ok understand and accept your opinion

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

Jos,

Thanks for that. :thumbsup:

Because I prefer to use the line continuation character I altered it a bit:

function AutoItTools:Demo()
    editor:BeginUndoAction()
    local FirstLine = editor:LineFromPosition(editor.SelectionStart)
    local LastLine = editor:LineFromPosition(editor.SelectionEnd)
    local CurrentLine = FirstLine
    editor:GotoLine(FirstLine)
    while (CurrentLine <= LastLine) do
        editor:Home()
        if CurrentLine == FirstLine then
            editor:AddText('$s = "' )
        else
            editor:AddText('"' )
        end
        editor:LineEnd()
        if CurrentLine == LastLine then
            editor:AddText('"' )
        else
            editor:AddText('" & @CRLF & _' )
        end
        CurrentLine = CurrentLine + 1
        editor:LineDown()
    end
    editor:EndUndoAction()
end
I would like to add a leading @TAB to other than the first line. I tried t but that did not work - how do I get a tab into SciTE? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Developers
  • Solution
Posted (edited)
  On 7/27/2013 at 10:33 AM, Melba23 said:

Thanks for that. :thumbsup:I would like to add a leading @TAB to other than the first line. I tried t but that did not work - how do I get a tab into SciTE? :huh:

 

This works fine for me:

function PersonalTools:Demo()
    editor:BeginUndoAction()
    local FirstLine = editor:LineFromPosition(editor.SelectionStart)
    local LastLine = editor:LineFromPosition(editor.SelectionEnd)
    local CurrentLine = FirstLine
    editor:GotoLine(FirstLine)
    while (CurrentLine <= LastLine) do
        editor:Home()
        if CurrentLine == FirstLine then
            editor:AddText('$s = "' )
        else
            editor:AddText('\t\t"' )
        end
        editor:LineEnd()
        if CurrentLine == LastLine then
            editor:AddText('"' )
        else
            editor:AddText('" & @CRLF & _' )
        end
        CurrentLine = CurrentLine + 1
        editor:LineDown()
    end
    editor:EndUndoAction()
end

Jos :)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

  • Moderators
Posted

Jos,

And now it does for me too. :wacko:

I must have been doing something wrong before - sorry to have bothered you. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Now it works better then I imagine  :thumbsup:

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Developers
Posted

Would it be a good idea to add support to the standard setup for a userfile containing your own LUA scripts which won't be zapped at the next installation of SciTE4AutoIt3?

I am thinking of adding an loadfile for a LUA file called "PersonalTools.lua" in SciTEStartUp.lua like this:

LoadLuaFile("SciTE_extras.lua")
f = io.open(props["SciteDefaultHome"] .. "\\Lua\\PersonalTools.lua")
if f ~= nil then
    LoadLuaFile("PersonalTools.lua",props["SciteDefaultHome"] .. "\\Lua\\")
    f:close()
end

All you need to do then is to add the file with this content and you are in business.

PersonalTools = EventClass:new(Common)

--------------------------------------------------------------------------------
-- demo()
--------------------------------------------------------------------------------
function PersonalTools:Demo()
    editor:BeginUndoAction()
    local FirstLine = editor:LineFromPosition(editor.SelectionStart)
    local LastLine = editor:LineFromPosition(editor.SelectionEnd)
    local CurrentLine = FirstLine
    editor:GotoLine(FirstLine)
    while (CurrentLine <= LastLine) do
        editor:Home()
        if CurrentLine == FirstLine then
            editor:AddText('$s = "' )
        else
            editor:AddText('/t\t"' )
        end
        editor:LineEnd()
        if CurrentLine == LastLine then
            editor:AddText('"' )
        else
            editor:AddText('" & @CRLF & _' )
        end
        CurrentLine = CurrentLine + 1
        editor:LineDown()
    end
    editor:EndUndoAction()
end

If we do this: Where should the file be located?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

  • Moderators
Posted

Jos,

 

  Quote

Would it be a good idea to add support to the standard setup for a userfile containing your own LUA scripts which won't be zapped at the next installation of SciTE4AutoIt3?

I will delete the PM I was about to send you suggesting that very thing! :D

 

  Quote

Where should the file be located?

I would suggest alongside the UserProperties, UserCallTip and Abbreviation files in the User folder - that away all the user files are in the same place. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Developers
Posted

Ok, just uploaded SciTEStartup.lua and an example PersonalTools.lua so you can have a play.

replace the existing version of SciTEStartup.lua with the new one and store PersonalTools.lua in your %USERPROFILE% directory.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

I am made happy entirely  :D 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

Jos,

Works nicely - dank je wel. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...