1 ;;; iso-acc.el -- minor mode providing electric accent keys
3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
5 ;; Author: Johan Vromans <jv@mh.nl>
6 ;; Version: 1.7 (modified)
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; Function `iso-accents-mode' activates a minor mode in which
30 ;; typewriter "dead keys" are emulated. The purpose of this emulation
31 ;; is to provide a simple means for inserting accented characters
32 ;; according to the ISO-8859-1 character set.
34 ;; In `iso-accents-mode', pseudo accent characters are used to
35 ;; introduce accented keys. The pseudo-accent characters are:
37 ;; ' (minute) -> grave accent
38 ;; ` (backtick) -> acute accent
39 ;; " (second) -> diaeresis
40 ;; ^ (caret) -> circumflex
41 ;; ~ (tilde) -> tilde over the character
42 ;; / (slash) -> slash through the character.
43 ;; Also: /A is A-with-ring and /E is AE ligature.
45 ;; The action taken depends on the key that follows the pseudo accent.
48 ;; pseudo-accent + appropriate letter -> accented letter
49 ;; pseudo-accent + space -> pseudo-accent
50 ;; pseudo-accent + pseudo-accent -> accent (if available)
51 ;; pseudo-accent + other -> pseudo-accent + other
53 ;; If the pseudo-accent is followed by anything else than a
54 ;; self-insert-command, the dead-key code is terminated, the
55 ;; pseudo-accent inserted 'as is' and the bell is rung to signal this.
57 ;; Function `iso-accents-mode' can be used to enable the iso accents
58 ;; minor mode, or disable it.
60 ;; If you want only some of these characters to serve as accents,
61 ;; add a language to `iso-languages' which specifies the accent characters
62 ;; that you want, then select the language with `iso-accents-customize'.
70 (?
' (?A . ?
\301) (?E . ?
\311) (?I . ?
\315) (?O . ?
\323) (?U . ?
\332)
71 (?C . ?
\307) (?a . ?
\341) (?e . ?
\351) (?i . ?
\355) (?o . ?
\363)
72 (?u . ?
\372) (?c . ?
\347) (?\ . ?
'))
73 (?
` (?A . ?
\300) (?a . ?
\340) (?\ . ?
`))
74 (?^
(?A . ?
\302) (?E . ?
\312) (?O . ?
\324) (?a . ?
\342) (?e . ?
\352)
75 (?o . ?
\364) (?\ . ?^
))
76 (?
\" (?U . ?
\334) (?u . ?
\374) (?\ . ?
\"))
77 (?\~
(?A . ?
\303) (?O . ?
\325) (?a . ?
\343) (?o . ?
\365) (?\ . ?\~
)))
80 (?
' (?A . ?
\301) (?E . ?
\311) (?I . ?
\315) (?O . ?
\323) (?U . ?
\332)
81 (?a . ?
\341) (?e . ?
\351) (?i . ?
\355) (?o . ?
\363) (?u . ?
\372)
85 (?
' (?A . ?
\301) (?E . ?
\311) (?I . ?
\315) (?O . ?
\323) (?U . ?
\332)
86 (?C . ?
\307) (?a . ?
\341) (?e . ?
\351) (?i . ?
\355) (?o . ?
\363)
87 (?u . ?
\372) (?c . ?
\347) (?\ . ?
'))
88 (?
` (?A . ?
\300) (?E . ?
\310) (?a . ?
\340) (?e . ?
\350) (?\ . ?
`))
89 (?^
(?A . ?
\302) (?E . ?
\312) (?I . ?
\316) (?O . ?
\324) (?U . ?
\333)
90 (?a . ?
\342) (?e . ?
\352) (?i . ?
\356) (?o . ?
\364) (?u . ?
\373)
92 (?
\" (?U . ?
\334) (?u . ?
\374) (?\ . ?
\"))
93 (?\~
(?A . ?
\303) (?O . ?
\325) (?a . ?
\343) (?o . ?
\365) (?\ . ?\~
)))
96 (?
' (?A . ?
\301) (?C . ?
\306) (?D . ?
\320) (?E . ?
\311) (?I . ?
\315)
97 (?L . ?
\305) (?N . ?
\321) (?O . ?
\323) (?R . ?
\300) (?S . ?
\246)
98 (?U . ?
\332) (?Y . ?
\335) (?Z . ?
\254) (?a . ?
\341) (?c . ?
\346)
99 (?d . ?
\360) (?e . ?
\351) (?i . ?
\355) (?l . ?
\345) (?n . ?
\361)
100 (?o . ?
\363) (?r . ?
\340) (?s . ?
\266) (?u . ?
\372) (?y . ?
\375)
101 (?z . ?
\274) (?
' . ?
\264) (?\ . ?
'))
102 (?
` (?A . ?
\241) (?C . ?
\307) (?E . ?
\312) (?L . ?
\243) (?S . ?
\252)
103 (?T . ?
\336) (?Z . ?
\257) (?a . ?
\261) (?l . ?
\263) (?c . ?
\347)
104 (?e . ?
\352) (?s . ?
\272) (?t . ?
\376) (?z . ?
\277) (?
` . ?
\252)
105 (?. . ?
\377) (?\ . ?
`))
106 (?^
(?A . ?
\302) (?O . ?
\324) (?a . ?
\342) (?o . ?
\364)
107 (?^ . ?^
) ; no special code?
109 (?
\" (?A . ?
\304) (?E . ?
\313) (?O . ?
\326) (?U . ?
\334) (?a . ?
\344)
110 (?e . ?
\353) (?o . ?
\366) (?s . ?
\337) (?u . ?
\374) (?
\" . ?
\250)
112 (?\~
(?A . ?
\303) (?C . ?
\310) (?D . ?
\317) (?L . ?
\245) (?N . ?
\322)
113 (?O . ?
\325) (?R . ?
\330) (?S . ?
\251) (?T . ?
\253) (?U . ?
\333)
114 (?Z . ?
\256) (?a . ?
\323) (?c . ?
\350) (?d . ?
\357) (?l . ?
\265)
115 (?n . ?
\362) (?o . ?
\365) (?r . ?
\370) (?s . ?
\271) (?t . ?
\273)
116 (?u . ?
\373) (?z . ?
\276)
117 (?v . ?
\242) ; v accent
118 (?\~ . ?
\242) ; v accent
119 (?\. . ?
\270) ; cedilla accent
123 (?
' (?A . ?
\301) (?E . ?
\311) (?I . ?
\315) (?O . ?
\323) (?U . ?
\332)
124 (?Y . ?
\335) (?a . ?
\341) (?e . ?
\351) (?i . ?
\355) (?o . ?
\363)
125 (?u . ?
\372) (?y . ?
\375) (?
' . ?
\264) (?\ . ?
'))
126 (?
` (?A . ?
\300) (?E . ?
\310) (?I . ?
\314) (?O . ?
\322) (?U . ?
\331)
127 (?a . ?
\340) (?e . ?
\350) (?i . ?
\354) (?o . ?
\362) (?u . ?
\371)
129 (?^
(?A . ?
\302) (?E . ?
\312) (?I . ?
\316) (?O . ?
\324) (?U . ?
\333)
130 (?a . ?
\342) (?e . ?
\352) (?i . ?
\356) (?o . ?
\364) (?u . ?
\373)
132 (?
\" (?A . ?
\304) (?E . ?
\313) (?I . ?
\317) (?O . ?
\326) (?U . ?
\334)
133 (?a . ?
\344) (?e . ?
\353) (?i . ?
\357) (?o . ?
\366) (?s . ?
\337)
134 (?u . ?
\374) (?y . ?
\377) (?
\" . ?
\250) (?\ . ?
\"))
135 (?\~
(?A . ?
\303) (?C . ?
\307) (?D . ?
\320) (?N . ?
\321) (?O . ?
\325)
136 (?T . ?
\336) (?a . ?
\343) (?c . ?
\347) (?d . ?
\360) (?n . ?
\361)
137 (?o . ?
\365) (?t . ?
\376) (?
> . ?
\273) (?
< . ?
\253) (?\~ . ?
\270)
138 (?
! . ?
\241) (?? . ?
\277)
140 (?\
/ (?A . ?
\305) (?E . ?
\306) (?O . ?
\330) (?a . ?
\345) (?e . ?
\346)
141 (?o . ?
\370) (?\
/ . ?
\260) (?\ . ?\
/))))
142 "List of language-specific customizations for the ISO Accents mode.
144 Each element of the list is of the form
147 (PSEUDO-ACCENT MAPPINGS)
148 (PSEUDO-ACCENT MAPPINGS)
151 LANGUAGE is a string naming the language.
152 PSEUDO-ACCENT is a char specifying an accent key.
153 MAPPINGS are cons cells of the form (CHAR . ISO-CHAR).
155 The net effect is that the key sequence PSEUDO-ACCENT CHAR is mapped
156 to ISO-CHAR on input.")
158 (defvar iso-language nil
159 "Language for which ISO Accents mode is currently customized.
160 Change it with the `iso-accents-customize' function.")
162 (defvar iso-accents-list nil
163 "Association list for ISO accent combinations, for the chosen language.")
165 (defvar iso-accents-mode nil
166 "*Non-nil enables ISO Accents mode.
167 Setting this variable makes it local to the current buffer.
168 See the function `iso-accents-mode'.")
169 (make-variable-buffer-local 'iso-accents-mode
)
171 (defvar iso-accents-enable
'(?
' ?
` ?^ ?
\" ?~ ?
/)
172 "*List of accent keys that become prefixes in ISO Accents mode.
173 The default is (?' ?` ?^ ?\" ?~ ?/), which contains all the supported
174 accent keys. If you set this variable to a list in which some of those
175 characters are missing, the missing ones do not act as accents.
177 Note that if you specify a language with `iso-accents-customize',
178 that can also turn off certain prefixes (whichever ones are not needed in
179 the language you choose).")
181 (defun iso-accents-accent-key (prompt)
182 "Modify the following character by adding an accent to it."
183 ;; Pick up the accent character.
184 (if (and iso-accents-mode
185 (memq last-input-char iso-accents-enable
))
186 (iso-accents-compose prompt
)
187 (char-to-string last-input-char
)))
189 (defun iso-accents-compose (prompt)
190 (let* ((first-char last-input-char
)
191 (list (assq first-char iso-accents-list
))
192 ;; Wait for the second key and look up the combination.
193 (second-char (if (or prompt
194 (not (eq (key-binding "a")
195 'self-insert-command
))
196 ;; Called from anything but the command loop.
200 (or prompt
"Compose with ")
205 (delete-region (1- (point)) (point)))))
206 (entry (cdr (assq second-char list
))))
208 ;; Found it: return the mapped char
210 ;; Otherwise, advance and schedule the second key for execution.
211 (setq unread-command-events
(list second-char
))
212 (vector first-char
))))
214 ;; It is a matter of taste if you want the minor mode indicated
215 ;; in the mode line...
216 ;; If so, uncomment the next four lines.
217 ;; (or (assq 'iso-accents-mode minor-mode-map-alist)
218 ;; (setq minor-mode-alist
219 ;; (append minor-mode-alist
220 ;; '((iso-accents-mode " ISO-Acc")))))
223 (defun iso-accents-mode (&optional arg
)
224 "Toggle ISO Accents mode, in which accents modify the following letter.
225 This permits easy insertion of accented characters according to ISO-8859-1.
226 When Iso-accents mode is enabled, accent character keys
227 \(`, ', \", ^, / and ~) do not self-insert; instead, they modify the following
228 letter key so that it inserts an ISO accented letter.
230 You can customize ISO Accents mode to a particular language
231 with the command `iso-accents-customize'.
233 Special combinations: ~c gives a c with cedilla,
234 ~d gives an Icelandic eth (d with dash).
235 ~t gives an Icelandic thorn.
236 \"s gives German sharp s.
237 /a gives a with ring.
238 /e gives an a-e ligature.
239 ~< and ~> give guillemots.
240 ~! gives an inverted exclamation mark.
241 ~? gives an inverted question mark.
243 With an argument, a positive argument enables ISO Accents mode,
244 and a negative argument disables it."
249 ;; Negative arg means switch it off.
250 (<= (prefix-numeric-value arg
) 0)
251 ;; No arg means toggle.
253 (setq iso-accents-mode nil
)
255 ;; Enable electric accents.
256 (setq iso-accents-mode t
)))
258 (defun iso-accents-customize (language)
259 "Customize the ISO accents machinery for a particular language.
260 It selects the customization based on the specifications in the
261 `iso-languages' variable."
262 (interactive (list (completing-read "Language: " iso-languages nil t
)))
263 (let ((table (assoc language iso-languages
))
266 (error "Unknown language '%s'" language
)
267 (setq iso-language language
268 iso-accents-list
(cdr table
))
269 (if key-translation-map
270 (substitute-key-definition
271 'iso-accents-accent-key nil key-translation-map
)
272 (setq key-translation-map
(make-sparse-keymap)))
273 ;; Set up translations for all the characters that are used as
274 ;; accent prefixes in this language.
275 (setq tail iso-accents-list
)
277 (define-key key-translation-map
(vector (car (car tail
)))
278 'iso-accents-accent-key
)
279 (setq tail
(cdr tail
))))))
281 (defun iso-accentuate (start end
)
282 "Convert two-character sequences in region into accented characters.
283 Noninteractively, this operates on text from START to END.
284 This uses the same conversion that ISO Accents mode uses for type-in."
288 (narrow-to-region start end
)
292 (while (< (point) end
)
293 (if (and (memq (preceding-char) iso-accents-enable
)
294 (setq entry
(cdr (assq (following-char) (assq (preceding-char) iso-accents-list
)))))
300 (forward-char 1)))))))
302 (defun iso-accent-rassoc-unit (value alist
)
304 (while (and alist
(not elt
))
305 (setq acc
(car (car alist
))
306 elt
(car (rassq value
(cdr (car alist
))))
311 (defun iso-unaccentuate (start end
)
312 "Convert accented characters in the region into two-character sequences.
313 Noninteractively, this operates on text from START to END.
314 This uses the opposite of the conversion done by ISO Accents mode for type-in."
318 (narrow-to-region start end
)
321 (while (< (point) end
)
322 (if (and (> (following-char) 127)
323 (setq entry
(iso-accent-rassoc-unit (following-char)
327 (insert (car entry
) (cdr entry
))
329 (forward-char 1)))))))
331 (defun iso-deaccentuate (start end
)
332 "Convert accented characters in the region into unaccented characters.
333 Noninteractively, this operates on text from START to END."
337 (narrow-to-region start end
)
340 (while (< (point) end
)
341 (if (and (> (following-char) 127)
342 (setq entry
(iso-accent-rassoc-unit (following-char)
346 (insert (cdr entry
)))
347 (forward-char 1)))))))
349 ;; Set up the default settings.
350 (iso-accents-customize "latin-1")
352 ;; Use Iso-Accents mode in the minibuffer
353 ;; if it was in use in the previous buffer.
354 (defun iso-acc-minibuf-setup ()
355 (setq iso-accents-mode
357 (set-buffer (window-buffer minibuffer-scroll-window
))
360 (add-hook 'minibuf-setup-hook
'iso-acc-minibuf-setup
)
362 ;;; iso-acc.el ends here