Mercurial > emacs
comparison lisp/international/encoded-kb.el @ 89704:f786eb22f54c
(encoded-kbd-self-insert-utf-8): New function.
(encoded-kbd-setup-keymap): Add code for handling utf-8.
(encoded-kbd-mode): Likewise.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 15 Jan 2004 02:15:34 +0000 |
parents | 2f877ed80fa6 |
children | 68c22ea6027c |
comparison
equal
deleted
inserted
replaced
89703:3756c51dab99 | 89704:f786eb22f54c |
---|---|
85 (define-key map (vector i) 'encoded-kbd-handle-8bit) | 85 (define-key map (vector i) 'encoded-kbd-handle-8bit) |
86 (setq i (1+ i))) | 86 (setq i (1+ i))) |
87 map) | 87 map) |
88 "Keymap for handling non-ASCII character set in Encoded-kbd mode.") | 88 "Keymap for handling non-ASCII character set in Encoded-kbd mode.") |
89 | 89 |
90 ;; One of the symbols `sjis', `iso2022-7', `iso2022-8', or `big5' to | 90 ;; One of the symbols `sjis', `iso2022-7', `iso2022-8', `big5', or |
91 ;; denote what kind of coding-system we are now handling in | 91 ;; `utf-8' to denote what kind of coding-system we are now handling in |
92 ;; Encoded-kbd mode. | 92 ;; Encoded-kbd mode. |
93 (defvar encoded-kbd-coding nil) | 93 (defvar encoded-kbd-coding nil) |
94 | 94 |
95 ;; Keep information of designation state of ISO2022 encoding. When | 95 ;; Keep information of designation state of ISO2022 encoding. When |
96 ;; Encoded-kbd mode is on, this is set to a vector of length 4, the | 96 ;; Encoded-kbd mode is on, this is set to a vector of length 4, the |
255 ;; infinite-loop for characters 160..255, this is a temporary | 255 ;; infinite-loop for characters 160..255, this is a temporary |
256 ;; workaround until we found a better solution. | 256 ;; workaround until we found a better solution. |
257 (let ((last-command-char c)) | 257 (let ((last-command-char c)) |
258 (self-insert-command arg)))) | 258 (self-insert-command arg)))) |
259 | 259 |
260 (defun encoded-kbd-self-insert-utf-8 (arg) | |
261 (interactive "p") | |
262 (let (len ch) | |
263 (cond ((< last-command-char #xE0) | |
264 (setq len 1 ch (logand last-command-char #x1F))) | |
265 ((< last-command-char #xF0) | |
266 (setq len 2 ch (logand last-command-char #x0F))) | |
267 ((< last-command-char #xF8) | |
268 (setq len 3 ch (logand last-command-char #x07))) | |
269 (t | |
270 (setq len 4 ch 0))) | |
271 (while (> len 0) | |
272 (setq ch (logior (lsh ch 6) (logand (read-char-exclusive) #x3F)) | |
273 len (1- len))) | |
274 (let ((last-command-char ch)) | |
275 (self-insert-command arg)))) | |
276 | |
260 (defun encoded-kbd-setup-keymap (coding) | 277 (defun encoded-kbd-setup-keymap (coding) |
261 ;; At first, reset the keymap. | 278 ;; At first, reset the keymap. |
262 (setcdr encoded-kbd-mode-map nil) | 279 (setcdr encoded-kbd-mode-map nil) |
263 ;; Then setup the keymap according to the keyboard coding system. | 280 ;; Then setup the keymap according to the keyboard coding system. |
264 (cond | 281 (cond |
313 (if (>= from 128) | 330 (if (>= from 128) |
314 (define-key encoded-kbd-mode-map | 331 (define-key encoded-kbd-mode-map |
315 (vector from) 'encoded-kbd-self-insert-ccl)) | 332 (vector from) 'encoded-kbd-self-insert-ccl)) |
316 (setq from (1+ from)))))) | 333 (setq from (1+ from)))))) |
317 | 334 |
335 ((eq encoded-kbd-coding 'utf-8) | |
336 (let ((i #xC0)) | |
337 (while (< i 256) | |
338 (define-key encoded-kbd-mode-map | |
339 (vector i) 'encoded-kbd-self-insert-utf-8) | |
340 (setq i (1+ i))))) | |
341 | |
318 (t | 342 (t |
319 (error "Invalid value in encoded-kbd-coding: %s" encoded-kbd-coding)))) | 343 (error "Invalid value in encoded-kbd-coding: %s" encoded-kbd-coding)))) |
320 | 344 |
321 | 345 |
322 ;; Input mode at the time Encoded-kbd mode is turned on is saved here. | 346 ;; Input mode at the time Encoded-kbd mode is turned on is saved here. |
385 (set-input-mode | 409 (set-input-mode |
386 (nth 0 saved-input-mode) (nth 1 saved-input-mode) | 410 (nth 0 saved-input-mode) (nth 1 saved-input-mode) |
387 'use-8th-bit (nth 3 saved-input-mode)) | 411 'use-8th-bit (nth 3 saved-input-mode)) |
388 (setq encoded-kbd-coding 'charset)) | 412 (setq encoded-kbd-coding 'charset)) |
389 | 413 |
414 ((eq (coding-system-type coding) 'utf-8) | |
415 (set-input-mode | |
416 (nth 0 saved-input-mode) (nth 1 saved-input-mode) | |
417 'use-8th-bit (nth 3 saved-input-mode)) | |
418 (setq encoded-kbd-coding 'utf-8)) | |
419 | |
390 (t | 420 (t |
391 (setq encoded-kbd-mode nil) | 421 (setq encoded-kbd-mode nil) |
392 (error "Coding-system `%s' is not supported in Encoded-kbd mode" | 422 (error "Coding-system `%s' is not supported in Encoded-kbd mode" |
393 (keyboard-coding-system)))) | 423 (keyboard-coding-system)))) |
394 (encoded-kbd-setup-keymap coding)))) | 424 (encoded-kbd-setup-keymap coding)))) |