summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/x-set-11.tex
blob: 920fd7426d0eed89085e17cf100eded190ae174a (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
%D \module
%D   [       file=x-set-11,
%D        version=2004.10.31,
%D         remark=setupx.tex: 1998.07.20 and later,
%D          title=\CONTEXT\ Setup Definitions,
%D       subtitle=Macro Definitions,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\loadmarkfile{x-set-11}

\endinput

% Old code, a mixture of loading in mkiv and processing in mkii.

\startluacode
    do
        document = document or { }

        document.setups = {
            loaded = { },
            root   = nil,
            used   = { },
        }

        function document.setups.load(filename)
            filename = resolvers.find_file(filename) or ""
            if filename ~= "" and not document.setups.loaded[filename] then
                local loaded = xml.load(filename)
                if loaded then
                    if document.setups.root then
                        xml.inject(document.setups.root,"/",loaded)
                    else
                        document.setups.root = loaded
                    end
                    document.setups.loaded[filename] = true
                end
            end
        end
        function document.setups.name(ek)
            local at = ek.at
            local name = at.name
            if at.type == 'environment' then
                name = "start" .. name
            end
            if at.variant then
                name = name .. ":" .. at.variant
            end
            if at.generated == "yes" then
                name = name .. "*"
            end
            return name:lower()
        end
        function document.setups.show(name)
            if document.setups.root then
                local name = name:gsub("[<>]","")
                local setup = xml.first(document.setups.root,"cd:command[@name='" .. name .. "']")
                document.setups.used[#document.setups.used+1] = setup
                xml.sprint(setup)
            end
        end
        function document.setups.showused()
            if document.setups.root and next(document.setups.used) then
                for k,v in ipairs(table.sortedkeys(document.setups.used)) do
                    xml.sprint(document.setups.used[v])
                end
            end
        end
        function document.setups.showall()
            if document.setups.root then
                local list = { }
                xml.each_element(document.setups.root,"cd:command", function(r,d,t)
                    local ek = d[t]
                    list[document.setups.name(ek)] = ek
                end )
                for k,v in ipairs(table.sortedkeys(list)) do
                    xml.sprint(list[v])
                end
            end
        end
        function document.setups.resolve(name)
            if document.setups.root then
                local e = xml.filter(document.setups.root,string.format("cd:define[@name='%s']/text()",name))
                if e then
                    xml.sprint(e)
                end
            end
        end
    end
\stopluacode

\def\mkloadsetups    #1{\ctxlua{document.setups.load("#1")}}
\def\mkshowsetup     #1{\ctxlua{document.setups.show("#1")}}
\def\mkshowusedsetups  {\bgroup\enableXML\ctxlua{document.setups.showused()}\egroup}
\def\mkshowallsetups   {\bgroup\enableXML\ctxlua{document.setups.showall ()}\egroup}

\def\mkshowsetup     #1{\bgroup\enableXML\ctxlua{document.setups.show("#1")}\egroup}

\defineXMLenvironmentsave [cd:define] [name=]
  {}

\defineXMLsingular [cd:resolve] [name=]
  {\enableXML\ignorespaces\ctxlua{document.setups.resolve("\XMLop{name}")}}

\endinput