typo-inj.lua /size: 3634 b    last modification: 2021-10-28 13:50
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
typo-inj
'
]
=
{
-- was node-par
2
version
=
1
.
001
,
3
comment
=
"
companion to typo-inj.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
tonumber
=
tonumber
10 11
local
context
=
context
12
local
implement
=
interfaces
.
implement
13 14
local
injectors
=
{
}
15
typesetters
.
injectors
=
injectors
16
local
list
=
{
}
17
injectors
.
list
=
list
18
local
showall
=
false
19 20
local
settings_to_array
=
utilities
.
parsers
.
settings_to_array
21 22
local
variables
=
interfaces
.
variables
23
local
v_next
=
variables
.
next
24
local
v_previous
=
variables
.
previous
25 26
local
ctx_domarkinjector
=
context
.
domarkinjector
27
local
ctx_doactivateinjector
=
context
.
doactivateinjector
28 29
table
.
setmetatableindex
(
list
,
function
(
t
,
k
)
30
local
v
=
{
31
counter
=
0
,
32
actions
=
{
}
,
33
show
=
false
,
34
active
=
false
,
35
}
36
t
[
k
]
=
v
37
return
v
38
end
)
39 40
function
injectors
.
reset
(
name
)
41
list
[
name
]
=
nil
42
end
43 44
local
function
activate
(
injector
,
name
)
45
if
not
injector
.
active
then
46
ctx_doactivateinjector
(
name
)
47
injector
.
active
=
true
48
if
showall
then
49
-- in case we already enabled tracing
50
injector
.
show
=
true
51
end
52
end
53
end
54 55
function
injectors
.
set
(
name
,
numbers
,
command
)
56
local
injector
=
list
[
name
]
57
local
actions
=
injector
.
actions
58
local
places
=
settings_to_array
(
numbers
)
59
for
i
=
1
,
#
places
do
60
actions
[
tonumber
(
places
[
i
]
)
]
=
command
61
end
62
-- not: injector.show = true
63
activate
(
injector
,
name
)
64
end
65 66
function
injectors
.
show
(
name
)
67
if
not
name
or
name
=
=
"
"
then
68
showall
=
true
69
local
names
=
settings_to_array
(
name
)
70
for
name
,
injector
in
next
,
list
do
71
injector
.
show
=
true
72
activate
(
injector
,
name
)
73
end
74
else
75
local
names
=
settings_to_array
(
name
)
76
for
i
=
1
,
#
names
do
77
local
name
=
names
[
i
]
78
local
injector
=
list
[
name
]
79
if
injector
then
80
injector
.
show
=
true
81
activate
(
injector
,
name
)
82
end
83
end
84
end
85
end
86 87
function
injectors
.
mark
(
name
,
show
)
88
local
injector
=
list
[
name
]
89
local
n
=
injector
.
counter
+
1
90
injector
.
counter
=
n
91
if
showall
or
injector
.
show
then
92
ctx_domarkinjector
(
injector
.
actions
[
n
]
and
1
or
0
,
n
)
93
end
94
end
95 96
function
injectors
.
check
(
name
,
n
)
-- we could also accent n = number : +/- 2
97
local
injector
=
list
[
name
]
98
if
not
n
or
n
=
=
"
"
or
n
=
=
v_next
then
99
n
=
injector
.
counter
+
1
100
elseif
n
=
=
v_previous
then
101
n
=
injector
.
counter
102
else
103
n
=
tonumber
(
n
)
or
0
104
end
105
local
action
=
injector
.
actions
[
n
]
106
if
action
then
107
context
(
action
)
108
end
109
end
110 111
implement
{
name
=
"
resetinjector
"
,
actions
=
injectors
.
reset
,
arguments
=
"
string
"
}
112
implement
{
name
=
"
showinjector
"
,
actions
=
injectors
.
show
,
arguments
=
"
string
"
}
113
implement
{
name
=
"
setinjector
"
,
actions
=
injectors
.
set
,
arguments
=
"
3 strings
"
}
114
implement
{
name
=
"
markinjector
"
,
actions
=
injectors
.
mark
,
arguments
=
"
string
"
}
115
implement
{
name
=
"
checkinjector
"
,
actions
=
injectors
.
check
,
arguments
=
"
2 strings
"
}
116
--------- { name = "checkpreviousinjector", actions = injectors.check, arguments = { "string", tokens.constant(v_previous) } }
117
--------- { name = "checknextinjector", actions = injectors.check, arguments = { "string", tokens.constant(v_next) } }
118