1 ;;; uni-input.el --- Hex Unicode input method
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
5 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
9 ;; Author: Dave Love <fx@gnu.org>
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; Provides an input method for entering characters by hex unicode in
30 ;; the form `uxxxx', similarly to the Yudit editor.
32 ;; This is not really a Quail method, but uses some Quail functions.
33 ;; There is probably A Better Way.
35 ;; You can get a similar effect by using C-q with
36 ;; `read-quoted-char-radix' set to 16.
38 ;; Note that this only allows you to enter BMP values unless someone
39 ;; extends it to use variable numbers of digits.
45 (defun ucs-input-insert-char (char)
47 (move-overlay quail-overlay
(overlay-start quail-overlay
) (point)))
49 (defun ucs-input-method (key)
50 (if (or buffer-read-only
51 (and (/= key ?U
) (/= key ?u
)))
53 (quail-setup-overlays nil
)
54 (ucs-input-insert-char key
)
55 (let ((modified-p (buffer-modified-p))
57 (input-method-function nil
)
66 (let ((seq (read-key-sequence nil
))
68 (if (and (stringp seq
)
70 (setq key
(aref seq
0))
71 (memq key
'(?
0 ?
1 ?
2 ?
3 ?
4 ?
5 ?
6 ?
7 ?
8 ?
9 ?a
72 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F
)))
75 (ucs-input-insert-char key
))
77 (throw 'non-digit
(append (reverse events
)
78 (listify-key-sequence seq
))))))
80 (let ((n (string-to-number (apply 'string
81 (cdr (nreverse events
)))
85 (quail-delete-overlays)
86 (set-buffer-modified-p modified-p
)
87 (run-hooks 'input-method-after-insert-chunk-hook
)))))
89 (defun ucs-input-activate (&optional arg
)
90 "Activate UCS input method.
91 With arg, activate UCS input method if and only if arg is positive.
93 While this input method is active, the variable
94 `input-method-function' is bound to the function `ucs-input-method'."
96 (< (prefix-numeric-value arg
) 0))
100 (quail-delete-overlays)
101 (setq describe-current-input-method-function nil
))
102 (kill-local-variable 'input-method-function
))
103 (setq inactivate-current-input-method-function
'ucs-input-inactivate
)
104 (setq describe-current-input-method-function
'ucs-input-help
)
105 (quail-delete-overlays)
106 (if (eq (selected-window) (minibuffer-window))
107 (add-hook 'minibuffer-exit-hook
'quail-exit-from-minibuffer
))
108 (set (make-local-variable 'input-method-function
)
111 (defun ucs-input-inactivate ()
112 "Inactivate UCS input method."
114 (ucs-input-activate -
1))
116 (defun ucs-input-help ()
118 (with-output-to-temp-buffer "*Help*"
120 Input method: ucs (mode line indicator:U+)
122 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number.")))
124 ;; The file ../leim-ext.el contains the following call.
125 ;; (register-input-method "ucs" "UTF-8" 'ucs-input-activate "U+"
126 ;; "Unicode input as hex in the form Uxxxx.")
130 ;; arch-tag: e0d91c7c-19a1-43d3-8f2b-28c0e031efaa
131 ;;; uni-input.el ends here