s-present-steps.mkiv /size: 4741 b    last modification: 2021-10-28 13:51
1%D \module
2%D   [      file=s-present-steps,
3%D        version=2018.05.17,
4%D          title=\CONTEXT\ Style File,
5%D       subtitle=Presentation Environment Repeated Steps,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D This a preliminary module, a quick hack and not entirely proper \CONTEXT, but
15%D let's see what more is needed.
16
17\startmodule[present-steps]
18
19\pushoverloadmode
20
21\startluacode
22
23moduledata.steps = moduledata.steps or { }
24
25local steps      = moduledata.steps
26local data       = { }
27local name       = "unknown"
28local set        = 0
29local settings   = nil
30
31function steps.startsteps(buffername)
32    set  = set + 1
33    data = { }
34    name = buffername
35end
36
37function steps.stopsteps()
38    local n = 0
39    for i=1,#data do
40        local state = "once"
41        local done  = 0
42        while true do
43            context.startprocessingsteps()
44            for j=1,i do
45                local step    = data[j]
46                local nested  = step.nested
47                local content = step.content
48                local last    = (i == #data) and (j == i) and 1 or 0
49                local option = step.option
50                local flush  = true
51                if option == interfaces.variables["title"] then
52                    if i > 1 then
53                        flush = false
54                    end
55                elseif option == interfaces.variables["repeat"] then
56                    if i == 1 then
57                        flush = false
58                    end
59                end
60                if flush then
61                    if j < i or nested == 0 then
62                        context(function()
63                            buffers.assign("step",content)
64                            context.processstep("step",i,0,last)
65                         -- context.writestatus("step a",string.formatters["%i %i %i"](i,0,last))
66                        end)
67                        state = "done"
68                    else
69                        done = done + 1
70                        local d = done
71                        context(function()
72                            buffers.assign("step",content)
73                            context.processstep("step",i,d,last)
74                         -- context.writestatus("step b",string.formatters["%i %i %i"](i,d,last))
75                        end)
76                        if done == nested then
77                            state = "done"
78                            n = n + nested
79                        else
80                            state = "busy"
81                        end
82                    end
83                end
84            end
85            context.stopprocessingsteps()
86            if state == "done" then
87                break
88            end
89        end
90    end
91end
92
93function steps.startstep(str)
94    settings = utilities.parsers.settings_to_hash(str)
95end
96
97function steps.stopstep()
98    settings.content = buffers.getcontent(name)
99    settings.nested  = tonumber(settings.n) or 0
100    data[#data+1] = settings
101end
102
103function steps.startsubstep(str)
104    local d = data[#data]
105    d.nested = d.nested + 1
106end
107
108function steps.stopsubstep()
109end
110
111\stopluacode
112
113\definebuffer
114  [step]
115
116\def\currentstep   {0}
117\def\currentsubstep{0}
118
119\unexpanded\def\startprocessingsteps
120  {\global\wantedsubstep\zerocount}
121
122\unexpanded\def\stopprocessingsteps
123  {}
124
125\unexpanded\def\processstep#1#2#3#4%
126  {\par
127   \edef\currentstep   {#2}%
128   \edef\currentsubstep{#3}%
129   \ifcase#4\relax
130      \setupreferencing[prefix=#2:#3]
131      \getbuffer[#1]%
132      \par
133   \else
134      \setupreferencing[prefix=]
135      \getbuffer[#1]%
136      \page
137   \fi}
138
139\let\normalstartstep\startstep
140
141\newcount\wantedsubstep
142
143\unexpanded\def\startsteps
144  {\ctxlua{moduledata.steps.startsteps("\thedefinedbuffer{step}")}}
145
146\unexpanded\def\stopsteps
147  {\ctxlua{moduledata.steps.stopsteps()}}
148
149\unexpanded\def\startstep
150  {\dosingleempty\startstepindeed}
151
152\def\startstepindeed[#1]%
153  {\ctxlua{moduledata.steps.startstep("#1")}%
154   \normalstartstep}
155
156\unexpanded\def\stopstep
157  {\ctxlua{moduledata.steps.stopstep()}}
158
159\let\stopsubstep\relax
160
161\unexpanded\def\startsubstep#1\stopsubstep
162  {\ctxlua{moduledata.steps.startsubstep()}%
163   \ifcase\currentsubstep\relax
164     #1%
165   \else
166     \global\advance\wantedsubstep\plusone
167     \ifnum\currentsubstep>\wantedsubstep\else
168       #1%
169     \fi
170   \fi
171   \ctxlua{moduledata.steps.stopsubstep()}}
172
173\popoverloadmode
174
175\stopmodule
176
177\continueifinputfile{s-present-steps.mkiv}
178
179\usemodule[present-common]
180
181\inputpresentationfile{examples/present-steps-001.tex}
182