1How to use 8 bit characters
2by 
3Johan Widen 
4(jw@sics.se) 
5and 
6Per Hedeland 
7(per@erix.ericsson.se)
8
9.pp
10(Disclaimer: This is really a sketch of an approach rather
11than a "how-to" document.
12Also, it is mostly relevant to Swedish X Window users...)
13
14.pp
15The way I use this facility at present is to add lines such as the following
16to my .cshrc:
17
18.nf 
19setenv NOREBIND
20setenv LC_CTYPE iso_8859_1
21foreach key ( \\\\304 \\\\305 \\\\326 \\\\344 \\\\345 \\\\366 )
22   bindkey $key self-insert-command
23end
24.fi
25
26.pp
27Note that if I used a system with a reasonably complete NLS
28(and a tcsh compiled to use it),
29all of the above could be replaced with simply setting the LANG environment
30variable to an appropriate value - the NLS would then indicate exactly which
31characters should be considered printable, and tcsh would do the rebinding
32of these automatically. The above works for tcsh's simulated NLS and for
33the NLS in SunOS 4.1 - without the NOREBIND setting, all of the
34Meta-<non-control-character> bindings would be undone in these cases.
35
36.pp
37These keybindings are the codes for my national characters, but the bindings
38(M-d, M-e etc) are not conveniently placed.
39They are however consistent with what other programs will see.
40
41.pp
42Now: I actually want the character \\304 to be inserted when I press say '{'
43together with a modifier key. I want the behavior to be the same not only
44in tcsh but in say cat, an editor and all other programs. I fix this by
45performing a keyboard remapping with the
46.i xmodmap
47program (I use X Windows).
48
49.pp
50I give xmodmap an input something like the following:
51
52.nf
53keycode 26 = Mode_switch
54add mod2 = Mode_switch
55! if you want Mode_switch to toggle, at the expense of losing
56! Caps- or whatever Lock you currently have, add the two lines below
57! clear Lock
58! add Lock = Mode_switch
59! 	Binds swedish characters on ][\\
60!
61keycode 71 = bracketleft braceleft adiaeresis Adiaeresis
62keycode 72 = bracketright braceright aring Aring
63keycode 95 = backslash bar odiaeresis Odiaeresis
64.fi
65
66or:
67
68.nf
69keysym Alt_R = Mode_switch
70add mod2 = Mode_switch
71keysym bracketleft = bracketleft braceleft Adiaeresis adiaeresis
72keysym bracketright = bracketright braceright Aring aring
73keysym backslash = backslash bar Odiaeresis odiaeresis
74.fi
75
76Another, more portable way of doing the same thing is:
77
78.nf
79#!/bin/sh
80# Make Alt-] etc produce the "appropriate" Swedish iso8859/1 keysym values
81# Should handle fairly strange initial mappings
82
83xmodmap -pk | sed -e 's/[()]//g' | \\
84awk 'BEGIN {
85	alt["bracketright"] = "Aring"; alt["braceright"] = "aring";
86	alt["bracketleft"] = "Adiaeresis"; alt["braceleft"] = "adiaeresis";
87	alt["backslash"] = "Odiaeresis"; alt["bar"] = "odiaeresis";
88}
89NF >= 5 && (alt[$3] != "" || alt[$5] != "") {
90	printf "keycode %s = %s %s ", $1, $3, $5;
91	if (alt[$3] != "") printf "%s ", alt[$3];
92	else printf "%s ", $3;
93	printf "%s\\n", alt[$5];
94	next;
95}
96alt[$3] != "" {
97	printf "keycode %s = %s %s %s\\n", $1, $3, $3, alt[$3];
98}
99NF >= 5 && ($3 ~ /^Alt_[LR]$/ || $5 ~ /^Alt_[LR]$/) {
100	printf "keycode %s = %s %s Mode_switch\\n", $1, $3, $5;
101	if ($3 ~ /^Alt_[LR]$/) altkeys = altkeys " " $3;
102	else altkeys = altkeys " " $5;
103	next;
104}
105$3 ~ /^Alt_[LR]$/ {
106	printf "keycode %s = %s %s Mode_switch\\n", $1, $3, $3;
107	altkeys = altkeys " " $3;
108}
109END {
110	if (altkeys != "") printf "clear mod2\\nadd mod2 =%s\\n", altkeys;
111}' | xmodmap -
112.fi
113
114.pp
115Finally, with the binding of the codes of my national characters to
116self-insert-command, I lost the ability to use the Meta key to call the
117functions previously bound to M-d, M-e, and M-v (<esc>d etc still works).
118However, with the assumption that
119most of my input to tcsh will be through the
120.i xterm
121terminal emulator, I can get that ability back via xterm bindings!
122Since M-d is the only one of the "lost" key combinations that was
123actually bound to a function in my case,
124and it had the same binding as M-D, I can use the following in
125my .Xdefaults file:
126
127.nf
128XTerm*VT100.Translations:	#override \\n\\
129			Meta ~Ctrl<Key>d:	string(0x1b) string(d)
130.fi
131
132- or, if I really want a complete mapping:
133
134.nf
135XTerm*VT100.Translations:	#override \\n\\
136			:Meta ~Ctrl<Key>d:	string(0x1b) string(d) \\n\\
137			:Meta ~Ctrl<Key>D:	string(0x1b) string(D) \\n\\
138			:Meta ~Ctrl<Key>e:	string(0x1b) string(e) \\n\\
139			:Meta ~Ctrl<Key>E:	string(0x1b) string(E) \\n\\
140			:Meta ~Ctrl<Key>v:	string(0x1b) string(v) \\n\\
141			:Meta ~Ctrl<Key>V:	string(0x1b) string(V)
142.fi
143