annotate lisp/international/encoded-kb.el @ 17721:4ebed8fa4fcb

(selection_data_to_lisp_data): If TYPE is `STRING' and DATA contains 8-bit codes, decode them as Latin-1 characters. (lisp_data_to_selection_data): Supply 4th arg TABLE as Qnil to find_charset_in_str.
author Kenichi Handa <handa@m17n.org>
date Sat, 10 May 1997 03:37:01 +0000
parents a3ca5e15c82a
children 8be34c35fa73
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17315
a3ca5e15c82a Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents: 17080
diff changeset
1 ;;; encoded-kb.el --- Handler to input multibyte characters encoded somehow
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6 ;; This file is part of GNU Emacs.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11 ;; any later version.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is distributed in the hope that it will be useful,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; GNU General Public License for more details.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
17071
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
21 ;; Boston, MA 02111-1307, USA.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23 (defvar encoded-kbd-mode nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24 "Non-nil if in Encoded-kbd minor mode.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25 (put 'encoded-kbd-mode 'permanent-local t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 (or (assq 'encoded-kbd-mode minor-mode-alist)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 (setq minor-mode-alist
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29 (cons '(encoded-kbd-mode " Encoded-kbd") minor-mode-alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31 (defvar encoded-kbd-mode-map
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32 (let ((map (make-sparse-keymap))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33 (i 128))
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
34 (define-key map "\e" 'encoded-kbd-iso2022-esc-prefix)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 (while (< i 256)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36 (define-key map (vector i) 'encoded-kbd-handle-8bit)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 (setq i (1+ i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38 map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39 "Keymap for Encoded-kbd minor mode.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 (or (assq 'encoded-kbd-mode minor-mode-map-alist)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 (setq minor-mode-map-alist
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43 (cons (cons 'encoded-kbd-mode encoded-kbd-mode-map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 minor-mode-map-alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 ;; Subsidiary keymaps for handling ISO2022 escape sequences.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48 (defvar encoded-kbd-iso2022-esc-map
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49 (let ((map (make-sparse-keymap)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
50 (define-key map "$" 'encoded-kbd-iso2022-esc-dollar-prefix)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51 (define-key map "(" 'encoded-kbd-iso2022-designation-prefix)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52 (define-key map ")" 'encoded-kbd-iso2022-designation-prefix)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53 (define-key map "," 'encoded-kbd-iso2022-designation-prefix)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54 (define-key map "-" 'encoded-kbd-iso2022-designation-prefix)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55 map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56 "Keymap for handling ESC code in Encoded-kbd mode.")
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
57 (fset 'encoded-kbd-iso2022-esc-prefix encoded-kbd-iso2022-esc-map)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
59 (defvar encoded-kbd-iso2022-esc-dollar-map
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 (let ((map (make-sparse-keymap)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61 (define-key map "(" 'encoded-kbd-iso2022-designation-prefix)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62 (define-key map ")" 'encoded-kbd-iso2022-designation-prefix)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
63 (define-key map "," 'encoded-kbd-iso2022-designation-prefix)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
64 (define-key map "-" 'encoded-kbd-iso2022-designation-prefix)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
65 (define-key map "@" 'encoded-kbd-iso2022-designation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
66 (define-key map "A" 'encoded-kbd-iso2022-designation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67 (define-key map "B" 'encoded-kbd-iso2022-designation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68 map)
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
69 "Keymap for handling ESC $ sequence in Encoded-kbd mode.")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70 (fset 'encoded-kbd-iso2022-esc-dollar-prefix
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71 encoded-kbd-iso2022-esc-dollar-map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
73 (defvar encoded-kbd-iso2022-designation-map
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 (let ((map (make-sparse-keymap))
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
75 (l charset-list))
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
76 (while l
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
77 (define-key map
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
78 (char-to-string (charset-iso-final-char (car l)))
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
79 'encoded-kbd-iso2022-designation)
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
80 (setq l (cdr l)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
81 map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
82 "Keymap for handling ISO2022 designation sequence in Encoded-kbd mode.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
83 (fset 'encoded-kbd-iso2022-designation-prefix
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
84 encoded-kbd-iso2022-designation-map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86 (defvar encoded-kbd-iso2022-non-ascii-map
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 (let ((map (make-keymap))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 (i 32))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 (while (< i 128)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 (define-key map (char-to-string i) 'encoded-kbd-self-insert-iso2022-7bit)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91 (setq i (1+ i)))
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
92 (define-key map "\e" 'encoded-kbd-iso2022-esc-prefix)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93 map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 "Keymap for handling non-ASCII character set in Encoded-kbd mode.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96 ;; One of the symbols `sjis', `iso2022-7', `iso2022-8', or `big5' to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97 ;; denote what kind of coding-system we are now handling in
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98 ;; Encoded-kbd mode.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
99 (defvar encoded-kbd-coding nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
100
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101 ;; Keep information of designation state of ISO2022 encoding. This is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102 ;; a vector of character sets currently designated to each graphic
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103 ;; registers (0..3).
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105 (defvar encoded-kbd-iso2022-designations nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 (make-variable-buffer-local 'encoded-kbd-iso2022-designations)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 (put 'encoded-kbd-iso2022-designations 'permanent-local t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 ;; Keep information of invocation state of ISO2022 encoding. This is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 ;; a vector of graphic register numbers currently invoked to each
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 ;; graphic plane (0..1), the third element is a single shifted graphic
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112 ;; register number.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 (defvar encoded-kbd-iso2022-invocations nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115 (make-variable-buffer-local 'encoded-kbd-iso2022-invocations)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 (put 'encoded-kbd-iso2022-invocations 'permanent-local t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 (defun encoded-kbd-iso2022-designation ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 "Do ISO2022 designation according to the curren key in Encoded-kbd mode.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120 The following key sequence may cause multilingual text insertion."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
121 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 (let ((key-seq (this-command-keys))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123 intermediate-char final-char
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 reg dimension chars charset)
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
125 (if (= (length key-seq) 4)
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
126 ;; ESC $ <intermediate-char> <final-char>
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
127 (setq intermediate-char (aref key-seq 2)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 dimension 2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 chars (if (< intermediate-char ?,) 94 96)
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
130 final-char (aref key-seq 3)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131 reg (mod intermediate-char 4))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 (if (= (aref key-seq 1) ?$)
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
133 ;; ESC $ <final-char>
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134 (setq dimension 2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 chars 94
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
136 final-char (aref key-seq 2)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 reg 0)
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
138 ;; ESC <intermediate-char> <final-char>
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
139 (setq intermediate-char (aref key-seq 1)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 dimension 1
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 chars (if (< intermediate-char ?,) 94 96)
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
142 final-char (aref key-seq 2)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 reg (mod intermediate-char 4))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (if (setq charset (iso-charset dimension chars final-char))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 (aset encoded-kbd-iso2022-designations reg charset)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (error "Character set of DIMENSION %s, CHARS %s, FINAL-CHAR `%c' is not supported"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 dimension chars final-char))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
149 (if (memq (aref encoded-kbd-iso2022-designations
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 (aref encoded-kbd-iso2022-invocations 0))
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
151 '(ascii latin-jisx0201))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 ;; Graphic plane 0 (0x20..0x7f) is for ASCII. We don't have
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 ;; to handle characters in this range specially.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 (throw 'exit nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 ;; Graphic plane 0 is for non-ASCII.
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
156 (let ((overriding-local-map encoded-kbd-iso2022-non-ascii-map))
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
157 (recursive-edit)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 (defun encoded-kbd-handle-8bit ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 "Handle an 8-bit character enterned in Encoded-kbd mode."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 (cond ((eq encoded-kbd-coding 'iso2022-7)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 (error "Can't handle the character code %d" last-command-char))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 ((eq encoded-kbd-coding 'iso2022-8)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 (cond ((= last-command-char ?\216)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 (aset encoded-kbd-iso2022-invocations 2 2))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 ((= last-command-char ?\217)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 (aset encoded-kbd-iso2022-invocations 2 3))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 ((> last-command-char ?\240)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 (encoded-kbd-self-insert-iso2022-8bit))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 (t
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 (error "Can't handle the character code %d"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 last-command-char))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 ((eq encoded-kbd-coding 'sjis)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 (encoded-kbd-self-insert-sjis))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 (t
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 (encoded-kbd-self-insert-big5))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 (defun encoded-kbd-self-insert-iso2022-7bit ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 (let* ((charset (aref encoded-kbd-iso2022-designations
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 (or (aref encoded-kbd-iso2022-invocations 2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 (aref encoded-kbd-iso2022-invocations 0))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 (last-command-char
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 (if (= (charset-bytes charset) 1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 (make-char charset last-command-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 (make-char charset last-command-char (read-char-exclusive)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 (self-insert-command 1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 (aset encoded-kbd-iso2022-invocations 2 nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 ))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 (defun encoded-kbd-self-insert-iso2022-8bit ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 (let* ((charset (aref encoded-kbd-iso2022-designations
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201 (or (aref encoded-kbd-iso2022-invocations 2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 (aref encoded-kbd-iso2022-invocations 1))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 (last-command-char
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 (if (= (charset-bytes charset) 1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205 (make-char charset last-command-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 (make-char charset last-command-char (read-char-exclusive)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
207 (self-insert-command 1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 (aset encoded-kbd-iso2022-invocations 2 nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209 ))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211 (defun encoded-kbd-self-insert-sjis ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 (let ((last-command-char
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
214 (if (or (< last-command-char ?\xA0) (>= last-command-char ?\xE0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
215 (decode-sjis-char (+ (ash last-command-char 8)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
216 (read-char-exclusive)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
217 (make-char 'latin-jisx0201 last-command-char))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
218 (self-insert-command 1)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
219
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
220 (defun encoded-kbd-self-insert-big5 ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
221 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
222 (let ((last-command-char
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223 (decode-big5-char (+ (ash last-command-char 8)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 (read-char-exclusive)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225 (self-insert-command 1)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
227 ;;;###autoload
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
228 (defun encoded-kbd-mode (&optional arg)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
229 "Toggle Encoded-kbd minor mode.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
230 With arg, turn Keyboard-kbd mode on in and only if arg is positive.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
231
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
232 When in Encoded-kbd mode, a text sent from a terminal keyboard
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
233 is accepted as a multilingual text encoded in a coding system
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
234 set by the command `set-keyboard-coding-system'"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
235 (interactive "P")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
236 (setq encoded-kbd-mode
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
237 (if (null arg) (null encoded-kbd-mode)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
238 (> (prefix-numeric-value arg) 0)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
239 (if encoded-kbd-mode
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
240 (let* ((coding (coding-system-vector (keyboard-coding-system)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
241 (input-mode (current-input-mode)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242 (cond ((null coding)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
243 (setq encoded-kbd-mode nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
244 (error "No coding-system for terminal keyboard is set"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
245
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
246 ((= (coding-vector-type coding) 1) ; SJIS
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
247 (set-input-mode (nth 0 input-mode) (nth 1 input-mode)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
248 'use-8th-bit (nth 3 input-mode))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
249 (setq encoded-kbd-coding 'sjis))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
250
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
251 ((= (coding-vector-type coding) 2) ; ISO2022
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
252 (if (aref (coding-vector-flags coding) 7) ; 7-bit only
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
253 (setq encoded-kbd-coding 'iso2022-7)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
254 (set-input-mode (nth 0 input-mode) (nth 1 input-mode)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
255 'use-8th-bit (nth 3 input-mode))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
256 (setq encoded-kbd-coding 'iso2022-8))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
257 (make-variable-buffer-local 'encoded-kbd-iso2022-designations)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258 (setq encoded-kbd-iso2022-designations (make-vector 4 nil))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259 (let ((flags (coding-vector-flags coding))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260 (i 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
261 (while (< i 4)
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
262 (if (charsetp (aref flags i))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
263 (aset encoded-kbd-iso2022-designations i
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
264 (aref flags i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
265 (setq i (1+ i))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
266 (make-variable-buffer-local 'encoded-kbd-iso2022-invocations)
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
267 (setq encoded-kbd-iso2022-invocations (make-vector 3 nil))
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
268 (aset encoded-kbd-iso2022-invocations 0 0)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
269 (aset encoded-kbd-iso2022-invocations 1 1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
270
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
271 ((= (coding-vector-type coding) 3) ; BIG5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
272 (set-input-mode (nth 0 input-mode) (nth 1 input-mode)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
273 'use-8th-bit (nth 3 input-mode))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
274 (setq encoded-kbd-coding 'big5))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
275
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
276 (t
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
277 (setq encoded-kbd-mode nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
278 (error "Coding-system `%s' is not supported in Encoded-kbd mode"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
279 (keyboard-coding-system))))
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
280 (setq inactivate-current-input-method-function 'encoded-kbd-mode)
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
281 (setq describe-current-input-method-function 'encoded-kbd-mode-help)
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
282 (run-hooks 'encoded-kbd-mode-hook))
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
283 (setq describe-current-input-method-function nil)
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
284 (setq current-input-method nil))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
285 (force-mode-line-update))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
286
17080
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
287 ;;;###autoload
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
288 (defun encoded-kbd-select-terminal (terminal coding-system)
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
289 "Activate Encoded-Kbd mode appropriately for TERMINAL using CODING-SYSTEM."
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
290 (interactive "STerminal name: \nzcoding-system: ")
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
291 (if window-system
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
292 (error "Should run emacs on an ordinary terminal"))
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
293 (set-terminal-coding-system coding-system)
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
294 (set-keyboard-coding-system coding-system)
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
295 (setq current-input-method-title terminal)
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
296 (encoded-kbd-mode t))
d80a8a46437e Many changes to cope with the above change.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
297
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
298 ;;; encoded-kb.el ends here