1 ;;; iso-acc.el -- minor mode providing electric accent keys
2 ;;; Copyright (C) 1993 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
28 ;; (`iso-accents-minor-mode') in which typewriter "dead keys" are
29 ;; emulated. The purpose of this emulation is to provide a simple
30 ;; means for inserting accented characters according to the ISO-8859-1
33 ;; In `iso-accents-minor-mode', pseudo accent characters are used to
34 ;; introduce accented keys. The pseudo-accent characterss are:
36 ;; ' (minute) -> grave accent
37 ;; ` (backtick) -> acute accent
38 ;; " (second) -> diaeresis
39 ;; ^ (caret) -> circumflex
40 ;; ~ (tilde) -> tilde over the character
41 ;; / (slash) -> slash through the character.
42 ;; Also: /A is A-with-ring and /E is AE ligature.
44 ;; The action taken depends on the key that follows the pseudo accent.
47 ;; pseudo-accent + appropriate letter -> accented letter
48 ;; pseudo-accent + space -> pseudo-accent
49 ;; pseudo-accent + pseudo-accent -> accent (if available)
50 ;; pseudo-accent + other -> pseudo-accent + other
52 ;; If the pseudo-accent is followed by anything else than a
53 ;; self-insert-command, the dead-key code is terminated, the
54 ;; pseudo-accent inserted 'as is' and the bell is rung to signal this.
56 ;; Function `iso-accents-mode' can be used to enable the iso accents
57 ;; minor mode, or disable it.
59 ;; If you want only some of these characters to serve as accents,
60 ;; set iso-accents-enable to the list of characters that should be special.
66 (defvar iso-accents-list
92 ((?
` ?
`) ?
`) ; no special code?
104 ((?^ ?^
) ?^
) ; no special code?
132 ((?\~ ?\~
) ?
\270) ;; cedilla accent
133 ((?\
/ ?A
) ?
\305) ;; A-with-ring (Norwegian and Danish)
134 ((?\
/ ?E
) ?
\306) ;; AE-ligature (Norwegian and Danish)
136 ((?\
/ ?a
) ?
\345) ;; a-with-ring (Norwegian and Danish)
137 ((?\
/ ?e
) ?
\346) ;; ae-ligature (Norwegian and Danish)
140 ((?\
/ ?\
/) ?
\260) ;; ring accent (actually degree sign?)
142 "Association list for ISO accent combinations.")
144 (defvar iso-accents-minor-mode nil
145 "*Non-nil enables ISO Accents mode.
146 Setting this variable makes it local to the current buffer.
147 See `iso-accents-mode'.")
148 (make-variable-buffer-local 'iso-accents-minor-mode
)
150 (defun iso-accents-accent-key (prompt)
151 "Modify the following character by adding an accent to it."
152 ;; Pick up the accent character.
153 (if iso-accents-minor-mode
154 (iso-accents-compose prompt
)
155 (char-to-string last-input-char
)))
157 (defun iso-accents-compose-key (prompt)
158 "Modify the following character by adding an accent to it."
159 ;; Pick up the accent character.
160 (let ((combined (iso-accents-compose prompt
)))
161 (if unread-command-events
162 (let ((unread unread-command-events
))
163 (setq unread-command-events nil
)
164 (error "Characters %s and %s cannot be composed"
165 (single-key-description (aref combined
0))
166 (single-key-description (car unread
)))))
169 (defun iso-accents-compose (prompt)
170 (let* ((first-char last-input-char
)
171 ;; Wait for the second key and look up the combination.
172 (second-char (if (or prompt
173 (not (eq (key-binding "a")
174 'self-insert-command
)))
177 (or prompt
"Compose with ")
182 (delete-region (1- (point)) (point)))))
183 (entry (assoc (list first-char second-char
) iso-accents-list
)))
185 ;; Found it: delete the first character and insert the combination.
186 (concat (list (nth 1 entry
)))
187 ;; Otherwise, advance and schedule the second key for execution.
188 (setq unread-command-events
(list second-char
))
189 (vector first-char
))))
191 (defvar iso-accents-enable
'(?
' ?
` ?^ ?
\" ?~ ?
/)
192 "*List of accent keys that become prefixes in ISO Accents mode.
193 The default is (?' ?` ?^ ?\" ?~ ?/), which contains all the supported
194 accent keys. For certain languages, you might want to remove some of
195 those characters that are not actually used.")
197 (or key-translation-map
(setq key-translation-map
(make-sparse-keymap)))
198 ;; For sequences starting with an accent character,
199 ;; use a function that tests iso-accents-minor-mode.
200 (if (memq ?
' iso-accents-enable
)
201 (define-key key-translation-map
"'" 'iso-accents-accent-key
))
202 (if (memq ?
` iso-accents-enable
)
203 (define-key key-translation-map
"`" 'iso-accents-accent-key
))
204 (if (memq ?^ iso-accents-enable
)
205 (define-key key-translation-map
"^" 'iso-accents-accent-key
))
206 (if (memq ?
\" iso-accents-enable
)
207 (define-key key-translation-map
"\"" 'iso-accents-accent-key
))
208 (if (memq ?~ iso-accents-enable
)
209 (define-key key-translation-map
"~" 'iso-accents-accent-key
))
210 (if (memq ?
/ iso-accents-enable
)
211 (define-key key-translation-map
"/" 'iso-accents-accent-key
))
213 ;; It is a matter of taste if you want the minor mode indicated
214 ;; in the mode line...
215 ;; If so, uncomment the next four lines.
216 ;; (or (assq 'iso-accents-minor-mode minor-mode-map-alist)
217 ;; (setq minor-mode-alist
218 ;; (append minor-mode-alist
219 ;; '((iso-accents-minor-mode " ISO-Acc")))))
222 (defun iso-accents-mode (&optional arg
)
223 "Toggle ISO Accents mode, in which accents modify the following letter.
224 This permits easy insertion of accented characters according to ISO-8859-1.
225 When Iso-accents mode is enabled, accent character keys
226 \(`, ', \", ^, / and ~) do not self-insert; instead, they modify the following
227 letter key so that it inserts an ISO accented letter.
229 The variable `iso-accents-enable' specifies the list of characters to
230 enable as accents. If you don't need all of them, remove the ones you
231 don't need from that list.
233 Special combinations: ~c gives a c with cedilla,
234 ~d gives a d with dash.
235 \"s gives German sharp s.
236 /a gives a with ring.
237 /e gives an a-e ligature.
238 ~< and ~> give guillemets.
240 With an argument, a positive argument enables ISO Accents mode,
241 and a negative argument disables it."
246 ;; Negative arg means switch it off.
247 (<= (prefix-numeric-value arg
) 0)
248 ;; No arg means toggle.
249 iso-accents-minor-mode
)
250 (setq iso-accents-minor-mode nil
)
252 ;; Enable electric accents.
253 (setq iso-accents-minor-mode t
)))
255 ;;; iso-acc.el ends here