summaryrefslogtreecommitdiff
path: root/tex/context/base/buff-par.mkvi
blob: 5efff51259dd630fe1c6256c89613ec621a46b81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
%D \module
%D   [       file=buff-par,
%D        version=2010.12.05,
%D          title=\CONTEXT\ Buffer Macros,
%D       subtitle=Parallel,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Buffer Macros / Parallel}

\registerctxluafile{buff-par}{1.001}

%D This module is developped for Thomas Schmitz as part of a project. There is
%D no documentation yet.
%D
%D \starttyping
%D \defineparallel[main][one,two]
%D
%D \startmain
%D \startone
%D     first 1
%D     [reference] first 2
%D     first 3
%D \stopone
%D \starttwo
%D     second 1
%D \stoptwo
%D \stopmain
%D
%D \placeparallel[main][one,two][criterium=all]

%D criterium=all start=<number> n=<number>

\unprotect

\installcorenamespace{parallel}
\installcorenamespace{parallelhandler}

\installcommandhandler \??parallel {parallel} \??parallel

\setupparallel
  [\c!setups=parallel:place:default]

\let\buff_parallel_define_saved\defineparallel
\let\buff_parallel_setup_saved \setupparallel

\unexpanded\def\defineparallel{\dodoubleargument\buff_parallel_define}
\unexpanded\def\setupparallel {\dotripleargument\buff_parallel_setup}

\def\buff_parallel_define[#name][#instances]%
  {\buff_parallel_define_saved[#name][\c!list={#instances}]% list is internal
   \ctxcommand{defineparallel("#name","#instances")}%
   \expandafter\newtoks\csname\??parallelhandler#name\endcsname
   \processcommacommand[#instances]{\buff_parallel_define_instance{#name}}%
   \setuevalue{\e!start#name}{\buff_parallel_start{#name}}%
   \setuevalue{\e!stop #name}{\buff_parallel_stop}}

\let\buff_process_parallel_instance\relax

\def\buff_process_parallel_instances
  {\the\csname\??parallelhandler\currentparallel\endcsname}

\def\buff_parallel_define_instance#name#instance%
  {\normalexpanded{\buff_parallel_define_saved[#instance][#name]}%
   \definebuffer[#instance]%
  %\edef\t_buff_parallel{\csname\??parallelhandler#name\endcsname}%
   \expandafter\let\expandafter\t_buff_parallel\csname\??parallelhandler#name\endcsname
   \appendtoks
      \edef\currentparallelinstance{#instance}%
      \buff_process_parallel_instance\relax
   \to \t_buff_parallel
   \setuevalue{\e!stop#instance}{\buff_parallel_save{#instance}}}

\def\buff_parallel_setup[#name][#instances][#setups]%
  {\processcommalist[#instances]{\buff_parallel_setup_instance{#name}{#setups}}}

\def\buff_parallel_setup_instance#name#setups#instance%
  {\buff_parallel_setup_saved[#name:#instance][#setups]}

\unexpanded\def\buff_parallel_start#name%
  {\pushmacro\currentparallel
   \edef\currentparallel{#name}%
   \ctxcommand{nextparallel("\currentparallel")}}

\unexpanded\def\buff_parallel_stop
  {\popmacro\currentparallel}

\unexpanded\def\buff_parallel_save#instance% defined moet ook aan de lua kant kunnen
  {\ctxcommand{saveparallel("\currentparallel","#instance",buffers.raw("\thedefinedbuffer{#instance}"))}}

\unexpanded\def\placeparallel
  {\dotripleempty\buff_parallel_place}

\def\buff_parallel_place[#name][#instance][#settings]%
  {\begingroup
   \edef\currentparallel{#name}%
   \setupcurrentparallel[#settings]%
   \ctxcommand{placeparallel("\currentparallel","#instance",{
    % setups    = "\parallelparameter\c!setups",
      start     = "\parallelparameter\c!start",
      n         = "\parallelparameter\c!n",
      criterium = "\parallelparameter\c!criterium",
   })}%
   \endgroup}

\def\doflushparallel#instance#status#line#label#content% called at lua end
  {\begingroup
   \def\currentparallelinstance{#instance}%
   \def\currentparallelnumber  {#status}%
   \def\currentparallelline    {#line}%
   \def\currentparallellabel   {#label}%
   \def\currentparallelcontent {#content}% can be kep at the lua end .. no need to use a virtual file
   \ifcase#status\relax
     \expandafter\buff_parallel_flush_nop
   \or
     \expandafter\buff_parallel_flush_yes
   \fi
   \endgroup}

\def\buff_parallel_flush_nop
  {}

\def\buff_parallel_flush_yes
  {\directsetup{\namedparallelparameter{\currentparallel:\currentparallelinstance}\c!setups}}

\unexpanded\def\doifelseparallel#name#instance%
  {\ctxcommand{doifelseparallel("#name","#instance")}}

\unexpanded\def\resetparallel
  {\dodoubleempty\buff_parallel_reset}

\def\buff_parallel_reset[#name][#instance]%
  {\ctxcommand{resetparallel("#name","#instance"))}}

\startsetups parallel:place:default
    \hangafter\plusone
    \hangindent4\emwidth
    \dontleavehmode
    \hbox to 3\emwidth \bgroup
        \hss
        \bf
        \doifsomething \currentparallellabel {
            \textreference[\currentparallellabel]{\currentparallelline}
        }
    \currentparallelline
    \quad
    \egroup
    \currentparallelcontent
    \par
\stopsetups

\protect \endinput