summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/third/vim/t-syntax-groups.tex
blob: ff24e81e4dfd35ecfc75234f3b7f4527de937602 (plain)
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
%D \module
%D   [     file=t-syntax-groups,
%D      version=2011.06.12,
%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> umich <dot> edu,
%D      license=Simplified BSD License]

\writestatus{loading}{ConTeXt User Module / Syntax Highlighting Support}

% 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   {@@@@\colorscheme::name\syntaxgroup::id}
\def\syntaxgroup::name        {}

\installparameterhandler  \syntaxgroup::namespace \syntaxgroup::id

\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 {##1}
         \getparameters[\syntaxgroup::namespace##1]
                       [\c!color=,\c!style=,\c!command=,#2]
         \doifsomething{\syntaxgroupparameter\c!color}
          {
             \expanded{\definecolor[\syntaxgroup::namespace-##1-color]
                                   [\syntaxgroupparameter\c!color]}
             \getparameters[\syntaxgroup::namespace##1][\c!color=\syntaxgroup::namespace-##1-color]
          }
    }
  }{
    \def\syntaxgroup::get_parameters##1%
    {
        \copyparameters[\syntaxgroup::namespace##1][\syntaxgroup::namespace#2]
                       [\c!color,\c!style,\c!command]
    }
  }
        
  \processcommalist[#1]\syntaxgroup::get_parameters
\stoptexdefinition

\def\startcolorscheme%
    {\dosingleargument\colorscheme::start}

\starttexdefinition colorscheme::start [#1]
     \pushmacro\colorscheme::name
     \setcolorscheme{#1}
     \getparameters[\syntaxgroup::namespace][\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
      \begingroup
      \edef\syntaxgroup::name{#1}%
      \syntaxgroupparameter\c!command
      {
        \dostartattributes{\syntaxgroup::namespace #1}\c!style\c!color
            #2
        \dostopattributes
      }
      \endgroup
\stoptexdefinition

\def\currentsyntaxgroup   {\syntaxgroup::name}

\protectmodulecatcodes
\stopmodule