]> code.delx.au - gnu-emacs/blobdiff - lisp/international/encoded-kb.el
(byte-compile-inline-expand):
[gnu-emacs] / lisp / international / encoded-kb.el
index 1da1f37dd61e24c641de9f46d110a81d090911cc..e23d9c4bd758426e862447ba414239377cee0baf 100644 (file)
       (define-key map (char-to-string i) 'encoded-kbd-self-insert-iso2022-7bit)
       (setq i (1+ i)))
     (define-key map "\e" 'encoded-kbd-iso2022-esc-prefix)
+    (setq i 160)
+    (while (< i 256)
+      (define-key map (vector i) 'encoded-kbd-handle-8bit)
+      (setq i (1+ i)))
     map)
   "Keymap for handling non-ASCII character set in Encoded-kbd mode.")
 
 ;; registers (0..3).
 
 (defvar encoded-kbd-iso2022-designations nil)
-(make-variable-buffer-local 'encoded-kbd-iso2022-designations)
 (put 'encoded-kbd-iso2022-designations 'permanent-local t)
 
 ;; Keep information of invocation state of ISO2022 encoding.  This is
 ;; register number.
 
 (defvar encoded-kbd-iso2022-invocations nil)
-(make-variable-buffer-local 'encoded-kbd-iso2022-invocations)
 (put 'encoded-kbd-iso2022-invocations 'permanent-local t)
 
 (defun encoded-kbd-iso2022-designation ()
 The following key sequence may cause multilingual text insertion."
   (interactive)
   (let ((key-seq (this-command-keys))
+       (prev-g0-charset (aref encoded-kbd-iso2022-designations
+                              (aref encoded-kbd-iso2022-invocations 0)))
        intermediate-char final-char
        reg dimension chars charset)
     (if (= (length key-seq) 4)
@@ -147,14 +151,18 @@ The following key sequence may cause multilingual text insertion."
             dimension chars final-char))
 
     (if (memq (aref encoded-kbd-iso2022-designations
-                (aref encoded-kbd-iso2022-invocations 0))
+                   (aref encoded-kbd-iso2022-invocations 0))
              '(ascii latin-jisx0201))
        ;; Graphic plane 0 (0x20..0x7f) is for ASCII.  We don't have
        ;; to handle characters in this range specially.
-       (throw 'exit nil)
+       (if (not (memq prev-g0-charset '(ascii latin-jisx0201)))
+           ;; We must exit recusive edit now.
+           (throw 'exit nil))
       ;; Graphic plane 0 is for non-ASCII.
-      (let ((overriding-local-map encoded-kbd-iso2022-non-ascii-map))
-       (recursive-edit)))))
+      (if (memq prev-g0-charset '(ascii latin-jisx0201))
+         ;; We must handle kyes specially.
+         (let ((overriding-local-map encoded-kbd-iso2022-non-ascii-map))
+           (recursive-edit))))))
 
 (defun encoded-kbd-handle-8bit ()
   "Handle an 8-bit character enterned in Encoded-kbd mode."
@@ -188,7 +196,7 @@ The following key sequence may cause multilingual text insertion."
                        (or (aref encoded-kbd-iso2022-invocations 2)
                            (aref encoded-kbd-iso2022-invocations 0))))
         (last-command-char
-         (if (= (charset-bytes charset) 1)
+         (if (= (charset-dimension charset) 1)
              (make-char charset last-command-char)
            (make-char charset last-command-char (read-char-exclusive)))))
     (self-insert-command 1)
@@ -201,7 +209,7 @@ The following key sequence may cause multilingual text insertion."
                        (or (aref encoded-kbd-iso2022-invocations 2)
                            (aref encoded-kbd-iso2022-invocations 1))))
         (last-command-char
-         (if (= (charset-bytes charset) 1)
+         (if (= (charset-dimension charset) 1)
              (make-char charset last-command-char)
            (make-char charset last-command-char (read-char-exclusive)))))
     (self-insert-command 1)
@@ -214,7 +222,7 @@ The following key sequence may cause multilingual text insertion."
         (if (or (< last-command-char ?\xA0) (>= last-command-char ?\xE0))
             (decode-sjis-char (+ (ash last-command-char 8)
                                  (read-char-exclusive)))
-          (make-char 'latin-jisx0201 last-command-char))))
+          (make-char 'katakana-jisx0201 last-command-char))))
     (self-insert-command 1)))
 
 (defun encoded-kbd-self-insert-big5 ()
@@ -224,64 +232,72 @@ The following key sequence may cause multilingual text insertion."
                              (read-char-exclusive)))))
     (self-insert-command 1)))
 
+;; Input mode at the time Encoded-kbd mode is turned on is saved here.
+(defvar saved-input-mode nil)
+
 ;;;###autoload
 (defun encoded-kbd-mode (&optional arg)
   "Toggle Encoded-kbd minor mode.
-With arg, turn Keyboard-kbd mode on if and only if arg is positive.
+With arg, turn Encoded-kbd mode on if and only if arg is positive.
 
-When in Encoded-kbd mode, a text sent from a terminal keyboard
-is accepted as a multilingual text encoded in a coding system
-set by the command `encoded-kbd-set-coding-system'"
-  (interactive "P")
+You should not turn this mode on manually, instead use the command
+\\[set-keyboard-coding-system] which turns on or off this mode
+automatically.
+
+In Encoded-kbd mode, a text sent from keyboard is accepted
+as a multilingual text encoded in a coding system set by
+\\[set-keyboard-coding-system]."
+  (if encoded-kbd-mode
+      ;; We must at first reset input-mode to the original.
+      (apply 'set-input-mode saved-input-mode))
   (setq encoded-kbd-mode
        (if (null arg) (null encoded-kbd-mode)
          (> (prefix-numeric-value arg) 0)))
   (if encoded-kbd-mode
-      (let* ((coding (coding-system-vector (keyboard-coding-system)))
-            (input-mode (current-input-mode)))
+      (let ((coding (keyboard-coding-system)))
+       (setq saved-input-mode  (current-input-mode))
        (cond ((null coding)
               (setq encoded-kbd-mode nil) 
-              (error "No coding-system for terminal keyboard is set"))
+              (error "No coding system for keyboard input is set"))
 
-             ((= (coding-vector-type coding) 1) ; SJIS
-              (set-input-mode (nth 0 input-mode) (nth 1 input-mode)
-                              'use-8th-bit (nth 3 input-mode)) 
+             ((= (coding-system-type coding) 1) ; SJIS
+              (set-input-mode
+               (nth 0 saved-input-mode) (nth 1 saved-input-mode)
+               'use-8th-bit (nth 3 saved-input-mode))  
               (setq encoded-kbd-coding 'sjis))
 
-             ((= (coding-vector-type coding) 2) ; ISO2022
-              (if (aref (coding-vector-flags coding) 7) ; 7-bit only
+             ((= (coding-system-type coding) 2) ; ISO2022
+              (if (aref (coding-system-flags coding) 7) ; 7-bit only
                   (setq encoded-kbd-coding 'iso2022-7)
-                (set-input-mode (nth 0 input-mode) (nth 1 input-mode)
-                                'use-8th-bit (nth 3 input-mode))       
+                (set-input-mode
+                 (nth 0 saved-input-mode) (nth 1 saved-input-mode)
+                 'use-8th-bit (nth 3 saved-input-mode))        
                 (setq encoded-kbd-coding 'iso2022-8))
-              (make-variable-buffer-local 'encoded-kbd-iso2022-designations)
               (setq encoded-kbd-iso2022-designations (make-vector 4 nil))
-              (let ((flags (coding-vector-flags coding))
+              (let ((flags (coding-system-flags coding))
                     (i 0))
                 (while (< i 4)
                   (if (charsetp (aref flags i))
                       (aset encoded-kbd-iso2022-designations i
-                            (aref flags i)))
+                            (aref flags i))
+                    (if (charsetp (car-safe (aref flags i)))
+                      (aset encoded-kbd-iso2022-designations i
+                            (car (aref flags i)))))
                   (setq i (1+ i))))
-              (make-variable-buffer-local 'encoded-kbd-iso2022-invocations)
               (setq encoded-kbd-iso2022-invocations (make-vector 3 nil))
               (aset encoded-kbd-iso2022-invocations 0 0)
               (aset encoded-kbd-iso2022-invocations 1 1))
 
-             ((= (coding-vector-type coding) 3) ; BIG5
-              (set-input-mode (nth 0 input-mode) (nth 1 input-mode)
-                              'use-8th-bit (nth 3 input-mode)) 
+             ((= (coding-system-type coding) 3) ; BIG5
+              (set-input-mode
+               (nth 0 saved-input-mode) (nth 1 saved-input-mode)
+               'use-8th-bit (nth 3 saved-input-mode))  
               (setq encoded-kbd-coding 'big5))
 
              (t
               (setq encoded-kbd-mode nil)
               (error "Coding-system `%s' is not supported in Encoded-kbd mode"
                      (keyboard-coding-system))))
-       (setq inactivate-current-input-method-function 'encoded-kbd-mode)
-       (setq describe-current-input-method-function 'encoded-kbd-mode-help)
-       (run-hooks 'encoded-kbd-mode-hook))
-    (setq describe-current-input-method-function nil)
-    (setq current-input-method nil))
-  (force-mode-line-update))
+       (run-hooks 'encoded-kbd-mode-hook))))
 
 ;;; encoded-kb.el ends here