Difference (from prior major revision)
(no other diffs)
Changed: 19c19
-- <khman@users.sf.net> public domain 20060902
|
-- <khman@users.sf.net> public domain 20060906
|
Added: 60a61
This is a demo of a script that arbitrarily colourises some text, and
keeps the text coloured when switching buffers. The following demo uses
SciteExtMan, but extman itself is not necessary for the
implementation of the colouring technique.
Note that this method is not a substitute for a proper lexer interface,
so it should not be used to implement a Lua extension-based syntax
highlighter. This is because any operation that forces some part of the
buffer to be restyled will cause breakage. However, this method of
colouring might be useful for anything that does not involve "normal"
editing operations.
local function SetColours(lexer, scheme)
local function dec(s) return tonumber(s, 16) end
if lexer then editor.Lexer = lexer end
for i, style in pairs(scheme) do
for prop, value in pairs(style) do
if (prop == "StyleFore" or prop == "StyleBack")
and type(value) == "string" then
local hex, hex, r, g, b =
string.find(value, "^(%x%x)(%x%x)(%x%x)$")
value = hex and (dec(r) + dec(g)*256 + dec(b)*65536) or 0
end
editor[prop][i] = value
end
end
end
scite_Command('ColourTest|ColourTest|Ctrl+8')
local ColourScheme = {
[1] = {StyleFore = "800000", StyleBold = true,},
[2] = {StyleFore = "008000", StyleBack = "E0E0E0", StyleItalic = true,},
}
function ColourTest()
local SIG = "ColourTest"
local function Colourise(n)
local segment = n * 2
editor:StartStyling(0, 31)
for i = 1, 10 do
editor:SetStyling(segment, 1)
editor:SetStyling(segment, 2)
end
end
scite_OnSwitchFile(function()
if not buffer[SIG] then return end
SetColours(SCLEX_CONTAINER, ColourScheme)
Colourise(editor.Length / 100)
return true
end)
scite.Open("")
buffer[SIG] = true;
SetColours(SCLEX_CONTAINER, ColourScheme)
for i = 1, 100 do
editor:AddText("The quick brown fox jumped over the lazy dog.\n")
end
Colourise(editor.Length / 100)
editor.ReadOnly = true
end
RecentChanges · preferences
edit · history
Last edited September 5, 2006 5:12 pm GMT (diff)