strc-blk.mkxl /size: 5148 b    last modification: 2021-10-28 13:51
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
\frozen
\setuevalue
{
\e!begin
\currentblock
}
{
\strc_blocks_begin
{
\currentblock
}
}
%
38
\frozen
\letvalue
{
\e!end
\currentblock
}
\donothing
39
\to
\everydefineblock
40 41
% We need to prevent too much lookahead which will gobble newlines that are needed
42
% for buffers. See blocks-002.tex as example.
43 44
% maybe: systemmode "block:<name>"
45 46
\let
\m_block
\empty
47
\let
\m_subblock
\empty
48 49
\protected
\def
\strc_blocks_begin
#
1
%
50
{
\edef
\m_block
{
#
1
}
%
51
\let
\m_subblock
\empty
52
\doifelsenextoptionalcs
\strc_blocks_begin_yes
\strc_blocks_begin_nop
}
53 54
\protected
\def
\strc_blocks_begin_yes
[
#
1
]
%
55
{
\doifelseassignmentcs
{
#
1
}
%
56
\strc_blocks_begin_indeed
57
\strc_blocks_begin_tagged
58
{
#
1
}
}
59 60
\protected
\def
\strc_blocks_begin_tagged
#
1
%
61
{
\edef
\m_subblock
{
#
1
}
%
62
\doifelsenextoptionalcs
\strc_blocks_begin_yes_yes
\strc_blocks_begin_nop
}
63 64
\protected
\def
\strc_blocks_begin_yes_yes
[
#
1
]
%
65
{
\strc_blocks_begin_indeed
{
#
1
}
}
66 67
\protected
\def
\strc_blocks_begin_nop
68
{
\strc_blocks_begin_indeed
{
}
}
69 70
\protected
\def
\strc_blocks_begin_indeed
#
1
%
71
{
\normalexpanded
{
\buff_pickup
{
\??block
}
{
\e!begin
\m_block
}
{
\e!end
\m_block
}
}
%
72
{
}
%
73
{
\clf_savestructureblock
{
\m_block
}
{
\m_subblock
}
{
#
1
}
{
\??block
}
}
%
74
\plusone
}
75 76
\let
\strc_blocks_setup
\relax
77 78
\newconstant
\c_strc_blocks_index
79
\newconditional
\c_strc_blocks_display
80 81
\permanent
\protected
\def
\dostarthiddenblock
% called at lua end
82
{
\begingroup
83
\visiblefalse
% blocks float
84
\startnointerference
85
\strc_start_block
}
86 87
\permanent
\protected
\def
\dostophiddenblock
% called at lua end
88
{
\strc_stop_block
89
\stopnointerference
90
\endgroup
}
91 92
\permanent
\protected
\def
\dostartnormalblock
% called at lua end
93
{
\begingroup
94
\visibletrue
95
\strc_start_block
}
96 97
\permanent
\protected
\def
\dostopnormalblock
% called at lua end
98
{
\strc_stop_block
99
\endgroup
}
100 101
\def
\strc_start_block
#
1
#
2
%
102
{
\edef
\currentblock
{
#
2
}
%
103
\c_strc_blocks_index
#
1
\relax
104
\strc_blocks_setup
105
\let
\strc_blocks_setup
\relax
106
\edef
\p_alternative
{
\blockparameter
\c!alternative
}
%
107
\ifx
\p_alternative
\v!text
108
\setfalse
\c_strc_blocks_display
109
\else
110
\settrue
\c_strc_blocks_display
111
\fi
112
\ifconditional
\c_strc_blocks_display
113
\blockparameter
\c!before
114
\fi
115
\begingroup
116
\usesetupsparameter
\blockparameter
\relax
117
\dostarttagged
\t!block
\currentblock
118
\useblockstyleandcolor
\c!style
\c!color
119
\blockparameter
\c!inner
% old
120
\ifconditional
\c_strc_blocks_display
121
\usealignparameter
\blockparameter
122
\else
123
\blockparameter
\c!left
124
\fi
125
\ignorespaces
}
126 127
\def
\strc_stop_block
128
{
\removeunwantedspaces
129
\ifconditional
\c_strc_blocks_display
130
\par
131
\else
132
\blockparameter
\c!right
133
\fi
134
\dostoptagged
135
\endgroup
136
\ifconditional
\c_strc_blocks_display
137
\blockparameter
\c!after
138
\fi
}
139 140
\tolerant
\def
\strc_blocks_set_state
[
#
1
]
#
*
[
#
2
]
#
*
[
#
3
]
% state name tag % todo: we could use the lua one directly
141
{
\clf_setstructureblockstate
{
#
1
}
{
#
2
}
{
#
3
}
}
142 143
\tolerant
\def
\strc_blocks_select
[
#
1
]
#
*
[
#
2
]
#
*
[
#
3
]
#
*
[
#
4
]
% state name tag setups
144
{
\begingroup
145
\ifhastok
=
{
#
3
}
%
146
\getparameters
[
\??blocktemp
]
[
\c!criterium
=
\v!text
,
#
3
]
%
147
\def
\strc_blocks_setup
{
\setupcurrentblock
[
#
3
]
}
%
148
\clf_selectstructureblock
{
#
1
}
{
#
2
}
{
}
{
\csname
\??blocktemp
\c!criterium
\endcsname
}
%
149
\else
150
\getparameters
[
\??blocktemp
]
[
\c!criterium
=
\v!text
,
#
4
]
%
151
\def
\strc_blocks_setup
{
\setupcurrentblock
[
#
4
]
}
%
152
\clf_selectstructureblock
{
#
1
}
{
#
2
}
{
#
3
}
{
\csname
\??blocktemp
\c!criterium
\endcsname
}
%
153
\fi
154
\endgroup
}
155 156
\permanent
\def
\blockuservariable
#
1
%
157
{
\clf_structureblockuservariable
\c_strc_blocks_index
{
#
1
}
}
158 159
% hide : save, if [+] also hidden execute
160
% keep : save and normal execute
161
% use : normal execute unless [-]
162
% process: hidden execute unless [-]
163
% select : idem use
164 165
\permanent
\protected
\def
\hideblocks
{
\strc_blocks_set_state
[
hide
]
}
166
\permanent
\protected
\def
\keepblocks
{
\strc_blocks_set_state
[
keep
]
}
167
\permanent
\protected
\def
\useblocks
{
\strc_blocks_select
[
use
]
}
168
\permanent
\protected
\def
\processblocks
{
\strc_blocks_select
[
process
]
}
169
\permanent
\protected
\def
\selectblocks
{
\strc_blocks_select
[
use
]
}
170 171
\permanent
\protected
\def
\doifelseblocksempty
{
\clf_doifelsestructureblocksempty
}
% {name}{tag}{criterium}
172 173
\protect
\endinput
174