summaryrefslogtreecommitdiff
path: root/tex/context/base/mult-aux.mkiv
blob: 295b0a71c7fba046ee042504f0022d566eabc56c (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
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
%D \module
%D   [       file=mult-aux,
%D        version=2010.08.2,
%D          title=\CONTEXT\ Multilingual Macros,
%D       subtitle=helpers,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright=PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D A generalization of \MKIV-like inheritance. Just something to play
%D with (interface might change). The code here evolved in an email
%D exchange between me and Wolgang Schuster.

\writestatus{loading}{ConTeXt Multilingual Macros / Helpers}

\registerctxluafile{mult-aux}{1.001}

\unprotect

%D \starttyping
%D \unprotect
%D     \def\????aa{@@@@aa}
%D
%D     \installparameterhandler  \????aa {whatever}
%D     \installsetuphandler      \????aa {whatever}
%D     \installdefinehandler     \????aa {whatever} \????aa % #3 == defaultroot
%D     \installattributehandler  \????aa {whatever}
%D
%D   % \installcommandhandler    \????aa {whatever} \????aa
%D \protect
%D
%D % \whateverparameter \c!test
%D % \whateverparameterhash \c!test
%D % \namedwhateverparameter \mycurrentwhatever \c!test
%D % \dosetwhateverattributes \c!style \c!color
%D % \everydefinewhatever (sets \currentwhatever)
%D % \everypresetwhatever (can be used to reset parameters as we can redefine)
%D % \everysetupwhatever (sets \currentwhatever)
%D
%D \starttext
%D     \definewhatever[first] \definewhatever[second][first]
%D                                           test: \def\currentwhatever{first}  \whateverparameter{method} \par
%D     \setupwhatever        [method=unset]  test: \def\currentwhatever{first}  \whateverparameter{method} \par
%D     \setupwhatever[first] [method=first]  test: \def\currentwhatever{first}  \whateverparameter{method} \par
%D                                           test: \def\currentwhatever{second} \whateverparameter{method} \par
%D     \setupwhatever[second][method=second] test: \def\currentwhatever{second} \whateverparameter{method} \par
%D \stoptext
%D \stoptyping

% problem: every* could clash

% There can be less {} in the following definitions if we assume \??aa and \c!somecs

% todo: \def\detokenized...parameter#1{\detokenize\expandafter\expandafter\expandafter{\csname#1#2\endcsname}} % always root

\unexpanded\def\doinstallparameterhandler#1#2#3#4#5#6#7%
  {\def#3##1{\csname#4{#1#2}{##1}\endcsname}%
   \def#4##1##2{\ifcsname##1##2\endcsname##1##2\else\expandafter#5\csname##1\s!parent\endcsname{##2}\fi}%
   \def#5##1##2{\ifx##1\relax\s!empty\else#4{##1}{##2}\fi}%
   \def#6##1##2{\csname#4{#1##1}{##2}\endcsname}%
   \def#7##1{\detokenize\expandafter\expandafter\expandafter{\csname#1##1\endcsname}}} % always root

\def\installparameterhandler#1#2%
  {\normalexpanded
     {\doinstallparameterhandler
        {\noexpand#1}% \??aa
        \expandafter\noexpand\csname current#2\endcsname
        \expandafter\noexpand\csname #2parameter\endcsname
        \expandafter\noexpand\csname do#2parameter\endcsname
        \expandafter\noexpand\csname do#2parentparameter\endcsname
        \expandafter\noexpand\csname named#2parameter\endcsname
        \expandafter\noexpand\csname detokenized#2parameter\endcsname}}

\unexpanded\def\doinstallparameterhashhandler#1#2#3#4#5%
  {\def#3##1{#4{#1#2}{##1}}%
   \def#4##1##2{\ifcsname##1##2\endcsname##1\else\expandafter#5\csname##1\s!parent\endcsname{##2}\fi}%
   \def#5##1##2{\ifx##1\relax\else#4{##1}{##2}\fi}}

\def\installparameterhashhandler#1#2%
  {\normalexpanded
     {\doinstallparameterhashhandler
        {\noexpand#1}% \??aa
        \expandafter\noexpand\csname current#2\endcsname
        \expandafter\noexpand\csname #2parameterhash\endcsname
        \expandafter\noexpand\csname do#2parameterhash\endcsname
        \expandafter\noexpand\csname do#2parentparameterhash\endcsname}}

\unexpanded\def\doinstallattributehandler#1#2#3% #1 not used here
  {\def#2##1##2% style color
     {\edef\fontattributehash {#3{##1}}%
      \edef\colorattributehash{#3{##2}}%
      \ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash {##1}\fi
      \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash{##2}\fi}}

\def\installattributehandler#1#2%
  {\normalexpanded
     {\doinstallattributehandler
        {\noexpand#1}% \??aa
        \expandafter\noexpand\csname doset#2attributes\endcsname
        \expandafter\noexpand\csname #2parameterhash\endcsname}}

\unexpanded\def\doinstalldefinehandler#1#2#3#4#5#6#7%
  {\unexpanded\def#2{\dodoubleempty#5}%
   \newtoks#6%
   \newtoks#7%
   \def#5[##1][##2]%
     {\edef#4{##1}%
      \the#6% predefine
      \ifsecondargument
        \getparameters[#1#4][\s!parent=#1,##2]%
      \else
        \getparameters[#1#4][\s!parent=#3]%
      \fi
      \the#7}}

\def\installdefinehandler#1#2#3%
  {\normalexpanded
     {\doinstalldefinehandler
        {\noexpand#1}% \??aa
        \expandafter\noexpand\csname define#2\endcsname
        {\noexpand#3}% root
        \expandafter\noexpand\csname current#2\endcsname
        \expandafter\noexpand\csname dodefine#2\endcsname
        \expandafter\noexpand\csname everypreset#2\endcsname
        \expandafter\noexpand\csname everydefine#2\endcsname}}

\unexpanded\def\doinstallsetuphandler#1#2#3#4#5%
  {\unexpanded\def#2{\dodoubleempty#4}%
   \newtoks#5%
   \def#4[##1][##2]%
     {\ifsecondargument
        \def\docommand####1% we will have a simple one as well
          {\edef#3{##1}%
           \getparameters[#1#3][##2]%
           \the#5}%
        \processcommalist[##1]\docommand
      \else
        \let#3\empty
        \getparameters[#1][##1]%
        \the#5%
      \fi}}

\def\installsetuphandler#1#2%
  {\normalexpanded
     {\doinstallsetuphandler
        {\noexpand#1}% \??aa
        \expandafter\noexpand\csname setup#2\endcsname
        \expandafter\noexpand\csname current#2\endcsname
        \expandafter\noexpand\csname dosetup#2\endcsname
        \expandafter\noexpand\csname everysetup#2\endcsname}}

\unexpanded\def\installcommandhandler#1#2#3% \??self name \??parent (can be \??self)
  {\installparameterhandler    {#1}{#2}%
   \installparameterhashhandler{#1}{#2}%
   \installdefinehandler       {#1}{#2}{#3}%
   \installsetuphandler        {#1}{#2}%
   \installattributehandler    {#1}{#2}}

\def\installnamespace#1%
  {\setvalue{????#1}{@@@@#1}}

% \start
%
% \enabletrackers[interfaces.namespaces]
%
% \definenamespace
%   [ws]
%   [type=module,
%    comment=letter module,
%    version=1,
%    name=letter,
%    style=yes,
%    command=yes,
%    setup=list,
%    parent=ws-common]
%
% \ttx \listnamespaces
%
% \defineletter[mine][whatever=true]  \setupletter[mine][whatever=true]
%
% \namedletterparameter{mine}{whatever}
%
% \def\currentletter{mine} \letterparameter{whatever}
%
% \stop

\def\definenamespace{\dodoubleargument\dodefinenamespace}

\def\dodefinenamespace[#1][#2]% namespace settings
  {\ctxlua{interfaces.namespaces.define(\!!bs#1\!!es,\!!bs#2\!!es)}}

\def\listnamespaces
  {\ctxlua{interfaces.namespaces.list()}}

\protect