summaryrefslogtreecommitdiff
path: root/tex/context/base/trac-ctx.lua
blob: 8134438166118bc2b41ed6c3632ea270d414be92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
if not modules then modules = { } end modules ['trac-ctx'] = {
    version   = 1.001,
    comment   = "companion to trac-ctx.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local commands, context = commands, context

tex.trackers = tex.trackers or { }

local textrackers = tex.trackers
local register    = trackers.register

storage.register("tex/trackers",textrackers,"tex.trackers")

local function doit(tag,v)
    local tt = textrackers[tag]
    if tt then
        context.unprotect()
        context(v and tt[1] or tt[2])
        context.protect()
    end
end

function commands.initializetextrackers()
    for tag, commands in next, textrackers do
        register(tag, function(v) doit(tag,v) end) -- todo: v,tag in caller
    end
end

function commands.installtextracker(tag,enable,disable)
    textrackers[tag] = { enable, disable }
    register(tag, function(v) doit(tag,v) end) -- todo: v,tag in caller
end