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