(paragraph-start, paragraph-separate): Default values no longer start
[bpt/emacs.git] / lisp / international / iso-acc.el
1 ;;; iso-acc.el -- minor mode providing electric accent keys
2 ;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
3
4 ;; Author: Johan Vromans <jv@mh.nl>
5 ;; Version: 1.7 (modified)
6 ;; Maintainer: FSF
7 ;; Keywords: i18n
8
9 ;; This file is part of GNU Emacs.
10
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)
14 ;; any later version.
15
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.
20
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.
24
25 ;;; Commentary:
26
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.
31 ;;
32 ;; In `iso-accents-mode', pseudo accent characters are used to
33 ;; introduce accented keys. The pseudo-accent characters are:
34 ;;
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.
42 ;;
43 ;; The action taken depends on the key that follows the pseudo accent.
44 ;; In general:
45 ;;
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
50 ;;
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.
54 ;;
55 ;; Function `iso-accents-mode' can be used to enable the iso accents
56 ;; minor mode, or disable it.
57
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.
60 \f
61 ;;; Code:
62
63 (provide 'iso-acc)
64
65 (defvar iso-accents-list
66 '(((?' ?A) ?\301)
67 ((?' ?E) ?\311)
68 ((?' ?I) ?\315)
69 ((?' ?O) ?\323)
70 ((?' ?U) ?\332)
71 ((?' ?Y) ?\335)
72 ((?' ?a) ?\341)
73 ((?' ?e) ?\351)
74 ((?' ?i) ?\355)
75 ((?' ?o) ?\363)
76 ((?' ?u) ?\372)
77 ((?' ?y) ?\375)
78 ((?' ?') ?\264)
79 ((?' ? ) ?')
80 ((?` ?A) ?\300)
81 ((?` ?E) ?\310)
82 ((?` ?I) ?\314)
83 ((?` ?O) ?\322)
84 ((?` ?U) ?\331)
85 ((?` ?a) ?\340)
86 ((?` ?e) ?\350)
87 ((?` ?i) ?\354)
88 ((?` ?o) ?\362)
89 ((?` ?u) ?\371)
90 ((?` ? ) ?`)
91 ((?` ?`) ?`) ; no special code?
92 ((?^ ?A) ?\302)
93 ((?^ ?E) ?\312)
94 ((?^ ?I) ?\316)
95 ((?^ ?O) ?\324)
96 ((?^ ?U) ?\333)
97 ((?^ ?a) ?\342)
98 ((?^ ?e) ?\352)
99 ((?^ ?i) ?\356)
100 ((?^ ?o) ?\364)
101 ((?^ ?u) ?\373)
102 ((?^ ? ) ?^)
103 ((?^ ?^) ?^) ; no special code?
104 ((?\" ?A) ?\304)
105 ((?\" ?E) ?\313)
106 ((?\" ?I) ?\317)
107 ((?\" ?O) ?\326)
108 ((?\" ?U) ?\334)
109 ((?\" ?a) ?\344)
110 ((?\" ?e) ?\353)
111 ((?\" ?i) ?\357)
112 ((?\" ?o) ?\366)
113 ((?\" ?s) ?\337)
114 ((?\" ?u) ?\374)
115 ((?\" ?y) ?\377)
116 ((?\" ? ) ?\")
117 ((?\" ?\") ?\250)
118 ((?\~ ?A) ?\303)
119 ((?\~ ?C) ?\307)
120 ((?\~ ?D) ?\320)
121 ((?\~ ?N) ?\321)
122 ((?\~ ?O) ?\325)
123 ((?\~ ?T) ?\336)
124 ((?\~ ?a) ?\343)
125 ((?\~ ?c) ?\347)
126 ((?\~ ?d) ?\360)
127 ((?\~ ?n) ?\361)
128 ((?\~ ?o) ?\365)
129 ((?\~ ?t) ?\376)
130 ((?\~ ?>) ?\273)
131 ((?\~ ?<) ?\253)
132 ((?\~ ?\ ) ?\~)
133 ((?\~ ?\~) ?\270) ;; cedilla accent
134 ((?\/ ?A) ?\305) ;; A-with-ring (Norwegian and Danish)
135 ((?\/ ?E) ?\306) ;; AE-ligature (Norwegian and Danish)
136 ((?\/ ?O) ?\330)
137 ((?\/ ?a) ?\345) ;; a-with-ring (Norwegian and Danish)
138 ((?\/ ?e) ?\346) ;; ae-ligature (Norwegian and Danish)
139 ((?\/ ?o) ?\370)
140 ((?\/ ?\ ) ?\/)
141 ((?\/ ?\/) ?\260) ;; ring accent (actually degree sign?)
142 )
143 "Association list for ISO accent combinations.")
144
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)
150
151 (defun iso-accents-accent-key (prompt)
152 "Modify the following character by adding an accent to it."
153 ;; Pick up the accent character.
154 (if iso-accents-mode
155 (iso-accents-compose prompt)
156 (char-to-string last-input-char)))
157
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)))))
168 combined))
169
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)))
176 (progn
177 (message "%s%c"
178 (or prompt "Compose with ")
179 first-char)
180 (read-event))
181 (insert first-char)
182 (prog1 (read-event)
183 (delete-region (1- (point)) (point)))))
184 (entry (assoc (list first-char second-char) iso-accents-list)))
185 (if entry
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))))
191
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.")
197
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))
213
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")))))
221
222 ;;;###autoload
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.
229
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.
233
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.
241
242 With an argument, a positive argument enables ISO Accents mode,
243 and a negative argument disables it."
244
245 (interactive "P")
246
247 (if (if arg
248 ;; Negative arg means switch it off.
249 (<= (prefix-numeric-value arg) 0)
250 ;; No arg means toggle.
251 iso-accents-mode)
252 (setq iso-accents-mode nil)
253
254 ;; Enable electric accents.
255 (setq iso-accents-mode t)))
256
257 ;;; iso-acc.el ends here