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