strc-blk.mkiv /size: 5277 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=strc-blk,
3
%D version=2008.10.20,
4
%D title=\CONTEXT\ Structure Macros,
5
%D subtitle=Blockmoves,
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
Structure
Macros
/
Blockmoves
}
15 16
\registerctxluafile
{
strc
-
blk
}{}
17 18
\unprotect
19 20
% we run on top of buffers and sections
21
%
22
% todo: prefix numbers (needs further integration elsewhere)
23
% check functionality
24
% alternative files (needs further integration elsewhere)
25
%
26
% order matters: \c!before (think of: \c!before=\startitemize)
27
%
28
% no \endgroups
29 30
\installcorenamespace
{
block
}
31
\installcorenamespace
{
blocktemp
}
32 33
\installcommandhandler
\??block
{
block
}
\??block
34 35
\appendtoks
36
\clf_definestructureblock
{
\currentblock
}
%
37
\setuevalue
{
\e!begin
\currentblock
}{
\strc_blocks_begin
{
\currentblock
}}
%
38
\letvalue
{
\e!end
\currentblock
}
\donothing
39
\to
\everydefineblock
40 41
% The naive way:
42
%
43
% \unexpanded\def\strc_blocks_begin#1%
44
% {\dotripleempty\strc_blocks_begin_indeed[#1]}
45
%
46
% \unexpanded\def\strc_blocks_begin_indeed[#1][#2][#3]%
47
% {\normalexpanded{\buff_pickup{\??block}{\e!begin#1}{\e!end#1}}
48
% {}%
49
% {\clf_savestructureblock{#1}{#2}{#3}{\??block}}%
50
% \plusone}%
51
%
52
% We need to prevent too much lookahead which will gobble newlines
53
% that are needed for buffers. See blocks-002.tex as example.
54 55
% maybe: systemmode "block:<name>"
56 57
\let
\m_block
\empty
58
\let
\m_subblock
\empty
59 60
\unexpanded
\def
\strc_blocks_begin
#
1
%
61
{
\edef
\m_block
{
#
1
}
%
62
\let
\m_subblock
\empty
63
\doifelsenextoptionalcs
\strc_blocks_begin_yes
\strc_blocks_begin_nop
}
64 65
\unexpanded
\def
\strc_blocks_begin_yes
[#
1
]
%
66
{
\doifelseassignmentcs
{
#
1
}
%
67
\strc_blocks_begin_indeed
68
\strc_blocks_begin_tagged
69
{
#
1
}}
70 71
\unexpanded
\def
\strc_blocks_begin_tagged
#
1
%
72
{
\edef
\m_subblock
{
#
1
}
%
73
\doifelsenextoptionalcs
\strc_blocks_begin_yes_yes
\strc_blocks_begin_nop
}
74 75
\unexpanded
\def
\strc_blocks_begin_yes_yes
[#
1
]
%
76
{
\strc_blocks_begin_indeed
{
#
1
}}
77 78
\unexpanded
\def
\strc_blocks_begin_nop
79
{
\strc_blocks_begin_indeed
{}}
80 81
\unexpanded
\def
\strc_blocks_begin_indeed
#
1
%
82
{
\normalexpanded
{
\buff_pickup
{
\??block
}{
\e!begin
\m_block
}{
\e!end
\m_block
}}
%
83
{}
%
84
{
\clf_savestructureblock
{
\m_block
}{
\m_subblock
}{
#
1
}{
\??block
}}
%
85
\plusone
}
86 87
\let
\strc_blocks_setup
\relax
88 89
\newconstant
\c_strc_blocks_index
90
\newconditional
\c_strc_blocks_display
91 92
\unexpanded
\def
\dostarthiddenblock
% called at lua end
93
{
\begingroup
94
\visiblefalse
% blocks float
95
\startnointerference
96
\strc_start_block
}
97 98
\unexpanded
\def
\dostophiddenblock
% called at lua end
99
{
\strc_stop_block
100
\stopnointerference
101
\endgroup
}
102 103
\unexpanded
\def
\dostartnormalblock
% called at lua end
104
{
\begingroup
105
\visibletrue
106
\strc_start_block
}
107 108
\unexpanded
\def
\dostopnormalblock
% called at lua end
109
{
\strc_stop_block
110
\endgroup
}
111 112
\def
\strc_start_block
#
1
#
2
%
113
{
\edef
\currentblock
{
#
2
}
%
114
\c_strc_blocks_index
#
1
\relax
115
\strc_blocks_setup
116
\let
\strc_blocks_setup
\relax
117
\edef
\p_alternative
{
\blockparameter
\c!alternative
}
%
118
\ifx
\p_alternative
\v!text
119
\setfalse
\c_strc_blocks_display
120
\else
121
\settrue
\c_strc_blocks_display
122
\fi
123
\ifconditional
\c_strc_blocks_display
124
\blockparameter
\c!before
125
\fi
126
\begingroup
127
\usesetupsparameter
\blockparameter
\relax
128
\dostarttagged
\t!block
\currentblock
129
\useblockstyleandcolor
\c!style\c!color
130
\blockparameter
\c!inner
% old
131
\ifconditional
\c_strc_blocks_display
132
\usealignparameter
\blockparameter
133
\else
134
\blockparameter
\c!left
135
\fi
136
\ignorespaces
}
137 138
\def
\strc_stop_block
139
{
\removeunwantedspaces
140
\ifconditional
\c_strc_blocks_display
141
\par
142
\else
143
\blockparameter
\c!right
144
\fi
145
\dostoptagged
146
\endgroup
147
\ifconditional
\c_strc_blocks_display
148
\blockparameter
\c!after
149
\fi
}
150 151
\def
\strc_blocks_set_state
[#
1
][#
2
][#
3
]
% state name tag
152
{
\clf_setstructureblockstate
{
#
1
}{
#
2
}{
#
3
}}
153 154
\def
\strc_blocks_select
[#
1
][#
2
][#
3
][#
4
]
% state name tag setups
155
{
\begingroup
156
\doifelseassignment
{
#
3
}
157
{
\getparameters
[
\??blocktemp
][
\c!criterium
=
\v!text
,
#
3
]
%
158
\def
\strc_blocks_setup
{
\setupcurrentblock
[#
3
]
}
%
159
\clf_selectstructureblock
{
#
1
}{
#
2
}{}{
\csname
\??blocktemp\c!criterium
\endcsname
}}
160
{
\getparameters
[
\??blocktemp
][
\c!criterium
=
\v!text
,
#
4
]
%
161
\def
\strc_blocks_setup
{
\setupcurrentblock
[#
4
]
}
%
162
\clf_selectstructureblock
{
#
1
}{
#
2
}{
#
3
}{
\csname
\??blocktemp\c!criterium
\endcsname
}}
%
163
\endgroup
}
164 165
\def
\blockuservariable
#
1
%
166
{
\clf_structureblockuservariable
\c_strc_blocks_index
{
#
1
}}
167 168
% hide : save, if [+] also hidden execute
169
% keep : save and normal execute
170
% use : normal execute unless [-]
171
% process: hidden execute unless [-]
172
% select : idem use
173 174
\unexpanded
\def
\hideblocks
{
\dotripleempty
\strc_blocks_set_state
[
hide
]
}
175
\unexpanded
\def
\keepblocks
{
\dotripleempty
\strc_blocks_set_state
[
keep
]
}
176
\unexpanded
\def
\useblocks
{
\doquadrupleempty
\strc_blocks_select
[
use
]
}
177
\unexpanded
\def
\processblocks
{
\doquadrupleempty
\strc_blocks_select
[
process
]
}
178
\unexpanded
\def
\selectblocks
{
\doquadrupleempty
\strc_blocks_select
[
use
]
}
179 180
\protect
\endinput
181