Is it ok to post SciTE LUA stuff here as well? I've updated my scripts for word highlighting in SciTE a la Notepad++. The new version allows to set a mode where any highlighted text is marked throughout the file, not just a whole word. In this mode, you can configure the minimum length of selected text to highlight. Here we go: SciTEUser.properties settings #global enable [0|1, def=1]
highlight.sel.text=1
#whole word mode [0|1, def=1]
highlight.whole.word=0
#min selected text length [integer, def=2]
highlight.min.length=2LUA script (mine is loaded from its own file, so modify SciTEStartup.lua accordingly) MyTools = EventClass:new(Common)
function MyTools:OnStartup()
-- class property to hold active marker state so we only update when necessary
self.bMarkersActive = false
-- class property to indicate programatic marker clearing and avoid double UI update
self.lastSelText = ""
-- initialize missing props
if props['highlight.sel.text'] ~= '0' and props['highlight.sel.text'] ~= '1' then
props['highlight.sel.text'] = '1'
end
if props['highlight.whole.word'] ~= '0' and props['highlight.whole.word'] ~= '1' then
props['highlight.whole.word'] = '1'
end
if props['highlight.min.length'] == '' then
props['highlight.min.length'] = '2'
end
end
function MyTools:OnUpdateUI()
if props['highlight.sel.text'] == '1' then
local selText = editor:GetSelText()
-- check if selection has changed, update accordingly
if selText == self.lastSelText then
return false
else
self.lastSelText = selText
end
--print('update')
local selStart = editor.SelectionStart
local selEnd = editor.SelectionEnd
-- 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 props['highlight.whole.word'] == '0' or (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)
if props['highlight.whole.word'] == '1' then
-- look for anything not allowed
local find = string.find(word, '[^%a%d_$#@.]')
if find == nil then
return true
else
return false
end
else
-- return true if selection length is >= highlight.min.length and no new lines
local find = string.find(word, '[\r\n]')
if find == nil and string.len(word) >= tonumber(props['highlight.min.length']) then
return true
else
return false
end
end
end
function MyTools:clearOccurrences()
if self.bMarkersActive then
--print('clearing')
scite.SendEditor(SCI_INDICATORCLEARRANGE, 0, editor.Length)
self.bMarkersActive = false
end
end
function MyTools:markOccurrences(selText)
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)
-- set search flags
--local flags = SCFIND_WHOLEWORD
local flags = 0
-- find each occurrence of the word and set the indicator range
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