comparison lisp/international/encoded-kb.el @ 90025:b826d8196afd

(encoded-kbd-decode-code-list): New function. (encoded-kbd-self-insert-charset): Support multibyte charsets. (encoded-kbd-setup-keymap): Likewise.
author Kenichi Handa <handa@m17n.org>
date Fri, 15 Oct 2004 07:26:15 +0000
parents 1e6118d38ca9
children befae6bafecb
comparison
equal deleted inserted replaced
90024:2289ad7ece19 90025:b826d8196afd
175 (while (= (length (setq result (ccl-execute-on-string ccl vec str t))) 0) 175 (while (= (length (setq result (ccl-execute-on-string ccl vec str t))) 0)
176 (dotimes (i 9) (aset vec i nil)) 176 (dotimes (i 9) (aset vec i nil))
177 (setq str (format "%s%c" str (read-char-exclusive)))) 177 (setq str (format "%s%c" str (read-char-exclusive))))
178 (vector (aref result 0)))) 178 (vector (aref result 0))))
179 179
180
181 ;; Decode list of codes in CODE-LIST by CHARSET and return the decoded
182 ;; characters. If CODE-LIST is too short for the dimension of
183 ;; CHARSET, read new codes and append them to the tail of CODE-LIST.
184 ;; Return nil if CODE-LIST can't be decoded.
185
186 (defun encoded-kbd-decode-code-list (charset code-list)
187 (let ((dimension (charset-dimension charset))
188 code)
189 (while (> dimension (length code-list))
190 (nconc code-list (list (read-char-exclusive))))
191 (setq code (car code-list))
192 (if (= dimension 1)
193 (decode-char charset code)
194 (setq code-list (cdr code-list)
195 code (logior (lsh code 8) (car code-list)))
196 (if (= dimension 2)
197 (decode-char charset code)
198 (setq code-list (cdr code-list)
199 code (logior (lsh code 8) (car code-list)))
200 (if (= dimension 3)
201 (decode-char charset code)
202 ;; As Emacs can't handle full 32-bit integer, we must give a
203 ;; cons of higher and lower 16-bit codes to decode-char.
204 (setq code (cons (lsh code -8)
205 (logior (lsh (car code-list) 8) (cadr code-list))))
206 (decode-char charset code))))))
207
180 (defun encoded-kbd-self-insert-charset (ignore) 208 (defun encoded-kbd-self-insert-charset (ignore)
181 (let* ((charset-list 209 (let ((charset-list
182 (coding-system-get (keyboard-coding-system) :charset-list)) 210 (coding-system-get (keyboard-coding-system) :charset-list))
183 (charset (car charset-list)) 211 (code-list (list (encoded-kbd-last-key)))
184 ;; For the moment, we can assume that the length of CHARSET-LIST 212 tail char)
185 ;; is 1, and the dimension of CHARSET is 1. 213 (while (and charset-list (not char))
186 (char (encoded-kbd-last-key))) 214 (setq char (encoded-kbd-decode-code-list (car charset-list) code-list)
187 (vector (or (decode-char charset char) char)))) 215 charset-list (cdr charset-list)))
216 (if char
217 (vector char)
218 (setq unread-command-events (cdr code-list))
219 (vector (car code-list)))))
188 220
189 (defun encoded-kbd-self-insert-utf-8 (arg) 221 (defun encoded-kbd-self-insert-utf-8 (arg)
190 (interactive "p") 222 (interactive "p")
191 (let ((char (encoded-kbd-last-key)) 223 (let ((char (encoded-kbd-last-key))
192 len) 224 len)
215 (vector i) 'encoded-kbd-self-insert-sjis) 247 (vector i) 'encoded-kbd-self-insert-sjis)
216 (setq i (1+ i)))) 248 (setq i (1+ i))))
217 8) 249 8)
218 250
219 ((eq (coding-system-type coding) 'charset) 251 ((eq (coding-system-type coding) 'charset)
220 (let* ((charset (car (coding-system-get coding :charset-list))) 252 (dolist (elt (mapcar
221 (code-space (get-charset-property charset :code-space)) 253 #'(lambda (x)
222 (from (max (aref code-space 0) 128)) 254 (let ((dim (charset-dimension x))
223 (to (aref code-space 1))) 255 (code-space (get-charset-property x :code-space)))
224 (while (<= from to) 256 (cons (aref code-space (* (1- dim) 2))
225 (define-key key-translation-map 257 (aref code-space (1+ (* (1- dim) 2))))))
226 (vector from) 'encoded-kbd-self-insert-charset) 258 (coding-system-get coding :charset-list)))
227 (setq from (1+ from)))) 259 (let ((from (max (car elt) 128))
260 (to (cdr elt)))
261 (while (<= from to)
262 (define-key key-translation-map
263 (vector from) 'encoded-kbd-self-insert-charset)
264 (setq from (1+ from)))))
228 8) 265 8)
229 266
230 ((eq (coding-system-type coding) 'iso-2022) 267 ((eq (coding-system-type coding) 'iso-2022)
231 (let ((flags (coding-system-get coding :flags)) 268 (let ((flags (coding-system-get coding :flags))
232 (designation (coding-system-get coding :designation))) 269 (designation (coding-system-get coding :designation)))