(iso-translate-conventions): Use case-dependent search and don't alter case.
[bpt/emacs.git] / lisp / international / iso-acc.el
1 ;;; iso-acc.el -- minor mode providing electric accent keys
2 ;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
3
4 ;; Author: Johan Vromans <jv@mh.nl>
5 ;; Version: 1.7 (modified)
6 ;; Maintainer: FSF
7 ;; Keywords: i18n
8
9 ;; This file is part of GNU Emacs.
10
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 2, or (at your option)
14 ;; any later version.
15
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.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;;; Commentary:
26
27 ;; Function `iso-accents-mode' activates a minor mode
28 ;; (`iso-accents-minor-mode') in which typewriter "dead keys" are
29 ;; emulated. The purpose of this emulation is to provide a simple
30 ;; means for inserting accented characters according to the ISO-8859-1
31 ;; character set.
32 ;;
33 ;; In `iso-accents-minor-mode', pseudo accent characters are used to
34 ;; introduce accented keys. The pseudo-accent characterss are:
35 ;;
36 ;; ' (minute) -> grave accent
37 ;; ` (backtick) -> acute accent
38 ;; " (second) -> diaeresis
39 ;; ^ (caret) -> circumflex
40 ;; ~ (tilde) -> tilde over the character
41 ;; / (slash) -> slash through the character.
42 ;; Also: /A is A-with-ring and /E is AE ligature.
43 ;;
44 ;; The action taken depends on the key that follows the pseudo accent.
45 ;; In general:
46 ;;
47 ;; pseudo-accent + appropriate letter -> accented letter
48 ;; pseudo-accent + space -> pseudo-accent
49 ;; pseudo-accent + pseudo-accent -> accent (if available)
50 ;; pseudo-accent + other -> pseudo-accent + other
51 ;;
52 ;; If the pseudo-accent is followed by anything else than a
53 ;; self-insert-command, the dead-key code is terminated, the
54 ;; pseudo-accent inserted 'as is' and the bell is rung to signal this.
55 ;;
56 ;; Function `iso-accents-mode' can be used to enable the iso accents
57 ;; minor mode, or disable it.
58
59 ;; If you want only some of these characters to serve as accents,
60 ;; set iso-accents-enable to the list of characters that should be special.
61 \f
62 ;;; Code:
63
64 (provide 'iso-acc)
65
66 (defvar iso-accents-list
67 '(((?' ?A) ?\301)
68 ((?' ?E) ?\311)
69 ((?' ?I) ?\315)
70 ((?' ?O) ?\323)
71 ((?' ?U) ?\332)
72 ((?' ?Y) ?\335)
73 ((?' ?a) ?\341)
74 ((?' ?e) ?\351)
75 ((?' ?i) ?\355)
76 ((?' ?o) ?\363)
77 ((?' ?u) ?\372)
78 ((?' ?y) ?\375)
79 ((?' ?') ?\264)
80 ((?' ? ) ?')
81 ((?` ?A) ?\300)
82 ((?` ?E) ?\310)
83 ((?` ?I) ?\314)
84 ((?` ?O) ?\322)
85 ((?` ?U) ?\331)
86 ((?` ?a) ?\340)
87 ((?` ?e) ?\350)
88 ((?` ?i) ?\354)
89 ((?` ?o) ?\362)
90 ((?` ?u) ?\371)
91 ((?` ? ) ?`)
92 ((?` ?`) ?`) ; no special code?
93 ((?^ ?A) ?\302)
94 ((?^ ?E) ?\312)
95 ((?^ ?I) ?\316)
96 ((?^ ?O) ?\324)
97 ((?^ ?U) ?\333)
98 ((?^ ?a) ?\342)
99 ((?^ ?e) ?\352)
100 ((?^ ?i) ?\356)
101 ((?^ ?o) ?\364)
102 ((?^ ?u) ?\373)
103 ((?^ ? ) ?^)
104 ((?^ ?^) ?^) ; no special code?
105 ((?\" ?A) ?\304)
106 ((?\" ?E) ?\313)
107 ((?\" ?I) ?\317)
108 ((?\" ?O) ?\326)
109 ((?\" ?U) ?\334)
110 ((?\" ?a) ?\344)
111 ((?\" ?e) ?\353)
112 ((?\" ?i) ?\357)
113 ((?\" ?o) ?\366)
114 ((?\" ?s) ?\337)
115 ((?\" ?u) ?\374)
116 ((?\" ?y) ?\377)
117 ((?\" ? ) ?\")
118 ((?\" ?\") ?\250)
119 ((?\~ ?A) ?\303)
120 ((?\~ ?C) ?\307)
121 ((?\~ ?D) ?\320)
122 ((?\~ ?N) ?\321)
123 ((?\~ ?O) ?\325)
124 ((?\~ ?a) ?\343)
125 ((?\~ ?c) ?\347)
126 ((?\~ ?d) ?\360)
127 ((?\~ ?n) ?\361)
128 ((?\~ ?o) ?\365)
129 ((?\~ ?>) ?\273)
130 ((?\~ ?<) ?\253)
131 ((?\~ ?\ ) ?\~)
132 ((?\~ ?\~) ?\270) ;; cedilla accent
133 ((?\/ ?A) ?\305) ;; A-with-ring (Norwegian and Danish)
134 ((?\/ ?E) ?\306) ;; AE-ligature (Norwegian and Danish)
135 ((?\/ ?O) ?\330)
136 ((?\/ ?a) ?\345) ;; a-with-ring (Norwegian and Danish)
137 ((?\/ ?e) ?\346) ;; ae-ligature (Norwegian and Danish)
138 ((?\/ ?o) ?\370)
139 ((?\/ ?\ ) ?\/)
140 ((?\/ ?\/) ?\260) ;; ring accent (actually degree sign?)
141 )
142 "Association list for ISO accent combinations.")
143
144 (defvar iso-accents-minor-mode nil
145 "*Non-nil enables ISO Accents mode.
146 Setting this variable makes it local to the current buffer.
147 See `iso-accents-mode'.")
148 (make-variable-buffer-local 'iso-accents-minor-mode)
149
150 (defun iso-accents-accent-key (prompt)
151 "Modify the following character by adding an accent to it."
152 ;; Pick up the accent character.
153 (if iso-accents-minor-mode
154 (iso-accents-compose prompt)
155 (char-to-string last-input-char)))
156
157 (defun iso-accents-compose-key (prompt)
158 "Modify the following character by adding an accent to it."
159 ;; Pick up the accent character.
160 (let ((combined (iso-accents-compose prompt)))
161 (if unread-command-events
162 (let ((unread unread-command-events))
163 (setq unread-command-events nil)
164 (error "Characters %s and %s cannot be composed"
165 (single-key-description (aref combined 0))
166 (single-key-description (car unread)))))
167 combined))
168
169 (defun iso-accents-compose (prompt)
170 (let* ((first-char last-input-char)
171 ;; Wait for the second key and look up the combination.
172 (second-char (if (or prompt
173 (not (eq (key-binding "a")
174 'self-insert-command)))
175 (progn
176 (message "%s%c"
177 (or prompt "Compose with ")
178 first-char)
179 (read-event))
180 (insert first-char)
181 (prog1 (read-event)
182 (delete-region (1- (point)) (point)))))
183 (entry (assoc (list first-char second-char) iso-accents-list)))
184 (if entry
185 ;; Found it: delete the first character and insert the combination.
186 (concat (list (nth 1 entry)))
187 ;; Otherwise, advance and schedule the second key for execution.
188 (setq unread-command-events (list second-char))
189 (vector first-char))))
190
191 (defvar iso-accents-enable '(?' ?` ?^ ?\" ?~ ?/)
192 "*List of accent keys that become prefixes in ISO Accents mode.
193 The default is (?' ?` ?^ ?\" ?~ ?/), which contains all the supported
194 accent keys. For certain languages, you might want to remove some of
195 those characters that are not actually used.")
196
197 (or key-translation-map (setq key-translation-map (make-sparse-keymap)))
198 ;; For sequences starting with an accent character,
199 ;; use a function that tests iso-accents-minor-mode.
200 (if (memq ?' iso-accents-enable)
201 (define-key key-translation-map "'" 'iso-accents-accent-key))
202 (if (memq ?` iso-accents-enable)
203 (define-key key-translation-map "`" 'iso-accents-accent-key))
204 (if (memq ?^ iso-accents-enable)
205 (define-key key-translation-map "^" 'iso-accents-accent-key))
206 (if (memq ?\" iso-accents-enable)
207 (define-key key-translation-map "\"" 'iso-accents-accent-key))
208 (if (memq ?~ iso-accents-enable)
209 (define-key key-translation-map "~" 'iso-accents-accent-key))
210 (if (memq ?/ iso-accents-enable)
211 (define-key key-translation-map "/" 'iso-accents-accent-key))
212
213 ;; It is a matter of taste if you want the minor mode indicated
214 ;; in the mode line...
215 ;; If so, uncomment the next four lines.
216 ;; (or (assq 'iso-accents-minor-mode minor-mode-map-alist)
217 ;; (setq minor-mode-alist
218 ;; (append minor-mode-alist
219 ;; '((iso-accents-minor-mode " ISO-Acc")))))
220
221 ;;;###autoload
222 (defun iso-accents-mode (&optional arg)
223 "Toggle ISO Accents mode, in which accents modify the following letter.
224 This permits easy insertion of accented characters according to ISO-8859-1.
225 When Iso-accents mode is enabled, accent character keys
226 \(`, ', \", ^, / and ~) do not self-insert; instead, they modify the following
227 letter key so that it inserts an ISO accented letter.
228
229 The variable `iso-accents-enable' specifies the list of characters to
230 enable as accents. If you don't need all of them, remove the ones you
231 don't need from that list.
232
233 Special combinations: ~c gives a c with cedilla,
234 ~d gives a d with dash.
235 \"s gives German sharp s.
236 /a gives a with ring.
237 /e gives an a-e ligature.
238 ~< and ~> give guillemets.
239
240 With an argument, a positive argument enables ISO Accents mode,
241 and a negative argument disables it."
242
243 (interactive "P")
244
245 (if (if arg
246 ;; Negative arg means switch it off.
247 (<= (prefix-numeric-value arg) 0)
248 ;; No arg means toggle.
249 iso-accents-minor-mode)
250 (setq iso-accents-minor-mode nil)
251
252 ;; Enable electric accents.
253 (setq iso-accents-minor-mode t)))
254
255 ;;; iso-acc.el ends here