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
111
112
113
114
115
116
117
118
|
if not modules then modules = { } end modules ['node-par'] = {
version = 1.001,
comment = "companion to node-ini.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local starttiming = statistics.starttiming
local stoptiming = statistics.stoptiming
local sequencers = utilities.sequencers
-- This is called a lot! I'm a bit reluctant with this one because it is sensitive
-- for order. In many other callbacks there is no action at the tex end but here ...
-- Anyway, it has been around for a while now (2019) and so far I had no need for
-- extensive usage so we're okay.
do
local actions = nodes.tasks.actions("everypar")
local function everypar(head)
starttiming(builders)
head = actions(head)
stoptiming(builders)
return head
end
callbacks.register("insert_par",everypar,"after paragraph start")
end
-- Originally this one was meant to deal with the indentation (like turn a box into
-- a skip or prevent it) but that never really was used. The return value still
-- determines if an indentation box or skip is injected. Will I change that?
do
local actions = sequencers.new {
name = "paragraph",
arguments = "mode,indented,context",
returnvalues = "indented",
results = "indented",
}
sequencers.appendgroup(actions,"before") -- user
sequencers.appendgroup(actions,"system") -- private
sequencers.appendgroup(actions,"after" ) -- user
local function paragraph(mode,indented,context) -- context used to be the cmd code
local runner = actions.runner
if runner then
starttiming(builders)
indented = runner(mode,indented,context)
stoptiming(builders)
end
return indented
end
callbacks.register("begin_paragraph",paragraph,"before paragraph start")
end
-- This one is a playground for some old metafun gimmicks that I want to improve
-- while I'm updating the manual to lmtx. but it might also be useful for other
-- purposes. It fits in the category obscure and probably takes while to stabelize
-- (if it stays at all). Again, this is one that has the danger of interference,
-- so when it finally got an action handler it only got a system one.
do
local actions = sequencers.new {
name = "paragraphcontext",
arguments = "context",
returnvalues = "ignore",
results = "ignore",
}
----------.appendgroup(actions,"before") -- user
sequencers.appendgroup(actions,"system") -- private
----------.appendgroup(actions,"after" ) -- user
local function parcontext(parcontext)
local runner = actions.runner
if runner then
starttiming(builders)
local ignore = runner(parcontext)
stoptiming(builders)
return ignore
end
end
callbacks.register("paragraph_context",parcontext,"when the context is dealt with")
end
-- These are node handlers but fit it the overall paragraph handling so we
-- hook it into the callback here.
-- do
-- local localboxactions = nodes.tasks.actions("localboxes")
-- function localboxfilter(...)
-- starttiming(builders)
-- localboxactions(...)
-- stoptiming(builders)
-- end
-- callbacks.register("local_box_filter",localboxfilter,"process local boxes")
-- end
-- This means that we now have most callbacks in use, even the ones that I'm not sure
-- about. It also means that with the above enabled we might have performance now at
-- its worst. I can optimize this a little but it's not worth the effort (and added
-- complication).
|