summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/scrn-ref.lua
blob: c1fc94871387a27cd76c5cd1fc1c467dfbdd3763 (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
if not modules then modules = { } end modules ['scrn-ref'] = {
    version   = 1.001,
    comment   = "companion to scrn-int.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

interactions            = interactions or { }
interactions.references = interactions.references or { }
local references        = interactions.references

local codeinjections    = backends.codeinjections

local expandcurrent     = structures.references.expandcurrent
local identify          = structures.references.identify

local implement         = interfaces.implement

local function check(what)
    if what and what ~= "" then
        local set, bug = identify("",what)
        return not bug and #set > 0 and set
    end
end

local function setopendocumentaction(open)
    local opendocument = check(open)
    if opendocument then
        codeinjections.registerdocumentopenaction(opendocument)
        expandcurrent()
    end
end

local function setclosedocumentaction(close)
    local closedocument = check(close)
    if closedocument then
        codeinjections.registerdocumentcloseaction(closedocument)
        expandcurrent()
    end
end

local function setopenpageaction(open)
    local openpage = check(open)
    if openpage then
        codeinjections.registerpageopenaction(openpage)
        expandcurrent()
    end
end

local function setclosepageaction(close)
    local closepage = check(close)
    if closepage then
        codeinjections.registerpagecloseaction(closepage)
        expandcurrent()
    end
end

references.setopendocument  = setopendocumentaction
references.setclosedocument = setclosedocumentaction
references.setopenpage      = setopenpageaction
references.setclosepage     = setclosepageaction

implement { name = "setopendocumentaction",  arguments = "string", actions = setopendocumentaction }
implement { name = "setclosedocumentaction", arguments = "string", actions = setclosedocumentaction }
implement { name = "setopenpageaction",      arguments = "string", actions = setopenpageaction }
implement { name = "setclosepageaction",     arguments = "string", actions = setclosepageaction }