1 ;;; iso-acc.el --- minor mode providing electric accent keys
3 ;; Copyright (C) 1993, 1994, 1996 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 ;; Not at start of a key sequence.
197 (> (length (this-single-command-keys)) 1)
198 ;; Called from anything but the command loop.
202 (or prompt
"Compose with ")
207 (delete-region (1- (point)) (point)))))
208 (entry (cdr (assq second-char list
))))
210 ;; Found it: return the mapped char
212 ;; Otherwise, advance and schedule the second key for execution.
213 (setq unread-command-events
(list second-char
))
214 (vector first-char
))))
216 ;; It is a matter of taste if you want the minor mode indicated
217 ;; in the mode line...
218 ;; If so, uncomment the next four lines.
219 ;; (or (assq 'iso-accents-mode minor-mode-map-alist)
220 ;; (setq minor-mode-alist
221 ;; (append minor-mode-alist
222 ;; '((iso-accents-mode " ISO-Acc")))))
225 (defun iso-accents-mode (&optional arg
)
226 "Toggle ISO Accents mode, in which accents modify the following letter.
227 This permits easy insertion of accented characters according to ISO-8859-1.
228 When Iso-accents mode is enabled, accent character keys
229 \(`, ', \", ^, / and ~) do not self-insert; instead, they modify the following
230 letter key so that it inserts an ISO accented letter.
232 You can customize ISO Accents mode to a particular language
233 with the command `iso-accents-customize'.
235 Special combinations: ~c gives a c with cedilla,
236 ~d gives an Icelandic eth (d with dash).
237 ~t gives an Icelandic thorn.
238 \"s gives German sharp s.
239 /a gives a with ring.
240 /e gives an a-e ligature.
241 ~< and ~> give guillemots.
242 ~! gives an inverted exclamation mark.
243 ~? gives an inverted question mark.
245 With an argument, a positive argument enables ISO Accents mode,
246 and a negative argument disables it."
251 ;; Negative arg means switch it off.
252 (<= (prefix-numeric-value arg
) 0)
253 ;; No arg means toggle.
255 (setq iso-accents-mode nil
)
257 ;; Enable electric accents.
258 (setq iso-accents-mode t
)))
260 (defun iso-accents-customize (language)
261 "Customize the ISO accents machinery for a particular language.
262 It selects the customization based on the specifications in the
263 `iso-languages' variable."
264 (interactive (list (completing-read "Language: " iso-languages nil t
)))
265 (let ((table (assoc language iso-languages
))
268 (error "Unknown language '%s'" language
)
269 (setq iso-language language
270 iso-accents-list
(cdr table
))
271 (if key-translation-map
272 (substitute-key-definition
273 'iso-accents-accent-key nil key-translation-map
)
274 (setq key-translation-map
(make-sparse-keymap)))
275 ;; Set up translations for all the characters that are used as
276 ;; accent prefixes in this language.
277 (setq tail iso-accents-list
)
279 (define-key key-translation-map
(vector (car (car tail
)))
280 'iso-accents-accent-key
)
281 (setq tail
(cdr tail
))))))
283 (defun iso-accentuate (start end
)
284 "Convert two-character sequences in region into accented characters.
285 Noninteractively, this operates on text from START to END.
286 This uses the same conversion that ISO Accents mode uses for type-in."
290 (narrow-to-region start end
)
294 (while (< (point) end
)
295 (if (and (memq (preceding-char) iso-accents-enable
)
296 (setq entry
(cdr (assq (following-char) (assq (preceding-char) iso-accents-list
)))))
302 (forward-char 1)))))))
304 (defun iso-accent-rassoc-unit (value alist
)
306 (while (and alist
(not elt
))
307 (setq acc
(car (car alist
))
308 elt
(car (rassq value
(cdr (car alist
))))
313 (defun iso-unaccentuate (start end
)
314 "Convert accented characters in the region into two-character sequences.
315 Noninteractively, this operates on text from START to END.
316 This uses the opposite of the conversion done by ISO Accents mode for type-in."
320 (narrow-to-region start end
)
323 (while (< (point) end
)
324 (if (and (> (following-char) 127)
325 (setq entry
(iso-accent-rassoc-unit (following-char)
329 (insert (car entry
) (cdr entry
))
331 (forward-char 1)))))))
333 (defun iso-deaccentuate (start end
)
334 "Convert accented characters in the region into unaccented characters.
335 Noninteractively, this operates on text from START to END."
339 (narrow-to-region start end
)
342 (while (< (point) end
)
343 (if (and (> (following-char) 127)
344 (setq entry
(iso-accent-rassoc-unit (following-char)
348 (insert (cdr entry
)))
349 (forward-char 1)))))))
351 ;; Set up the default settings.
352 (iso-accents-customize "latin-1")
354 ;; Use Iso-Accents mode in the minibuffer
355 ;; if it was in use in the previous buffer.
356 (defun iso-acc-minibuf-setup ()
357 (setq iso-accents-mode
359 (set-buffer (window-buffer minibuffer-scroll-window
))
362 (add-hook 'minibuf-setup-hook
'iso-acc-minibuf-setup
)
364 ;;; iso-acc.el ends here