typo-par.lmt /size: 2776 b    last modification: 2023-12-21 09:44
1if not modules then modules = { } end modules ['typo-par'] = {
2    version   = 1.001,
3    comment   = "companion to node-ini.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-- Just some experimental stuff .. trying to improve some ancient metafun manual
10-- hackery that has been on the angenda for too long already. Names might names
11-- anyway.
12
13local insert, remove = table.insert, table.remove
14
15local texget        = tex.get
16local texset        = tex.set
17local shiftparshape = tex.shiftparshape
18
19local sequencers    = utilities.sequencers
20local appendaction  = sequencers.appendaction
21local enableaction  = sequencers.enableaction
22local disableaction = sequencers.disableaction
23
24local implement     = interfaces.implement
25
26local stack   = { }
27local top     = nil
28local enabled = false
29
30local trace   = false  trackers.register("paragraphs.tweaks",function(v) trace = v end)
31
32local report  = logs.reporter("paragraphs","tweaks")
33
34implement {
35    name      = "pushparagraphtweak",
36    public    = true,
37    protected = true,
38    arguments = "string",
39    actions   = function(t)
40        insert(stack,top)
41        if not enabled then
42            if trace then
43                report("enabling")
44            end
45            enableaction("paragraphcontext","builders.checkparcontext")
46            enabled = true
47        end
48        top = t
49    end
50}
51
52implement {
53    name      = "popparagraphtweak",
54    public    = true,
55    protected = true,
56    actions   = function()
57        top = remove(stack)
58        if enabled and not top then
59            if trace then
60                report("disabling")
61            end
62            disableaction("paragraphcontext","builders.checkparcontext")
63            enabled = false
64        end
65    end
66}
67
68function builders.checkparcontext(where)
69    if top and (where == "normal" or where == "vmode") then -- vmode added, needs checking
70        if top == "cycle" then
71            local s = texget("parshape",true)
72            if s then
73                local p = texget("prevgraf")
74                while p > s do
75                    p = p - s
76                end
77                if trace then
78                    report("cycling %i",s)
79                end
80                shiftparshape(p,true)
81                return true
82            end
83        elseif top == "shift" then
84            local s = texget("parshape",true)
85            if s then
86                if trace then
87                    report("shifting %i", s)
88                end
89                shiftparshape(texget("prevgraf"))
90                return true
91            end
92        end
93    end
94end
95
96appendaction("paragraphcontext","system","builders.checkparcontext")
97