comparison lisp/international/encoded-kb.el @ 89965:5e9097d1ad99

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-31 Adjust code merged from trunk for unicode branch
author Miles Bader <miles@gnu.org>
date Wed, 18 Aug 2004 06:38:14 +0000
parents 3fd4a5c21153
children 1e6118d38ca9
comparison
equal deleted inserted replaced
89964:6491b455697c 89965:5e9097d1ad99
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 (defun encoded-kbd-self-insert-charset (arg) 180 (defun encoded-kbd-self-insert-charset (ignore)
181 (interactive "p")
182 (let* ((charset-list 181 (let* ((charset-list
183 (coding-system-get (keyboard-coding-system) :charset-list)) 182 (coding-system-get (keyboard-coding-system) :charset-list))
184 (charset (car charset-list)) 183 (charset (car charset-list))
185 ;; For the moment, we can assume that the length of CHARSET-LIST 184 ;; For the moment, we can assume that the length of CHARSET-LIST
186 ;; is 1, and the dimension of CHARSET is 1. 185 ;; is 1, and the dimension of CHARSET is 1.
187 (c (decode-char charset last-command-char))) 186 (char (encoded-kbd-last-key)))
188 (unless c 187 (vector (or (decode-char charset char) char))))
189 (error "Can't decode the code point %d by %s"
190 last-command-char charset))
191 ;; As simply setting unread-command-events may result in
192 ;; infinite-loop for characters 160..255, this is a temporary
193 ;; workaround until we found a better solution.
194 (let ((last-command-char c))
195 (self-insert-command arg))))
196 188
197 (defun encoded-kbd-self-insert-utf-8 (arg) 189 (defun encoded-kbd-self-insert-utf-8 (arg)
198 (interactive "p") 190 (interactive "p")
199 (let (len ch) 191 (let ((char (encoded-kbd-last-key))
200 (cond ((< last-command-char #xE0) 192 len)
201 (setq len 1 ch (logand last-command-char #x1F))) 193 (cond ((< char #xE0)
202 ((< last-command-char #xF0) 194 (setq len 1 char (logand char #x1F)))
203 (setq len 2 ch (logand last-command-char #x0F))) 195 ((< char #xF0)
204 ((< last-command-char #xF8) 196 (setq len 2 char (logand char #x0F)))
205 (setq len 3 ch (logand last-command-char #x07))) 197 ((< char #xF8)
198 (setq len 3 char (logand char #x07)))
206 (t 199 (t
207 (setq len 4 ch 0))) 200 (setq len 4 char 0)))
208 (while (> len 0) 201 (while (> len 0)
209 (setq ch (logior (lsh ch 6) (logand (read-char-exclusive) #x3F)) 202 (setq char (logior (lsh char 6) (logand (read-char-exclusive) #x3F))
210 len (1- len))) 203 len (1- len)))
211 (let ((last-command-char ch)) 204 (vector char)))
212 (self-insert-command arg))))
213 205
214 (defun encoded-kbd-setup-keymap (coding) 206 (defun encoded-kbd-setup-keymap (coding)
215 ;; At first, reset the keymap. 207 ;; At first, reset the keymap.
216 (define-key encoded-kbd-mode-map "\e" nil) 208 (define-key encoded-kbd-mode-map "\e" nil)
217 ;; Then setup the keymap according to the keyboard coding system. 209 ;; Then setup the keymap according to the keyboard coding system.
218 (cond 210 (cond
219 ((eq encoded-kbd-coding 'charset) 211 ((eq (coding-system-type coding) 'shift-jis)
220 (let* ((charset (car (coding-system-get coding :charset-list)))
221 (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 encoded-kbd-mode-map
226 (vector from) 'encoded-kbd-self-insert-charset)
227 (setq from (1+ from)))))
228
229 ((eq (coding-system-type coding) 1) ; SJIS
230 (let ((i 128)) 212 (let ((i 128))
231 (while (< i 256) 213 (while (< i 256)
232 (define-key key-translation-map 214 (define-key key-translation-map
233 (vector i) 'encoded-kbd-self-insert-sjis) 215 (vector i) 'encoded-kbd-self-insert-sjis)
234 (setq i (1+ i)))) 216 (setq i (1+ i))))
235 8) 217 8)
236 218
237 ((eq (coding-system-type coding) 3) ; Big5 219 ((eq (coding-system-type coding) 'charset)
238 (let ((i 161)) 220 (let* ((charset (car (coding-system-get coding :charset-list)))
239 (while (< i 255) 221 (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)
240 (define-key key-translation-map 225 (define-key key-translation-map
241 (vector i) 'encoded-kbd-self-insert-big5) 226 (vector from) 'encoded-kbd-self-insert-charset)
242 (setq i (1+ i)))) 227 (setq from (1+ from))))
243 8) 228 8)
244 229
245 ((eq (coding-system-type coding) 2) ; ISO-2022 230 ((eq (coding-system-type coding) 'iso-2022)
246 (let ((flags (coding-system-flags coding)) 231 (let ((flags (coding-system-get coding :flags))
247 use-designation) 232 (designation (coding-system-get coding :designation)))
248 (if (aref flags 8) 233 (if (memq 'locking-shift flags)
249 nil ; Don't support locking-shift. 234 nil ; Don't support locking-shift.
250 (setq encoded-kbd-iso2022-designations (make-vector 4 nil) 235 (setq encoded-kbd-iso2022-designations (make-vector 4 nil)
251 encoded-kbd-iso2022-invocations (make-vector 3 nil)) 236 encoded-kbd-iso2022-invocations (make-vector 3 nil))
252 (dotimes (i 4) 237 (dotimes (i 4)
253 (if (aref flags i) 238 (if (aref designation i)
254 (if (charsetp (aref flags i)) 239 (if (charsetp (aref designation i))
255 (aset encoded-kbd-iso2022-designations 240 (aset encoded-kbd-iso2022-designations
256 i (aref flags i)) 241 i (aref designation i))
257 (setq use-designation t) 242 (if (charsetp (car-safe (aref designation i)))
258 (if (charsetp (car-safe (aref flags i)))
259 (aset encoded-kbd-iso2022-designations 243 (aset encoded-kbd-iso2022-designations
260 i (car (aref flags i))))))) 244 i (car (aref designation i)))))))
261 (aset encoded-kbd-iso2022-invocations 0 0) 245 (aset encoded-kbd-iso2022-invocations 0 0)
262 (if (aref encoded-kbd-iso2022-designations 1) 246 (if (aref encoded-kbd-iso2022-designations 1)
263 (aset encoded-kbd-iso2022-invocations 1 1)) 247 (aset encoded-kbd-iso2022-invocations 1 1))
264 (when use-designation 248 (when (memq 'designation flags)
265 (define-key encoded-kbd-mode-map "\e" 'encoded-kbd-iso2022-esc-prefix) 249 (define-key encoded-kbd-mode-map "\e" 'encoded-kbd-iso2022-esc-prefix)
266 (define-key key-translation-map "\e" 'encoded-kbd-iso2022-esc-prefix)) 250 (define-key key-translation-map "\e" 'encoded-kbd-iso2022-esc-prefix))
267 (when (or (aref flags 2) (aref flags 3)) 251 (when (or (aref designation 2) (aref designation 3))
268 (define-key key-translation-map 252 (define-key key-translation-map
269 [?\216] 'encoded-kbd-iso2022-single-shift) 253 [?\216] 'encoded-kbd-iso2022-single-shift)
270 (define-key key-translation-map 254 (define-key key-translation-map
271 [?\217] 'encoded-kbd-iso2022-single-shift)) 255 [?\217] 'encoded-kbd-iso2022-single-shift))
272 (or (eq (aref flags 0) 'ascii) 256 (or (eq (aref designation 0) 'ascii)
273 (dotimes (i 96) 257 (dotimes (i 96)
274 (define-key key-translation-map 258 (define-key key-translation-map
275 (vector (+ 32 i)) 'encoded-kbd-self-insert-iso2022-7bit))) 259 (vector (+ 32 i)) 'encoded-kbd-self-insert-iso2022-7bit)))
276 (if (aref flags 7) 260 (if (memq '7-bit flags)
277 t 261 t
278 (dotimes (i 96) 262 (dotimes (i 96)
279 (define-key key-translation-map 263 (define-key key-translation-map
280 (vector (+ 160 i)) 'encoded-kbd-self-insert-iso2022-8bit)) 264 (vector (+ 160 i)) 'encoded-kbd-self-insert-iso2022-8bit))
281 8)))) 265 8))))
294 (define-key key-translation-map 278 (define-key key-translation-map
295 (vector from) 'encoded-kbd-self-insert-ccl)) 279 (vector from) 'encoded-kbd-self-insert-ccl))
296 (setq from (1+ from)))) 280 (setq from (1+ from))))
297 8)) 281 8))
298 282
299 ((eq encoded-kbd-coding 'utf-8) 283 ((eq (coding-system-type coding) 'utf-8)
300 (let ((i #xC0)) 284 (let ((i #xC0))
301 (while (< i 256) 285 (while (< i 256)
302 (define-key encoded-kbd-mode-map 286 (define-key key-translation-map
303 (vector i) 'encoded-kbd-self-insert-utf-8) 287 (vector i) 'encoded-kbd-self-insert-utf-8)
304 (setq i (1+ i))))) 288 (setq i (1+ i)))))
305 289
306 (t 290 (t
307 nil))) 291 nil)))
325 309
326 In Encoded-kbd mode, a text sent from keyboard is accepted 310 In Encoded-kbd mode, a text sent from keyboard is accepted
327 as a multilingual text encoded in a coding system set by 311 as a multilingual text encoded in a coding system set by
328 \\[set-keyboard-coding-system]." 312 \\[set-keyboard-coding-system]."
329 :global t 313 :global t
330 ;; We must at first reset input-mode to the original. 314
331 (if saved-input-mode (apply 'set-input-mode saved-input-mode))
332 (if encoded-kbd-mode 315 (if encoded-kbd-mode
333 (let ((coding (keyboard-coding-system))) 316 ;; We are turning on Encoded-kbd mode.
334 (setq saved-input-mode (current-input-mode)) 317 (let ((coding (keyboard-coding-system))
335 (cond ((null coding) 318 result)
336 (setq encoded-kbd-mode nil) 319 (or saved-key-translation-map
337 (error "No coding system for keyboard input is set")) 320 (if (keymapp key-translation-map)
338 321 (setq saved-key-translation-map
339 ((eq (coding-system-type coding) 'shift-jis) 322 (copy-keymap key-translation-map))
340 (set-input-mode 323 (setq key-translation-map (make-sparse-keymap))))
341 (nth 0 saved-input-mode) (nth 1 saved-input-mode) 324 (or saved-input-mode
342 'use-8th-bit (nth 3 saved-input-mode)) 325 (setq saved-input-mode
343 (setq encoded-kbd-coding 'sjis)) 326 (current-input-mode)))
344 327 (setq result (and coding (encoded-kbd-setup-keymap coding)))
345 ((eq (coding-system-type coding) 'iso-2022) 328 (if result
346 (if (memq '7-bit (coding-system-get coding :flags)) 329 (if (eq result 8)
347 (setq encoded-kbd-coding 'iso2022-7) 330 (set-input-mode
348 (set-input-mode 331 (nth 0 saved-input-mode)
349 (nth 0 saved-input-mode) (nth 1 saved-input-mode) 332 (nth 1 saved-input-mode)
350 'use-8th-bit (nth 3 saved-input-mode)) 333 'use-8th-bit
351 (setq encoded-kbd-coding 'iso2022-8)) 334 (nth 3 saved-input-mode)))
352 (setq encoded-kbd-iso2022-designations 335 (setq encoded-kbd-mode nil
353 (coding-system-get coding :designation)) 336 saved-key-translation-map nil
354 (setq encoded-kbd-iso2022-invocations (make-vector 3 nil)) 337 saved-input-mode nil)
355 (aset encoded-kbd-iso2022-invocations 0 0) 338 (error "Unsupported coding system in Encoded-kbd mode: %S"
356 (aset encoded-kbd-iso2022-invocations 1 1)) 339 coding)))
357 340
358 ((eq (coding-system-type coding) 'big5) 341 ;; We are turning off Encoded-kbd mode.
359 (set-input-mode 342 (setq key-translation-map saved-key-translation-map
360 (nth 0 saved-input-mode) (nth 1 saved-input-mode) 343 saved-key-translation-map nil)
361 'use-8th-bit (nth 3 saved-input-mode)) 344 (apply 'set-input-mode saved-input-mode)
362 (setq encoded-kbd-coding 'big5)) 345 (setq saved-input-mode nil)))
363
364 ((eq (coding-system-type coding) 'ccl)
365 (set-input-mode
366 (nth 0 saved-input-mode) (nth 1 saved-input-mode)
367 'use-8th-bit (nth 3 saved-input-mode))
368 (setq encoded-kbd-coding 'ccl))
369
370 ((and (eq (coding-system-type coding) 'charset)
371 (let* ((charset-list (coding-system-get coding
372 :charset-list))
373 (charset (car charset-list)))
374 (and (= (length charset-list) 1)
375 (= (charset-dimension charset) 1))))
376 (set-input-mode
377 (nth 0 saved-input-mode) (nth 1 saved-input-mode)
378 'use-8th-bit (nth 3 saved-input-mode))
379 (setq encoded-kbd-coding 'charset))
380
381 ((eq (coding-system-type coding) 'utf-8)
382 (set-input-mode
383 (nth 0 saved-input-mode) (nth 1 saved-input-mode)
384 'use-8th-bit (nth 3 saved-input-mode))
385 (setq encoded-kbd-coding 'utf-8))
386
387 (t
388 (setq encoded-kbd-mode nil)
389 (error "Coding-system `%s' is not supported in Encoded-kbd mode"
390 (keyboard-coding-system))))
391 (encoded-kbd-setup-keymap coding))))
392 346
393 (provide 'encoded-kb) 347 (provide 'encoded-kb)
394 348
395 ;;; arch-tag: 76f0f9b3-65e7-45c3-b692-59509a87ad44 349 ;;; arch-tag: 76f0f9b3-65e7-45c3-b692-59509a87ad44
396 ;;; encoded-kb.el ends here 350 ;;; encoded-kb.el ends here