4
|
1 ;;; iso-acc.el --- minor mode providing electric accent keys
|
|
2
|
|
3 ;; Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
|
4
|
153
|
5 ;; Author: Johan Vromans
|
94
|
6 ;; Maintainer: Alexandre Oliva <oliva@dcc.unicamp.br>
|
4
|
7 ;; Keywords: i18n
|
153
|
8 ;; $Revision: 1.5 $
|
|
9 ;; $Date: 1997/05/29 23:49:45 $
|
4
|
10
|
|
11 ;; This file is part of GNU Emacs.
|
|
12
|
|
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
14 ;; it under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;; GNU General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; Function `iso-accents-mode' activates a minor mode in which
|
|
31 ;; typewriter "dead keys" are emulated. The purpose of this emulation
|
|
32 ;; is to provide a simple means for inserting accented characters
|
153
|
33 ;; according to the ISO-8859-1 and other character sets.
|
4
|
34 ;;
|
|
35 ;; In `iso-accents-mode', pseudo accent characters are used to
|
|
36 ;; introduce accented keys. The pseudo-accent characters are:
|
|
37 ;;
|
|
38 ;; ' (minute) -> grave accent
|
|
39 ;; ` (backtick) -> acute accent
|
|
40 ;; " (second) -> diaeresis
|
|
41 ;; ^ (caret) -> circumflex
|
|
42 ;; ~ (tilde) -> tilde over the character
|
94
|
43 ;; / (slash) -> slash through the character
|
153
|
44 ;; Also: /A is A-with-ring and /E is AE ligature.
|
94
|
45 ;; . (dot) -> dot over the character
|
153
|
46 ;; , (cedilla) -> cedilla under the character (some languages only)
|
4
|
47 ;;
|
|
48 ;; The action taken depends on the key that follows the pseudo accent.
|
|
49 ;; In general:
|
|
50 ;;
|
|
51 ;; pseudo-accent + appropriate letter -> accented letter
|
94
|
52 ;; pseudo-accent + space -> pseudo-accent (except comma)
|
4
|
53 ;; pseudo-accent + pseudo-accent -> accent (if available)
|
|
54 ;; pseudo-accent + other -> pseudo-accent + other
|
|
55 ;;
|
|
56 ;; If the pseudo-accent is followed by anything else than a
|
|
57 ;; self-insert-command, the dead-key code is terminated, the
|
|
58 ;; pseudo-accent inserted 'as is' and the bell is rung to signal this.
|
|
59 ;;
|
|
60 ;; Function `iso-accents-mode' can be used to enable the iso accents
|
|
61 ;; minor mode, or disable it.
|
|
62
|
|
63 ;; If you want only some of these characters to serve as accents,
|
|
64 ;; add a language to `iso-languages' which specifies the accent characters
|
|
65 ;; that you want, then select the language with `iso-accents-customize'.
|
|
66
|
|
67 ;;; Code:
|
|
68
|
|
69 (provide 'iso-acc)
|
|
70
|
153
|
71 ;; multiple Emacs versions compatibility section
|
|
72
|
|
73 (if (fboundp 'make-char)
|
|
74 (defalias 'iso-make-char 'make-char)
|
|
75 (defun iso-make-char (charset) 128))
|
|
76
|
144
|
77 (if (fboundp 'read-event)
|
|
78 (defalias 'iso-read-event 'read-event)
|
|
79 (defun iso-read-event ()
|
|
80 (event-key (next-command-event))))
|
4
|
81
|
94
|
82 (if (fboundp 'character-to-event)
|
153
|
83 (progn
|
|
84 (defun iso-char-list-to-event (l)
|
|
85 "returns an event containing the given list of characters"
|
|
86 (character-to-event l))
|
|
87 (defun iso-char-to-event (ch)
|
|
88 "returns an event containing the given character"
|
|
89 (iso-char-list-to-event (list ch))))
|
|
90 (defalias 'iso-char-to-event 'identity)
|
|
91 (defalias 'iso-char-list-to-event 'identity))
|
4
|
92
|
|
93 (if (fboundp 'this-single-command-keys) ()
|
|
94 (if (string-match "Lucid" (version))
|
|
95 (defun this-single-command-keys ()
|
|
96 (setq this-command (not (this-command-keys)))
|
|
97 (this-command-keys))
|
|
98 (defun this-single-command-keys () (this-command-keys))))
|
|
99
|
153
|
100 (defvar iso-accents-insert-offset
|
|
101 (if (boundp 'nonascii-insert-offset)
|
|
102 nonascii-insert-offset
|
|
103 0)
|
|
104 "*Offset added by ISO Accents mode to character codes 0200 and above.")
|
|
105
|
|
106 ;; end of compatibility section
|
94
|
107
|
4
|
108 (defvar iso-languages
|
153
|
109 '(("catalan"
|
|
110 ;; Note this includes some extra characters used in Spanish,
|
|
111 ;; on the idea that someone who uses Catalan is likely to use Spanish
|
|
112 ;; as well.
|
|
113 (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
|
|
114 (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363) (?u . ?\372)
|
|
115 (?\ . ?'))
|
|
116 (?` (?A . ?\300) (?E . ?\310) (?O . ?\322)
|
|
117 (?a . ?\340) (?e . ?\350) (?o . ?\362) (?\ . ?`))
|
|
118 (?\" (?I . ?\317) (?U . ?\334) (?i . ?\357) (?u . ?\374) (?\ . ?\"))
|
|
119 (?~ (?C . ?\307) (?N . ?\321) (?c . ?\347) (?n . ?\361)
|
|
120 (?> . ?\273) (?< . ?\253) (?! . ?\241) (?? . ?\277)
|
|
121 (?\ . ?~)))
|
|
122
|
|
123 ("esperanto"
|
|
124 (?^ (?H . ?\246) (?J . ?\254) (?h . ?\266) (?j . ?\274) (?C . ?\306)
|
|
125 (?G . ?\330) (?S . ?\336) (?c . ?\346) (?g . ?\370) (?s . ?\376)
|
|
126 (?^ . ?^) (?\ . ?^))
|
|
127 (?~ (?U . ?\335) (?u . ?\375) (?\ . ?~)))
|
|
128
|
|
129 ("french"
|
|
130 (?' (?E . ?\311) (?C . ?\307)
|
|
131 (?e . ?\351) (?c . ?\347)
|
|
132 (?\ . ?') (space . ?'))
|
|
133 (?` (?A . ?\300) (?E . ?\310) (?U . ?\331)
|
|
134 (?a . ?\340) (?e . ?\350) (?u . ?\371)
|
|
135 (?\ . ?`) (space . ?`))
|
|
136 (?^ (?A . ?\302) (?E . ?\312) (?I . ?\316) (?O . ?\324) (?U . ?\333)
|
|
137 (?a . ?\342) (?e . ?\352) (?i . ?\356) (?o . ?\364) (?u . ?\373)
|
|
138 (?\ . ?^) (space . ?^))
|
|
139 (?\" (?E . ?\313) (?I . ?\317)
|
|
140 (?e . ?\353) (?i . ?\357)
|
|
141 (?\ . ?\") (space . ?\"))
|
|
142 (?~ (?< . ?\253) (?> . ?\273)
|
|
143 (?C . ?\307) (?c . ?\347)
|
|
144 (?\ . ?~) (space . ?~))
|
|
145 (?, (?c . ?\347) (?C . ?\307) (?, . ?,)))
|
|
146
|
|
147 ("german"
|
|
148 (?\" (?A . ?\304) (?O . ?\326) (?U . ?\334)
|
|
149 (?a . ?\344) (?o . ?\366) (?u . ?\374) (?s . ?\337) (?\ . ?\")))
|
|
150
|
|
151 ("irish"
|
|
152 (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
|
|
153 (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363) (?u . ?\372)
|
|
154 (?\ . ?') (space . ?')))
|
|
155
|
|
156 ("portuguese"
|
4
|
157 (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
|
|
158 (?C . ?\307) (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363)
|
|
159 (?u . ?\372) (?c . ?\347) (?\ . ?') (space . ?'))
|
|
160 (?` (?A . ?\300) (?a . ?\340) (?\ . ?`) (space . ?`))
|
|
161 (?^ (?A . ?\302) (?E . ?\312) (?O . ?\324) (?a . ?\342) (?e . ?\352)
|
|
162 (?o . ?\364) (?\ . ?^) (space . ?^))
|
|
163 (?\" (?U . ?\334) (?u . ?\374) (?\ . ?\") (space . ?\"))
|
153
|
164 (?~ (?A . ?\303) (?O . ?\325)
|
|
165 (?a . ?\343) (?o . ?\365)
|
|
166 (?\ . ?~) (space . ?~))
|
|
167 (?, (?c . ?\347) (?C . ?\307) (?, . ?,)))
|
|
168
|
|
169 ("spanish"
|
4
|
170 (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
|
|
171 (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363) (?u . ?\372)
|
153
|
172 (?\ . ?'))
|
|
173 (?\" (?U . ?\334) (?u . ?\374) (?\ . ?\"))
|
|
174 (?~ (?N . ?\321) (?n . ?\361) (?> . ?\273) (?< . ?\253) (?! . ?\241)
|
|
175 (?? . ?\277) (?\ . ?~)))
|
4
|
176
|
|
177 ("latin-1"
|
|
178 (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
|
|
179 (?Y . ?\335) (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363)
|
|
180 (?u . ?\372) (?y . ?\375) (?' . ?\264) (?\ . ?') (space . ?'))
|
|
181 (?` (?A . ?\300) (?E . ?\310) (?I . ?\314) (?O . ?\322) (?U . ?\331)
|
|
182 (?a . ?\340) (?e . ?\350) (?i . ?\354) (?o . ?\362) (?u . ?\371)
|
|
183 (?` . ?`) (?\ . ?`) (space . ?`))
|
|
184 (?^ (?A . ?\302) (?E . ?\312) (?I . ?\316) (?O . ?\324) (?U . ?\333)
|
|
185 (?a . ?\342) (?e . ?\352) (?i . ?\356) (?o . ?\364) (?u . ?\373)
|
|
186 (?^ . ?^) (?\ . ?^) (space . ?^))
|
|
187 (?\" (?A . ?\304) (?E . ?\313) (?I . ?\317) (?O . ?\326) (?U . ?\334)
|
|
188 (?a . ?\344) (?e . ?\353) (?i . ?\357) (?o . ?\366) (?s . ?\337)
|
|
189 (?u . ?\374) (?y . ?\377) (?\" . ?\250) (?\ . ?\") (space . ?\"))
|
153
|
190 (?~ (?A . ?\303) (?C . ?\307) (?D . ?\320) (?N . ?\321) (?O . ?\325)
|
|
191 (?T . ?\336) (?a . ?\343) (?c . ?\347) (?d . ?\360) (?n . ?\361)
|
|
192 (?o . ?\365) (?t . ?\376) (?> . ?\273) (?< . ?\253) (?~ . ?\270)
|
|
193 (?! . ?\241) (?? . ?\277)
|
|
194 (?\ . ?~) (space . ?~))
|
|
195 (?/ (?A . ?\305) (?E . ?\306) (?O . ?\330) (?a . ?\345) (?e . ?\346)
|
|
196 (?o . ?\370) (?/ . ?\260) (?\ . ?/) (space . ?/)))
|
|
197
|
|
198 ("latin-2" latin-iso8859-2
|
|
199 (?' (?A . ?\301) (?C . ?\306) (?D . ?\320) (?E . ?\311) (?I . ?\315)
|
|
200 (?L . ?\305) (?N . ?\321) (?O . ?\323) (?R . ?\300) (?S . ?\246)
|
|
201 (?U . ?\332) (?Y . ?\335) (?Z . ?\254)
|
|
202 (?a . ?\341) (?c . ?\346) (?d . ?\360) (?e . ?\351) (?i . ?\355)
|
|
203 (?l . ?\345) (?n . ?\361) (?o . ?\363) (?r . ?\340) (?s . ?\266)
|
|
204 (?u . ?\372) (?y . ?\375) (?z . ?\274)
|
|
205 (?' . ?\264) (?\ . ?') (space . ?'))
|
|
206 (?` (?A . ?\241) (?C . ?\307) (?E . ?\312) (?L . ?\243) (?S . ?\252)
|
|
207 (?T . ?\336) (?Z . ?\257)
|
|
208 (?a . ?\261) (?l . ?\263) (?c . ?\347) (?e . ?\352) (?s . ?\272)
|
|
209 (?t . ?\376) (?z . ?\277)
|
|
210 (?` . ?\252)
|
|
211 (?. . ?\377) (?\ . ?`) (space . ?`))
|
|
212 (?^ (?A . ?\302) (?I . ?\316) (?O . ?\324)
|
|
213 (?a . ?\342) (?i . ?\356) (?o . ?\364)
|
|
214 (?^ . ?^) ; no special code?
|
|
215 (?\ . ?^) (space . ?^))
|
|
216 (?\" (?A . ?\304) (?E . ?\313) (?O . ?\326) (?U . ?\334)
|
|
217 (?a . ?\344) (?e . ?\353) (?o . ?\366) (?s . ?\337) (?u . ?\374)
|
|
218 (?\" . ?\250)
|
|
219 (?\ . ?\") (space . ?\"))
|
|
220 (?~ (?A . ?\303) (?C . ?\310) (?D . ?\317) (?L . ?\245) (?N . ?\322)
|
|
221 (?O . ?\325) (?R . ?\330) (?S . ?\251) (?T . ?\253) (?U . ?\333)
|
|
222 (?Z . ?\256)
|
|
223 (?a . ?\343) (?c . ?\350) (?d . ?\357) (?l . ?\265) (?n . ?\362)
|
|
224 (?o . ?\365) (?r . ?\370) (?s . ?\271) (?t . ?\273) (?u . ?\373)
|
|
225 (?z . ?\276)
|
|
226 (?v . ?\242) ; v accent
|
|
227 (?~ . ?\242) ; v accent
|
|
228 (?. . ?\270) ; cedilla accent
|
|
229 (?\ . ?~) (space . ?~)))
|
|
230
|
|
231 ("latin-3" latin-iso8859-3
|
|
232 (?' (?A . ?\301) (?E . ?\311) (?I . ?\315) (?O . ?\323) (?U . ?\332)
|
|
233 (?a . ?\341) (?e . ?\351) (?i . ?\355) (?o . ?\363) (?u . ?\372)
|
|
234 (?' . ?\264) (?\ . ?') (space . ?'))
|
|
235 (?` (?A . ?\300) (?E . ?\310) (?I . ?\314) (?O . ?\322) (?U . ?\331)
|
|
236 (?a . ?\340) (?e . ?\350) (?i . ?\354) (?o . ?\362) (?u . ?\371)
|
|
237 (?` . ?`) (?\ . ?`) (space . ?`))
|
|
238 (?^ (?A . ?\302) (?C . ?\306) (?E . ?\312) (?G . ?\330)
|
|
239 (?H . ?\246) (?I . ?\316) (?J . ?\254) (?O . ?\324)
|
|
240 (?S . ?\336) (?U . ?\333)
|
|
241 (?a . ?\342) (?c . ?\346) (?e . ?\352) (?g . ?\370) (?h . ?\266)
|
|
242 (?i . ?\356) (?j . ?\274) (?o . ?\364) (?s . ?\376) (?u . ?\373)
|
|
243 (?^ . ?^) (?\ . ?^) (space . \^))
|
|
244 (?\" (?A . ?\304) (?E . ?\313) (?I . ?\317) (?O . ?\326) (?U . ?\334)
|
|
245 (?a . ?\344) (?e . ?\353) (?i . ?\357) (?o . ?\366) (?u . ?\374)
|
|
246 (?s . ?\337)
|
|
247 (?\" . ?\250) (?\ . ?\") (space . ?\"))
|
|
248 (?. (?C . ?\305) (?G . ?\325) (?I . ?\251) (?Z . ?\257)
|
|
249 (?c . ?\345) (?g . ?\365) (?z . ?\277))
|
|
250 (?~ (?A . ?\303) (?C . ?\307) (?D . ?\320) (?G . ?\253) (?N . ?\321)
|
|
251 (?O . ?\325) (?S . ?\252) (?U . ?\335)
|
|
252 (?a . ?\343) (?c . ?\347) (?d . ?\360) (?g . ?\273) (?n . ?\361)
|
|
253 (?o . ?\365) (?s . ?\252) (?u . ?\375)
|
|
254 (?h . ?\261) (?$ . ?\245) (?` . ?\242)
|
|
255 (?~ . ?\270) (?\ . ?~) (space . ?~))
|
|
256 (?/ (?C . ?\305) (?G . ?\325) (?H . ?\241) (?I . ?\251) (?Z . ?\257)
|
|
257 (?c . ?\345) (?g . ?\365) (?h . ?\261) (?i . ?\271) (?z . ?\277)
|
|
258 (?r . ?\256) (?. . ?\377) (?# . ?\243) (?$ . ?\244)
|
|
259 (?/ . ?\260) (?\ . ?/) (space . ?/)))
|
|
260 )
|
4
|
261 "List of language-specific customizations for the ISO Accents mode.
|
|
262
|
|
263 Each element of the list is of the form
|
|
264
|
153
|
265 (LANGUAGE [CHARSET]
|
4
|
266 (PSEUDO-ACCENT MAPPINGS)
|
|
267 (PSEUDO-ACCENT MAPPINGS)
|
|
268 ...)
|
|
269
|
|
270 LANGUAGE is a string naming the language.
|
153
|
271 CHARSET (which may be omitted) is the symbol name
|
|
272 of the character set used in this language.
|
|
273 If CHARSET is omitted, latin-iso8859-1 is the default.
|
4
|
274 PSEUDO-ACCENT is a char specifying an accent key.
|
|
275 MAPPINGS are cons cells of the form (CHAR . ISO-CHAR).
|
|
276
|
|
277 The net effect is that the key sequence PSEUDO-ACCENT CHAR is mapped
|
|
278 to ISO-CHAR on input.")
|
|
279
|
|
280 (defvar iso-language nil
|
|
281 "Language for which ISO Accents mode is currently customized.
|
|
282 Change it with the `iso-accents-customize' function.")
|
|
283
|
|
284 (defvar iso-accents-list nil
|
|
285 "Association list for ISO accent combinations, for the chosen language.")
|
|
286
|
|
287 (defvar iso-accents-mode nil
|
|
288 "*Non-nil enables ISO Accents mode.
|
|
289 Setting this variable makes it local to the current buffer.
|
|
290 See the function `iso-accents-mode'.")
|
|
291 (make-variable-buffer-local 'iso-accents-mode)
|
|
292
|
94
|
293 (defvar iso-accents-enable '(?' ?` ?^ ?\" ?~ ?/ ?, ?.)
|
4
|
294 "*List of accent keys that become prefixes in ISO Accents mode.
|
94
|
295 The default is (?' ?` ?^ ?\" ?~ ?/ ?, ?.), which contains all the supported
|
4
|
296 accent keys. If you set this variable to a list in which some of those
|
|
297 characters are missing, the missing ones do not act as accents.
|
|
298
|
|
299 Note that if you specify a language with `iso-accents-customize',
|
|
300 that can also turn off certain prefixes (whichever ones are not needed in
|
|
301 the language you choose).")
|
|
302
|
|
303 (defun iso-accents-accent-key (prompt)
|
|
304 "Modify the following character by adding an accent to it."
|
|
305 ;; Pick up the accent character.
|
|
306 (if (and iso-accents-mode
|
|
307 (memq last-input-char iso-accents-enable))
|
|
308 (iso-accents-compose prompt)
|
|
309 (char-to-string last-input-char)))
|
|
310
|
|
311 (defun iso-accents-compose (prompt)
|
|
312 (let* ((first-char last-input-char)
|
|
313 (list (assq first-char iso-accents-list))
|
|
314 ;; Wait for the second key and look up the combination.
|
|
315 (second-char (if (or prompt
|
|
316 (not (eq (key-binding "a")
|
|
317 'self-insert-command))
|
|
318 ;; Not at start of a key sequence.
|
|
319 (> (length (this-single-command-keys)) 1)
|
|
320 ;; Called from anything but the command loop.
|
|
321 this-command)
|
|
322 (progn
|
|
323 (message "%s%c"
|
|
324 (or prompt "Compose with ")
|
|
325 first-char)
|
144
|
326 (iso-read-event))
|
4
|
327 (insert first-char)
|
144
|
328 (prog1 (iso-read-event)
|
4
|
329 (delete-region (1- (point)) (point)))))
|
|
330 (entry (cdr (assq second-char list))))
|
|
331 (if entry
|
94
|
332 ;; Found it: return the mapped char
|
153
|
333 (vector
|
|
334 (iso-char-to-event
|
|
335 (if (and (boundp 'enable-multibyte-characters)
|
|
336 enable-multibyte-characters
|
|
337 (>= entry ?\200))
|
|
338 (+ iso-accents-insert-offset entry)
|
|
339 entry)))
|
4
|
340 ;; Otherwise, advance and schedule the second key for execution.
|
153
|
341 (setq unread-command-events (cons (iso-char-list-to-event
|
|
342 (list second-char))
|
94
|
343 unread-command-events))
|
|
344 (vector (iso-char-to-event first-char)))))
|
4
|
345
|
|
346 ;; It is a matter of taste if you want the minor mode indicated
|
|
347 ;; in the mode line...
|
|
348 ;; If so, uncomment the next four lines.
|
|
349 ;; (or (assq 'iso-accents-mode minor-mode-alist)
|
|
350 ;; (setq minor-mode-alist
|
153
|
351 ;; (append minor-mode-alist
|
|
352 ;; '((iso-accents-mode " ISO-Acc")))))
|
4
|
353
|
|
354 ;;;###autoload
|
|
355 (defun iso-accents-mode (&optional arg)
|
|
356 "Toggle ISO Accents mode, in which accents modify the following letter.
|
|
357 This permits easy insertion of accented characters according to ISO-8859-1.
|
|
358 When Iso-accents mode is enabled, accent character keys
|
|
359 \(`, ', \", ^, / and ~) do not self-insert; instead, they modify the following
|
|
360 letter key so that it inserts an ISO accented letter.
|
|
361
|
|
362 You can customize ISO Accents mode to a particular language
|
|
363 with the command `iso-accents-customize'.
|
|
364
|
|
365 Special combinations: ~c gives a c with cedilla,
|
|
366 ~d gives an Icelandic eth (d with dash).
|
|
367 ~t gives an Icelandic thorn.
|
|
368 \"s gives German sharp s.
|
|
369 /a gives a with ring.
|
|
370 /e gives an a-e ligature.
|
|
371 ~< and ~> give guillemots.
|
|
372 ~! gives an inverted exclamation mark.
|
|
373 ~? gives an inverted question mark.
|
|
374
|
|
375 With an argument, a positive argument enables ISO Accents mode,
|
|
376 and a negative argument disables it."
|
|
377
|
|
378 (interactive "P")
|
|
379
|
|
380 (if (if arg
|
|
381 ;; Negative arg means switch it off.
|
|
382 (<= (prefix-numeric-value arg) 0)
|
|
383 ;; No arg means toggle.
|
|
384 iso-accents-mode)
|
|
385 (setq iso-accents-mode nil)
|
|
386
|
|
387 ;; Enable electric accents.
|
|
388 (setq iso-accents-mode t)))
|
|
389
|
|
390 (defun iso-accents-customize (language)
|
|
391 "Customize the ISO accents machinery for a particular language.
|
|
392 It selects the customization based on the specifications in the
|
|
393 `iso-languages' variable."
|
|
394 (interactive (list (completing-read "Language: " iso-languages nil t)))
|
153
|
395 (let ((table (cdr (assoc language iso-languages)))
|
94
|
396 tail)
|
4
|
397 (if (not table)
|
153
|
398 (error "Unknown language `%s'" language)
|
|
399 (setq iso-accents-insert-offset (- (iso-make-char
|
|
400 (if (symbolp (car table))
|
|
401 (car table)
|
|
402 'latin-iso8859-1))
|
|
403 128))
|
|
404 (if (symbolp (car table))
|
|
405 (setq table (cdr table)))
|
4
|
406 (setq iso-language language
|
153
|
407 iso-accents-list table)
|
4
|
408 (if key-translation-map
|
|
409 (substitute-key-definition
|
|
410 'iso-accents-accent-key nil key-translation-map)
|
|
411 (setq key-translation-map (make-sparse-keymap)))
|
|
412 ;; Set up translations for all the characters that are used as
|
|
413 ;; accent prefixes in this language.
|
|
414 (setq tail iso-accents-list)
|
|
415 (while tail
|
94
|
416 (define-key key-translation-map (vector (iso-char-to-event
|
|
417 (car (car tail))))
|
4
|
418 'iso-accents-accent-key)
|
|
419 (setq tail (cdr tail))))))
|
|
420
|
|
421 (defun iso-accentuate (start end)
|
|
422 "Convert two-character sequences in region into accented characters.
|
|
423 Noninteractively, this operates on text from START to END.
|
|
424 This uses the same conversion that ISO Accents mode uses for type-in."
|
|
425 (interactive "r")
|
|
426 (save-excursion
|
|
427 (save-restriction
|
|
428 (narrow-to-region start end)
|
|
429 (goto-char start)
|
|
430 (forward-char 1)
|
|
431 (let (entry)
|
|
432 (while (< (point) end)
|
|
433 (if (and (memq (preceding-char) iso-accents-enable)
|
|
434 (setq entry (cdr (assq (following-char) (assq (preceding-char) iso-accents-list)))))
|
|
435 (progn
|
|
436 (forward-char -1)
|
|
437 (delete-char 2)
|
|
438 (insert entry)
|
|
439 (setq end (1- end)))
|
|
440 (forward-char 1)))))))
|
|
441
|
|
442 (defun iso-accent-rassoc-unit (value alist)
|
|
443 (let (elt acc)
|
|
444 (while (and alist (not elt))
|
|
445 (setq acc (car (car alist))
|
|
446 elt (car (rassq value (cdr (car alist))))
|
|
447 alist (cdr alist)))
|
|
448 (if elt
|
|
449 (cons acc elt))))
|
|
450
|
|
451 (defun iso-unaccentuate (start end)
|
|
452 "Convert accented characters in the region into two-character sequences.
|
|
453 Noninteractively, this operates on text from START to END.
|
|
454 This uses the opposite of the conversion done by ISO Accents mode for type-in."
|
|
455 (interactive "r")
|
|
456 (save-excursion
|
|
457 (save-restriction
|
|
458 (narrow-to-region start end)
|
|
459 (goto-char start)
|
|
460 (let (entry)
|
|
461 (while (< (point) end)
|
|
462 (if (and (> (following-char) 127)
|
|
463 (setq entry (iso-accent-rassoc-unit (following-char)
|
|
464 iso-accents-list)))
|
|
465 (progn
|
|
466 (delete-char 1)
|
|
467 (insert (car entry) (cdr entry))
|
|
468 (setq end (1+ end)))
|
|
469 (forward-char 1)))))))
|
|
470
|
|
471 (defun iso-deaccentuate (start end)
|
|
472 "Convert accented characters in the region into unaccented characters.
|
|
473 Noninteractively, this operates on text from START to END."
|
|
474 (interactive "r")
|
|
475 (save-excursion
|
|
476 (save-restriction
|
|
477 (narrow-to-region start end)
|
|
478 (goto-char start)
|
|
479 (let (entry)
|
|
480 (while (< (point) end)
|
|
481 (if (and (> (following-char) 127)
|
|
482 (setq entry (iso-accent-rassoc-unit (following-char)
|
|
483 iso-accents-list)))
|
|
484 (progn
|
|
485 (delete-char 1)
|
|
486 (insert (cdr entry)))
|
|
487 (forward-char 1)))))))
|
|
488
|
|
489 ;; Set up the default settings.
|
|
490 (iso-accents-customize "latin-1")
|
|
491
|
|
492 ;; Use Iso-Accents mode in the minibuffer
|
|
493 ;; if it was in use in the previous buffer.
|
|
494 (defun iso-acc-minibuf-setup ()
|
|
495 (setq iso-accents-mode
|
|
496 (save-excursion
|
|
497 (set-buffer (window-buffer minibuffer-scroll-window))
|
|
498 iso-accents-mode)))
|
|
499
|
153
|
500 (if (boundp 'minibuffer-setup-hook)
|
|
501 (add-hook 'minibuffer-setup-hook 'iso-acc-minibuf-setup)
|
|
502 (add-hook 'minibuf-setup-hook 'iso-acc-minibuf-setup))
|
4
|
503
|
|
504 ;;; iso-acc.el ends here
|