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>
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)
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.
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
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.
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.
58 (defvar iso-accents-list
82 ((?
` ?
`) ?
`) ; no special code?
94 ((?^ ?^
) ?^
) ; no special code?
108 "Association list for ISO accent combinations.")
110 (defun iso-accents-accent-key ()
111 "Modify the following character by adding an accent to it."
114 ;; Pick up the accent character.
115 (let ((first-char last-command-char
))
117 ;; Display it and backup.
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
)))
125 ;; Found it: delete the first character and insert the combination.
128 (insert (car (cdr entry
))))
130 ;; Otherwise, advance and schedule the second key for execution.
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
)
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
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")))))
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."
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