Anas

Scite fold within Regions

16 posts in this topic

Hi,

Is it possible to make Scite fold functions within regions?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try this following 2 steps:

CTRL+LEFTMOUSEBUTTON on the "-" sign (folding sign on the left - near to #Region statement) 
and now 
ALT+LEFTMOUSEBUTTON on the same "+" folding sign.

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

@Jos

It folds the regions but not the functions within them.

#Region Already gets folded
Func DoesNotFold()
EndFunc
#EndRegion

 

@mLipok

I'm looking for a way to have it fold all functions within all regions by default, like "fold.on.open=1"

also, this will fold everything within the region, including the IF/While/For ...

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Folds fine for me:

Knipsel.PNG

Don't think there is an option to fold one level lower on opening though. maybe a lua function could do that for you.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Now that I've re-read my OP, I realised I didn't specify that I want to do it using "View>Toggle all folds" and " fold.on.open=1"

Share this post


Link to post
Share on other sites

In case  you or somenbody is interested in a LUA function for this:

  1. Add this code to file  %localappdata%\AutoIt v3\SciTE\PersonalTools.lua:
  2. function PersonalTools:ToggleFoldLevel(x)
        if editor.Lexer == SCLEX_AU3 then
            -- clear output pane when debugging
    --~         output:ClearAll()
            fldonlev=tonumber(x)
    --~         print("### Fold toggle fold level ", fldonlev)
            local savlinlev1=-1
            local fldinlev1=0
            for a = 0, editor.LineCount-1, 1
            do
    --~             print("--",a+1, editor.FoldLevel[a],editor.FoldParent[a],savlinlev1,fldinlev1)
                -- outside of a fold again
                if editor.FoldParent[a+1] < savlinlev1 then
    --~                 print("End of fold block")
                    savlinlev1=editor.FoldParent[a+1]
                    fldinlev1=fldinlev1-1
                elseif editor.FoldParent[a+1] > savlinlev1 then
    --~                 print("Start of fold block")
                    savlinlev1=editor.FoldParent[a+1]
                    if fldonlev == fldinlev1 then
    --~                     print("! Toggle fold for line ", a+1)
                        editor:ToggleFold(a)
                    end
                    fldinlev1=fldinlev1+1
                end
            end
        end
    end
  3. Add these lines to your Sciteuser.properties: the number behind the func is the level to toggle the fold for.
  4. #x lua test func
    command.name.41.$(au3)=ToggleFoldLevel
    command.mode.41.$(au3)=subsystem:lua,savebefore:no
    command.shortcut.41.$(au3)=Ctrl+Shift+F
    command.41.$(au3)=InvokeTool PersonalTools.ToggleFoldLevel 2
    The shortcut Ctrl+Shift+f should now do a toggle fold for only the level 2 folds.

Jos 

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Very good solutions @Jos,
Thanks.

 

But as I remember long time ago I was thiniking about something like that but I would prefer little diferent behavior.
So I dig in your code and in Scintilla Documentation  and after 20 minute of learning I change a little:

editor:FoldChildren(a, 2)
-- editor:ToggleFold(a)

here is complete changed lua script:

function PersonalTools:ToggleFoldLevel(x)
    if editor.Lexer == SCLEX_AU3 then
        -- clear output pane when debugging
--~         output:ClearAll()
        fldonlev=tonumber(x)
--~         print("### Fold toggle fold level ", fldonlev)
        local savlinlev1=-1
        local fldinlev1=0
        for a = 0, editor.LineCount-1, 1
        do
--~             print("--",a+1, editor.FoldLevel[a],editor.FoldParent[a],savlinlev1,fldinlev1)
            -- outside of a fold again
            if editor.FoldParent[a+1] < savlinlev1 then
--~                 print("End of fold block")
                savlinlev1=editor.FoldParent[a+1]
                fldinlev1=fldinlev1-1
            elseif editor.FoldParent[a+1] > savlinlev1 then
--~                 print("Start of fold block")
                savlinlev1=editor.FoldParent[a+1]
                if fldonlev == fldinlev1 then
--~                     print("! Toggle fold for line ", a+1)
                    editor:FoldChildren(a, 2)
                    -- editor:ToggleFold(a)
                end
                fldinlev1=fldinlev1+1
            end
        end
    end
end

Try with this testing script and you will see the difference

_Example1()

#Region - 1
Func _Example1()
    If True Then ; Check here
        For $i = 1 To 2
            _Example2()
            For $x = 1 To 2
                _Example2()
            Next
        Next
    EndIf

    If False Then
        ; test2
        ; test2
    EndIf

EndFunc   ;==>_Example1
#EndRegion - 1

#Region - 2
Func _Example2()
    If True Then
        ; test1
        ; test1
    EndIf

    If False Then
        ; test2
        ; test2
    EndIf

EndFunc   ;==>_Example2
#EndRegion - 2

Just after using CTRL+SHIFT+F then try to unfold this line:

If True Then ; Check here

 

Cheers.

mLipok

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Thanks Jos, this is very handy.

I use this LUA script to make Scite fold all first-levels throughout the script, and second-levels only in regions:

 

function PersonalTools:ToggleFoldLevel()
    if editor.Lexer == SCLEX_AU3 then
        local InRgn = false

        for i = 0, editor.LineCount - 1 do
            local FoldLVL = editor.FoldLevel[i]
            local STR = editor:GetLine(i)

            if not InRgn and FoldLVL == 67183616 and string.starts(STR, "#Region") then
                InRgn = true
            elseif InRgn and FoldLVL == 67109889 and string.starts(STR, "#EndRegion") then
                InRgn = false
            end

            if FoldLVL == 1024 and (i+1) < editor.LineCount then
                print(i+1)
                print(FoldLVL)
                print(STR)
                print(InRgn)
                print("============")
            end

            if FoldLVL == 67183616 or (InRgn and FoldLVL == 67249153) then editor:FoldLine(i,0) end
        end
    end
end

function string.starts(String, Start)
    local success, value = pcall(string.sub,String,1,string.len(Start))
    if success and value == Start then return true end
    return false
end


But I've a problem with it, after some lines (69 in this example), editor.FoldLevel it's stops returning the correct Fold-level value and just returns 1024:

 

Global $T

Func Func1()
    If $T Then

    Else

    EndIf
EndFunc

#Region 1
Func FuncInRegion1()
    If $T Then

    Else

    EndIf
EndFunc
#EndRegion

Func Func2()
    If $T Then

    Else

    EndIf
EndFunc

Func Func3()
    If $T Then

    Else

    EndIf
EndFunc

Func Func4()
    If $T Then

    Else

    EndIf
EndFunc

Func Func5()
    If $T Then

    Else

    EndIf
EndFunc

Func Func6()
    If $T Then

    Else

    EndIf
EndFunc

Func Func7()
    If $T Then

    Else

    EndIf
EndFunc

Func Func8()
    If $T Then

    Else

    EndIf
EndFunc

 

If I use "View>Toggle all folds", it starts to work as expected.

 

Edit:

As a workaround, I reset fold.on.open=1 and renamed the func to OnOpen to call it at launch.

Why is the output cleared when the function is called? even if I don't print anything.

Edited by Anas

Share this post


Link to post
Share on other sites

@Anas,

This version of my LUA script extracts just the Level number from the FoldLevel returned value and has your Region logic in it as well (a little modified to coupe with mixed case). 
Explanation can be found in the script and let me know when you have questions:

function string.starts(String, Start)
    if String == nil then return false end
    String=string.lower(String)
    Start=string.lower(Start)
    local success, value = pcall(string.sub,String,1,string.len(Start))
    if success and value == Start then return true end
    return false
end

function PersonalTools:ToggleFoldLevel(x)
    -- set to true when debugging
--~     debug=true
    debug=false
    -- clear output pane when debugging
    if debug then output:ClearAll()end
    --
    fldonlev=tonumber(x)
    if debug then print("### Fold toggle fold level ", fldonlev) end
    if debug then print("--","Line", "FoldLevel","FParent","fld+InR", "InRgn", "flp", "fl", "fln") end
    -- local vars
    local InRgn=0
    -- loop through lines, starts at 0 for first line
    for a = 0, editor.LineCount-1, 1
    do
        local STR = editor:GetLine(a)
        -- Explanation how editor.FoldLevel value is build up. we need the last 2 characters
        --~ enu FoldLevel=SC_FOLDLEVEL
        --~ val SC_FOLDLEVELBASE=0x400
        --~ val SC_FOLDLEVELWHITEFLAG=0x1000
        --~ val SC_FOLDLEVELHEADERFLAG=0x2000
        --~ val SC_FOLDLEVELBOXHEADERFLAG=0x4000
        --~ val SC_FOLDLEVELBOXFOOTERFLAG=0x8000
        --~ val SC_FOLDLEVELCONTRACTED=0x10000
        --~ val SC_FOLDLEVELUNINDENT=0x20000
        --~ val SC_FOLDLEVELNUMBERMASK=0x0FFF   (I only use the last 2 characters for level calculation
        -- get foldlevel previous line    ( the "or 0" is to avoid a nil error)
        local foldlevp=tonumber(string.sub(string.format("%x",editor.FoldLevel[a-1]),6),16) or 0
        -- get foldlevel current line
        local foldlev=tonumber(string.sub(string.format("%x",editor.FoldLevel[a]),6),16) or 0
        -- get foldlevel next line
        local foldlevn=tonumber(string.sub(string.format("%x",editor.FoldLevel[a+1]),6),16) or 0
        --
        -- check for first level #Region and #EndRegion statements
        if  foldlev==0 and string.starts(STR, "#Region") then
            InRgn = 1
            if debug then print("+ Inside region")end
        elseif foldlev==1 and string.starts(STR, "#EndRegion") then
            InRgn = 0
            if debug then print("- Outside region") end
        end
        if debug then print("--",a+1, editor.FoldLevel[a],editor.FoldParent[a],fldonlev + InRgn, InRgn, foldlevp, foldlev, foldlevn,STR) end
        --
        -- check for lower fold level (Not used anymore in the logic)
        if foldlev < foldlevp then
            if debug then print("End of fold block") end
        end
        --
        -- check for higher fold level
        if foldlevn > foldlev then
            if debug then print("Start of fold block") end
            -- check if toggle fold is needed for this level
            if fldonlev + InRgn == foldlevn then
                if debug then print("! Toggle fold for line ", a+1) end
                editor:ToggleFold(a)
            end
        end
    end
end

  Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Hello Jos,

Thank you for taking the time, but it seems that your example have the same "editor.FoldLevel" problem as well, at least for me:

Start of fold block
--  65  67240962    63  1   0   1   2   2   

--  66  67175426    63  1   0   2   2   1       EndIf

--  67  67109889    60  1   0   2   1   0   EndFunc

End of fold block
--  68  67109888    -1  1   0   1   0   0   

End of fold block
--  69  1024    -1  1   0   0   0   0   Func Func8()

--  70  1024    -1  1   0   0   0   0       If $T Then

--  71  1024    -1  1   0   0   0   0   

--  72  1024    -1  1   0   0   0   0       Else

--  73  1024    -1  1   0   0   0   0   

--  74  1024    -1  1   0   0   0   0       EndIf

--  75  1024    -1  1   0   0   0   0   EndFunc

--  76  1024    -1  1   0   0   0   0   nil

I found this old bug report that might explain it better.
BTW, since "fold.on.open=1" fixes it, this bug doesn't matter to me anymore.

 

But I'd like to stop Scite/Lua from clearing the output when the function is called. Is this possible?

Edited by Anas

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I used you script  to test and don't see the same values for FoldLevel.

Start of fold block
--  65  67240962    63  1   0   1   2   2   

--  66  67175426    63  1   0   2   2   1       EndIf

--  67  67109889    60  1   0   2   1   0   EndFunc

End of fold block
--  68  67109888    -1  1   0   1   0   0   

End of fold block
--  69  67183616    -1  1   0   0   0   1   Func Func8()

Start of fold block
! Toggle fold for line  69
--  70  67249153    68  1   0   0   1   2       If $T Then

Start of fold block
--  71  67240962    69  1   0   1   2   1   

--  72  67249153    68  1   0   2   1   2       Else

End of fold block
Start of fold block
--  73  67240962    71  1   0   1   2   2   

--  74  67175426    71  1   0   2   2   1       EndIf

--  75  67109889    68  1   0   2   1   0   EndFunc

End of fold block
--  76  1024    -1  1   0   1   0   0   nil
End of fold block


Which version of SciTE are you using and do the actual folding indicators look correct for those lines in SciTE?

Not sure whether there is an option to avoid clearing the OutputPane when using a LUA function... need a little research for that.

Jos

 

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I had SciTE v.3.6.2.0, and updated to v.3.6.6.0 and still get the same results.

No, the function is not folded in SciTE nor does the indicator look like it does.

funcs.jpg

Did you have "fold.on.open" enabled when you tested?

Edited by Anas

Share this post


Link to post
Share on other sites

Strange... 

Just now, Anas said:

No, the function is not folded in SciTE.

 

I meant whether you see the Folding marks for the lines that return 1024:

Knipsel.PNG

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
1 minute ago, Jos said:

I meant whether you see the Folding marks for the lines that return 1024:

I Edit my previous post.

I thought reinstalling SciTE would've solved it.

 

Did you have "fold.on.open" enabled when you tested?

Share this post


Link to post
Share on other sites
11 minutes ago, Anas said:

Did you have "fold.on.open" enabled when you tested?

No, but tried that as well as well and don't see the behavior see and it still works as expected.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • okolaris
      By okolaris
      Hey everyone,
      I thought I might share my little Language UDF plus the more powerful SciTE Tool to ship Strings from SciTE into the xml file. While I haven't had the time to fully adapt the small UDF to one of the big XML-UDFs the so called "Language Transmitter" that basically writes the XML file for you runs mostly on "XML DOM wrapper (COM)" by eltorro. The Transmitter should work with other XML-Language-UDFs depending on their encoding.
       
      First let's start with the UDF, there are two functions of interest: _LangInit($sFilePath) and s($sString) As you will have guessed, _LangInit($sFilePath) is called once to initialize the UDF and s($sString) is used to receive the string to your key. Plain and simple.
      Now to the actual "new" part, the Language Transmitter. It basically allows you to transfer a selected String from SciTE into a xml file. While doing so it will scan for AutoIt variables, macros etc. and parse the string to fit StringFormat(). It then saves the formatted string in the xml file and returns the formatted call into SciTE. If the selected string is already defined it will directly parse the key into SciTE. To change the default output file, you can either edit the ini-file in the @ScriptDir of the LanguageTransmitter.exe or press Alt+A on empty space again and keep clicking cancel/no until the Transmitter let's you select the current output file. Standard output is strings.xml in the current opened AutoIt Script.
      Example:
      ; given the line: MsgBox(16, 'Error', 'Error message') ; select 'Error' run the Transmitter follow the instructions, repeat with 'Error message'. Outcome (e.g.): MsgBox(16, s('Error'), s('Error_msg')) ; Variables and Macro example: $sString = "Value: " & $iValue & @CRLF & 'Another value: '& $iValue2 ; Select the full string including all AutoIt variables and macros etc. in SciTE and press Alt+A (default) to run the LanguageTransmitter ; follow the instructions and it will then paste a formatted string like that into SciTE: $sVar = StringFormat(s('Key'), $iValue, $iValue2) ; the correlating xml entry should look like that: ; <string name="Key">Value: %s\r\nAnother value: %s</string> ; as you can see @CRLF has been replaced with \r\n as well. If you are working on a project and want to directly add a string to the xml file just start the Language Transmitter without selecting any text, enter your string and a key.
      SetUp/Installation
      Examples
      Since xml files are required all examples can be found in the zip file. There are two examples, one includes a language selection interface.
      Language File Checker
      I added a script to check whether the xml file contains all required strings or even unnecessary strings.
       
      Hope you like my little helper!
       
      UDF - LanguageSupport.zip
    • BugFix
      By BugFix
      Hi,
      I think, you all know this: You look at a script containing color values. You have a rough idea of the colors, but would like to know how it looks like. 
      I have created a Lua script that displays the color of the value in SciTE as Calltip. Set the cursor in the Hex-value, press the hotkey. Above the value a Call tip appears. The background color corresponds to the hex value.
      Read the function header to obtain installation instructions.
      So it looks.  
      EDIT:
      I think it's better to bind the function not only of AutoIt. If it can be called in all files, also the color settings in the * .properties can view. For this purpose remove the file attachment from the call. Use: command.13.*=  instead of: command.13.*.au3=
       
      EDIT 20.07.2015:
      Now I've made some changes
      - You can switch to show colors as RGB or BGR
      - added new function: PreviewBackForeColor
      To have a preview for back and fore color:
      - Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR
        have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)".
        If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true"
      - No other color value may be included in this line. If any - the first and second color will used.
      - Set the cursor in this line and hit the Hotkey.
      - A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value.
      - If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color.
        In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0"
      Because you've different functions in one script, you need another way to install and call it. Read the instructions inside the script.
      First color used as back color, second as fore color.
       
      Function called with flag - first color is now the fore color.
       

       
      EDIT 2018-01-16:
      Added: 
      Now be also recognized in au3 scripts, variables/constants which have an color assignment inside the script or inside an include file from this script.
      But it can only be one assignment per line. If the assignment is inside a comment line or -block, it will ignored.
      The assignment can also be build by using function(s) [from script or include files].
      example:  "Local $COLOR = '0x' & Hex(Mod(@SEC, 2) ? Random(0,0x000FFF, 1) : Random(0x001000, 0xFFF000, 1), 8)"
      But the functions must NOT CONTAIN any VARIABLES! This would require a recursive assignment search. Impossible if variables get values only at runtime.
      You can disable the search inside include files with an entry in SciTEUser.properties:
      #~ "ShowHexColorFromCursor.lua", Dis/Enable search in Includes (0/1  NO/YES)
      Get.Color.Assignment.Includes=0
      The default value (without settings) is '1', enabled.
      Includes in comments will ignored.
      current version v0.8

       
      -- TIME_STAMP 2018-01-16 17:37:44 v 0.8 --[[------------- I N S T A L L A T I O N A N D U S I N G I N S T R U C T I O N -------------- Save the file. At first, make an entry in your SciTEStartup.lua LoadLuaFile("ShowHexColorFromCursor.lua", "C:\\Your Path\\with Backslash\\") Select free command-numbers from your SciTEUser.properties. Customize the following settings with this numbers. # 13 Show HexColor RGB command.name.13.*=Show RGB-Color From Cursor command.13.*=dostring ShowHexColorFromCursor() command.mode.13.*=subsystem:lua,savebefore:yes command.shortcut.13.*=Ctrl+Shift+F11 # 14 Show HexColor BGR command.name.14.*=Show BGR-Color From Cursor command.14.*=dostring ShowHexColorFromCursor(true) command.mode.14.*=subsystem:lua,savebefore:yes command.shortcut.14.*=Ctrl+Alt+F11 Set the cursor in the Hex-value, press the hotkey to show the color as RGB or as BGR. Above the value a Call tip appears. The background color corresponds to the hex value. A possible alpha component is ignored. [NEW] Now be also recognized in au3 scripts, variables/constants which have an color assignment inside the script or inside an include file from this script. But it can only be one assignment per line. If the assignment is inside a comment line or -block, it will ignored. The assignment can also be build by using function(s) [from script or include files]. example: "Local $COLOR = '0x' & Hex(Mod(@SEC, 2) ? Random(0,0x000FFF, 1) : Random(0x001000, 0xFFF000, 1), 8)" But the functions must NOT CONTAIN any VARIABLES! This would require a recursive assignment search. Impossible if variables get values only at runtime. You can disable the search inside include files with an entry in SciTEUser.properties: #~ "ShowHexColorFromCursor.lua", Dis/Enable search in Includes (0/1 NO/YES) Get.Color.Assignment.Includes=0 The default value (without settings) is '1', enabled. Includes in comments will ignored. Be recognized AutoIt hex color code "0x12AB34" and also HTML hex color code "#12AB34". PREVIEW FOR BACK AND FORE COLOR: - Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)". If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true" - No other color value may be included in this line. If any - the first and second color will used. - Set the cursor in this line and hit the Hotkey. - A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value. - If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color. In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0" For use with AutoIt color values only. To have both calls (w/wo flag) make two commands: # 11 Preview Back and Fore Color / first color value is back color command.name.11.*.au3=Preview Back and Fore Color command.11.*.au3=dostring PreviewBackForeColor() command.mode.11.*.au3=subsystem:lua,savebefore:yes command.shortcut.11.*.au3=Ctrl+Shift+F12 # 16 Preview Fore and Back Color / first color value is fore color command.name.16.*.au3=Preview Fore and Back Color command.16.*.au3=dostring PreviewBackForeColor(true) command.mode.16.*.au3=subsystem:lua,savebefore:yes command.shortcut.16.*.au3=Ctrl+Alt+F12 --------------------------------------------------------------------------------------------------]] ------------------------------------------------------------ list object to manipulate simple tables local objList = { list = {}, delall = function(self) self.list = {} return self end, addonce = function(self, _val, _casesense) -- return true, if added local exists = function(_val, _casesense) for k in pairs(self.list) do if _casesense then if self.list[k] == _val then return true end else if tostring(self.list[k]):upper() == tostring(_val):upper() then return true end end end return false end if not exists(_val, _casesense) then table.insert(self.list, _val) return true end return nil end, new = function(self, _obj) _obj = _obj or {} setmetatable(_obj, self) self.__index = self return _obj end } --------------------------------------------------------------------------------------- /object list --------------------------------------------------------------------------------------- object color local objColor = { --------------------------------------------- variable will un/set if color-calltip is not/shown colortip_show = false, --------------------------------- user can disable search inside include files, default: enabled search_in_includes = true, ------------------------------------------------------------------- the default calltip position calltips_pos_def = false, ------------------------------------------------------------ the default calltip highlight color calltips_colorhlt_def = 0x0000FF, -- BGR (red) ---------------------------------------------------------- list with include storage directories lInclPathes = objList:new(), -------------------------------------------------- list/string with includes from current buffer lIncl = objList:new(), sIncl = '', ---------------------------------------------------------------------------------------- pattern pattHex = '()0x([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])', pattHex2 = '[0-9a-fA-F][0-9a-fA-F]', pattCS1 = '^#[Cc][Oo][Mm][Mm][Ee][Nn][Tt][Ss]%-[Ss][Tt][Aa][Rr][Tt]', pattCE1 = '^#[Cc][Oo][Mm][Mm][Ee][Nn][Tt][Ss]%-[Ee][Nn][Dd]', pattCS2 = '^#[Cc][Ss]', pattCE2 = '^#[Cc][Ee]', pattComment = '^%s*;', ----------------------------------------------------------------------------------------- pathes sPathGetColorAU3, sFileResult, TEMPDIR = props['SciteUserHome']..'\\..\\..\\Temp', sAU3exe = props['SciteDefaultHome']..'\\..\\AutoIt3.exe', ------------------------------------------------------------------------------------------------ ------------------------------------------------------------ set calltip values back to defaults SetCalltipsDefault = function(self) scite.SendEditor(SCI_CALLTIPSETBACK, 0xFFFFFF) scite.SendEditor(SCI_CALLTIPSETFOREHLT, self.calltips_colorhlt_def) scite.SendEditor(SCI_CALLTIPSETPOSITION, self.calltips_pos_def) self.colortip_show = false end, ---------------------------------------------------------------------------- /SetCalltipsDefault ------------------------------------------------------------------------------ initialize values Startup = function(self) if props['Get.Color.Assignment.Includes'] == '0' then self.search_in_includes = false end if tonumber(props['calltips.set.above']) == 1 then self.calltips_pos_def = true end if props['calltips.color.highlight'] ~= '' then local colorhlt_user = myCallTips:BGR2Decimal(props['calltips.color.highlight']) if colorhlt_user ~= nil then self.calltips_colorhlt_def = colorhlt_user end end local sProp = props['openpath.$(au3)'] for w in sProp:gmatch('([^;]+)') do self.lInclPathes:addonce(w) end self.sPathGetColorAU3 = self.TEMPDIR..'\\ExecLineGetColor.au3' self.sFileResult = self.TEMPDIR..'\\ExecLineColor.txt' end, --------------------------------------------------------------------------------------- /Startup -------- check for comment line/block. Return "true/false, 0/1/-1" (0=comment line/1=#cs/-1=#ce) -- returned number for de/increase comment counter CheckComment = function(self, _s) local iMatch = _s:find(self.pattComment) if iMatch ~= nil then return true, 0 end iMatch = _s:find(self.pattCS1) or _s:find(self.pattCS2) if iMatch ~= nil then return true, 1 end iMatch = _s:find(self.pattCE1) or _s:find(self.pattCE2) if iMatch ~= nil then return true, -1 end return false, 0 end, ------------------------------------------------------------------------------------------------ --------------------------------------------------------- read include files from current buffer IncludesFromBuffer = function(self) local sText, boolCmnt, countCmnt, n, incl = editor:GetText(), false, 0 self.lIncl:delall() self.sIncl = '' for line in sText:gmatch('([^\r\n]+)') do boolCmnt, n = self:CheckComment(line) if boolCmnt then countCmnt = countCmnt + (n) end if not boolCmnt and countCmnt == 0 then -- none comment line or block -- #include <abc.au3> incl = line:match("#[iI][nN][cC][lL][uU][dD][eE]%s-<([%w%s_.]+)>") if incl ~= nil then if self.lIncl:addonce(incl) then self.sIncl = self.sIncl..'#include <'..incl..'>\n' end else -- #include 'abc.au3' or #include "abc.au3" _, incl = line:match("#[iI][nN][cC][lL][uU][dD][eE]%s-([\"'])([%w%s_.:\\]+)%1") if incl ~= nil then if incl:sub(1,1) == '\\' then incl = incl:sub(2,-1) end if self.lIncl:addonce(incl) then if incl:sub(2,2) == ':' then self.sIncl = self.sIncl..'#include "'..incl..'"\n' else self.sIncl = self.sIncl..'#include "'..props['FileDir']..'\\'..incl..'"\n' end end end end end end end, ---------------------------------------------------------------------------- /IncludesFromBuffer ------------------------------------------ create the au3 file for executing the assignment line CreateAU3 = function(self, _sLineAssignment) local sTextAU3 = self.sIncl.. 'Global $sFileExport = @TempDir & "\\ExecLineColor.txt"\n'.. 'FileDelete($sFileExport)\n'.. 'Global $sLine = "'.._sLineAssignment..'" ; line: $Variable = assignment\n'.. 'If $sLine = "NONE" Then Exit\n'.. 'Global $sExec = StringTrimLeft($sLine, StringInStr($sLine, "="))\n'.. 'Global $sColor = "0x" & Hex(Execute($sExec), 6)\n'.. 'If Not StringRegExp($sColor, "^0x[0-9A-F]{6}$") Then Exit\n'.. 'FileWrite($sFileExport, $sColor)\n' local fH = io.open(self.sPathGetColorAU3, 'w+') fH:write(sTextAU3) fH:close() end, ------------------------------------------------------------------------------------- /CreateAU3 --------------------------------- check, if file containing the assignment for selected variable FindAssignment = function(self, _path, _sSelection) local fH = io.open(_path) if fH ~= nil then local sRead, boolCmnt, countCmnt, n = fH:read('*all'), false, 0 fH:close() for line in sRead:gmatch('([^\r\n]+)') do boolCmnt, n = self:CheckComment(line) if boolCmnt then countCmnt = countCmnt + (n) end if not boolCmnt and countCmnt == 0 then -- none comment line or block if line:find(_sSelection..'%s*=') then return line end end end end return nil end, -------------------------------------------------------------------------------- /FindAssignment -------------------------------------------------------------------- detects color from variable GetColorValueFromVariable = function(self, _sSelection, _iCursor, _var_beginPos, _var_endPos, _fBGR) local sLine = self:FindAssignment(props['FilePath'], _sSelection) if sLine == nil then -- search inside include files -- do it not, if the user has disabled: "Get.Color.Assignment.Includes=0" (default = 1 - enabled) if self.search_in_includes then self:IncludesFromBuffer() -- get include files if #self.lIncl.list ~= 0 then -- open each include file, search line with assignment "_sSelection =" for i=1, #self.lIncl.list do if self.lIncl.list[i]:sub(2,2) == ':' then -- include has full path, search only in this file sLine = self:FindAssignment(self.lIncl.list[i], _sSelection) elseif self.lIncl.list[i]:find('\\') then -- include has partial path, check first if exist in @ScriptDir sLine = self:FindAssignment(props['FileDir']..'\\'..self.lIncl.list[i], _sSelection) else -- include has filename only (or partial path), if sLine ~= nil then break end -- .. concanate all directories with this for searching for j=1, #self.lInclPathes.list do sLine = self:FindAssignment(self.lInclPathes.list[j]..'\\'..self.lIncl.list[i], _sSelection) if sLine ~= nil then break end end end end end end end if sLine == nil then sLine = 'NONE' end -- create the au3-file for executing the assignment line, with 'NONE' - the last result file will delete self:CreateAU3(sLine) -- run the au3-file local sCmd = '"'..self.sAU3exe..'" /AutoIt3ExecuteScript "'..self.sPathGetColorAU3..'"'..' "'..sLine..'"' if shell then shell.exec(sCmd, nil, true, true) else os.execute('start "" '..sCmd) end -- check for result local fH = io.open(self.sFileResult) if fH == nil then scite.SendEditor(SCI_CALLTIPSHOW, _var_beginPos +1, (' NONE COLOR ASSIGNED! ')) scite.SendEditor(SCI_CALLTIPSETHLT, 0, 22) scite.SendEditor(SCI_CALLTIPSETBACK, 0x33FFFF) scite.SendEditor(SCI_CALLTIPSETFOREHLT, 0x0000FF) scite.SendEditor(SCI_CALLTIPSETPOSITION, true) else local sValue = fH:read() fH:close() local R,G,B = sValue:match('('..self.pattHex2..')('..self.pattHex2..')('..self.pattHex2..')$') local iLen = _var_endPos - _var_beginPos -1 scite.SendEditor(SCI_CALLTIPSHOW, _var_beginPos +1, (' '):rep(iLen)) scite.SendEditor(SCI_CALLTIPSETHLT, 0, iLen) scite.SendEditor(SCI_CALLTIPSETPOSITION, true) if _fBGR == true then scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', R,G,B))) else scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', B,G,R))) end end self.colortip_show = true editor:SetSelection(_iCursor, _iCursor) end, --------------------------------------------------------------------- /GetColorValueFromVariable ----------------------------------------- grabs the color value or variable from cursor position FromCursor = function(self, _fBGR) local iLen = 8 local function isHexChar(_asc) local sChar = string.char(_asc) if sChar == '#' then iLen = 7 end if sChar:find('[#x0-9a-fA-F]') then return true else return false end end local cursor = editor.CurrentPos -- check if cursor is possible inside a variable local var_beginPos, var_endPos = cursor if string.char(editor.CharAt[cursor]) ~= '$' then -- cursor is inside or behind the variable (if its a variable) editor:WordLeft() -- skip to the left end var_beginPos = editor.CurrentPos -- is it a variable? if string.char(editor.CharAt[var_beginPos]) == '$' then -- now the cursor is in front of variable editor:WordRight() var_endPos = editor.CurrentPos editor:SetSelection(var_beginPos, var_endPos) local sSelection = editor:GetSelText() local iLenSel = sSelection:len() -- trim spaces on right site, if any sSelection = sSelection:gsub('%s+$','') var_endPos = var_endPos - (iLenSel - sSelection:len()) return self:GetColorValueFromVariable(sSelection, cursor, var_beginPos, var_endPos, _fBGR) end -- cursor inside hex value? local beginPos, endPos = cursor, cursor while isHexChar(editor.CharAt[beginPos-1]) do beginPos = beginPos - 1 end while isHexChar(editor.CharAt[endPos]) do endPos = endPos + 1 end if beginPos ~= endPos then if endPos - beginPos > iLen then editor:SetSelection(beginPos + iLen, beginPos) elseif endPos - beginPos == iLen then editor:SetSelection(endPos, beginPos) else return end local R,G,B = tostring(editor:GetSelText()):match('('..self.pattHex2..')('..self.pattHex2..')('..self.pattHex2..')$') scite.SendEditor(SCI_CALLTIPSHOW, beginPos+1, (' '):rep(iLen-1)) scite.SendEditor(SCI_CALLTIPSETHLT, 0, iLen-1) scite.SendEditor(SCI_CALLTIPSETPOSITION, true) if _fBGR == true then scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', R,G,B))) else scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', B,G,R))) end self.colortip_show = true end end, ------------------------------------------------------------------------------------ /FromCursor ----------------------------------------------------------------------- show back and fore color PreviewBackForeColor = function(self, _fFore1st) local iBackCol, iForeCol = 0xF0F0F0, 0x000000 local cursor = editor.CurrentPos local sLine, iColumn = editor:GetCurLine() local iLineStartPos = cursor - iColumn local tMatch, beginPos = {}, nil for s, r, g, b in sLine:gmatch(self.pattHex) do if beginPos == nil then beginPos = s end local t = {} t['R']=r t['G']=g t['B']=b table.insert(tMatch, t) end if #tMatch == 0 then return elseif #tMatch == 1 then if _fFore1st == true then iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) else iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) end else if _fFore1st == true then iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) iBackCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)) else iForeCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)) iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) end end scite.SendEditor(SCI_CALLTIPSHOW, iLineStartPos + beginPos, ' FORE-COLOR ') scite.SendEditor(SCI_CALLTIPSETHLT, 0, 12) scite.SendEditor(SCI_CALLTIPSETBACK, iBackCol) scite.SendEditor(SCI_CALLTIPSETFOREHLT, iForeCol) self.colortip_show = true end -------------------------------------------------------------------------- /PreviewBackForeColor } -------------------------------------------------------------------------------------- /object color ---------------------------------------------------------------------------------- region EventClass ShowColorEvt = EventClass:new(Common) function ShowColorEvt:OnKey(_keycode, _shift, _ctrl, _alt) if objColor.colortip_show then objColor:SetCalltipsDefault() end end function ShowColorEvt:OnDwellStart(_pos, _word) if objColor.colortip_show then objColor:SetCalltipsDefault() end end --------------------------------------------------------------------------------- /region EventClass -------------------------------------------------------------------------- function call redirection function ShowHexColorFromCursor(_fBGR) objColor:FromCursor(_fBGR) end --> ShowHexColorFromCursor function PreviewBackForeColor(_fFore1st) objColor:PreviewBackForeColor(_fFore1st) end --> PreviewBackForeColor ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- run startup objColor:Startup() ----------------------------------------------------------------------------------------------------  
      ShowHexColorFromCursor[0.3].lua
      ShowHexColorFromCursor[0.8].lua
    • wakillon
      By wakillon
      SciTE Hopper : Jump to Any line by one click and many other helpfull functions !


      As Ashalshaikh suggested me after leaving me the task to continue >SciTE Hopper, i open a new Topic about it.
      It will be more easy for futures updates.

      Many helpfull functions in contextual menu.
      SciTE Hopper is now multipurpose.
      • Color Catcher added
      • BinaryToAu3Kompressor added
      • TinyAu3Search replaced by StringFinder
      • RegJumper added
      • Edit With SciTE added (available in Options)
      • SpecialCharactersViewer added (available in Tray menu)
      New Contextual Menu :

      For a right Click on a function :

      • Copy function name
      • Insert a function header
      • Cut function
      • Copy function
      • Delete function
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments

      For entire script :

      • Create a functions List
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments
      • ( Open in SciTE a ) Duplicate of current Script in Temp Dir
      • ( Open in SciTE a ) Duplicate of current Script in Same Dir
      • Explore Parent Script Folder
      • Copy Script name
      • Copy Script path
      • Find Unused Functions
      • Find Unused Variables
      • Set all functions in alphabetic order.( func headers and regions ( in fact, all lines between functions ) are not supported.)

      SciTE Editor New Contextual Menu if SciTE Hopper is added ( in Options ) to SciTE Editor :
      when you made a selection in SciTE Editor you can :

      • Open a Reg Key in Regedit using RegJumper
      • Open a Url in your default Browser
      • Search on google in your default Browser
      • Search on AutoIt Website in your default Browser
      Now Can be added to windows start (minimized)
      Options are available by Tray Menu.
      A double click on tray icon will open clipboard content to SciTE Editor ( Handy when you have copied some code from your browser )

      How to proceed for add SciTE Hopper to SciTE Editor :
      Run Scite Editor, run Scite Hopper ( compiled! ) go to Options and select Add/Remove to SciTE Tab. then click on Add button and it's done !
      Right click on SciTE Editor and choose SciTE Hopper in Contextual Menu for run it when you need it !
      Update of 07 Dec 2017
      TinyAu3Search is replaced by StringFinder

      Previous downloads : 1287
      Script and compiled version are available in the download section
       
      Thanks to Ashalshaikh, Melba23, Th3 MMA, Alzri2, taitel, Manadar, taz742, Yashield, Authenticity, Xenobiologist for their help
      and asdf8 for his >Includes Helper and azjio for his >FileSearch.

      Hope it help you and happy Scripting !

       
    • wakillon
      By wakillon
      For more details go to the Topic
    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )