(iso-translate-conventions): Use case-dependent search and don't alter case.
[bpt/emacs.git] / lisp / international / iso-acc.el
CommitLineData
bf4de26a 1;;; iso-acc.el -- minor mode providing electric accent keys
8f1204db 2;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
bf4de26a
RS
3
4;; Author: Johan Vromans <jv@mh.nl>
a2b2b91b 5;; Version: 1.7 (modified)
7ab500f0
RS
6;; Maintainer: FSF
7;; Keywords: i18n
bf4de26a
RS
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
9c89d223
RS
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.
bf4de26a
RS
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
7ab500f0
RS
39;; ^ (caret) -> circumflex
40;; ~ (tilde) -> tilde over the character
41;; / (slash) -> slash through the character.
a2b2b91b 42;; Also: /A is A-with-ring and /E is AE ligature.
bf4de26a
RS
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;;
8669cecf
RS
56;; Function `iso-accents-mode' can be used to enable the iso accents
57;; minor mode, or disable it.
6da676ad
RS
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.
bf4de26a
RS
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)
7ab500f0 72 ((?' ?Y) ?\335)
bf4de26a
RS
73 ((?' ?a) ?\341)
74 ((?' ?e) ?\351)
75 ((?' ?i) ?\355)
76 ((?' ?o) ?\363)
77 ((?' ?u) ?\372)
1784bc32 78 ((?' ?y) ?\375)
bf4de26a
RS
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?
4d524b08 93 ((?^ ?A) ?\302)
bf4de26a
RS
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)
ab4d6ceb 114 ((?\" ?s) ?\337)
bf4de26a 115 ((?\" ?u) ?\374)
7ab500f0 116 ((?\" ?y) ?\377)
bf4de26a
RS
117 ((?\" ? ) ?\")
118 ((?\" ?\") ?\250)
7ab500f0
RS
119 ((?\~ ?A) ?\303)
120 ((?\~ ?C) ?\307)
121 ((?\~ ?D) ?\320)
122 ((?\~ ?N) ?\321)
123 ((?\~ ?O) ?\325)
124 ((?\~ ?a) ?\343)
1784bc32 125 ((?\~ ?c) ?\347)
7ab500f0
RS
126 ((?\~ ?d) ?\360)
127 ((?\~ ?n) ?\361)
128 ((?\~ ?o) ?\365)
4d524b08
RS
129 ((?\~ ?>) ?\273)
130 ((?\~ ?<) ?\253)
ea9e2543
KH
131 ((?\~ ?\ ) ?\~)
132 ((?\~ ?\~) ?\270) ;; cedilla accent
a2b2b91b
RS
133 ((?\/ ?A) ?\305) ;; A-with-ring (Norwegian and Danish)
134 ((?\/ ?E) ?\306) ;; AE-ligature (Norwegian and Danish)
7ab500f0 135 ((?\/ ?O) ?\330)
a2b2b91b
RS
136 ((?\/ ?a) ?\345) ;; a-with-ring (Norwegian and Danish)
137 ((?\/ ?e) ?\346) ;; ae-ligature (Norwegian and Danish)
7ab500f0 138 ((?\/ ?o) ?\370)
ea9e2543
KH
139 ((?\/ ?\ ) ?\/)
140 ((?\/ ?\/) ?\260) ;; ring accent (actually degree sign?)
bf4de26a 141 )
8669cecf 142 "Association list for ISO accent combinations.")
bf4de26a 143
bf4de26a 144(defvar iso-accents-minor-mode nil
884f2b81 145 "*Non-nil enables ISO Accents mode.
9c89d223 146Setting this variable makes it local to the current buffer.
2051e259 147See `iso-accents-mode'.")
9c89d223 148(make-variable-buffer-local 'iso-accents-minor-mode)
bf4de26a 149
da8d0b9e
RS
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)))
9c89d223 156
da8d0b9e
RS
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
6da676ad
RS
191(defvar iso-accents-enable '(?' ?` ?^ ?\" ?~ ?/)
192 "*List of accent keys that become prefixes in ISO Accents mode.
193The default is (?' ?` ?^ ?\" ?~ ?/), which contains all the supported
194accent keys. For certain languages, you might want to remove some of
195those characters that are not actually used.")
196
da8d0b9e
RS
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.
6da676ad
RS
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))
9c89d223 212
bf4de26a
RS
213;; It is a matter of taste if you want the minor mode indicated
214;; in the mode line...
9c89d223 215;; If so, uncomment the next four lines.
bf4de26a
RS
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
8669cecf 222(defun iso-accents-mode (&optional arg)
884f2b81 223 "Toggle ISO Accents mode, in which accents modify the following letter.
8669cecf
RS
224This permits easy insertion of accented characters according to ISO-8859-1.
225When Iso-accents mode is enabled, accent character keys
7ab500f0 226\(`, ', \", ^, / and ~) do not self-insert; instead, they modify the following
8669cecf
RS
227letter key so that it inserts an ISO accented letter.
228
6da676ad
RS
229The variable `iso-accents-enable' specifies the list of characters to
230enable as accents. If you don't need all of them, remove the ones you
231don't need from that list.
232
7ab500f0
RS
233Special combinations: ~c gives a c with cedilla,
234~d gives a d with dash.
ab4d6ceb
RS
235\"s gives German sharp s.
236/a gives a with ring.
237/e gives an a-e ligature.
4d524b08 238~< and ~> give guillemets.
7ab500f0 239
6da676ad 240With an argument, a positive argument enables ISO Accents mode,
8669cecf 241and a negative argument disables it."
bf4de26a
RS
242
243 (interactive "P")
244
8669cecf
RS
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)
bf4de26a
RS
250 (setq iso-accents-minor-mode nil)
251
252 ;; Enable electric accents.
9c89d223 253 (setq iso-accents-minor-mode t)))
bf4de26a
RS
254
255;;; iso-acc.el ends here