buff-par.mkvi /size: 5259 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=buff-par,
3
%D version=2010.12.05,
4
%D title=\CONTEXT\ Buffer Macros,
5
%D subtitle=Parallel,
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
\writestatus
{
loading
}{
ConTeXt
Buffer
Macros
/
Parallel
}
15 16
\registerctxluafile
{
buff
-
par
}{}
17 18
%D This module is made for Thomas Schmitz as part of a project. There is
19
%D no documentation yet. Also, this code is unfinished and not tested well.
20
%D
21
%D \starttyping
22
%D \defineparallel[main][one,two]
23
%D
24
%D \startmain
25
%D \startone
26
%D first 0
27
%D [reference] first 1
28
%D first 2
29
%D first 3
30
%D \stopone
31
%D \starttwo
32
%D second 1
33
%D second 2
34
%D \stoptwo
35
%D \stopmain
36
%D
37
%D \startmain
38
%D \startone
39
%D first 4
40
%D first 4
41
%D \stopone
42
%D \starttwo
43
%D second 3
44
%D second 4
45
%D \stoptwo
46
%D \stopmain
47
%D
48
%D \placeparallel[main][one][criterium=all]
49
%D
50
%D \placeparallel[main][two][criterium=all]
51
%D \stoptyping
52 53
%D criterium=all start=<number> n=<number>
54 55
\unprotect
56 57
\installcorenamespace
{
parallel
}
58
\installcorenamespace
{
parallelhandler
}
59 60
\installcommandhandler
\??parallel
{
parallel
}
\??parallel
61 62
\setupparallel
63
[
\c!setups
=
parallel
:
place
:
default
]
64 65
\let
\buff_parallel_define_saved
\defineparallel
66
\let
\buff_parallel_setup_saved
\setupparallel
67 68
\unexpanded
\def
\defineparallel
{
\dodoubleargument
\buff_parallel_define
}
69
\unexpanded
\def
\setupparallel
{
\dotripleargument
\buff_parallel_setup
}
70 71
\def
\buff_parallel_define
[#
name
][#
instances
]
%
72
{
\buff_parallel_define_saved
[#
name
][
\c!list
=
{
#
instances
}
]
% list is internal
73
\clf_defineparallel
{
#
name
}{
#
instances
}
%
74
\expandafter
\newtoks
\csname
\??parallelhandler
#
name
\endcsname
75
\processcommacommand
[#
instances
]
{
\buff_parallel_define_instance
{
#
name
}}
%
76
\setuevalue
{
\e!start
#
name
}{
\buff_parallel_start
{
#
name
}}
%
77
\setuevalue
{
\e!stop
#
name
}{
\buff_parallel_stop
}}
78 79
\let
\buff_process_parallel_instance
\relax
80 81
\def
\buff_process_parallel_instances
82
{
\the\csname
\??parallelhandler
\currentparallel
\endcsname
}
83 84
\def
\buff_parallel_define_instance
#
name
#
instance
%
85
{
\normalexpanded
{
\buff_parallel_define_saved
[#
instance
][#
name
]
}
%
86
\definebuffer
[#
instance
]
%
87
%\edef\t_buff_parallel{\csname\??parallelhandler#name\endcsname}%
88
\expandafter\let\expandafter
\t_buff_parallel
\csname
\??parallelhandler
#
name
\endcsname
89
\appendtoks
90
\edef
\currentparallelinstance
{
#
instance
}
%
91
\buff_process_parallel_instance
\relax
92
\to
\t_buff_parallel
93
\setuevalue
{
\e!stop
#
instance
}{
\buff_parallel_save
{
#
instance
}}}
94 95
\def
\buff_parallel_setup
[#
name
][#
instances
][#
setups
]
%
96
{
\processcommalist
[#
instances
]
{
\buff_parallel_setup_instance
{
#
name
}{
#
setups
}}}
97 98
\def
\buff_parallel_setup_instance
#
name
#
setups
#
instance
%
99
{
\buff_parallel_setup_saved
[#
name
:
#
instance
][#
setups
]
}
100 101
\unexpanded
\def
\buff_parallel_start
#
name
%
102
{
\pushmacro
\currentparallel
103
\edef
\currentparallel
{
#
name
}
%
104
\clf_nextparallel
{
\currentparallel
}}
105 106
\unexpanded
\def
\buff_parallel_stop
107
{
\popmacro
\currentparallel
}
108 109
\unexpanded
\def
\buff_parallel_save
#
instance
% defined moet ook aan de lua kant kunnen
110
{
\clf_saveparallel
111
{
\currentparallel
}
%
112
{
#
instance
}
%
113
{
\thedefinedbuffer
{
#
instance
}}
%
114
\relax
}
115 116
\unexpanded
\def
\placeparallel
117
{
\dotripleempty
\buff_parallel_place
}
118 119
\def
\buff_parallel_place
[#
name
][#
instance
][#
settings
]
%
120
{
\begingroup
121
\edef
\currentparallel
{
#
name
}
%
122
\setupcurrentparallel
[#
settings
]
%
123
\clf_placeparallel
124
{
\currentparallel
}
%
125
{
#
instance
}
%
126
{
%
127
% setups {\parallelparameter\c!setups}%
128
start
{
\parallelparameter
\c!start
}
%
129
n
{
\parallelparameter
\c!n
}
%
130
criterium
{
\parallelparameter
\c!criterium
}
%
131
}
%
132
\relax
133
\endgroup
}
134 135
\def
\doflushparallel
#
instance
#
status
#
line
#
label
#
content
% called at lua end
136
{
\begingroup
137
\def
\currentparallelinstance
{
#
instance
}
%
138
\def
\currentparallelnumber
{
#
status
}
%
139
\def
\currentparallelline
{
#
line
}
%
140
\def
\currentparallellabel
{
#
label
}
%
141
\def
\currentparallelcontent
{
#
content
}
% can be kep at the lua end .. no need to use a virtual file
142
\ifcase
#
status
\relax
143
\expandafter
\buff_parallel_flush_nop
144
\or
145
\expandafter
\buff_parallel_flush_yes
146
\fi
147
\endgroup
}
148 149
\def
\buff_parallel_flush_nop
150
{}
151 152
\def
\buff_parallel_flush_yes
153
%{\directsetup{\namedparallelparameter{\currentparallel:\currentparallelinstance}\c!setups}}
154
{
\directsetup
{
\namedparallelparameter
{
\currentparallelinstance
}
\c!setups
}}
155 156
\unexpanded
\def
\doifelseparallel
#
name
#
instance
%
157
{
\clf_doifelseparallel
{
#
name
}{
#
instance
}}
158 159
\let
\doifparallelelse\doifelseparallel
160 161
\unexpanded
\def
\resetparallel
162
{
\dodoubleempty
\buff_parallel_reset
}
163 164
\def
\buff_parallel_reset
[#
name
][#
instance
]
%
165
{
\clf_resetparallel
{
#
name
}{
#
instance
}}
166 167
\startsetups
parallel
:
place
:
default
168
\hangafter
\plusone
169
\hangindent
4
\emwidth
170
\dontleavehmode
171
\hbox
to
3
\emwidth
\bgroup
172
\hss
173
\bf
174
\doifsomething
\currentparallellabel
{
175
\textreference
[
\currentparallellabel
]
{
\currentparallelline
}
176
}
177
\currentparallelline
178
\quad
179
\egroup
180
\currentparallelcontent
181
\par
182
\stopsetups
183 184
\protect
\endinput
185