/[emacs]/emacs/lisp/international/encoded-kb.el
ViewVC logotype

Diff of /emacs/lisp/international/encoded-kb.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28.6.4 by miles, Tue Aug 10 07:46:39 2004 UTC revision 1.28.6.5 by miles, Wed Aug 18 06:38:14 2004 UTC
# Line 177  The following key sequence may cause mul Line 177  The following key sequence may cause mul
177        (setq str (format "%s%c" str (read-char-exclusive))))        (setq str (format "%s%c" str (read-char-exclusive))))
178      (vector (aref result 0))))      (vector (aref result 0))))
179    
180  (defun encoded-kbd-self-insert-charset (arg)  (defun encoded-kbd-self-insert-charset (ignore)
   (interactive "p")  
181    (let* ((charset-list    (let* ((charset-list
182            (coding-system-get (keyboard-coding-system) :charset-list))            (coding-system-get (keyboard-coding-system) :charset-list))
183           (charset (car charset-list))           (charset (car charset-list))
184           ;; For the moment, we can assume that the length of CHARSET-LIST           ;; For the moment, we can assume that the length of CHARSET-LIST
185           ;; is 1, and the dimension of CHARSET is 1.           ;; is 1, and the dimension of CHARSET is 1.
186           (c (decode-char charset last-command-char)))           (char (encoded-kbd-last-key)))
187      (unless c      (vector (or (decode-char charset char) char))))
       (error "Can't decode the code point %d by %s"  
              last-command-char charset))  
     ;; As simply setting unread-command-events may result in  
     ;; infinite-loop for characters 160..255, this is a temporary  
     ;; workaround until we found a better solution.  
     (let ((last-command-char c))  
       (self-insert-command arg))))  
188    
189  (defun encoded-kbd-self-insert-utf-8 (arg)  (defun encoded-kbd-self-insert-utf-8 (arg)
190    (interactive "p")    (interactive "p")
191    (let (len ch)    (let ((char (encoded-kbd-last-key))
192      (cond ((< last-command-char #xE0)          len)
193             (setq len 1 ch (logand last-command-char #x1F)))      (cond ((< char #xE0)
194            ((< last-command-char #xF0)             (setq len 1 char (logand char #x1F)))
195             (setq len 2 ch (logand last-command-char #x0F)))            ((< char #xF0)
196            ((< last-command-char #xF8)             (setq len 2 char (logand char #x0F)))
197             (setq len 3 ch (logand last-command-char #x07)))            ((< char #xF8)
198               (setq len 3 char (logand char #x07)))
199            (t            (t
200             (setq len 4 ch 0)))             (setq len 4 char 0)))
201      (while (> len 0)      (while (> len 0)
202        (setq ch (logior (lsh ch 6) (logand (read-char-exclusive) #x3F))        (setq char (logior (lsh char 6) (logand (read-char-exclusive) #x3F))
203              len (1- len)))              len (1- len)))
204      (let ((last-command-char ch))      (vector char)))
       (self-insert-command arg))))  
205    
206  (defun encoded-kbd-setup-keymap (coding)  (defun encoded-kbd-setup-keymap (coding)
207    ;; At first, reset the keymap.    ;; At first, reset the keymap.
208    (define-key encoded-kbd-mode-map "\e" nil)    (define-key encoded-kbd-mode-map "\e" nil)
209    ;; Then setup the keymap according to the keyboard coding system.    ;; Then setup the keymap according to the keyboard coding system.
210    (cond    (cond
211     ((eq encoded-kbd-coding 'charset)     ((eq (coding-system-type coding) 'shift-jis)
     (let* ((charset (car (coding-system-get coding :charset-list)))  
            (code-space (get-charset-property charset :code-space))  
            (from (max (aref code-space 0) 128))  
            (to (aref code-space 1)))  
       (while (<= from to)  
         (define-key encoded-kbd-mode-map  
           (vector from) 'encoded-kbd-self-insert-charset)  
         (setq from (1+ from)))))  
   
    ((eq (coding-system-type coding) 1)  ; SJIS  
212      (let ((i 128))      (let ((i 128))
213        (while (< i 256)        (while (< i 256)
214          (define-key key-translation-map          (define-key key-translation-map
# Line 234  The following key sequence may cause mul Line 216  The following key sequence may cause mul
216          (setq i (1+ i))))          (setq i (1+ i))))
217      8)      8)
218    
219     ((eq (coding-system-type coding) 3)  ; Big5     ((eq (coding-system-type coding) 'charset)
220      (let ((i 161))      (let* ((charset (car (coding-system-get coding :charset-list)))
221        (while (< i 255)             (code-space (get-charset-property charset :code-space))
222               (from (max (aref code-space 0) 128))
223               (to (aref code-space 1)))
224          (while (<= from to)
225          (define-key key-translation-map          (define-key key-translation-map
226            (vector i) 'encoded-kbd-self-insert-big5)            (vector from) 'encoded-kbd-self-insert-charset)
227          (setq i (1+ i))))          (setq from (1+ from))))
228      8)      8)
229    
230     ((eq (coding-system-type coding) 2) ; ISO-2022     ((eq (coding-system-type coding) 'iso-2022)
231      (let ((flags (coding-system-flags coding))      (let ((flags (coding-system-get coding :flags))
232            use-designation)            (designation (coding-system-get coding :designation)))
233        (if (aref flags 8)        (if (memq 'locking-shift flags)
234            nil                           ; Don't support locking-shift.            nil                           ; Don't support locking-shift.
235          (setq encoded-kbd-iso2022-designations (make-vector 4 nil)          (setq encoded-kbd-iso2022-designations (make-vector 4 nil)
236                encoded-kbd-iso2022-invocations (make-vector 3 nil))                encoded-kbd-iso2022-invocations (make-vector 3 nil))
237          (dotimes (i 4)          (dotimes (i 4)
238            (if (aref flags i)            (if (aref designation i)
239                (if (charsetp (aref flags i))                (if (charsetp (aref designation i))
240                    (aset encoded-kbd-iso2022-designations                    (aset encoded-kbd-iso2022-designations
241                          i (aref flags i))                          i (aref designation i))
242                  (setq use-designation t)                  (if (charsetp (car-safe (aref designation i)))
                 (if (charsetp (car-safe (aref flags i)))  
243                      (aset encoded-kbd-iso2022-designations                      (aset encoded-kbd-iso2022-designations
244                            i (car (aref flags i)))))))                            i (car (aref designation i)))))))
245          (aset encoded-kbd-iso2022-invocations 0 0)          (aset encoded-kbd-iso2022-invocations 0 0)
246          (if (aref encoded-kbd-iso2022-designations 1)          (if (aref encoded-kbd-iso2022-designations 1)
247              (aset encoded-kbd-iso2022-invocations 1 1))              (aset encoded-kbd-iso2022-invocations 1 1))
248          (when use-designation          (when (memq 'designation flags)
249            (define-key encoded-kbd-mode-map "\e" 'encoded-kbd-iso2022-esc-prefix)            (define-key encoded-kbd-mode-map "\e" 'encoded-kbd-iso2022-esc-prefix)
250            (define-key key-translation-map "\e" 'encoded-kbd-iso2022-esc-prefix))            (define-key key-translation-map "\e" 'encoded-kbd-iso2022-esc-prefix))
251          (when (or (aref flags 2) (aref flags 3))          (when (or (aref designation 2) (aref designation 3))
252            (define-key key-translation-map            (define-key key-translation-map
253              [?\216] 'encoded-kbd-iso2022-single-shift)              [?\216] 'encoded-kbd-iso2022-single-shift)
254            (define-key key-translation-map            (define-key key-translation-map
255              [?\217] 'encoded-kbd-iso2022-single-shift))              [?\217] 'encoded-kbd-iso2022-single-shift))
256          (or (eq (aref flags 0) 'ascii)          (or (eq (aref designation 0) 'ascii)
257              (dotimes (i 96)              (dotimes (i 96)
258                (define-key key-translation-map                (define-key key-translation-map
259                  (vector (+ 32 i)) 'encoded-kbd-self-insert-iso2022-7bit)))                  (vector (+ 32 i)) 'encoded-kbd-self-insert-iso2022-7bit)))
260          (if (aref flags 7)          (if (memq '7-bit flags)
261              t              t
262            (dotimes (i 96)            (dotimes (i 96)
263              (define-key key-translation-map              (define-key key-translation-map
# Line 296  The following key sequence may cause mul Line 280  The following key sequence may cause mul
280            (setq from (1+ from))))            (setq from (1+ from))))
281        8))        8))
282    
283     ((eq encoded-kbd-coding 'utf-8)     ((eq (coding-system-type coding) 'utf-8)
284      (let ((i #xC0))      (let ((i #xC0))
285        (while (< i 256)        (while (< i 256)
286          (define-key encoded-kbd-mode-map          (define-key key-translation-map
287            (vector i) 'encoded-kbd-self-insert-utf-8)            (vector i) 'encoded-kbd-self-insert-utf-8)
288          (setq i (1+ i)))))          (setq i (1+ i)))))
289    
# Line 327  In Encoded-kbd mode, a text sent from ke Line 311  In Encoded-kbd mode, a text sent from ke
311  as a multilingual text encoded in a coding system set by  as a multilingual text encoded in a coding system set by
312  \\[set-keyboard-coding-system]."  \\[set-keyboard-coding-system]."
313    :global t    :global t
314    ;; We must at first reset input-mode to the original.  
   (if saved-input-mode (apply 'set-input-mode saved-input-mode))  
315    (if encoded-kbd-mode    (if encoded-kbd-mode
316        (let ((coding (keyboard-coding-system)))        ;; We are turning on Encoded-kbd mode.
317          (setq saved-input-mode  (current-input-mode))        (let ((coding (keyboard-coding-system))
318          (cond ((null coding)              result)
319                 (setq encoded-kbd-mode nil)          (or saved-key-translation-map
320                 (error "No coding system for keyboard input is set"))              (if (keymapp key-translation-map)
321                    (setq saved-key-translation-map
322                ((eq (coding-system-type coding) 'shift-jis)                        (copy-keymap key-translation-map))
323                 (set-input-mode                (setq key-translation-map (make-sparse-keymap))))
324                  (nth 0 saved-input-mode) (nth 1 saved-input-mode)          (or saved-input-mode
325                  'use-8th-bit (nth 3 saved-input-mode))              (setq saved-input-mode
326                 (setq encoded-kbd-coding 'sjis))                    (current-input-mode)))
327            (setq result (and coding (encoded-kbd-setup-keymap coding)))
328                ((eq (coding-system-type coding) 'iso-2022)          (if result
329                 (if (memq '7-bit (coding-system-get coding :flags))              (if (eq result 8)
330                     (setq encoded-kbd-coding 'iso2022-7)                  (set-input-mode
331                   (set-input-mode                   (nth 0 saved-input-mode)
332                    (nth 0 saved-input-mode) (nth 1 saved-input-mode)                   (nth 1 saved-input-mode)
333                    'use-8th-bit (nth 3 saved-input-mode))                   'use-8th-bit
334                   (setq encoded-kbd-coding 'iso2022-8))                   (nth 3 saved-input-mode)))
335                 (setq encoded-kbd-iso2022-designations            (setq encoded-kbd-mode nil
336                       (coding-system-get coding :designation))                  saved-key-translation-map nil
337                 (setq encoded-kbd-iso2022-invocations (make-vector 3 nil))                  saved-input-mode nil)
338                 (aset encoded-kbd-iso2022-invocations 0 0)            (error "Unsupported coding system in Encoded-kbd mode: %S"
339                 (aset encoded-kbd-iso2022-invocations 1 1))                   coding)))
340    
341                ((eq (coding-system-type coding) 'big5)      ;; We are turning off Encoded-kbd mode.
342                 (set-input-mode      (setq key-translation-map saved-key-translation-map
343                  (nth 0 saved-input-mode) (nth 1 saved-input-mode)            saved-key-translation-map nil)
344                  'use-8th-bit (nth 3 saved-input-mode))      (apply 'set-input-mode saved-input-mode)
345                 (setq encoded-kbd-coding 'big5))      (setq saved-input-mode nil)))
   
               ((eq (coding-system-type coding) 'ccl)  
                (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 'ccl))  
   
               ((and (eq (coding-system-type coding) 'charset)  
                     (let* ((charset-list (coding-system-get coding  
                                                             :charset-list))  
                            (charset (car charset-list)))  
                       (and (= (length charset-list) 1)  
                            (= (charset-dimension charset) 1))))  
                (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 'charset))  
   
               ((eq (coding-system-type coding) 'utf-8)  
                (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 'utf-8))  
   
               (t  
                (setq encoded-kbd-mode nil)  
                (error "Coding-system `%s' is not supported in Encoded-kbd mode"  
                       (keyboard-coding-system))))  
         (encoded-kbd-setup-keymap coding))))  
346    
347  (provide 'encoded-kb)  (provide 'encoded-kb)
348    

Legend:
Removed from v.1.28.6.4  
changed lines
  Added in v.1.28.6.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26