Fix typo in previous change.
[emacs.git] / lisp / international / iso-acc.el
blobe165b0d25f0ec2d436587e5b57e57457ee5bac17
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
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 ;;; Commentary:
25 ;; Function `iso-accents-mode' activates a minor mode
26 ;; (`iso-accents-minor-mode') in which typewriter "dead keys" are
27 ;; emulated. The purpose of this emulation is to provide a simple
28 ;; means for inserting accented characters according to the ISO-8859-1
29 ;; character set.
31 ;; In `iso-accents-minor-mode', pseudo accent characters are used to
32 ;; introduce accented keys. The pseudo-accent characterss are:
34 ;; ' (minute) -> grave accent
35 ;; ` (backtick) -> acute accent
36 ;; " (second) -> diaeresis
37 ;; ^ (caret) -> circonflexe
39 ;; The action taken depends on the key that follows the pseudo accent.
40 ;; In general:
42 ;; pseudo-accent + appropriate letter -> accented letter
43 ;; pseudo-accent + space -> pseudo-accent
44 ;; pseudo-accent + pseudo-accent -> accent (if available)
45 ;; pseudo-accent + other -> pseudo-accent + other
47 ;; If the pseudo-accent is followed by anything else than a
48 ;; self-insert-command, the dead-key code is terminated, the
49 ;; pseudo-accent inserted 'as is' and the bell is rung to signal this.
51 ;; Function `iso-accents-mode' can be used to enable the iso accents
52 ;; minor mode, or disable it.
54 ;;; Code:
56 (provide 'iso-acc)
58 (defvar iso-accents-list
59 '(((?' ?A) ?\301)
60 ((?' ?E) ?\311)
61 ((?' ?I) ?\315)
62 ((?' ?O) ?\323)
63 ((?' ?U) ?\332)
64 ((?' ?a) ?\341)
65 ((?' ?e) ?\351)
66 ((?' ?i) ?\355)
67 ((?' ?o) ?\363)
68 ((?' ?u) ?\372)
69 ((?' ?') ?\264)
70 ((?' ? ) ?')
71 ((?` ?A) ?\300)
72 ((?` ?E) ?\310)
73 ((?` ?I) ?\314)
74 ((?` ?O) ?\322)
75 ((?` ?U) ?\331)
76 ((?` ?a) ?\340)
77 ((?` ?e) ?\350)
78 ((?` ?i) ?\354)
79 ((?` ?o) ?\362)
80 ((?` ?u) ?\371)
81 ((?` ? ) ?`)
82 ((?` ?`) ?`) ; no special code?
83 ((?` ?A) ?\302)
84 ((?^ ?E) ?\312)
85 ((?^ ?I) ?\316)
86 ((?^ ?O) ?\324)
87 ((?^ ?U) ?\333)
88 ((?^ ?a) ?\342)
89 ((?^ ?e) ?\352)
90 ((?^ ?i) ?\356)
91 ((?^ ?o) ?\364)
92 ((?^ ?u) ?\373)
93 ((?^ ? ) ?^)
94 ((?^ ?^) ?^) ; no special code?
95 ((?\" ?A) ?\304)
96 ((?\" ?E) ?\313)
97 ((?\" ?I) ?\317)
98 ((?\" ?O) ?\326)
99 ((?\" ?U) ?\334)
100 ((?\" ?a) ?\344)
101 ((?\" ?e) ?\353)
102 ((?\" ?i) ?\357)
103 ((?\" ?o) ?\366)
104 ((?\" ?u) ?\374)
105 ((?\" ? ) ?\")
106 ((?\" ?\") ?\250)
108 "Association list for ISO accent combinations.")
110 (defun iso-accents-accent-key ()
111 "Modify the following character by adding an accent to it."
112 (interactive)
114 ;; Pick up the accent character.
115 (let ((first-char last-command-char))
117 ;; Display it and backup.
118 (insert first-char)
119 (backward-char 1)
121 ;; Wait for the second key and look up the combination in the list.
122 (let* ((second-char (read-event))
123 (entry (assoc (list first-char second-char) iso-accents-list)))
124 (if entry
125 ;; Found it: delete the first character and insert the combination.
126 (progn
127 (delete-char 1)
128 (insert (car (cdr entry))))
130 ;; Otherwise, advance and schedule the second key for execution.
131 (forward-char 1)
132 (setq unread-command-events (list second-char))
134 ;; If it is not a self-insert-command, ring the terminal bell.
135 (or (eq (key-binding (make-vector 1 second-char)) 'self-insert-command)
136 (beep 1))))))
138 (defvar iso-accents-minor-mode nil
139 "*Non-nil enables ISO-accents mode.
140 Setting this variable makes it local to the current buffer.
141 See `iso-accents-mode'.")
142 (make-variable-buffer-local 'iso-accents-minor-mode)
144 ;; A minor mode map `iso-accents-prefix-map' is used to activate the
145 ;; dead key handling depending on the value of iso-accents-minor-mode.
146 (defvar iso-accents-prefix-map nil
147 "Keymap for ISO-accents minor mode.")
149 ;; Create the minor-mode keymap, if needed.
150 (or iso-accents-prefix-map
151 (progn
152 (setq iso-accents-prefix-map (make-sparse-keymap))
153 (define-key iso-accents-prefix-map "'" 'iso-accents-dead-key)
154 (define-key iso-accents-prefix-map "`" 'iso-accents-dead-key)
155 (define-key iso-accents-prefix-map "^" 'iso-accents-dead-key)
156 (define-key iso-accents-prefix-map "\"" 'iso-accents-dead-key)))
158 ;; Add the dead key minor mode map to the minor mode maps.
159 (or (assq 'iso-accents-minor-mode minor-mode-map-alist)
160 (setq minor-mode-map-alist
161 (cons (cons 'iso-accents-minor-mode iso-accents-prefix-map)
162 minor-mode-map-alist)))
164 ;; It is a matter of taste if you want the minor mode indicated
165 ;; in the mode line...
166 ;; If so, uncomment the next four lines.
167 ;; (or (assq 'iso-accents-minor-mode minor-mode-map-alist)
168 ;; (setq minor-mode-alist
169 ;; (append minor-mode-alist
170 ;; '((iso-accents-minor-mode " ISO-Acc")))))
172 ;;;###autoload
173 (defun iso-accents-mode (&optional arg)
174 "Toggle a minor mode in which accents modify the following letter.
175 This permits easy insertion of accented characters according to ISO-8859-1.
176 When Iso-accents mode is enabled, accent character keys
177 \(', \", ^ and ~) do not self-insert; instead, they modify the following
178 letter key so that it inserts an ISO accented letter.
180 With an argument, a positive argument enables ISO-accents mode,
181 and a negative argument disables it."
183 (interactive "P")
185 (if (if arg
186 ;; Negative arg means switch it off.
187 (<= (prefix-numeric-value arg) 0)
188 ;; No arg means toggle.
189 iso-accents-minor-mode)
190 (setq iso-accents-minor-mode nil)
192 ;; Enable electric accents.
193 (setq iso-accents-minor-mode t)))
195 ;;; iso-acc.el ends here