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