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