1 ;;; iso-acc.el -- minor mode providing electric accent keys
2 ;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
4 ;; Author: Johan Vromans <jv@mh.nl>
5 ;; Version: 1.7 (modified)
9 ;; This file is part of GNU Emacs.
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)
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.
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.
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.
32 ;; In `iso-accents-mode', pseudo accent characters are used to
33 ;; introduce accented keys. The pseudo-accent characters are:
35 ;; ' (minute) -> grave accent
36 ;; ` (backtick) -> acute accent
37 ;; " (second) -> diaeresis
38 ;; ^ (caret) -> circumflex
39 ;; ~ (tilde) -> tilde over the character
40 ;; / (slash) -> slash through the character.
41 ;; Also: /A is A-with-ring and /E is AE ligature.
43 ;; The action taken depends on the key that follows the pseudo accent.
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
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.
55 ;; Function `iso-accents-mode' can be used to enable the iso accents
56 ;; minor mode, or disable it.
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.
65 (defvar iso-accents-list
91 ((?
` ?
`) ?
`) ; no special code?
103 ((?^ ?^
) ?^
) ; no special code?
133 ((?\~ ?\~
) ?
\270) ;; cedilla accent
134 ((?\
/ ?A
) ?
\305) ;; A-with-ring (Norwegian and Danish)
135 ((?\
/ ?E
) ?
\306) ;; AE-ligature (Norwegian and Danish)
137 ((?\
/ ?a
) ?
\345) ;; a-with-ring (Norwegian and Danish)
138 ((?\
/ ?e
) ?
\346) ;; ae-ligature (Norwegian and Danish)
141 ((?\
/ ?\
/) ?
\260) ;; ring accent (actually degree sign?)
143 "Association list for ISO accent combinations.")
145 (defvar iso-accents-mode nil
146 "*Non-nil enables ISO Accents mode.
147 Setting this variable makes it local to the current buffer.
148 See function `iso-accents-mode'.")
149 (make-variable-buffer-local 'iso-accents-mode
)
151 (defun iso-accents-accent-key (prompt)
152 "Modify the following character by adding an accent to it."
153 ;; Pick up the accent character.
155 (iso-accents-compose prompt
)
156 (char-to-string last-input-char
)))
158 (defun iso-accents-compose-key (prompt)
159 "Modify the following character by adding an accent to it."
160 ;; Pick up the accent character.
161 (let ((combined (iso-accents-compose prompt
)))
162 (if unread-command-events
163 (let ((unread unread-command-events
))
164 (setq unread-command-events nil
)
165 (error "Characters %s and %s cannot be composed"
166 (single-key-description (aref combined
0))
167 (single-key-description (car unread
)))))
170 (defun iso-accents-compose (prompt)
171 (let* ((first-char last-input-char
)
172 ;; Wait for the second key and look up the combination.
173 (second-char (if (or prompt
174 (not (eq (key-binding "a")
175 'self-insert-command
)))
178 (or prompt
"Compose with ")
183 (delete-region (1- (point)) (point)))))
184 (entry (assoc (list first-char second-char
) iso-accents-list
)))
186 ;; Found it: delete the first character and insert the combination.
187 (concat (list (nth 1 entry
)))
188 ;; Otherwise, advance and schedule the second key for execution.
189 (setq unread-command-events
(list second-char
))
190 (vector first-char
))))
192 (defvar iso-accents-enable
'(?
' ?
` ?^ ?
\" ?~ ?
/)
193 "*List of accent keys that become prefixes in ISO Accents mode.
194 The default is (?' ?` ?^ ?\" ?~ ?/), which contains all the supported
195 accent keys. For certain languages, you might want to remove some of
196 those characters that are not actually used.")
198 (or key-translation-map
(setq key-translation-map
(make-sparse-keymap)))
199 ;; For sequences starting with an accent character,
200 ;; use a function that tests iso-accents-mode.
201 (if (memq ?
' iso-accents-enable
)
202 (define-key key-translation-map
"'" 'iso-accents-accent-key
))
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
))
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 The variable `iso-accents-enable' specifies the list of characters to
231 enable as accents. If you don't need all of them, remove the ones you
232 don't need from that list.
234 Special combinations: ~c gives a c with cedilla,
235 ~d gives an Icelandic eth (d with dash).
236 ~t gives an Icelandic thorn.
237 \"s gives German sharp s.
238 /a gives a with ring.
239 /e gives an a-e ligature.
240 ~< and ~> give guillemets.
242 With an argument, a positive argument enables ISO Accents mode,
243 and a negative argument disables it."
248 ;; Negative arg means switch it off.
249 (<= (prefix-numeric-value arg
) 0)
250 ;; No arg means toggle.
252 (setq iso-accents-mode nil
)
254 ;; Enable electric accents.
255 (setq iso-accents-mode t
)))
257 ;;; iso-acc.el ends here