catc-act.mkiv /size: 2640 b    last modification: 2021-10-28 13:50
1
%D \module
2
%D [ file=catc-act,
3
%D version=2006.09.18,
4
%D title=\CONTEXT\ Catcode Macros,
5
%D subtitle=Default Catcode Tables,
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
%D This module deals with some active character handling. Use
15
%D with care.
16 17
\unprotect
18 19
% todo: \letcharcode<number>=\something
20 21
%D \macros
22
%D {installactivecharacter}
23 24
\let
\m_syst_catcodes_temp
\empty
25 26
\protected
\def
\installactivecharacter
#
1
%
27
{
\edef
\m_syst_catcodes_temp
{
\detokenize
{
#
1
}
}
%
28
\c_syst_catcodes_c
\expandafter
`
\m_syst_catcodes_temp
\relax
% relax needed
29
\expandafter
\startextendcatcodetable
30
\expandafter
\ctxcatcodes
\expandafter
\catcode
\the
\c_syst_catcodes_c
\activecatcode
31
\stopextendcatcodetable
32
\letcatcodecommand
\ctxcatcodes
\c_syst_catcodes_c
\m_syst_catcodes_temp
\relax
33
\ifnum
\currentcatcodetable
=
\ctxcatcodes
\setcatcodetable
\ctxcatcodes
\fi
34
\let
\m_syst_catcodes_temp
\empty
}
35 36
%D \macros
37
%D {defineactivecharacter}
38
%D
39
%D Use this one with care, esp in combination with catcode
40
%D vectors. There are better ways now.
41 42
\setnewconstant
\c_syst_catcodes_hack
\tildeasciicode
% also defined in catc-ini.mkiv
43 44
\protected
\def
\defineactivecharacter
#
1
#
2
#
3
% uses \doifelsenumber which is not yet defined
45
{
\c_syst_catcodes_c
\uccode
\c_syst_catcodes_hack
46
\if
#
1
"
\uccode
\c_syst_catcodes_hack
\expandafter
\doifelsenumber
\expandafter
{
\string
#
1
#
2
}
\empty
#
1
#
2
\else
47
\uccode
\c_syst_catcodes_hack
\expandafter
\doifelsenumber
\expandafter
{
\string
#
1
#
2
}
\empty
`
#
1
#
2
\fi
48
\catcode
\uccode
\c_syst_catcodes_hack
\activecatcode
49
\uppercase
{
\def
\m_syst_catcodes_temp
{
~
}
}
% brrr
50
\uccode
\c_syst_catcodes_hack
\c_syst_catcodes_c
51
\expandafter
\expandafter
\expandafter
\def
\expandafter
\m_syst_catcodes_temp
\expandafter
52
{
\expandafter
\syst_catcodes_handle
\m_syst_catcodes_temp
{
#
3
}
}
%
53
\let
\m_syst_catcodes_temp
\empty
}
54 55
\chardef
\activecharactermode
\plusone
% overloading still backward compatible
56 57
\def
\syst_catcodes_handle
58
{
\ifcase
\activecharactermode
59
\expandafter
\syst_catcodes_handle_nop
60
\else
61
\expandafter
\syst_catcodes_handle_yes
62
\fi
}
63 64
\def
\syst_catcodes_handle_yes
#
1
#
2
{
#
2
}
65
\def
\syst_catcodes_handle_nop
#
1
#
2
{
\noexpand
#
1
}
66 67
\protected
\def
\makecharacteractive
#
1
%
68
{
\catcode
`
#
1
\activecatcode
}
69 70
\protected
\def
\installanddefineactivecharacter
#
1
% #2%
71
{
\normalexpanded
{
\noexpand
\installactivecharacter
\utfchar
{
#
1
}
}
%
72
\defineactivecharacter
#
1
}
% {#2}}
73 74
\protect
\endinput
75