spac-lin.mkiv /size: 5712 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=spac-lin,
3%D        version=2012.01.08, % 2009.10.16 (core-ver) 1997.03.31 (core-spa)
4%D          title=\CONTEXT\ Spacing Macros,
5%D       subtitle=Vertical,
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 Spacing Macros / Lines}
15
16\unprotect
17
18%D When spacing is active we need to handle commands in
19%D a special way:
20%D
21%D \starttyping
22%D \setuplines[space=on]
23%D
24%D \startlines
25%D Let's talk about this{\ttsl\gobbleoneargument or}that.
26%D \stoplines
27%D
28%D \startlines
29%D Let's talk about this{\getvalue{ttsl}or}that.
30%D \stoplines
31%D \stoptyping
32%D
33%D One can indent in several ways:
34%D
35%D \starttyping
36%D \setupindenting[medium] \setuplines[indenting=odd] % no yes odd even
37%D
38%D \startlines
39%D first
40%D second
41%D third
42%D fourth
43%D \stoplines
44%D \stoptyping
45
46%D Contrary to \MKII\ we can now define classes of lines (generalized by
47%D Wolfgang). I will probably rewrite bits in \LUA.
48
49\installcorenamespace{lines}
50
51\installcommandhandler \??lines {lines} \??lines
52
53\setuplines
54  [\c!option=,
55   \c!command=,
56   \c!before=\blank,
57   \c!after=\blank,
58   \c!inbetween=\blank,
59   \c!indenting=\v!no,
60   \c!space=\v!default]
61
62\appendtoks
63   \setuevalue{\e!start\currentlines}{\spac_lines_start[\currentlines]}%
64   \letvalue  {\e!stop \currentlines }\spac_lines_stop
65\to \everydefinelines
66
67\unexpanded\def\spac_lines_start[#1]%
68  {\bgroup
69   \edef\currentlines{#1}%
70   \obeylines
71   \dosingleempty\spac_lines_start_indeed}
72
73\let\p_lines_option\empty
74
75\let\spac_lines_break            \relax
76\let\spac_after_first_obeyed_line\relax
77\let\spac_lines_indent           \relax
78
79%D See \type {indentation-005.tex}:
80%D
81%D \starttyping
82%D \setuplines[indentlist={0pt,10pt,15pt,20pt}]
83%D
84%D \setupindenting[yes,1em]
85%D \setuplines[indentlist={0pt,*,*}]
86%D
87%D \setuplines[indentlist={0pt,1em,*}]
88%D \starttyping
89
90\newcount\c_spac_lines_indent_cnt
91\newcount\c_spac_lines_indent_max
92\newdimen\d_spac_lines_indent
93
94\def\spac_lines_indent_indeed
95  {\ifnum\c_spac_lines_indent_cnt=\c_spac_lines_indent_max
96     \c_spac_lines_indent_cnt\plusone
97   \else
98     \advance\c_spac_lines_indent_cnt\plusone
99   \fi
100   \getfromcommacommand[\m_spac_lines_indentlist][\c_spac_lines_indent_cnt]%
101   \ifx\commalistelement\wildcardsymbol
102     \hskip\d_spac_lines_indent
103   \else
104     \scratchdimen\dimexpr\commalistelement\relax
105     \hskip\ifdim\scratchdimen=\zeropoint
106       \zeropoint
107     \else
108       \scratchdimen
109       \d_spac_lines_indent\scratchdimen
110     \fi
111   \fi
112   \relax}
113
114\def\spac_lines_start_indeed[#1]% new: optional second argument (WS)
115  {\iffirstargument
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]% todo use fast variant
134   %\obeylines % move upwards to keep spaces in the first line due to optional argument
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% we could have states instead and handle option in there
156
157\def\spac_lines_after_first_obeyed_line_a % tzt two pass, like itemize
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 % can be a dummy one as we don't look ahead
172   \par
173   \dostarttagged\t!line\empty
174   \futurelet\nexttoken\spac_lines_between}
175
176\unexpanded\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 % brrr
189       {\donefalse\linesparameter\c!inbetween}
190       {\donetrue\spac_after_first_obeyed_line}%
191   \fi}
192
193\definelines[\v!lines]
194
195\unexpanded\def\emptylines
196  {\dosingleempty\spac_lines_empty}
197
198% \def\spac_lines_empty[#1]%
199%   {\endgraf
200%    \dorecurse{\iffirstargument#1\else3\fi}\crlf}
201
202\def\spac_lines_empty[#1]%
203  {\endgraf
204   \begingroup
205  %\forgetall % debatable
206   \ifhmode
207      \crlf % finish the current line
208   \fi
209   \dorecurse{\iffirstargument#1\else3\fi}{\strut\crlf}%
210   \endgroup}
211
212\ifdefined\startlines \else
213    \expandafter\let\expandafter\startlines\csname\e!start\v!lines\endcsname
214    \expandafter\let\expandafter\stoplines \csname\e!stop \v!lines\endcsname
215\fi
216
217\protect \endinput
218