(Management Parameters): Mention sticky.
[emacs.git] / leim / quail / uni-input.el
blob6737f76903d33995752e0f81ccaa7da96ea0c05b
1 ;;; uni-input.el --- Hex Unicode input method
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
5 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
9 ;; Author: Dave Love <fx@gnu.org>
10 ;; Keywords: i18n
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/>.
27 ;;; Commentary:
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.
41 ;;; Code:
43 (require 'quail)
45 (defun ucs-input-insert-char (char)
46 (insert 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)))
52 (list key)
53 (quail-setup-overlays nil)
54 (ucs-input-insert-char key)
55 (let ((modified-p (buffer-modified-p))
56 (buffer-undo-list t)
57 (input-method-function nil)
58 (echo-keystrokes 0)
59 (help-char nil)
60 (events (list key))
61 (str " "))
62 (unwind-protect
63 (catch 'non-digit
64 (progn
65 (dotimes (i 4)
66 (let ((seq (read-key-sequence nil))
67 key)
68 (if (and (stringp seq)
69 (= 1 (length 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)))
73 (progn
74 (push key events)
75 (ucs-input-insert-char key))
76 (quail-delete-region)
77 (throw 'non-digit (append (reverse events)
78 (listify-key-sequence seq))))))
79 (quail-delete-region)
80 (let ((n (string-to-number (apply 'string
81 (cdr (nreverse events)))
82 16)))
83 (if (characterp n)
84 (list n)))))
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'."
95 (if (and arg
96 (< (prefix-numeric-value arg) 0))
97 (unwind-protect
98 (progn
99 (quail-hide-guidance)
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)
109 'ucs-input-method)))
111 (defun ucs-input-inactivate ()
112 "Inactivate UCS input method."
113 (interactive)
114 (ucs-input-activate -1))
116 (defun ucs-input-help ()
117 (interactive)
118 (with-output-to-temp-buffer "*Help*"
119 (princ "\
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.")
128 (provide 'uni-input)
130 ;; arch-tag: e0d91c7c-19a1-43d3-8f2b-28c0e031efaa
131 ;;; uni-input.el ends here