iso-transl.el 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. ;;; iso-transl.el --- keyboard input definitions for ISO 8859-1 -*- coding: iso-8859-1 -*-
  2. ;; Copyright (C) 1987, 1993-1999, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Howard Gayle
  4. ;; Maintainer: FSF
  5. ;; Keywords: i18n
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Loading this package defines three ways of entering the non-ASCII
  19. ;; printable characters with codes above 127: the prefix C-x 8, or the
  20. ;; Alt key, or a dead accent key. For example, you can enter uppercase
  21. ;; A-umlaut as `C-x 8 " A' or `Alt-" A' (if you have an Alt key) or
  22. ;; `umlaut A' (if you have an umlaut/diaeresis key).
  23. ;; C-x 8 is set up to autoload this package,
  24. ;; but Alt keys and dead accent keys are only defined
  25. ;; once you have loaded the package. It is nontrivial
  26. ;; to make all of the Alt keys autoload, and it is not clear
  27. ;; that the dead accent keys SHOULD autoload this package.
  28. ;;; Code:
  29. ;;; Provide some binding for startup:
  30. ;;;###autoload (or key-translation-map (setq key-translation-map (make-sparse-keymap)))
  31. ;;;###autoload (define-key key-translation-map "\C-x8" 'iso-transl-ctl-x-8-map)
  32. ;;;###autoload (autoload 'iso-transl-ctl-x-8-map "iso-transl" "Keymap for C-x 8 prefix." t 'keymap)
  33. (defvar iso-transl-dead-key-alist
  34. '((?\' . mute-acute)
  35. (?\` . mute-grave)
  36. (?\" . mute-diaeresis)
  37. (?^ . mute-asciicircum)
  38. (?\~ . mute-asciitilde)
  39. (?\' . dead-acute)
  40. (?\` . dead-grave)
  41. (?\" . dead-diaeresis)
  42. (?^ . dead-asciicircum)
  43. (?\~ . dead-asciitilde)
  44. (?^ . dead-circum)
  45. (?^ . dead-circumflex)
  46. (?\~ . dead-tilde)
  47. ;; Someone reports that these keys don't work if shifted.
  48. ;; This might fix it--no word yet.
  49. (?\' . S-dead-acute)
  50. (?\` . S-dead-grave)
  51. (?\" . S-dead-diaeresis)
  52. (?^ . S-dead-asciicircum)
  53. (?\~ . S-dead-asciitilde)
  54. (?^ . S-dead-circum)
  55. (?^ . S-dead-circumflex)
  56. (?\~ . S-dead-tilde))
  57. "Mapping of ASCII characters to their corresponding dead-key symbols.")
  58. ;; The two-character mnemonics are intended to be available in all languages.
  59. ;; The ones beginning with `*' have one-character synonyms, but a
  60. ;; language-specific table might override the short form for its own use.
  61. (defvar iso-transl-char-map
  62. '(("* " . [? ])
  63. (" " . [? ])
  64. ("*!" . [?¡])
  65. ("!" . [?¡])
  66. ("\"\"" . [?¨])
  67. ("\"A" . [?Ä])
  68. ("\"E" . [?Ë])
  69. ("\"I" . [?Ï])
  70. ("\"O" . [?Ö])
  71. ("\"U" . [?Ü])
  72. ("\"a" . [?ä])
  73. ("\"e" . [?ë])
  74. ("\"i" . [?ï])
  75. ("\"o" . [?ö])
  76. ("\"s" . [?ß])
  77. ("\"u" . [?ü])
  78. ("\"y" . [?ÿ])
  79. ("''" . [?´])
  80. ("'A" . [?Á])
  81. ("'E" . [?É])
  82. ("'I" . [?Í])
  83. ("'O" . [?Ó])
  84. ("'U" . [?Ú])
  85. ("'Y" . [?Ý])
  86. ("'a" . [?á])
  87. ("'e" . [?é])
  88. ("'i" . [?í])
  89. ("'o" . [?ó])
  90. ("'u" . [?ú])
  91. ("'y" . [?ý])
  92. ("*$" . [?¤])
  93. ("$" . [?¤])
  94. ("*+" . [?±])
  95. ("+" . [?±])
  96. (",," . [?¸])
  97. (",C" . [?Ç])
  98. (",c" . [?ç])
  99. ("*-" . [?­])
  100. ("-" . [?­])
  101. ("*." . [?·])
  102. ("." . [?·])
  103. ("//" . [?÷])
  104. ("/A" . [?Å])
  105. ("/E" . [?Æ])
  106. ("/O" . [?Ø])
  107. ("/a" . [?å])
  108. ("/e" . [?æ])
  109. ("/o" . [?ø])
  110. ("1/2" . [?½])
  111. ("1/4" . [?¼])
  112. ("3/4" . [?¾])
  113. ("*<" . [?«])
  114. ("<" . [?«])
  115. ("*=" . [?¯])
  116. ("=" . [?¯])
  117. ("*>" . [?»])
  118. (">" . [?»])
  119. ("*?" . [?¿])
  120. ("?" . [?¿])
  121. ("*C" . [?©])
  122. ("C" . [?©])
  123. ("*L" . [?£])
  124. ("L" . [?£])
  125. ("*P" . [?¶])
  126. ("P" . [?¶])
  127. ("*R" . [?®])
  128. ("R" . [?®])
  129. ("*S" . [?§])
  130. ("S" . [?§])
  131. ("*Y" . [?¥])
  132. ("Y" . [?¥])
  133. ("^1" . [?¹])
  134. ("^2" . [?²])
  135. ("^3" . [?³])
  136. ("^A" . [?Â])
  137. ("^E" . [?Ê])
  138. ("^I" . [?Î])
  139. ("^O" . [?Ô])
  140. ("^U" . [?Û])
  141. ("^a" . [?â])
  142. ("^e" . [?ê])
  143. ("^i" . [?î])
  144. ("^o" . [?ô])
  145. ("^u" . [?û])
  146. ("_a" . [?ª])
  147. ("_o" . [?º])
  148. ("`A" . [?À])
  149. ("`E" . [?È])
  150. ("`I" . [?Ì])
  151. ("`O" . [?Ò])
  152. ("`U" . [?Ù])
  153. ("`a" . [?à])
  154. ("`e" . [?è])
  155. ("`i" . [?ì])
  156. ("`o" . [?ò])
  157. ("`u" . [?ù])
  158. ("*c" . [?¢])
  159. ("c" . [?¢])
  160. ("*o" . [?°])
  161. ("o" . [?°])
  162. ("*u" . [?µ])
  163. ("u" . [?µ])
  164. ("*m" . [?µ])
  165. ("m" . [?µ])
  166. ("*x" . [?×])
  167. ("x" . [?×])
  168. ("*|" . [?¦])
  169. ("|" . [?¦])
  170. ("~A" . [?Ã])
  171. ("~D" . [?Ð])
  172. ("~N" . [?Ñ])
  173. ("~O" . [?Õ])
  174. ("~T" . [?Þ])
  175. ("~a" . [?ã])
  176. ("~d" . [?ð])
  177. ("~n" . [?ñ])
  178. ("~o" . [?õ])
  179. ("~t" . [?þ])
  180. ("~~" . [?¬])
  181. ("' " . "'")
  182. ("` " . "`")
  183. ("\" " . "\"")
  184. ("^ " . "^")
  185. ("~ " . "~"))
  186. "Alist of character translations for entering ISO characters.
  187. Each element has the form (STRING . VECTOR).
  188. The sequence STRING of ASCII chars translates into the
  189. sequence VECTOR. (VECTOR is normally one character long.)")
  190. ;; Language-specific translation lists.
  191. (defvar iso-transl-language-alist
  192. '(("Esperanto"
  193. ("C" . [?Æ])
  194. ("G" . [?Ø])
  195. ("H" . [?¦])
  196. ("J" . [?¬])
  197. ("S" . [?Þ])
  198. ("U" . [?Ý])
  199. ("c" . [?æ])
  200. ("g" . [?ø])
  201. ("h" . [?¶])
  202. ("j" . [?¼])
  203. ("s" . [?þ])
  204. ("u" . [?ý]))
  205. ("French"
  206. ("C" . [?Ç])
  207. ("c" . [?ç]))
  208. ("German"
  209. ("A" . [?Ä])
  210. ("O" . [?Ö])
  211. ("U" . [?Ü])
  212. ("a" . [?ä])
  213. ("o" . [?ö])
  214. ("s" . [?ß])
  215. ("u" . [?ü]))
  216. ("Portuguese"
  217. ("C" . [?Ç])
  218. ("c" . [?ç]))
  219. ("Spanish"
  220. ("!" . [?¡])
  221. ("?" . [?¿])
  222. ("N" . [?Ñ])
  223. ("n" . [?ñ]))))
  224. (defvar iso-transl-ctl-x-8-map nil
  225. "Keymap for C-x 8 prefix.")
  226. (or iso-transl-ctl-x-8-map
  227. (fset 'iso-transl-ctl-x-8-map
  228. (setq iso-transl-ctl-x-8-map (make-sparse-keymap))))
  229. (or key-translation-map
  230. (setq key-translation-map (make-sparse-keymap)))
  231. (define-key key-translation-map "\C-x8" iso-transl-ctl-x-8-map)
  232. ;; For each entry in the alist, we'll make up to three ways to generate
  233. ;; the character in question: the prefix `C-x 8'; the ALT modifier on
  234. ;; the first key of the sequence; and (if applicable) replacing the first
  235. ;; key of the sequence with the corresponding dead key. For example, a
  236. ;; character associated with the string "~n" can be input with `C-x 8 ~ n'
  237. ;; or `Alt-~ n' or `mute-asciitilde n'.
  238. (defun iso-transl-define-keys (alist)
  239. (while alist
  240. (let ((translated-vec (cdr (car alist))))
  241. (define-key iso-transl-ctl-x-8-map (car (car alist)) translated-vec)
  242. (let ((inchar (aref (car (car alist)) 0))
  243. (vec (vconcat (car (car alist))))
  244. (tail iso-transl-dead-key-alist))
  245. (aset vec 0 (logior (aref vec 0) ?\A-\^@))
  246. (define-key key-translation-map vec translated-vec)
  247. (define-key isearch-mode-map (vector (aref vec 0)) nil)
  248. (while tail
  249. (if (eq (car (car tail)) inchar)
  250. (let ((deadvec (copy-sequence vec))
  251. (deadkey (cdr (car tail))))
  252. (aset deadvec 0 deadkey)
  253. (define-key isearch-mode-map (vector deadkey) nil)
  254. (define-key key-translation-map deadvec translated-vec)))
  255. (setq tail (cdr tail)))))
  256. (setq alist (cdr alist))))
  257. (defun iso-transl-set-language (lang)
  258. (interactive (list (let ((completion-ignore-case t))
  259. (completing-read "Set which language? "
  260. iso-transl-language-alist nil t))))
  261. (iso-transl-define-keys (cdr (assoc lang iso-transl-language-alist))))
  262. ;; The standard mapping comes automatically. You can partially overlay it
  263. ;; with a language-specific mapping by using `M-x iso-transl-set-language'.
  264. (iso-transl-define-keys iso-transl-char-map)
  265. (define-key isearch-mode-map "\C-x" nil)
  266. (define-key isearch-mode-map [?\C-x t] 'isearch-other-control-char)
  267. (define-key isearch-mode-map "\C-x8" nil)
  268. (provide 'iso-transl)
  269. ;;; iso-transl.el ends here