spac-brk.lmt /size: 1494 b    last modification: 2025-02-21 11:03
1if not modules then modules = { } end modules ['spac-brk'] = {
2    version   = 1.001,
3    comment   = "companion to spac-brk.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-- This one is an outlier because the callback has several different calls all over
10-- the line break routine. It started out as a tracing feature but can also be used
11-- for adding functionality. For performance reasons we assume single usage but that
12-- might change. The steps kept the identifiers from tracing: initialize, start,
13-- list, stop, collect, line, delete, report, wrapup. The checks parameter is the
14-- value of the 'checklinebreaks' integer variable.
15--
16-- In addition to the overload and tracers usage we now also handle twins with this
17-- mechanism but that might change (for instance we could move that to the engine
18-- but keep a traced version here.
19
20local checklist                = { }
21nodes.handlers.linebreakchecks = checklist
22
23local report      = logs.reporter("linebreaks")
24local breakcodes  = tex.breakcodes
25
26checklist[-1] = function(what)
27    report("callback %i : %s",what,breakcodes[what])
28end
29
30local function check(what,checks,...)
31    local check = checklist[checks]
32    if check then
33        return check(what,checks,...)
34    else
35        -- invalid one, waste of overhead
36    end
37end
38
39callback.register("line_break",check)
40callback.register("balance",   check)
41