1if not modules then modules = { } end modules ['luatex-gadgets'] = {
2 version = 1.001,
3 comment = "companion to luatex-gadgets.tex",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9if context then return end
10
11
12
13
14
15gadgets = gadgets or { }
16
17
18
19local marking = { }
20gadgets.marking = marking
21
22local marksignal = 5001
23local lastmarked = 0
24local marked = { }
25local local_par_code = 9
26
27function marking.setsignal(n)
28 marksignal = tonumber(n) or marksignal
29end
30
31function marking.mark(str)
32 local currentmarked = marked[str]
33 if not currentmarked then
34 lastmarked = lastmarked + 1
35 currentmarked = lastmarked
36 marked[str] = currentmarked
37 end
38 tex.setattribute(marksignal,currentmarked)
39end
40
41function marking.remove(str)
42 local attr = marked[str]
43 if not attr then
44 return
45 end
46 local list = tex.nest[tex.nest.ptr]
47 if list then
48 local head = list.head
49 local tail = list.tail
50 local last = tail
51 if last[marksignal] == attr then
52 local first = last
53 while true do
54 local prev = first.prev
55 if not prev or prev[marksignal] ~= attr or prev.id == local_par_code then
56 break
57 else
58 first = prev
59 end
60 end
61 if first == head then
62 list.head = nil
63 list.tail = nil
64 else
65 local prev = first.prev
66 list.tail = prev
67 prev.next = nil
68 end
69 node.flush_list(first)
70 end
71 end
72end
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 |