summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/spac-par.lmt
blob: 595eabe62192da0b972a101b93b37493677cc546 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
if not modules then modules = { } end modules ['spac-par'] = {
    version   = 1.001,
    comment   = "companion to spac-par.mkxl",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local context = context
local implement = interfaces.implement

local collected = utilities.storage.allocate()
local tobesaved = utilities.storage.allocate()
local wrappers  = { }

local jobparwrappers = {
    collected = collected,
    tobesaved = tobesaved,
}

job.parwrappers = jobparwrappers

local function initializer()
    tobesaved = jobparwrappers.tobesaved
    collected = jobparwrappers.collected
end

local function finalizer()
    -- nothing yet
end

job.register('job.parwrappers.collected', tobesaved, initializer, finalizer)

implement {
    name      = "newparwrapper",
    arguments = "string",
    actions   = function(id)
        local t = tobesaved[id]
        local n
        if t then
            n = #t + 1
            t[n] = 0
        else
            n = 1
            tobesaved[id] = { 0 }
        end
        wrappers[id] = n
    end
}

implement {
    name      = "setparwrapper",
    arguments = "string",
    actions   = function(id)
        local t = tobesaved[id]
        local n = #t
        t[n] = t[n] + 1
    end
}

implement {
    name      = "getparwrapper",
    arguments = "string",
    public    = true,
    actions   = function(id)
        local t = tobesaved[id]
        context(t and t[#t] or 0)
    end
}

implement {
    name      = "lastparwrapper",
    arguments = "string",
    public    = true,
    actions   = function(id)
        local t = collected and collected[id]
        context(t and t[wrappers[id]] or 0)
    end
}