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
|
%D \module
%D [ file=t-syntax-groups,
%D version=2011.09.03,
%D title=\CONTEXT\ User Module,
%D subtitle=Syntax highlighting support,
%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}{Syntax highlighting groups (ver: 2011.09.03)}
\tracingmacros=1
% Colors are specified in hex; in MkII the hex mode needs to be activated.
\doifmode\s!mkii
{\setupcolor[hex]}
\startmodule [syntax-group]
\usemodule [module-catcodes]
\unprotectmodulecatcodes
\def\colorscheme::name {}
\def\syntaxgroup::id {syntaxgroup}
\def\syntaxgroup::namespace {@@@@\syntaxgroup::id}
\def\syntaxgroup::name {}
\installparameterhandler \syntaxgroup::namespace \syntaxgroup::id
\installsetuphandler \syntaxgroup::namespace \syntaxgroup::id
\def\m!syntaxgroup{t-syntax-group}
\def\definesyntaxgroup
{\dodoubleargument\syntaxgroup::define}
\starttexdefinition syntaxgroup::define [#1][#2]
% #1 list name
% #2 options
\doifassignmentelse{#2}
{
\def\syntaxgroup::get_parameters##1%
{
\edef\syntaxgroup::name {\colorscheme::name##1}
\setupsyntaxgroup[\syntaxgroup::name]
[\c!color=,\c!style=,\c!command=,#2]
\doifsomething{\syntaxgroupparameter\c!color}
{
\expanded{\definecolor[\syntaxgroup::namespace-##1-color]
[\syntaxgroupparameter\c!color]}
\setupsyntaxgroup[\syntaxgroup::name][\c!color=\syntaxgroup::namespace-##1-color]
}
}
}{
\def\syntaxgroup::get_parameters##1%
{
\edef\syntaxgroup::name {\colorscheme::name##1}
\expanded{\setupsyntaxgroup[\syntaxgroup::name]
[\c!color=\namedsyntaxgroupparameter{\colorscheme::name#2}\c!color,
\c!style=\namedsyntaxgroupparameter{\colorscheme::name#2}\c!style,
\c!command=\namedsyntaxgroupparameter{\colorscheme::name#2}\c!command,
]}
% In MkII, \expanded messes up the definition of \currentsyntaxgroup
\def\currentsyntaxgroup {\syntaxgroup::name}
}
}
\processcommalist[#1]\syntaxgroup::get_parameters
\stoptexdefinition
\def\startcolorscheme%
{\dosingleargument\colorscheme::start}
\starttexdefinition colorscheme::start [#1]
\pushmacro\colorscheme::name
\setcolorscheme{#1}
%\setupsyntaxgroup[\c!color=,\c!style=,\c!command=]
\stoptexdefinition
\def\stopcolorscheme
{\popmacro\colorscheme::name}
\def\setcolorscheme#1%
{\edef\colorscheme::name{#1}}
\starttexdefinition syntaxgroup [#1]#2
% #1 = style
% #2 = content
\syntaxgroupparameter\c!before
\begingroup
\edef\syntaxgroup::name{\colorscheme::name#1}%
\iftracesyntaxgroups
\syntaxgroup::show_values
\fi
\syntaxgroupparameter\c!command
{
\externalfilter::attributes_start\syntaxgroup::id\c!style\c!color
#2
\externalfilter::attributes_stop
}
\endgroup
\syntaxgroupparameter\c!after
\stoptexdefinition
%D Tracing macros
\newif\iftracesyntaxgroups
\let\tracesyntaxgroups\tracesyntaxgroupstrue
\def\currentsyntaxgroup {\syntaxgroup::name}
\starttexdefinition syntaxgroup::show_values
\writestatus\m!syntaxgroup{color scheme : \colorscheme::name}
\writestatus\m!syntaxgroup{current group: \syntaxgroup::name}
\writestatus\m!syntaxgroup{command : \syntaxgroupparameter\c!command}
\writestatus\m!syntaxgroup{style : \syntaxgroupparameter\c!style}
\writestatus\m!syntaxgroup{color : \syntaxgroupparameter\c!color}
\stoptexdefinition
\protectmodulecatcodes
\stopmodule
|