PageRenderTime 31ms CodeModel.GetById 10ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/contrib/tcsh/eight-bit.me

https://bitbucket.org/freebsd/freebsd-head/
Unknown | 143 lines | 126 code | 17 blank | 0 comment | 0 complexity | 7f4159242d237933d4d910993bf15be3 MD5 | raw file
  1.\" $tcsh: eight-bit.me,v 3.2 2006/03/02 18:46:44 christos Exp $
  2How to use 8 bit characters
  3by 
  4Johan Widen 
  5(jw@sics.se) 
  6and 
  7Per Hedeland 
  8(per@erix.ericsson.se)
  9
 10.pp
 11(Disclaimer: This is really a sketch of an approach rather
 12than a "how-to" document.
 13Also, it is mostly relevant to Swedish X Window users...)
 14
 15.pp
 16The way I use this facility at present is to add lines such as the following
 17to my .cshrc:
 18
 19.nf 
 20setenv NOREBIND
 21setenv LC_CTYPE iso_8859_1
 22foreach key ( \\\\304 \\\\305 \\\\326 \\\\344 \\\\345 \\\\366 )
 23   bindkey $key self-insert-command
 24end
 25.fi
 26
 27.pp
 28Note that if I used a system with a reasonably complete NLS
 29(and a tcsh compiled to use it),
 30all of the above could be replaced with simply setting the LANG environment
 31variable to an appropriate value - the NLS would then indicate exactly which
 32characters should be considered printable, and tcsh would do the rebinding
 33of these automatically. The above works for tcsh's simulated NLS and for
 34the NLS in SunOS 4.1 - without the NOREBIND setting, all of the
 35Meta-<non-control-character> bindings would be undone in these cases.
 36
 37.pp
 38These keybindings are the codes for my national characters, but the bindings
 39(M-d, M-e etc) are not conveniently placed.
 40They are however consistent with what other programs will see.
 41
 42.pp
 43Now: I actually want the character \\304 to be inserted when I press say '{'
 44together with a modifier key. I want the behavior to be the same not only
 45in tcsh but in say cat, an editor and all other programs. I fix this by
 46performing a keyboard remapping with the
 47.i xmodmap
 48program (I use X Windows).
 49
 50.pp
 51I give xmodmap an input something like the following:
 52
 53.nf
 54keycode 26 = Mode_switch
 55add 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!
 62keycode 71 = bracketleft braceleft adiaeresis Adiaeresis
 63keycode 72 = bracketright braceright aring Aring
 64keycode 95 = backslash bar odiaeresis Odiaeresis
 65.fi
 66
 67or:
 68
 69.nf
 70keysym Alt_R = Mode_switch
 71add mod2 = Mode_switch
 72keysym bracketleft = bracketleft braceleft Adiaeresis adiaeresis
 73keysym bracketright = bracketright braceright Aring aring
 74keysym backslash = backslash bar Odiaeresis odiaeresis
 75.fi
 76
 77Another, 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
 84xmodmap -pk | sed -e 's/[()]//g' | \\
 85awk 'BEGIN {
 86	alt["bracketright"] = "Aring"; alt["braceright"] = "aring";
 87	alt["bracketleft"] = "Adiaeresis"; alt["braceleft"] = "adiaeresis";
 88	alt["backslash"] = "Odiaeresis"; alt["bar"] = "odiaeresis";
 89}
 90NF >= 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}
 97alt[$3] != "" {
 98	printf "keycode %s = %s %s %s\\n", $1, $3, $3, alt[$3];
 99}
100NF >= 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}
110END {
111	if (altkeys != "") printf "clear mod2\\nadd mod2 =%s\\n", altkeys;
112}' | xmodmap -
113.fi
114
115.pp
116Finally, with the binding of the codes of my national characters to
117self-insert-command, I lost the ability to use the Meta key to call the
118functions previously bound to M-d, M-e, and M-v (<esc>d etc still works).
119However, with the assumption that
120most of my input to tcsh will be through the
121.i xterm
122terminal emulator, I can get that ability back via xterm bindings!
123Since M-d is the only one of the "lost" key combinations that was
124actually bound to a function in my case,
125and it had the same binding as M-D, I can use the following in
126my .Xdefaults file:
127
128.nf
129XTerm*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
136XTerm*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