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