40712
|
1 ;;; uni-input.el --- Hex Unicode input method
|
|
2
|
88785
|
3 ;; Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
40712
|
4
|
|
5 ;; Author: Dave Love <fx@gnu.org>
|
|
6 ;; Keywords: i18n
|
|
7
|
42320
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
40712
|
10 ;; This file is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; This file is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; 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
|
|
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
|
24
|
|
25 ;;; Commentary:
|
|
26
|
|
27 ;; Provides an input method for entering characters by hex unicode in
|
|
28 ;; the form `uxxxx', similarly to the Yudit editor.
|
|
29
|
|
30 ;; This is not really a Quail method, but uses some Quail functions.
|
|
31 ;; There is probably A Better Way.
|
|
32
|
88785
|
33 ;; You can get a similar effect by using C-q with
|
|
34 ;; `read-quoted-char-radix' set to 16.
|
40712
|
35
|
89384
|
36 ;; Note that this only allows you to enter BMP values unless someone
|
|
37 ;; extends it to use variable numbers of digits.
|
|
38
|
40712
|
39 ;;; Code:
|
|
40
|
|
41 (require 'quail)
|
|
42
|
|
43 (defun ucs-input-method (key)
|
|
44 (if (or buffer-read-only
|
|
45 (and (/= key ?U) (/= key ?u)))
|
|
46 (list key)
|
|
47 (quail-setup-overlays nil)
|
|
48 (let ((current-prefix-arg)
|
|
49 (last-command-char key))
|
|
50 (call-interactively 'self-insert-command))
|
|
51 (let ((modified-p (buffer-modified-p))
|
|
52 (buffer-undo-list t)
|
|
53 (input-method-function nil)
|
|
54 (echo-keystrokes 0)
|
|
55 (help-char nil)
|
|
56 (events (list key))
|
|
57 (str " "))
|
|
58 (unwind-protect
|
|
59 (catch 'non-digit
|
|
60 (progn
|
|
61 (dotimes (i 4)
|
|
62 (let ((seq (read-key-sequence nil))
|
|
63 key)
|
|
64 (if (and (stringp seq)
|
|
65 (= 1 (length seq))
|
|
66 (setq key (aref seq 0))
|
|
67 (memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a
|
88785
|
68 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F)))
|
40712
|
69 (progn
|
|
70 (push key events)
|
|
71 (let ((last-command-char key)
|
|
72 (current-prefix-arg))
|
|
73 (call-interactively 'self-insert-command)))
|
|
74 (let ((last-command-char key)
|
|
75 (current-prefix-arg))
|
|
76 (condition-case nil
|
|
77 (call-interactively (key-binding seq))))
|
|
78 (quail-delete-region)
|
|
79 (throw 'non-digit (append (reverse events)
|
|
80 (listify-key-sequence seq))))))
|
|
81 (quail-delete-region)
|
88785
|
82 (let ((n (string-to-number (apply 'string
|
|
83 (cdr (nreverse events)))
|
|
84 16)))
|
|
85 (if (characterp n)
|
|
86 (list n)))))
|
40712
|
87 (quail-delete-overlays)
|
|
88 (set-buffer-modified-p modified-p)
|
|
89 (run-hooks 'input-method-after-insert-chunk-hook)))))
|
|
90
|
|
91 (defun ucs-input-activate (&optional arg)
|
|
92 "Activate UCS input method.
|
|
93 With arg, activate UCS input method if and only if arg is positive.
|
|
94
|
|
95 While this input method is active, the variable
|
|
96 `input-method-function' is bound to the function `ucs-input-method'."
|
|
97 (if (and arg
|
|
98 (< (prefix-numeric-value arg) 0))
|
|
99 (unwind-protect
|
|
100 (progn
|
|
101 (quail-hide-guidance-buf)
|
|
102 (quail-delete-overlays)
|
|
103 (setq describe-current-input-method-function nil))
|
|
104 (kill-local-variable 'input-method-function))
|
|
105 (setq inactivate-current-input-method-function 'ucs-input-inactivate)
|
|
106 (setq describe-current-input-method-function 'ucs-input-help)
|
|
107 (quail-delete-overlays)
|
|
108 (if (eq (selected-window) (minibuffer-window))
|
|
109 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))
|
|
110 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t)
|
|
111 (set (make-local-variable 'input-method-function)
|
|
112 'ucs-input-method)))
|
|
113
|
|
114 (defun ucs-input-inactivate ()
|
|
115 "Inactivate UCS input method."
|
|
116 (interactive)
|
|
117 (ucs-input-activate -1))
|
|
118
|
|
119 (defun ucs-input-help ()
|
|
120 (interactive)
|
|
121 (with-output-to-temp-buffer "*Help*"
|
|
122 (princ "\
|
|
123 Input method: ucs (mode line indicator:U)
|
|
124
|
|
125 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number.")))
|
|
126
|
|
127 (register-input-method "ucs" "UTF-8" 'ucs-input-activate "U+"
|
|
128 "Unicode input as hex in the form Uxxxx.")
|
|
129
|
|
130 (provide 'uni-input)
|
|
131
|
|
132 ;;; uni-input.el ends here
|