1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Spacing Macros Lines}
15
16\unprotect
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\installcorenamespace{lines}
49
50\installcommandhandler \??lines {lines} \??lines
51
52\setuplines
53 [\c!option=,
54 \c!command=,
55 \c!before=\blank,
56 \c!after=\blank,
57 \c!inbetween=\blank,
58 \c!indenting=\v!no,
59 \c!space=\v!default]
60
61\appendtoks
62 \frozen\instance\protected\edefcsname\e!start\currentlines\endcsname{\spac_lines_start[\currentlines]}
63 \frozen\instance\letcsname \e!stop \currentlines\endcsname \spac_lines_stop
64\to \everydefinelines
65
66
67
68\let\spac_lines_break \relax
69\let\spac_after_first_obeyed_line\relax
70\let\spac_lines_indent \relax
71
72
73
74
75
76
77
78
79
80
81
82
83\newinteger \c_spac_lines_indent_cnt
84\newinteger \c_spac_lines_indent_max
85\newdimension\d_spac_lines_indent
86
87\def\spac_lines_indent_indeed
88 {\ifnum\c_spac_lines_indent_cnt=\c_spac_lines_indent_max
89 \c_spac_lines_indent_cnt\plusone
90 \else
91 \advanceby\c_spac_lines_indent_cnt\plusone
92 \fi
93 \getfromcommacommand[\m_spac_lines_indentlist][\c_spac_lines_indent_cnt]
94 \ifx\commalistelement\wildcardsymbol
95 \hskip\d_spac_lines_indent
96 \else
97 \scratchdimen{\commalistelement}
98 \hskip
99 \ifzeropt\scratchdimen
100 \zeropoint
101 \else
102 \scratchdimen
103 \d_spac_lines_indent\scratchdimen
104 \fi
105 \fi
106 \relax}
107
108
109
110
111
112
113
114
115
116
117
118
119\permanent\tolerant\protected\def\spac_lines_start[#1]
120 {\bgroup
121 \cdef\currentlines{#1}
122 \obeylines
123 \spac_lines_start_indeed}
124
125\tolerant\def\spac_lines_start_indeed[#S#1]
126 {\ifarguments\or
127 \setupcurrentlines[#1]
128 \fi
129
130
131 \ifcstok{\linesparameter\c!option}\v!packed
132 \let\spac_lines_break\nobreak
133 \c_spac_lines_as_paragraph\conditionalfalse
134 \orelse\ifcstok{\linesparameter\c!keeptogether}\v!paragraph
135 \let\spac_lines_break\relax
136 \c_spac_lines_as_paragraph\conditionaltrue
137 \else
138 \let\spac_lines_break\relax
139 \c_spac_lines_as_paragraph\conditionalfalse
140 \fi
141 \linesparameter\c!before
142 \push_macro_checkindentation
143 \whitespace
144 \dostarttaggedchained\t!lines\currentlines\currentlines\??lines
145 \begingroup
146 \uselinesstyleandcolor\c!style\c!color
147 \useindentingparameter\linesparameter
148 \usealignparameter\linesparameter
149 \typesettinglinestrue
150 \setupwhitespace[\v!none]
151
152
153 \edef\m_spac_lines_indentlist{\linesparameter\c!indentlist}
154 \getcommacommandsize[\m_spac_lines_indentlist]
155 \c_spac_lines_indent_max\commalistsize
156 \c_spac_lines_indent_cnt\zerocount
157 \ifnum\c_spac_lines_indent_max>\plusone
158 \let\spac_lines_indent\spac_lines_indent_indeed
159 \d_spac_lines_indent\d_spac_indentation_par
160 \else
161 \let\spac_lines_indent\relax
162 \fi
163
164 \ignorespaces
165 \glet\spac_after_first_obeyed_line\spac_lines_after_first_obeyed_line_a
166 \enforced\let\obeyedline\spac_lines_obeyed_line
167 \activatespacehandler{\linesparameter\c!space}
168 \dostarttaggednodetail\t!line
169 \ignorepars}
170
171
172
173\def\spac_lines_after_first_obeyed_line_a
174 {\linesparameter\c!command
175 \spac_lines_indent
176 \linesparameter\c!left
177 \glet\spac_after_first_obeyed_line\spac_lines_after_first_obeyed_line_b}
178
179\def\spac_lines_after_first_obeyed_line_b
180 {\spac_lines_break
181 \linesparameter\c!command
182 \spac_lines_indent
183 \linesparameter\c!left}
184
185\newconditional \c_spac_lines_as_paragraph
186
187\def\spac_lines_obeyed_line
188 {\ifdone\linesparameter\c!right\fi
189 \dostoptagged
190 \ifconditional\c_spac_lines_as_paragraph
191 \parbreak
192 \else
193 \par
194 \fi
195 \dostarttaggednodetail\t!line
196 \futurelet\nexttoken\spac_lines_between}
197
198\protected\def\spac_lines_stop
199 {\dostoptagged
200 \endgroup
201 \dostoptagged
202 \pop_macro_checkindentation
203 \linesparameter\c!after
204 \egroup}
205
206\def\spac_lines_between
207 {\ifx\nexttoken\spac_lines_stop
208 \donefalse
209 \else
210 \doifelsemeaning\nexttoken\obeyedline
211 {\donefalse\linesparameter\c!inbetween}
212 {\donetrue\spac_after_first_obeyed_line}
213 \fi}
214
215\definelines[\v!lines]
216
217\permanent\tolerant\protected\def\emptylines[#1]
218 {\endgraf
219 \begingroup
220
221 \ifhmode
222 \crlf
223 \fi
224 \scratchcounter\ifparameter#1\or#1\else3\fi\relax
225 \dorecurse\scratchcounter{\strut\crlf}
226 \endgroup}
227
228\ifdefined\startlines \else
229 \aliased\expandafter\let\expandafter\startlines\csname\e!start\v!lines\endcsname
230 \aliased\expandafter\let\expandafter\stoplines \csname\e!stop \v!lines\endcsname
231\fi
232
233\protect \endinput
234 |