1 |
;;; uni-input.el --- Hex Unicode input method |
;;; uni-input.el --- Hex Unicode input method |
2 |
|
|
3 |
;; Copyright (C) 2001 Free Software Foundation, Inc. |
;; Copyright (C) 2001, 2002 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: Dave Love <fx@gnu.org> |
;; Author: Dave Love <fx@gnu.org> |
6 |
;; Keywords: i18n |
;; Keywords: i18n |
30 |
;; This is not really a Quail method, but uses some Quail functions. |
;; This is not really a Quail method, but uses some Quail functions. |
31 |
;; There is probably A Better Way. |
;; There is probably A Better Way. |
32 |
|
|
33 |
;; Compare `ucs-insert', which explicitly inserts a unicoded character |
;; You can get a similar effect by using C-q with |
34 |
;; rather than supplying an input method. |
;; `read-quoted-char-radix' set to 16. |
35 |
|
|
36 |
|
;; Note that this only allows you to enter BMP values unless someone |
37 |
|
;; extends it to use variable numbers of digits. |
38 |
|
|
39 |
;;; Code: |
;;; Code: |
40 |
|
|
41 |
(require 'quail) |
(require 'quail) |
42 |
|
|
|
;; Maybe stolen from Mule-UCS -- I don't remember. |
|
|
(define-ccl-program utf-8-ccl-encode |
|
|
`(4 (if (r0 < ?\x80) |
|
|
((write r0)) |
|
|
(if (r0 < #x800) |
|
|
((write ((r0 >> 6) | ?\xC0)) |
|
|
(write ((r0 & ?\x3F) | ?\x80))) |
|
|
(if (r0 < #x10000) |
|
|
((write ((r0 >> 12) | ?\xE0)) |
|
|
(write (((r0 >> 6) & ?\x3F) | ?\x80)) |
|
|
(write ((r0 & ?\x3F) | ?\x80))) |
|
|
(if (r0 < #x200000) |
|
|
((write ((r0 >> 18) | ?\xF0)) |
|
|
(write (((r0 >> 12) & ?\x3F) | ?\x80)) |
|
|
(write (((r0 >> 6) & ?\x3F) | ?\x80)) |
|
|
(write ((r0 & ?\x3F) | ?\x80))) |
|
|
(if (r0 < #x4000000) |
|
|
((write ((r0 >> 24) | ?\xF8)) |
|
|
(write (((r0 >> 18) & ?\x3F) | ?\x80)) |
|
|
(write (((r0 >> 12) & ?\x3F) | ?\x80)) |
|
|
(write (((r0 >> 6) & ?\x3F) | ?\x80)) |
|
|
(write ((r0 & ?\x3F) | ?\x80))) |
|
|
((write ((r0 >> 30) | ?\xFC)) |
|
|
(write (((r0 >> 24) & ?\x3F) | ?\x80)) |
|
|
(write (((r0 >> 18) & ?\x3F) | ?\x80)) |
|
|
(write (((r0 >> 12) & ?\x3F) | ?\x80)) |
|
|
(write (((r0 >> 6) & ?\x3F) | ?\x80)) |
|
|
(write ((r0 & ?\x3F) | ?\x80)))))))))) |
|
|
|
|
43 |
(defun ucs-input-method (key) |
(defun ucs-input-method (key) |
44 |
(if (or buffer-read-only |
(if (or buffer-read-only |
45 |
(and (/= key ?U) (/= key ?u))) |
(and (/= key ?U) (/= key ?u))) |
65 |
(= 1 (length seq)) |
(= 1 (length seq)) |
66 |
(setq key (aref seq 0)) |
(setq key (aref seq 0)) |
67 |
(memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a |
(memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a |
68 |
?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F))) |
?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F))) |
69 |
(progn |
(progn |
70 |
(push key events) |
(push key events) |
71 |
(let ((last-command-char key) |
(let ((last-command-char key) |
79 |
(throw 'non-digit (append (reverse events) |
(throw 'non-digit (append (reverse events) |
80 |
(listify-key-sequence seq)))))) |
(listify-key-sequence seq)))))) |
81 |
(quail-delete-region) |
(quail-delete-region) |
82 |
(let* ((n (string-to-number (apply 'string |
(let ((n (string-to-number (apply 'string |
83 |
(cdr (nreverse events))) |
(cdr (nreverse events))) |
84 |
16)) |
16))) |
85 |
(c (decode-char 'ucs n)) |
(if (characterp n) |
86 |
(status (make-vector 9 nil))) |
(list n))))) |
|
(if c |
|
|
(list c) |
|
|
(aset status 0 n) |
|
|
(string-to-list (ccl-execute-on-string |
|
|
'utf-8-ccl-encode status "")))))) |
|
87 |
(quail-delete-overlays) |
(quail-delete-overlays) |
88 |
(set-buffer-modified-p modified-p) |
(set-buffer-modified-p modified-p) |
89 |
(run-hooks 'input-method-after-insert-chunk-hook))))) |
(run-hooks 'input-method-after-insert-chunk-hook))))) |