| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
(require 'quail) |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
(define-ccl-program utf-8-ccl-encode |
|---|
| 46 |
`(4 (if (r0 < ?\x80) |
|---|
| 47 |
((write r0)) |
|---|
| 48 |
(if (r0 < #x800) |
|---|
| 49 |
((write ((r0 >> 6) | ?\xC0)) |
|---|
| 50 |
(write ((r0 & ?\x3F) | ?\x80))) |
|---|
| 51 |
(if (r0 < #x10000) |
|---|
| 52 |
((write ((r0 >> 12) | ?\xE0)) |
|---|
| 53 |
(write (((r0 >> 6) & ?\x3F) | ?\x80)) |
|---|
| 54 |
(write ((r0 & ?\x3F) | ?\x80))) |
|---|
| 55 |
(if (r0 < #x200000) |
|---|
| 56 |
((write ((r0 >> 18) | ?\xF0)) |
|---|
| 57 |
(write (((r0 >> 12) & ?\x3F) | ?\x80)) |
|---|
| 58 |
(write (((r0 >> 6) & ?\x3F) | ?\x80)) |
|---|
| 59 |
(write ((r0 & ?\x3F) | ?\x80))) |
|---|
| 60 |
(if (r0 < #x4000000) |
|---|
| 61 |
((write ((r0 >> 24) | ?\xF8)) |
|---|
| 62 |
(write (((r0 >> 18) & ?\x3F) | ?\x80)) |
|---|
| 63 |
(write (((r0 >> 12) & ?\x3F) | ?\x80)) |
|---|
| 64 |
(write (((r0 >> 6) & ?\x3F) | ?\x80)) |
|---|
| 65 |
(write ((r0 & ?\x3F) | ?\x80))) |
|---|
| 66 |
((write ((r0 >> 30) | ?\xFC)) |
|---|
| 67 |
(write (((r0 >> 24) & ?\x3F) | ?\x80)) |
|---|
| 68 |
(write (((r0 >> 18) & ?\x3F) | ?\x80)) |
|---|
| 69 |
(write (((r0 >> 12) & ?\x3F) | ?\x80)) |
|---|
| 70 |
(write (((r0 >> 6) & ?\x3F) | ?\x80)) |
|---|
| 71 |
(write ((r0 & ?\x3F) | ?\x80)))))))))) |
|---|
| 72 |
|
|---|
| 73 |
(defun ucs-input-insert-char (char) |
|---|
| 74 |
(insert char) |
|---|
| 75 |
(move-overlay quail-overlay (overlay-start quail-overlay) (point))) |
|---|
| 76 |
|
|---|
| 77 |
(defun ucs-input-method (key) |
|---|
| 78 |
(if (or buffer-read-only |
|---|
| 79 |
(and (/= key ?U) (/= key ?u))) |
|---|
| 80 |
(list key) |
|---|
| 81 |
(quail-setup-overlays nil) |
|---|
| 82 |
(ucs-input-insert-char key) |
|---|
| 83 |
(let ((modified-p (buffer-modified-p)) |
|---|
| 84 |
(buffer-undo-list t) |
|---|
| 85 |
(input-method-function nil) |
|---|
| 86 |
(echo-keystrokes 0) |
|---|
| 87 |
(help-char nil) |
|---|
| 88 |
(events (list key)) |
|---|
| 89 |
(str " ")) |
|---|
| 90 |
(unwind-protect |
|---|
| 91 |
(catch 'non-digit |
|---|
| 92 |
(progn |
|---|
| 93 |
(dotimes (i 4) |
|---|
| 94 |
(let ((seq (read-key-sequence nil)) |
|---|
| 95 |
key) |
|---|
| 96 |
(if (and (stringp seq) |
|---|
| 97 |
(= 1 (length seq)) |
|---|
| 98 |
(setq key (aref seq 0)) |
|---|
| 99 |
(memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a |
|---|
| 100 |
?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F))) |
|---|
| 101 |
(progn |
|---|
| 102 |
(push key events) |
|---|
| 103 |
(ucs-input-insert-char key)) |
|---|
| 104 |
(quail-delete-region) |
|---|
| 105 |
(throw 'non-digit (append (reverse events) |
|---|
| 106 |
(listify-key-sequence seq)))))) |
|---|
| 107 |
(quail-delete-region) |
|---|
| 108 |
(let* ((n (string-to-number (apply 'string |
|---|
| 109 |
(cdr (nreverse events))) |
|---|
| 110 |
16)) |
|---|
| 111 |
(c (decode-char 'ucs n))) |
|---|
| 112 |
(if c |
|---|
| 113 |
(list c) |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
(error "Character U+%04X is not yet supported" n))))) |
|---|
| 122 |
(quail-delete-overlays) |
|---|
| 123 |
(set-buffer-modified-p modified-p) |
|---|
| 124 |
(run-hooks 'input-method-after-insert-chunk-hook))))) |
|---|
| 125 |
|
|---|
| 126 |
(defun ucs-input-activate (&optional arg) |
|---|
| 127 |
"Activate UCS input method. |
|---|
| 128 |
With arg, activate UCS input method if and only if arg is positive. |
|---|
| 129 |
|
|---|
| 130 |
While this input method is active, the variable |
|---|
| 131 |
`input-method-function' is bound to the function `ucs-input-method'." |
|---|
| 132 |
(if (and arg |
|---|
| 133 |
(< (prefix-numeric-value arg) 0)) |
|---|
| 134 |
(unwind-protect |
|---|
| 135 |
(progn |
|---|
| 136 |
(quail-hide-guidance) |
|---|
| 137 |
(quail-delete-overlays) |
|---|
| 138 |
(setq describe-current-input-method-function nil)) |
|---|
| 139 |
(kill-local-variable 'input-method-function)) |
|---|
| 140 |
(setq inactivate-current-input-method-function 'ucs-input-inactivate) |
|---|
| 141 |
(setq describe-current-input-method-function 'ucs-input-help) |
|---|
| 142 |
(quail-delete-overlays) |
|---|
| 143 |
(if (eq (selected-window) (minibuffer-window)) |
|---|
| 144 |
(add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)) |
|---|
| 145 |
(set (make-local-variable 'input-method-function) |
|---|
| 146 |
'ucs-input-method))) |
|---|
| 147 |
|
|---|
| 148 |
(defun ucs-input-inactivate () |
|---|
| 149 |
"Inactivate UCS input method." |
|---|
| 150 |
(interactive) |
|---|
| 151 |
(ucs-input-activate -1)) |
|---|
| 152 |
|
|---|
| 153 |
(defun ucs-input-help () |
|---|
| 154 |
(interactive) |
|---|
| 155 |
(with-output-to-temp-buffer "*Help*" |
|---|
| 156 |
(princ "\ |
|---|
| 157 |
Input method: ucs (mode line indicator:U+) |
|---|
| 158 |
|
|---|
| 159 |
Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number."))) |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
(provide 'uni-input) |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|