Jump to content

New SciTE4AutoIt3 available with SciTE v1.79


Jos
 Share

Recommended Posts

SciTE can highlight all occurrences of the current word or selected text. Here is an example of the settings I now have set:

Nice, I like that one from Notepad++. Any way to make it act like N++, where it only highlights if you select the word? Now it highlights all the time even if you just place the cursor somewhere. Edited by wraithdu
Link to comment
Share on other sites

  • Replies 299
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Mat, is there some reason you need to keep multiple files? Why not keep a single file, paste the contents into that file and run it. That is what I do although I'm sure I run far less code than you since I tend not to run code from the forum.

Link to comment
Share on other sites

Mat, is there some reason you need to keep multiple files? Why not keep a single file, paste the contents into that file and run it. That is what I do although I'm sure I run far less code than you since I tend not to run code from the forum.

Where possible I do use the same file, but sometimes it's not really possible. TBH I've got used to it. I have an AutoIt script that creates the next file and opens it in SciTE, but I seem to remember PSPad had something where they would save as temp files... IIRC they even let you run just the selected text which was interesting.
Link to comment
Share on other sites

Something I found in the new SciTE version that I really like is the file preview when you open a file inside SciTE. I don't know if it had this in the previous version, but it never showed before if it did. It's very cool if you have ambiguous names of some test files, like I do, lets you make sure you're opening the right one before actually opening it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Something I found in the new SciTE version that I really like is the file preview when you open a file inside SciTE. I don't know if it had this in the previous version, but it never showed before if it did. It's very cool if you have ambiguous names of some test files, like I do, lets you make sure you're opening the right one before actually opening it.

The Preview Pane is a feature of Windows Explorer and is available for every application. See the ? icon on the right below the search bar? See the icon directly to the left of that? Yeah, that toggles the Preview pane on/off. It works for the standard dialogs other applications use as well as for Explorer itself. It has nothing to do with SciTE.
Link to comment
Share on other sites

The Preview Pane is a feature of Windows Explorer and is available for every application. See the ? icon on the right below the search bar? See the icon directly to the left of that? Yeah, that toggles the Preview pane on/off. It works for the standard dialogs other applications use as well as for Explorer itself. It has nothing to do with SciTE.

Interesting, I never played around with that button before, and it's not showing in the normal Windows Explorer that way. I wonder why it shows the preview pane by default in SciTE even though I'm not using it in Windows?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

So everybody is still happy with this new version of SciTE?

Mmm. well, sins you asked.

The potential flickering from the "document closing and reopening" part when using, for example, [Tidy AutoIt Source] seems to got worse. (never really noted it until changing to 2.26(scite4autoit3 beta).)

- seems directly related to the position of the edit-screen in swapping document. (lower down, scite taking longer to display the new document, ergo: temporary showing a other open document longer. (having documents open with different backgrounds(style) makes it of course also harder to digest/ignore.)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

As much as I love the word highlight feature in Scintilla, SciTE's implementation bugs the hell outta me. It should be more like Notepad++ where you have to highlight a whole word before it kicks in, instead of highlighting ALL THE TIME. But I digress. Here's a quickie LUA function to toggle on the fly. Stick it in the Tools.lua file.

function Tools:toggleWordHighlight()
    if props['highlight.current.word'] == '' or props['highlight.current.word'] == '0' then
        props['highlight.current.word'] = '1'
    else
        props['highlight.current.word'] = '0'
    end
end

And the shortcut:

# 38 Toggle word highlight
command.name.38.$(au3)=Toggle Word Highlight
command.mode.38.$(au3)=subsystem:lua,savebefore:no
command.38.$(au3)=InvokeTool Tools.toggleWordHighlight
command.shortcut.38.$(au3)=Alt+H
Edited by wraithdu
Link to comment
Share on other sites

You could use the OnUpdateUI() event to poll the current selection and if there is a single-word selection then programatticaly toggle the property. Alternatively you may be able to use OnDwellStart() to turn it on only when actually hovering over a word. I too don't exactly like how it works so I may see about trying OnDwellStart() toggling or something.

Link to comment
Share on other sites

I feel like I'm really close, but the highlighting is not appearing. The property is set correctly however. Any idea what I'm missing?

It's worth noting that even with the hotkey toggle I posted above, if an entire word is selected, then highlighting is toggled, nothing happens until the caret moves again. I've tried some tricks with CurrentPos, SetSel, etc with no luck.

MyTools = EventClass:new(Common)

function MyTools:OnUpdateUI()
    local selStart = editor.SelectionStart
    local selEnd = editor.SelectionEnd
    -- check no spaces in selection
    local selText = editor:GetSelText()
    local spcIndex = string.find(selText, ' ')
    if selStart ~= selEnd and spcIndex == nil then
        -- check if selected whole word
        if self:IsWordBoundry(editor.CharAt[selStart-1]) and self:IsWordBoundry(editor.CharAt[selEnd]) then
            if props['highlight.current.word'] ~= '1' then
                props['highlight.current.word'] = '1'
            end
        else
            if props['highlight.current.word'] ~= '0' then
                props['highlight.current.word'] = '0'
            end
        end
    else
        if props['highlight.current.word'] ~= '0' then
            props['highlight.current.word'] = '0'
        end
    end
    
    return false
end

function MyTools:IsWordBoundry(char)
    local strChar = string.char(char)
    local beginIndex = string.find(strChar, '%w')
    if beginIndex == nil and strChar ~= '_' and strChar ~= '$' and strChar ~= '#' then
        return true
    end
    
    return false
end
Link to comment
Share on other sites

This however, works great. I can't take all the credit as I found a sample script for marking stuff, then adapted it.

*snip*

One question though. The SciTE docs here: http://www.scintilla.org/ScintillaDoc.html#Indicators say indicators 0-7 are reserved for lexers. Does AutoIt's lexer use any of these indicators? My function above just uses indicator 0, but I'm not sure if that is safe.

Edited by wraithdu
Link to comment
Share on other sites

Based on my above class, can I do this to create a new class property? I want a private variable that only my class can access.

MyTools = EventClass:new(Common)
MyTools.myPrivateVar = 'private'

function MyTools:foo()
    -- not sure this is correct, since self.myPrivateVar does not work here
    print(MyTools.myPrivateVar)
end
Edited by wraithdu
Link to comment
Share on other sites

Well, if by private you really mean "member" then yes, that is correct. Lua doesn't have access control. I'm not sure why self.myPrivateVar won't work unless you are calling foo() before myPrivateVar is initialized. I just tested the following code and it works correctly:

MyTools = EventClass:new(Common)
MyTools.myPrivateVar = 'private'

function MyTools:foo()
    -- not sure this is correct, since self.myPrivateVar does not work here
    print(self.myPrivateVar)
end

MyTools:foo()

Unless you really need to create myPrivateVar outside the class (for example, if another class is going to access it) then you should really use this code:

MyTools = EventClass:new(Common)

function MyTools:OnStartup()
    self.myPrivateVar = 'private'
    print(self.myPrivateVar)
end
onstartup() is called whenever EventClass:BeginEvents() is invoked which should be the last thing that appears in SciTEStartup.lua. It is guaranteed to be called before any other events fire. Placing member declarations at global scope as you have done is only required if that member may be accessed before EventClass:BeginEvents() is invoked which generally only happens in very rare cases.

Edit: The other reason self.myPrivateVar would fail is if you used dot syntax to invoke foo() instead of colon syntax. There is a difference. The dot syntax does not pass the object as the first parameter, the colon syntax secretly passes the object as the parameter named self. In order to access self you must use colon notation.

Edited by Valik
Link to comment
Share on other sites

Awesome. I like the onstartup method better... and I found my syntax error with period versus colon - I had one call where I mistakenly used a period. Here's the updated functions to get highlighting just like Notepad++

MyTools = EventClass:new(Common)

function MyTools:OnStartup()
    -- class property to hold active marker state so we only update when necessary
    self.bMarkersActive = false
    -- initialize missing prop
    if props['highlight.sel.text'] == '' then
        props['highlight.sel.text'] = '1'
    end
end

function MyTools:OnUpdateUI()
    if props['highlight.sel.text'] == '1' then
        local selStart = editor.SelectionStart
        local selEnd = editor.SelectionEnd
        local selText = editor:GetSelText()
        -- check if selected text is an allowed word
        if selStart ~= selEnd and self:IsWord(selText) then
            -- check for word boundaries at ends of selection
            if not self:IsWord(string.char(editor.CharAt[selStart-1])) and not self:IsWord(string.char(editor.CharAt[selEnd])) then
                self:markOccurrences(selText)
            else
                self:clearOccurrences()
            end
        else
            self:clearOccurrences()
        end
    end

    return false
end

function MyTools:IsWord(word)
    -- look for anything not allowed
    local find = string.find(word, '[^%a%d_$#@.]')
    if find == nil then
        return true
    else
        return false
    end
end

function MyTools:clearOccurrences()
    if self.bMarkersActive then
        self.bMarkersActive = false
        scite.SendEditor(SCI_INDICATORCLEARRANGE, 0, editor.Length)
    end
end

function MyTools:markOccurrences(selText)
    if not self.bMarkersActive then
        -- self:clearOccurrences()
        -- set flag markers are active
        self.bMarkersActive = true
        -- set indicator style
        local curIndic = 0
        scite.SendEditor(SCI_SETINDICATORCURRENT, curIndic)
        scite.SendEditor(SCI_INDICSETALPHA, curIndic, 255)
        scite.SendEditor(SCI_INDICSETUNDER, curIndic, true)
        scite.SendEditor(SCI_INDICSETSTYLE, curIndic, INDIC_ROUNDBOX)
        scite.SendEditor(SCI_INDICSETFORE, curIndic, 0xFFF55D)
        -- find each occurrence of the word and set the indicator range
        local flags = SCFIND_WHOLEWORD
        local s,e = editor:findtext(selText, flags, 0)
        while s do
            scite.SendEditor(SCI_INDICATORFILLRANGE, s, e - s)
            s,e = editor:findtext(selText, flags, e+1)
        end
    end
end
My other question about the indicator values... is 0 safe to use in this script? Or does the AutoIt lexer use some of them?

Edit-

Updated code to allow disabling highlighting with prop:

highlight.sel.text=0
Edited by wraithdu
Link to comment
Share on other sites

  • Developers

Uploaded a Beta version of SciTE v 2.27 with our modification is it here for those who would like to give that a try.

Just copy the 3 files to your SciTE directory.

The 2 HTML files contain the updated Docs and History so you can see the changes made to SciTE since the latest v1.79 and v2.26 Beta we currently use.

Jos :huh2:

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.
  :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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