comparison leim/quail/uni-input.el @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 3994dfe96c97
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 ;;; uni-input.el --- Hex Unicode input method 1 ;;; uni-input.el --- Hex Unicode input method
2 2
3 ;; Copyright (C) 2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 2001, 2003 Free Software Foundation, Inc.
4 ;; Copyright (C) 2004
5 ;; National Institute of Advanced Industrial Science and Technology (AIST)
6 ;; Registration Number H14PRO021
4 7
5 ;; Author: Dave Love <fx@gnu.org> 8 ;; Author: Dave Love <fx@gnu.org>
6 ;; Keywords: i18n 9 ;; Keywords: i18n
7 10
8 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details. 21 ;; GNU General Public License for more details.
19 22
20 ;; You should have received a copy of the GNU General Public License 23 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to 24 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 25 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02111-1307, USA. 26 ;; Boston, MA 02110-1301, USA.
24 27
25 ;;; Commentary: 28 ;;; Commentary:
26 29
27 ;; Provides an input method for entering characters by hex unicode in 30 ;; Provides an input method for entering characters by hex unicode in
28 ;; the form `uxxxx', similarly to the Yudit editor. 31 ;; the form `uxxxx', similarly to the Yudit editor.
64 (write (((r0 >> 18) & ?\x3F) | ?\x80)) 67 (write (((r0 >> 18) & ?\x3F) | ?\x80))
65 (write (((r0 >> 12) & ?\x3F) | ?\x80)) 68 (write (((r0 >> 12) & ?\x3F) | ?\x80))
66 (write (((r0 >> 6) & ?\x3F) | ?\x80)) 69 (write (((r0 >> 6) & ?\x3F) | ?\x80))
67 (write ((r0 & ?\x3F) | ?\x80)))))))))) 70 (write ((r0 & ?\x3F) | ?\x80))))))))))
68 71
72 (defun ucs-input-insert-char (char)
73 (insert char)
74 (move-overlay quail-overlay (overlay-start quail-overlay) (point)))
75
69 (defun ucs-input-method (key) 76 (defun ucs-input-method (key)
70 (if (or buffer-read-only 77 (if (or buffer-read-only
71 (and (/= key ?U) (/= key ?u))) 78 (and (/= key ?U) (/= key ?u)))
72 (list key) 79 (list key)
73 (quail-setup-overlays nil) 80 (quail-setup-overlays nil)
74 (let ((current-prefix-arg) 81 (ucs-input-insert-char key)
75 (last-command-char key))
76 (call-interactively 'self-insert-command))
77 (let ((modified-p (buffer-modified-p)) 82 (let ((modified-p (buffer-modified-p))
78 (buffer-undo-list t) 83 (buffer-undo-list t)
79 (input-method-function nil) 84 (input-method-function nil)
80 (echo-keystrokes 0) 85 (echo-keystrokes 0)
81 (help-char nil) 86 (help-char nil)
92 (setq key (aref seq 0)) 97 (setq key (aref seq 0))
93 (memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a 98 (memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a
94 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F))) 99 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F)))
95 (progn 100 (progn
96 (push key events) 101 (push key events)
97 (let ((last-command-char key) 102 (ucs-input-insert-char key))
98 (current-prefix-arg))
99 (call-interactively 'self-insert-command)))
100 (let ((last-command-char key) 103 (let ((last-command-char key)
101 (current-prefix-arg)) 104 (current-prefix-arg))
102 (condition-case nil 105 (condition-case err
103 (call-interactively (key-binding seq)))) 106 (call-interactively (key-binding seq))
107 (quail-error (message "%s" (cdr err)) (beep))))
104 (quail-delete-region) 108 (quail-delete-region)
105 (throw 'non-digit (append (reverse events) 109 (throw 'non-digit (append (reverse events)
106 (listify-key-sequence seq)))))) 110 (listify-key-sequence seq))))))
107 (quail-delete-region) 111 (quail-delete-region)
108 (let* ((n (string-to-number (apply 'string 112 (let* ((n (string-to-number (apply 'string
109 (cdr (nreverse events))) 113 (cdr (nreverse events)))
110 16)) 114 16))
111 (c (decode-char 'ucs n)) 115 (c (decode-char 'ucs n))
112 (status (make-vector 9 nil))) 116 (status (make-vector 9 nil)))
113 (if c 117 (if c
114 (list c) 118 (list c)
115 (aset status 0 n) 119 (aset status 0 n)
116 (string-to-list (ccl-execute-on-string 120 (string-to-list (ccl-execute-on-string
117 'utf-8-ccl-encode status "")))))) 121 'utf-8-ccl-encode status ""))))))
127 `input-method-function' is bound to the function `ucs-input-method'." 131 `input-method-function' is bound to the function `ucs-input-method'."
128 (if (and arg 132 (if (and arg
129 (< (prefix-numeric-value arg) 0)) 133 (< (prefix-numeric-value arg) 0))
130 (unwind-protect 134 (unwind-protect
131 (progn 135 (progn
132 (quail-hide-guidance-buf) 136 (quail-hide-guidance)
133 (quail-delete-overlays) 137 (quail-delete-overlays)
134 (setq describe-current-input-method-function nil)) 138 (setq describe-current-input-method-function nil))
135 (kill-local-variable 'input-method-function)) 139 (kill-local-variable 'input-method-function))
136 (setq inactivate-current-input-method-function 'ucs-input-inactivate) 140 (setq inactivate-current-input-method-function 'ucs-input-inactivate)
137 (setq describe-current-input-method-function 'ucs-input-help) 141 (setq describe-current-input-method-function 'ucs-input-help)
138 (quail-delete-overlays) 142 (quail-delete-overlays)
139 (if (eq (selected-window) (minibuffer-window)) 143 (if (eq (selected-window) (minibuffer-window))
140 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)) 144 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))
141 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t)
142 (set (make-local-variable 'input-method-function) 145 (set (make-local-variable 'input-method-function)
143 'ucs-input-method))) 146 'ucs-input-method)))
144 147
145 (defun ucs-input-inactivate () 148 (defun ucs-input-inactivate ()
146 "Inactivate UCS input method." 149 "Inactivate UCS input method."
153 (princ "\ 156 (princ "\
154 Input method: ucs (mode line indicator:U) 157 Input method: ucs (mode line indicator:U)
155 158
156 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number."))) 159 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number.")))
157 160
158 (register-input-method "ucs" "UTF-8" 'ucs-input-activate "U+" 161 ;; The file ../leim-ext.el contains the following call.
159 "Unicode input as hex in the form Uxxxx.") 162 ;; (register-input-method "ucs" "UTF-8" 'ucs-input-activate "U+"
163 ;; "Unicode input as hex in the form Uxxxx.")
160 164
161 (provide 'uni-input) 165 (provide 'uni-input)
162 166
167 ;;; arch-tag: e0d91c7c-19a1-43d3-8f2b-28c0e031efaa
163 ;;; uni-input.el ends here 168 ;;; uni-input.el ends here