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\lettonothing\p_lines_option
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\dimexpr\commalistelement\relax
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\permanent\tolerant\protected\def\spac_lines_start[#1]
109 {\bgroup
110 \cdef\currentlines{#1}
111 \obeylines
112 \spac_lines_start_indeed}
113
114\tolerant\def\spac_lines_start_indeed[#S#1]
115 {\ifarguments\or
116 \setupcurrentlines[#1]
117 \fi
118 \edef\p_lines_option{\linesparameter\c!option}
119 \ifx\p_lines_option\v!packed
120 \let\spac_lines_break\nobreak
121 \else
122 \let\spac_lines_break\relax
123 \fi
124 \linesparameter\c!before
125 \push_macro_checkindentation
126 \whitespace
127 \dostarttaggedchained\t!lines\currentlines\??lines
128 \begingroup
129 \uselinesstyleandcolor\c!style\c!color
130 \useindentingparameter\linesparameter
131 \usealignparameter\linesparameter
132 \typesettinglinestrue
133 \setupwhitespace[\v!none]
134
135
136 \edef\m_spac_lines_indentlist{\linesparameter\c!indentlist}
137 \getcommacommandsize[\m_spac_lines_indentlist]
138 \c_spac_lines_indent_max\commalistsize
139 \c_spac_lines_indent_cnt\zerocount
140 \ifnum\c_spac_lines_indent_max>\plusone
141 \let\spac_lines_indent\spac_lines_indent_indeed
142 \d_spac_lines_indent\d_spac_indentation_par
143 \else
144 \let\spac_lines_indent\relax
145 \fi
146
147 \ignorespaces
148 \glet\spac_after_first_obeyed_line\spac_lines_after_first_obeyed_line_a
149 \enforced\let\obeyedline\spac_lines_obeyed_line
150 \activatespacehandler{\linesparameter\c!space}
151 \dostarttagged\t!line\empty
152 \ignorepars}
153
154
155
156
157\def\spac_lines_after_first_obeyed_line_a
158 {\linesparameter\c!command
159 \spac_lines_indent
160 \linesparameter\c!left
161 \glet\spac_after_first_obeyed_line\spac_lines_after_first_obeyed_line_b}
162
163\def\spac_lines_after_first_obeyed_line_b
164 {\spac_lines_break
165 \linesparameter\c!command
166 \spac_lines_indent
167 \linesparameter\c!left}
168
169\def\spac_lines_obeyed_line
170 {\ifdone\linesparameter\c!right\fi
171 \dostoptagged
172 \par
173 \dostarttagged\t!line\empty
174 \futurelet\nexttoken\spac_lines_between}
175
176\protected\def\spac_lines_stop
177 {\dostoptagged
178 \endgroup
179 \dostoptagged
180 \pop_macro_checkindentation
181 \linesparameter\c!after
182 \egroup}
183
184\def\spac_lines_between
185 {\ifx\nexttoken\spac_lines_stop
186 \donefalse
187 \else
188 \doifelsemeaning\nexttoken\obeyedline
189 {\donefalse\linesparameter\c!inbetween}
190 {\donetrue\spac_after_first_obeyed_line}
191 \fi}
192
193\definelines[\v!lines]
194
195\permanent\tolerant\protected\def\emptylines[#1]
196 {\endgraf
197 \begingroup
198
199 \ifhmode
200 \crlf
201 \fi
202 \scratchcounter\ifparameter#1\or#1\else3\fi\relax
203 \dorecurse\scratchcounter{\strut\crlf}
204 \endgroup}
205
206\ifdefined\startlines \else
207 \aliased\expandafter\let\expandafter\startlines\csname\e!start\v!lines\endcsname
208 \aliased\expandafter\let\expandafter\stoplines \csname\e!stop \v!lines\endcsname
209\fi
210
211\protect \endinput
212 |