diff options
Diffstat (limited to 'tex/context/base/lang-wrd.lua')
-rw-r--r-- | tex/context/base/lang-wrd.lua | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/tex/context/base/lang-wrd.lua b/tex/context/base/lang-wrd.lua index bf066fc09..b564a02ae 100644 --- a/tex/context/base/lang-wrd.lua +++ b/tex/context/base/lang-wrd.lua @@ -14,7 +14,10 @@ local P, S, Cs = lpeg.P, lpeg.S, lpeg.Cs local report_words = logs.reporter("languages","words") -local nodes, node, languages = nodes, node, languages +local nodes = nodes +local languages = languages + +local implement = interfaces.implement languages.words = languages.words or { } local words = languages.words @@ -26,7 +29,18 @@ words.threshold = 4 local numbers = languages.numbers local registered = languages.registered -local traverse_nodes = node.traverse +local nuts = nodes.nuts +local tonut = nuts.tonut + +local getfield = nuts.getfield +local getnext = nuts.getnext +local getid = nuts.getid +local getsubtype = nuts.getsubtype +local getchar = nuts.getchar +local setattr = nuts.setattr + +local traverse_nodes = nuts.traverse + local wordsdata = words.data local chardata = characters.data local tasks = nodes.tasks @@ -96,7 +110,7 @@ end -- there is an n=1 problem somewhere in nested boxes local function mark_words(head,whenfound) -- can be optimized and shared - local current, language, done = head, nil, nil, 0, false + local current, language, done = tonut(head), nil, nil, 0, false local str, s, nds, n = { }, 0, { }, 0 -- n could also be a table, saves calls local function action() if s > 0 then @@ -112,9 +126,9 @@ local function mark_words(head,whenfound) -- can be optimized and shared n, s = 0, 0 end while current do - local id = current.id + local id = getid(current) if id == glyph_code then - local a = current.lang + local a = getfield(current,"lang") if a then if a ~= language then if s > 0 then @@ -126,16 +140,16 @@ local function mark_words(head,whenfound) -- can be optimized and shared action() language = a end - local components = current.components + local components = getfield(current,"components") if components then n = n + 1 nds[n] = current for g in traverse_nodes(components) do s = s + 1 - str[s] = utfchar(g.char) + str[s] = utfchar(getchar(g)) end else - local code = current.char + local code = getchar(current) local data = chardata[code] if is_letter[data.category] then n = n + 1 @@ -151,12 +165,12 @@ local function mark_words(head,whenfound) -- can be optimized and shared n = n + 1 nds[n] = current end - elseif id == kern_code and current.subtype == kerning_code and s > 0 then + elseif id == kern_code and getsubtype(current) == kerning_code and s > 0 then -- ok elseif s > 0 then action() end - current = current.next + current = getnext(current) end if s > 0 then action() @@ -176,6 +190,8 @@ local enabled = false function words.check(head) if enabled then return methods[wordmethod](head) + elseif not head then + return head, false else return head, false end @@ -207,7 +223,7 @@ table.setmetatableindex(cache, function(t,k) -- k == language, numbers[k] == tag else c = colist["word:" .. (numbers[k] or "unset")] or colist["word:unknown"] end - local v = c and function(n) n[a_color] = c end or false + local v = c and function(n) setattr(n,a_color,c) end or false t[k] = v return v end) @@ -226,7 +242,7 @@ end methods[1] = function(head) for n in traverse_nodes(head) do - n[a_color] = unsetvalue -- hm, not that selective (reset color) + setattr(n,a_color,unsetvalue) -- hm, not that selective (reset color) end return mark_words(head,sweep) end @@ -327,7 +343,7 @@ end methods[3] = function(head) for n in traverse_nodes(head) do - n[a_color] = unsetvalue + setattr(n,a_color,unsetvalue) end return mark_words(head,sweep) end @@ -348,6 +364,24 @@ end -- interface -commands.enablespellchecking = words.enable -commands.disablespellchecking = words.disable -commands.loadspellchecklist = words.load +implement { + name = "enablespellchecking", + actions = words.enable, + arguments = { + { + { "method" }, + { "list" } + } + } +} + +implement { + name = "disablespellchecking", + actions = words.disable +} + +implement { + name = "loadspellchecklist", + arguments = { "string", "string" }, + actions = words.load +} |