diff options
author | Hans Hagen <pragma@wxs.nl> | 2017-11-14 14:35:42 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2017-11-14 14:35:42 +0100 |
commit | 6f55552ca1456f0a2d50d1d0fdc8dc813d9ace77 (patch) | |
tree | 4be2ae8eabfd71f42977c74055b2f15d4f253d7b /context/data/scite/context/scite-ctx.lua | |
parent | 3c5bdb02c68293a907c765f109641c3939c13f6c (diff) | |
download | context-6f55552ca1456f0a2d50d1d0fdc8dc813d9ace77.tar.gz |
2017-11-14 13:58:00
Diffstat (limited to 'context/data/scite/context/scite-ctx.lua')
-rw-r--r-- | context/data/scite/context/scite-ctx.lua | 514 |
1 files changed, 336 insertions, 178 deletions
diff --git a/context/data/scite/context/scite-ctx.lua b/context/data/scite/context/scite-ctx.lua index 809f36041..271a7581a 100644 --- a/context/data/scite/context/scite-ctx.lua +++ b/context/data/scite/context/scite-ctx.lua @@ -223,7 +223,7 @@ function get_dir_list(mask) os.execute(cmd) f = io.open(tmpfile) end - local files = {} + local files = { } if not f then -- path check added return files end @@ -238,23 +238,25 @@ end do - local wordpath = props['ctx.spellcheck.wordpath'] + print("Some CTX extensions:") - if wordpath and wordpath ~= "" then - print("loading scite-ctx.lua definition file\n") - print("- see scite-ctx.properties for configuring info\n") - print("- ctx.spellcheck.wordpath set to " .. wordpath) - if find(lower(wordpath),"ctxspellpath") then - if os.getenv('ctxspellpath') then - print("- ctxspellpath set to " .. os.getenv('CTXSPELLPATH')) - else - print("- 'ctxspellpath is not set") - end - print("- ctx.spellcheck.wordpath expands to " .. expand(wordpath)) - end - else - print("- 'ctxspellpath is not set") - end + -- local wordpath = props['ctx.spellcheck.wordpath'] + -- + -- if wordpath and wordpath ~= "" then + -- print("loading scite-ctx.lua definition file\n") + -- print("- see scite-ctx.properties for configuring info\n") + -- print("- ctx.spellcheck.wordpath set to " .. wordpath) + -- if find(lower(wordpath),"ctxspellpath") then + -- if os.getenv('ctxspellpath') then + -- print("- ctxspellpath set to " .. os.getenv('CTXSPELLPATH')) + -- else + -- print("- 'ctxspellpath is not set") + -- end + -- print("- ctx.spellcheck.wordpath expands to " .. expand(wordpath)) + -- end + -- else + -- print("- 'ctxspellpath is not set") + -- end local wraplength = props['ctx.wraptext.length'] @@ -546,163 +548,147 @@ end -- Jagged Little Pill and Tori Amos' Beekeeper after -- reinstalling my good old ATH-7 -local language = props["ctx.spellcheck.language"] -local wordsize = props["ctx.spellcheck.wordsize"] -local wordpath = props["ctx.spellcheck.wordpath"] - -if language == '' then language = 'uk' end -if wordsize == '' then wordsize = 4 else wordsize = tonumber(wordsize) end - -local wordfile = "" -local wordlist = {} -local worddone = 0 - --- we use wordlist as a hash so that we can add entries without the --- need to sort and also use a fast (built in) search - --- function kpsewhich_file(filename,filetype,progname) --- local progflag, typeflag = '', '' --- local tempname = os.tmpname() --- if progname then --- progflag = " --progname=" .. progname .. " " +-- local language = props["ctx.spellcheck.language"] +-- local wordsize = props["ctx.spellcheck.wordsize"] +-- local wordpath = props["ctx.spellcheck.wordpath"] +-- +-- if language == '' then language = 'uk' end +-- if wordsize == '' then wordsize = 4 else wordsize = tonumber(wordsize) end +-- +-- local wordfile = "" +-- local wordlist = { } +-- local worddone = 0 +-- +-- -- we use wordlist as a hash so that we can add entries without the +-- -- need to sort and also use a fast (built in) search +-- +-- function check_text() -- obsolete, replaced by lexer +-- +-- local dlanguage = props["ctx.spellcheck.language"] +-- local dwordsize = props["ctx.spellcheck.wordsize"] +-- local dwordpath = props["ctx.spellcheck.wordpath"] +-- +-- if dlanguage ~= '' then dlanguage = tostring(language) end +-- if dwordsize ~= '' then dwordsize = tonumber(wordsize) end +-- +-- local firstline, skipfirst = editor:GetLine(0), false +-- local filetype, wordskip, wordgood = getfiletype(), '', '' +-- +-- if filetype == 'tex' then +-- wordskip = "\\" +-- elseif filetype == 'xml' then +-- wordskip = "<" +-- wordgood = ">" -- end --- if filetype then --- typeflag = " --format=" .. filetype .. " " +-- +-- if props["ctx.spellcheck.language"] == 'auto' then +-- if filetype == 'tex' then +-- -- % version =1.0 language=uk +-- firstline = gsub(firstline,"^%%%s*",'') +-- firstline = gsub(firstline,"%s*$",'') +-- for key, val in gmatch(firstline,"(%w+)=(%w+)") do +-- if key == "language" then +-- language = val +-- traceln("auto document language " .. "'" .. language .. "' (tex)") +-- end +-- end +-- skipfirst = true +-- elseif filetype == 'xml' then +-- -- <?xml version='1.0' language='uk' ?> +-- firstline = gsub(firstline,"^%<%?xml%s*", '') +-- firstline = gsub(firstline,"%s*%?%>%s*$", '') +-- for key, val in gmatch(firstline,"(%w+)=[\"\'](.-)[\"\']") do +-- if key == "language" then +-- language = val +-- traceln("auto document language " .. "'" .. language .. "' (xml)") +-- end +-- end +-- skipfirst = true +-- end -- end --- local command = "kpsewhich" .. progflag .. typeflag .. " " .. filename .. " > " .. tempname --- os.execute(command) --- for line in io.lines(tempname) do --- return gsub(line, "\s*$", '') +-- +-- local fname = props["ctx.spellcheck.wordfile." .. language] +-- local fsize = props["ctx.spellcheck.wordsize." .. language] +-- +-- if fsize ~= '' then wordsize = tonumber(fsize) end +-- +-- if fname ~= '' and fname ~= wordfile then +-- wordfile, worddone, wordlist = fname, 0, { } +-- for filename in gmatch(wordfile,"[^%,]+") do +-- if wordpath ~= '' then +-- filename = expand(wordpath) .. '/' .. filename +-- end +-- if io.exists(filename) then +-- traceln("loading " .. filename) +-- for line in io.lines(filename) do +-- if not find(line,"^[%#-]") then +-- str = gsub(line,"%s*$", '') +-- rawset(wordlist,str,true) +-- worddone = worddone + 1 +-- end +-- end +-- else +-- traceln("unknown file '" .. filename .."'") +-- end +-- end +-- traceln(worddone .. " words loaded") -- end +-- +-- reset_text() +-- +-- if worddone == 0 then +-- traceln("no (valid) language or wordfile specified") +-- else +-- traceln("start checking") +-- if wordskip ~= '' then +-- traceln("ignoring " .. wordskip .. "..." .. wordgood) +-- end +-- local i, j, lastpos, startpos, endpos, snippet, len, first = 0, 0, -1, 0, 0, '', 0, 0 +-- local ok, skip, ch = false, false, '' +-- if skipfirst then first = #firstline end +-- for k = first, editor.TextLength do +-- ch = editor:textrange(k,k+1) +-- if wordgood ~= '' and ch == wordgood then +-- skip = false +-- elseif ch == wordskip then +-- skip = true +-- end +-- if find(ch,"%w") and not find(ch,"%d") then +-- if not skip then +-- if ok then +-- endpos = k +-- else +-- startpos = k +-- endpos = k +-- ok = true +-- end +-- end +-- elseif ok and not skip then +-- len = endpos - startpos + 1 +-- if len >= wordsize then +-- snippet = editor:textrange(startpos,endpos+1) +-- i = i + 1 +-- if wordlist[snippet] or wordlist[lower(snippet)] then +-- j = j + 1 +-- else +-- editor:StartStyling(startpos,INDICS_MASK) +-- editor:SetStyling(len,INDIC2_MASK) -- INDIC0_MASK+2 +-- end +-- end +-- ok = false +-- elseif wordgood == '' then +-- skip = (ch == wordskip) +-- end +-- end +-- traceln(i .. " words checked, " .. (i-j) .. " errors") +-- end +-- +-- end +-- +-- function reset_text() +-- editor:StartStyling(0,INDICS_MASK) +-- editor:SetStyling(editor.TextLength,INDIC_PLAIN) -- end - -function check_text() -- obsolete, replaced by lexer - - local dlanguage = props["ctx.spellcheck.language"] - local dwordsize = props["ctx.spellcheck.wordsize"] - local dwordpath = props["ctx.spellcheck.wordpath"] - - if dlanguage ~= '' then dlanguage = tostring(language) end - if dwordsize ~= '' then dwordsize = tonumber(wordsize) end - - local firstline, skipfirst = editor:GetLine(0), false - local filetype, wordskip, wordgood = getfiletype(), '', '' - - if filetype == 'tex' then - wordskip = "\\" - elseif filetype == 'xml' then - wordskip = "<" - wordgood = ">" - end - - if props["ctx.spellcheck.language"] == 'auto' then - if filetype == 'tex' then - -- % version =1.0 language=uk - firstline = gsub(firstline,"^%%%s*",'') - firstline = gsub(firstline,"%s*$",'') - for key, val in gmatch(firstline,"(%w+)=(%w+)") do - if key == "language" then - language = val - traceln("auto document language " .. "'" .. language .. "' (tex)") - end - end - skipfirst = true - elseif filetype == 'xml' then - -- <?xml version='1.0' language='uk' ?> - firstline = gsub(firstline,"^%<%?xml%s*", '') - firstline = gsub(firstline,"%s*%?%>%s*$", '') - for key, val in gmatch(firstline,"(%w+)=[\"\'](.-)[\"\']") do - if key == "language" then - language = val - traceln("auto document language " .. "'" .. language .. "' (xml)") - end - end - skipfirst = true - end - end - - local fname = props["ctx.spellcheck.wordfile." .. language] - local fsize = props["ctx.spellcheck.wordsize." .. language] - - if fsize ~= '' then wordsize = tonumber(fsize) end - - if fname ~= '' and fname ~= wordfile then - wordfile, worddone, wordlist = fname, 0, {} - for filename in gmatch(wordfile,"[^%,]+") do - if wordpath ~= '' then - filename = expand(wordpath) .. '/' .. filename - end - if io.exists(filename) then - traceln("loading " .. filename) - for line in io.lines(filename) do - if not find(line,"^[%#-]") then - str = gsub(line,"%s*$", '') - rawset(wordlist,str,true) - worddone = worddone + 1 - end - end - else - traceln("unknown file '" .. filename .."'") - end - end - traceln(worddone .. " words loaded") - end - - reset_text() - - if worddone == 0 then - traceln("no (valid) language or wordfile specified") - else - traceln("start checking") - if wordskip ~= '' then - traceln("ignoring " .. wordskip .. "..." .. wordgood) - end - local i, j, lastpos, startpos, endpos, snippet, len, first = 0, 0, -1, 0, 0, '', 0, 0 - local ok, skip, ch = false, false, '' - if skipfirst then first = #firstline end - for k = first, editor.TextLength do - ch = editor:textrange(k,k+1) - if wordgood ~= '' and ch == wordgood then - skip = false - elseif ch == wordskip then - skip = true - end - if find(ch,"%w") and not find(ch,"%d") then - if not skip then - if ok then - endpos = k - else - startpos = k - endpos = k - ok = true - end - end - elseif ok and not skip then - len = endpos - startpos + 1 - if len >= wordsize then - snippet = editor:textrange(startpos,endpos+1) - i = i + 1 - if wordlist[snippet] or wordlist[lower(snippet)] then - j = j + 1 - else - editor:StartStyling(startpos,INDICS_MASK) - editor:SetStyling(len,INDIC2_MASK) -- INDIC0_MASK+2 - end - end - ok = false - elseif wordgood == '' then - skip = (ch == wordskip) - end - end - traceln(i .. " words checked, " .. (i-j) .. " errors") - end - -end - -function reset_text() - editor:StartStyling(0,INDICS_MASK) - editor:SetStyling(editor.TextLength,INDIC_PLAIN) -end function add_text() @@ -732,15 +718,180 @@ function add_text() end +-- test + +local bidi +local cat + +local dirty = { } + +-- if needed we can cache + +local function toutfcode(pos) + local c1 = cat[pos] + if c1 < 0 then + c1 = 256 + c1 + end + if c1 < 128 then + return c1, 1 + end + if c1 < 224 then + local c2 = cat[pos+1] + if c2 < 0 then + c2 = 256 + c2 + end + return c1 * 64 + c2 - 12416, 2 + end + if c1 < 240 then + local c2 = cat[pos+1] + local c3 = cat[pos+2] + if c2 < 0 then + c2 = 256 + c2 + end + if c3 < 0 then + c3 = 256 + c3 + end + return (c1 * 64 + c2) * 64 + c3 - 925824, 3 + end + if c1 < 245 then + local c2 = cat[pos+1] + local c3 = cat[pos+2] + local c4 = cat[pos+3] + if c2 < 0 then + c2 = 256 + c2 + end + if c3 < 0 then + c3 = 256 + c3 + end + if c4 < 0 then + c4 = 256 + c4 + end + return ((c1 * 64 + c2) * 64 + c3) * 64 + c4 - 63447168, 4 + end +end + +local mapping = { + l = 0, -- "Left-to-Right", + lre = 7, -- "Left-to-Right Embedding", + lro = 7, -- "Left-to-Right Override", + r = 2, -- "Right-to-Left", + al = 3, -- "Right-to-Left Arabic", + rle = 7, -- "Right-to-Left Embedding", + rlo = 7, -- "Right-to-Left Override", + pdf = 7, -- "Pop Directional Format", + en = 4, -- "European Number", + es = 4, -- "European Number Separator", + et = 4, -- "European Number Terminator", + an = 5, -- "Arabic Number", + cs = 6, -- "Common Number Separator", + nsm = 6, -- "Non-Spacing Mark", + bn = 7, -- "Boundary Neutral", + b = 0, -- "Paragraph Separator", + s = 7, -- "Segment Separator", + ws = 0, -- "Whitespace", + on = 7, -- "Other Neutrals", +} + +-- todo: take from scite-context-theme.lua + +local colors = { -- b g r + [0] = 0x000000, -- black + [1] = 0x00007F, -- red + [2] = 0x007F00, -- green + [3] = 0x7F0000, -- blue + [4] = 0x7F7F00, -- cyan + [5] = 0x7F007F, -- magenta + [6] = 0x007F7F, -- yellow + [7] = 0x007FB0, -- orange + [8] = 0x4F4F4F, -- dark +} + +-- SendEditor(SCI_COLOURISE, 0, -1) -- forces styling + +function show_bidi() + + cat = editor.CharAt + + editor.CodePage = SC_CP_UTF8 + + editor.Lexer = SCLEX_CONTAINER + + for i=1,#colors do + editor.StyleFore[i] = colors[i] + end + + if not bidi then + bidi = require("context.scite-ctx-bidi") + end + + local len = editor.TextLength + local str = editor:textrange(0,len-1) + + local t = { } + local a = { } + local n = 0 + local i = 0 + + local v + while i < len do + n = n + 1 + v, s = toutfcode(i) + t[n] = v + a[n] = s + i = i + s + end + + local t = bidi.process(t) + + editor:StartStyling(0,31) + + local defaultcolor = mapping.l + local mirrorcolor = 1 + + if false then + for i=1,n do + local direction = t[i].direction + local color = direction and (mapping[direction] or 0) or defaultcolor + editor:SetStyling(a[i],color) + end + else + local lastcolor = -1 + local runlength = 0 + for i=1,n do + local ti = t[i] + local direction = ti.direction + local mirror = t[i].mirror + local color = (mirror and mirrorcolor) or (direction and mapping[direction]) or defaultcolor + if color == lastcolor then + runlength = runlength + a[i] + else + if runlength > 0 then + editor:SetStyling(runlength,lastcolor) + end + lastcolor = color + runlength = a[i] + end + end + if runlength > 0 then + editor:SetStyling(runlength,lastcolor) + end + end + + editor:SetStyling(2,31) + + dirty[props.FileNameExt] = true + +end + -- menu -local menuactions = {} -local menufunctions = {} +local menuactions = { } +local menufunctions = { } function UserListShow(menutrigger, menulist) - local menuentries = {} + local menuentries = { } local list = grab(menulist,"[^%|]+") - menuactions = {} + menuactions = { } for i=1, #list do if list[i] ~= '' then for key, val in gmatch(list[i],"%s*(.+)=(.+)%s*") do @@ -793,9 +944,9 @@ local ctx_template_paths = { "./ctx-templates", "../ctx-templates", "../../ctx-t local ctx_auto_templates = false local ctx_template_list = "" -local ctx_path_list = {} -local ctx_path_done = {} -local ctx_path_name = {} +local ctx_path_list = { } +local ctx_path_done = { } +local ctx_path_name = { } function ctx_list_loaded(path) return ctx_path_list[path] and #ctx_path_list[path] > 0 @@ -861,7 +1012,6 @@ function insert_template(templatelist) end end - -- ctx.template.[whatever].[filetype] -- ctx.template.[whatever].data.[filetype] -- ctx.template.[whatever].file.[filetype] @@ -1450,6 +1600,14 @@ function OnOpen(filename) editor:Colourise(0,editor.TextLength) end + +function OnSwitchFile(filename) + if dirty[props.FileNameExt] then + editor:Colourise(0,editor.TextLength) + dirty[props.FileNameExt] = false + end +end + -- Last time I checked the source the output pane errorlist lexer was still -- hardcoded and could not be turned off ... alas. |