1 ;;; uni-input.el --- Hex Unicode input method
3 ;; Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
5 ;; National Institute of Advanced Industrial Science and Technology (AIST)
6 ;; Registration Number H14PRO021
8 ;; Author: Dave Love <fx@gnu.org>
11 ;; This file is part of GNU Emacs.
13 ;; This file is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; This file is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; Provides an input method for entering characters by hex unicode in
31 ;; the form `uxxxx', similarly to the Yudit editor.
33 ;; This is not really a Quail method, but uses some Quail functions.
34 ;; There is probably A Better Way.
36 ;; You can get a similar effect by using C-q with
37 ;; `read-quoted-char-radix' set to 16.
39 ;; Note that this only allows you to enter BMP values unless someone
40 ;; extends it to use variable numbers of digits.
46 (defun ucs-input-insert-char (char)
48 (move-overlay quail-overlay (overlay-start quail-overlay) (point)))
50 (defun ucs-input-method (key)
51 (if (or buffer-read-only
52 (and (/= key ?U) (/= key ?u)))
54 (quail-setup-overlays nil)
55 (ucs-input-insert-char key)
56 (let ((modified-p (buffer-modified-p))
58 (input-method-function nil)
67 (let ((seq (read-key-sequence nil))
69 (if (and (stringp seq)
71 (setq key (aref seq 0))
72 (memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a
73 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F)))
76 (ucs-input-insert-char key))
77 (let ((last-command-char key)
80 (call-interactively (key-binding seq))
81 (quail-error (message "%s" (cdr err)) (beep))))
83 (throw 'non-digit (append (reverse events)
84 (listify-key-sequence seq))))))
86 (let ((n (string-to-number (apply 'string
87 (cdr (nreverse events)))
91 (quail-delete-overlays)
92 (set-buffer-modified-p modified-p)
93 (run-hooks 'input-method-after-insert-chunk-hook)))))
95 (defun ucs-input-activate (&optional arg)
96 "Activate UCS input method.
97 With arg, activate UCS input method if and only if arg is positive.
99 While this input method is active, the variable
100 `input-method-function' is bound to the function `ucs-input-method'."
102 (< (prefix-numeric-value arg) 0))
105 (quail-hide-guidance)
106 (quail-delete-overlays)
107 (setq describe-current-input-method-function nil))
108 (kill-local-variable 'input-method-function))
109 (setq inactivate-current-input-method-function 'ucs-input-inactivate)
110 (setq describe-current-input-method-function 'ucs-input-help)
111 (quail-delete-overlays)
112 (if (eq (selected-window) (minibuffer-window))
113 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))
114 (set (make-local-variable 'input-method-function)
117 (defun ucs-input-inactivate ()
118 "Inactivate UCS input method."
120 (ucs-input-activate -1))
122 (defun ucs-input-help ()
124 (with-output-to-temp-buffer "*Help*"
126 Input method: ucs (mode line indicator:U)
128 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number.")))
130 ;; The file ../leim-ext.el contains the following call.
131 ;; (register-input-method "ucs" "UTF-8" 'ucs-input-activate "U+"
132 ;; "Unicode input as hex in the form Uxxxx.")
136 ;;; arch-tag: e0d91c7c-19a1-43d3-8f2b-28c0e031efaa
137 ;;; uni-input.el ends here