1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
%D \module
%D [ file=t-syntax-highlight,
%D version=2012.06.07,
%D title=\CONTEXT\ User Module,
%D subtitle=Code syntax highlighting,
%D author=Aditya Mahajan,
%D date=\currentdate,
%D copyright=Aditya Mahajan,
%D email=adityam <at> ieee <dot> org,
%D license=Simplified BSD License]
\writestatus{loading}{Code syntax highlighting (ver: 2012.06.07)}
\startmodule [syntax-highlight]
\usemodule [syntax-groups]
\usemodule [filter] % loads module-catcodes
\unprotect
\startinterface all
\setinterfaceconstant {syntax} {syntax}
\setinterfaceconstant {highlight} {highlight}
\setinterfaceconstant {highlightcolor} {highlightcolor}
\stopinterface
%D Name space
\definenamespace
[syntaxhighlighting]
[\c!type=module,
\c!name=syntaxhighlighting,
\c!command=\v!yes,
setup=\v!list,
\c!style=\v!no,
\s!parent=syntaxhighlighting]
\appendtoks
\defineexternalfilter[\currentsyntaxhighlighting]
[\s!parent=\????syntaxhighlighting\currentexternalfilter,\c!taglabel=\vimtyping@id]%
\definelinenumbering [\currentsyntaxhighlighting]%
\setevalue{type\currentsyntaxhighlighting file}{\getvalue{process\currentsyntaxhighlighting file}}%
\to\everydefinesyntaxhighlighting
\appendtoks
% \externalfitlterparameter does not work, so it is better to use
% \syntaxhighlighting parameter.
\normalexpanded{\setuplinenumbering[\currentsyntaxhighlighting]
[
\c!method=\syntaxhighlightingparameter{\c!number\c!method},
\c!conversion=\syntaxhighlightingparameter\c!numberconversion,
\c!location=\syntaxhighlightingparameter{\c!number\c!location},
\c!style=\syntaxhighlightingparameter\c!numberstyle,
\c!color=\syntaxhighlightingparameter\c!numbercolor,
\c!width=\syntaxhighlightingparameter{\c!number\c!width},
\c!left=\syntaxhighlightingparameter{\c!number\c!left},
\c!right=\syntaxhighlightingparameter{\c!number\c!right},
\c!command=\syntaxhighlightingparameter\c!numbercommand,
\c!distance=\syntaxhighlightingparameter{\c!number\c!distance},
\c!align=\syntaxhighlightingparameter{\c!number\c!align},
]}%
\to\everysetupsyntaxhighlighting
\def\syntaxhighlighting@id {syntaxhighlighting}
\edef\t!syntaxhighlighting {\syntaxhighlighting@id}
%D Helper macro
\def\syntaxhighlighting@yes{\v!yes,\v!on}
\startsetups syntaxhighlighting@setup
\edef\currentsyntaxhighlighting{\currentexternalfilter}
\edef\colorscheme@name{\externalfilterparameter\c!alternative}
\let\SYN\syntaxgroup
\edef\HGL{\externalfilterparameter{\c!highlight\c!command}}
\let\\\textbackslash
\let\{\textbraceleft
\let\}\textbraceright
\setupbar[syntaxhighlightline][color=\externalfilterparameter\c!highlightcolor]
\def\tab##1%
{\dorecurse{##1}{\obeyedspace}}%
\forgetall
\doifinset{\externalfilterparameter\c!option}{\v!packed}
{\setupwhitespace[\v!none,\v!flexible]}%
\doifnotinset{\externalfilterparameter\c!option}{\v!hyphenated}
{\language\minusone}%
\setcatcodetable\externalfilter@minimal_catcodes
\expandafter\def\activeendoflinetoken{\strut\par}
\activatespacehandler{\????syntaxhighlighting\externalfilterparameter\c!space}
\raggedright
\stopsetups
\starttexdefinition syntaxhighlighting@read_command #1
\syntaxhighlighting@linenumbering_start
\ReadFile{#1}
\syntaxhighlighting@linenumbering_stop
\stoptexdefinition
\starttexdefinition syntaxhighlighting@linenumbering_start
\doifinset{\externalfilterparameter\c!numbering}\syntaxhighlighting@yes
{\startlinenumbering
[\currentsyntaxhighlighting]
[
\c!start=\externalfilterparameter{\c!number\c!start},
\c!step=\externalfilterparameter{\c!number\c!step},
\c!continue=\externalfilterparameter{\c!number\c!continue},
]}
\dostarttagged\t!syntaxhighlighting\colorscheme@name
\stoptexdefinition
\starttexdefinition syntaxhighlighting@linenumbering_stop
\dostoptagged
\doifinset{\externalfilterparameter\c!numbering}\syntaxhighlighting@yes
{\stoplinenumbering}
\stoptexdefinition
\setupsyntaxhighlighting
[\c!tab=4,
\c!space=\v!off,
\c!lines=\v!fixed,
\c!start=1,
\c!stop=0,
% \c!syntax=context,
\c!alternative=pscolor,
\c!before=,
\c!after=,
\c!spacebefore=\v!none,
\c!spaceafter=\v!none,
\c!location=\v!paragraph,
\c!style=\tttf,
\c!color=,
\c!align={\v!flushleft,\v!nothyphenated}, %Does not work due to \forgetall
\c!filtercommand=echo, % placeholder
\c!continue=yes,
\c!read=\v!yes,
\c!readcommand=\syntaxhighlighting@read_command,
\c!output=\externalfilterinputfile, % placeholder
\c!setups=syntaxhighlighting@setup,
\c!option=\v!packed, % \v!hyphenated
\s!parent=\????externalfilter,
% Numbering options
\c!numbering=\v!no,
\c!number\c!start=1,
\c!number\c!step=1,
\c!number\c!continue=\v!no,
\c!numberconversion=\v!numbers,
\c!number\c!method=\v!first,
\c!number\c!location=\v!left,
\c!numberstyle=\ttx,
\c!numbercolor=,
\c!number\c!width=2em,
\c!number\c!left=,
\c!number\c!right=,
\c!numbercommand=,
\c!number\c!distance=0.5em,
\c!number\c!align=\v!flushright,
%Highlight options
\c!highlight=,
\c!highlightcolor=lightgray,
\c!highlight\c!command=\syntaxhighlightline,
]
% Space handler
%
% The space handing code for MkII and MkIV is not consistent. So, we provide our
% own versions.
\setvalue{\????syntaxhighlighting::\c!lines::\v!split}{\hskip}
\setvalue{\????syntaxhighlighting::\c!lines::\v!fixed}{\dontleavehmode\kern}
% default
\setvalue{\????syntaxhighlighting::\c!lines::}{\dontleavehmode\kern}
\def\syntaxhighlighting@split%
{\getvalue{\????syntaxhighlighting::\c!lines::\externalfilterparameter\c!lines}}
% Visible space
\installspacemethod {\????syntaxhighlighting\v!on}
{\obeyspaces
\unexpanded\def\obeyedspace
{\syntaxhighlighting@split\zeropoint\relax
\hbox{\normalcontrolspace}%
\syntaxhighlighting@split\zeropoint\relax}}%
% Invisible space
\installspacemethod {\????syntaxhighlighting\v!off}
{\obeyspaces
\unexpanded\def\obeyedspace
{\syntaxhighlighting@split\interwordspace\relax}}
% Default
\installspacemethod {\????syntaxhighlighting}
{\activatespacehandler {\????syntaxhighlighting\v!off}}
% Line highlighting
\definebar[syntaxhighlightline]
[\c!order=\v!background,
\c!rulethickness=2.5,
\c!method=0,
\c!offset=1.375,
\c!continue=\v!yes,
\c!color=\externalfilterparameter\c!highlightcolor,
]
% For backward compatibility
\def\syntaxhighlighting@namespace {\????syntaxhighlighting}
\def\syntaxhighlighting@name {\currentsyntaxhighlighting}
\protect
\stopmodule
|