comparison lisp/international/iso-acc.el @ 4720:797fe2b66800

Initial revision
author Richard M. Stallman <rms@gnu.org>
date Tue, 14 Sep 1993 16:51:54 +0000
parents
children d34c02ddea9f
comparison
equal deleted inserted replaced
4719:f250e1299a74 4720:797fe2b66800
1 ;;; iso-acc.el -- minor mode providing electric accent keys
2 ;;; Copyright (C) 1993 Free Software Foundation, Inc.
3
4 ;; Author: Johan Vromans <jv@mh.nl>
5 ;; Version: 1.4
6
7 ;; This file is part of GNU Emacs.
8
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.
13
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.
18
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.
22
23 ;;; Commentary:
24
25 ;; Function `iso-accents' activates a minor mode (`iso-accents-minor-mode')
26 ;; in which typewriter "dead keys" are emulated. The purpose of this
27 ;; emulation is to provide a simple means for inserting accented
28 ;; characters according to the ISO-8859-1 character set.
29 ;;
30 ;; In `iso-accents-minor-mode', pseudo accent characters are used to
31 ;; introduce accented keys. The pseudo-accent characterss are:
32 ;;
33 ;; ' (minute) -> grave accent
34 ;; ` (backtick) -> acute accent
35 ;; " (second) -> diaeresis
36 ;; ^ (caret) -> circonflexe
37 ;;
38 ;; The action taken depends on the key that follows the pseudo accent.
39 ;; In general:
40 ;;
41 ;; pseudo-accent + appropriate letter -> accented letter
42 ;; pseudo-accent + space -> pseudo-accent
43 ;; pseudo-accent + pseudo-accent -> accent (if available)
44 ;; pseudo-accent + other -> pseudo-accent + other
45 ;;
46 ;; If the pseudo-accent is followed by anything else than a
47 ;; self-insert-command, the dead-key code is terminated, the
48 ;; pseudo-accent inserted 'as is' and the bell is rung to signal this.
49 ;;
50 ;; Function `iso-accents' can be used to enable the iso accents
51 ;; minor mode, or disable it when called with a non-null argument.
52
53 ;;; Code:
54
55 (provide 'iso-acc)
56
57 (defvar iso-accents-list
58 '(((?' ?A) ?\301)
59 ((?' ?E) ?\311)
60 ((?' ?I) ?\315)
61 ((?' ?O) ?\323)
62 ((?' ?U) ?\332)
63 ((?' ?a) ?\341)
64 ((?' ?e) ?\351)
65 ((?' ?i) ?\355)
66 ((?' ?o) ?\363)
67 ((?' ?u) ?\372)
68 ((?' ?') ?\264)
69 ((?' ? ) ?')
70 ((?` ?A) ?\300)
71 ((?` ?E) ?\310)
72 ((?` ?I) ?\314)
73 ((?` ?O) ?\322)
74 ((?` ?U) ?\331)
75 ((?` ?a) ?\340)
76 ((?` ?e) ?\350)
77 ((?` ?i) ?\354)
78 ((?` ?o) ?\362)
79 ((?` ?u) ?\371)
80 ((?` ? ) ?`)
81 ((?` ?`) ?`) ; no special code?
82 ((?` ?A) ?\302)
83 ((?^ ?E) ?\312)
84 ((?^ ?I) ?\316)
85 ((?^ ?O) ?\324)
86 ((?^ ?U) ?\333)
87 ((?^ ?a) ?\342)
88 ((?^ ?e) ?\352)
89 ((?^ ?i) ?\356)
90 ((?^ ?o) ?\364)
91 ((?^ ?u) ?\373)
92 ((?^ ? ) ?^)
93 ((?^ ?^) ?^) ; no special code?
94 ((?\" ?A) ?\304)
95 ((?\" ?E) ?\313)
96 ((?\" ?I) ?\317)
97 ((?\" ?O) ?\326)
98 ((?\" ?U) ?\334)
99 ((?\" ?a) ?\344)
100 ((?\" ?e) ?\353)
101 ((?\" ?i) ?\357)
102 ((?\" ?o) ?\366)
103 ((?\" ?u) ?\374)
104 ((?\" ? ) ?\")
105 ((?\" ?\") ?\250)
106 )
107 "Association list for iso accent combinations.")
108
109 (defun iso-accents-dead-key ()
110 "Emulate typewriter dead keys."
111 (interactive)
112
113 ;; Pick up the dead-key.
114 (let ((first-char last-command-char))
115
116 ;; Display it and backup.
117 (insert first-char)
118 (backward-char 1)
119
120 ;; Wait for the second key and look up the combination in the list.
121 (let* ((second-char (read-event))
122 (entry (assoc (list first-char second-char) iso-accents-list)))
123 (if entry
124 ;; Found it: delete the first character and insert the combination.
125 (progn
126 (delete-char 1)
127 (insert (car (cdr entry))))
128
129 ;; Otherwise, advance and schedule the second key for execution.
130 (forward-char 1)
131 (setq unread-command-events (list second-char))
132
133 ;; If it is not a self-insert-command, ring the terminal bell.
134 (or (eq (key-binding (make-vector 1 second-char)) 'self-insert-command)
135 (beep 1))))))
136
137 (defvar iso-accents-minor-mode nil
138 "Buffer local variable that denotes 'dead key' minor mode.")
139
140 (defvar iso-accents-prefix-map nil
141 "Keymap for 'dead key' minor mode.")
142
143 ;; It is a matter of taste if you want the minor mode indicated
144 ;; in the mode line...
145 ;; If so, uncomment the next three lines.
146 ;; (or (assq 'iso-accents-minor-mode minor-mode-map-alist)
147 ;; (setq minor-mode-alist
148 ;; (append minor-mode-alist
149 ;; '((iso-accents-minor-mode " ISO-Acc")))))
150
151 ;;;###autoload
152 (defun iso-accents (&optional arg)
153 "Allow easy insertion of accented characters according to ISO-8859-1.
154 When called without an argument, or with a null argument, pseudo-accent
155 keys (', \", ^ and ~) will behave like dead typewriter keys: when
156 followed by an appropriate character the combination will be replaced
157 by the corresponding ISO character code for the accented character.
158 Calling `iso-accents' with an argument will make all keys normal again."
159 ;; When called, a buffer local variable iso-accents-minor-mode is created
160 ;; to record iso-accents-minor-mode status.
161 ;; A minor mode map `iso-accents-prefix-map' is used to activate the dead
162 ;; key handling dependend on the value of iso-accents-minor-mode.
163
164 (interactive "P")
165
166 ;; Create buffer local variable iso-accents-minor-mode.
167 (make-local-variable 'iso-accents-minor-mode)
168
169 (if arg
170 ;; Switch it off.
171 (setq iso-accents-minor-mode nil)
172
173 ;; Enable electric accents.
174 (setq iso-accents-minor-mode t)
175
176 ;; Create the minor-mode keymap, if needed.
177 (or iso-accents-prefix-map
178 (progn
179 (setq iso-accents-prefix-map (make-sparse-keymap))
180 (define-key iso-accents-prefix-map "'" 'iso-accents-dead-key)
181 (define-key iso-accents-prefix-map "`" 'iso-accents-dead-key)
182 (define-key iso-accents-prefix-map "^" 'iso-accents-dead-key)
183 (define-key iso-accents-prefix-map "\"" 'iso-accents-dead-key)
184
185 ;; Add the dead key minor mode map to the minor mode maps.
186 (or (assq 'iso-accents-minor-mode minor-mode-map-alist)
187 (setq minor-mode-map-alist
188 (cons (cons 'iso-accents-minor-mode iso-accents-prefix-map)
189 minor-mode-map-alist)))))))
190
191 ;;; iso-acc.el ends here
192