aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1993-10-24 23:21:21 +0000
committerRichard M. Stallman1993-10-24 23:21:21 +0000
commitda8d0b9e2db7fba9c080de786a75a6b838f987ea (patch)
tree07789d19ed87db700cd127f58ea02708d4cfe81a
parent30d47262d12a35bb381f1ca66cbf0428183270fc (diff)
downloademacs-da8d0b9e2db7fba9c080de786a75a6b838f987ea.tar.gz
emacs-da8d0b9e2db7fba9c080de786a75a6b838f987ea.zip
Define "dead keys" in key-translation-map, not in global-map.
(iso-accents-compose): New subroutine to do the composition. Method of doing so is new. (iso-accents-accent-key): Use iso-accents-compose. (iso-accents-compose-key): New function.
-rw-r--r--lisp/international/iso-acc.el103
1 files changed, 56 insertions, 47 deletions
diff --git a/lisp/international/iso-acc.el b/lisp/international/iso-acc.el
index e165b0d25f0..4f1e9bc31ea 100644
--- a/lisp/international/iso-acc.el
+++ b/lisp/international/iso-acc.el
@@ -107,59 +107,68 @@
107 ) 107 )
108 "Association list for ISO accent combinations.") 108 "Association list for ISO accent combinations.")
109 109
110(defun iso-accents-accent-key ()
111 "Modify the following character by adding an accent to it."
112 (interactive)
113
114 ;; Pick up the accent character.
115 (let ((first-char last-command-char))
116
117 ;; Display it and backup.
118 (insert first-char)
119 (backward-char 1)
120
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))))
129
130 ;; Otherwise, advance and schedule the second key for execution.
131 (forward-char 1)
132 (setq unread-command-events (list second-char))
133
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))))))
137
138(defvar iso-accents-minor-mode nil 110(defvar iso-accents-minor-mode nil
139 "*Non-nil enables ISO-accents mode. 111 "*Non-nil enables ISO-accents mode.
140Setting this variable makes it local to the current buffer. 112Setting this variable makes it local to the current buffer.
141See `iso-accents-mode'.") 113See `iso-accents-mode'.")
142(make-variable-buffer-local 'iso-accents-minor-mode) 114(make-variable-buffer-local 'iso-accents-minor-mode)
143 115
144;; A minor mode map `iso-accents-prefix-map' is used to activate the 116(defun iso-accents-accent-key (prompt)
145;; dead key handling depending on the value of iso-accents-minor-mode. 117 "Modify the following character by adding an accent to it."
146(defvar iso-accents-prefix-map nil 118 ;; Pick up the accent character.
147 "Keymap for ISO-accents minor mode.") 119 (if iso-accents-minor-mode
148 120 (iso-accents-compose prompt)
149;; Create the minor-mode keymap, if needed. 121 (char-to-string last-input-char)))
150(or iso-accents-prefix-map 122
151 (progn 123(defun iso-accents-compose-key (prompt)
152 (setq iso-accents-prefix-map (make-sparse-keymap)) 124 "Modify the following character by adding an accent to it."
153 (define-key iso-accents-prefix-map "'" 'iso-accents-dead-key) 125 ;; Pick up the accent character.
154 (define-key iso-accents-prefix-map "`" 'iso-accents-dead-key) 126 (let ((combined (iso-accents-compose prompt)))
155 (define-key iso-accents-prefix-map "^" 'iso-accents-dead-key) 127 (if unread-command-events
156 (define-key iso-accents-prefix-map "\"" 'iso-accents-dead-key))) 128 (let ((unread unread-command-events))
157 129 (setq unread-command-events nil)
158;; Add the dead key minor mode map to the minor mode maps. 130 (error "Characters %s and %s cannot be composed"
159(or (assq 'iso-accents-minor-mode minor-mode-map-alist) 131 (single-key-description (aref combined 0))
160 (setq minor-mode-map-alist 132 (single-key-description (car unread)))))
161 (cons (cons 'iso-accents-minor-mode iso-accents-prefix-map) 133 combined))
162 minor-mode-map-alist))) 134
135(defun iso-accents-compose (prompt)
136 (let* ((first-char last-input-char)
137 ;; Wait for the second key and look up the combination.
138 (second-char (if (or prompt
139 (not (eq (key-binding "a")
140 'self-insert-command)))
141 (progn
142 (message "%s%c"
143 (or prompt "Compose with ")
144 first-char)
145 (read-event))
146 (insert first-char)
147 (prog1 (read-event)
148 (delete-region (1- (point)) (point)))))
149 (entry (assoc (list first-char second-char) iso-accents-list)))
150 (if entry
151 ;; Found it: delete the first character and insert the combination.
152 (concat (list (nth 1 entry)))
153 ;; Otherwise, advance and schedule the second key for execution.
154 (setq unread-command-events (list second-char))
155 (vector first-char))))
156
157(or key-translation-map (setq key-translation-map (make-sparse-keymap)))
158;; For sequences starting with an accent character,
159;; use a function that tests iso-accents-minor-mode.
160(define-key key-translation-map "'" 'iso-accents-accent-key)
161(define-key key-translation-map "`" 'iso-accents-accent-key)
162(define-key key-translation-map "^" 'iso-accents-accent-key)
163(define-key key-translation-map "\"" 'iso-accents-accent-key)
164;; For sequences starting with a compose key,
165;; always do the compose processing.
166(define-key key-translation-map [compose ?\'] 'iso-accents-compose-key)
167(define-key key-translation-map [compose ?\`] 'iso-accents-compose-key)
168(define-key key-translation-map [compose ?^] 'iso-accents-compose-key)
169(define-key key-translation-map [compose ?\"] 'iso-accents-compose-key)
170;; The way to make compose work is to translate some other key sequence
171;; into it, using key-translation-map.
163 172
164;; It is a matter of taste if you want the minor mode indicated 173;; It is a matter of taste if you want the minor mode indicated
165;; in the mode line... 174;; in the mode line...