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
|
|
36 ;;; Code:
|
|
37
|
|
38 (require 'quail)
|
|
39
|
|
40 (defun ucs-input-method (key)
|
|
41 (if (or buffer-read-only
|
|
42 (and (/= key ?U) (/= key ?u)))
|
|
43 (list key)
|
|
44 (quail-setup-overlays nil)
|
|
45 (let ((current-prefix-arg)
|
|
46 (last-command-char key))
|
|
47 (call-interactively 'self-insert-command))
|
|
48 (let ((modified-p (buffer-modified-p))
|
|
49 (buffer-undo-list t)
|
|
50 (input-method-function nil)
|
|
51 (echo-keystrokes 0)
|
|
52 (help-char nil)
|
|
53 (events (list key))
|
|
54 (str " "))
|
|
55 (unwind-protect
|
|
56 (catch 'non-digit
|
|
57 (progn
|
|
58 (dotimes (i 4)
|
|
59 (let ((seq (read-key-sequence nil))
|
|
60 key)
|
|
61 (if (and (stringp seq)
|
|
62 (= 1 (length seq))
|
|
63 (setq key (aref seq 0))
|
|
64 (memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a
|
88785
|
65 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F)))
|
40712
|
66 (progn
|
|
67 (push key events)
|
|
68 (let ((last-command-char key)
|
|
69 (current-prefix-arg))
|
|
70 (call-interactively 'self-insert-command)))
|
|
71 (let ((last-command-char key)
|
|
72 (current-prefix-arg))
|
|
73 (condition-case nil
|
|
74 (call-interactively (key-binding seq))))
|
|
75 (quail-delete-region)
|
|
76 (throw 'non-digit (append (reverse events)
|
|
77 (listify-key-sequence seq))))))
|
|
78 (quail-delete-region)
|
88785
|
79 (let ((n (string-to-number (apply 'string
|
|
80 (cdr (nreverse events)))
|
|
81 16)))
|
|
82 (if (characterp n)
|
|
83 (list n)))))
|
40712
|
84 (quail-delete-overlays)
|
|
85 (set-buffer-modified-p modified-p)
|
|
86 (run-hooks 'input-method-after-insert-chunk-hook)))))
|
|
87
|
|
88 (defun ucs-input-activate (&optional arg)
|
|
89 "Activate UCS input method.
|
|
90 With arg, activate UCS input method if and only if arg is positive.
|
|
91
|
|
92 While this input method is active, the variable
|
|
93 `input-method-function' is bound to the function `ucs-input-method'."
|
|
94 (if (and arg
|
|
95 (< (prefix-numeric-value arg) 0))
|
|
96 (unwind-protect
|
|
97 (progn
|
|
98 (quail-hide-guidance-buf)
|
|
99 (quail-delete-overlays)
|
|
100 (setq describe-current-input-method-function nil))
|
|
101 (kill-local-variable 'input-method-function))
|
|
102 (setq inactivate-current-input-method-function 'ucs-input-inactivate)
|
|
103 (setq describe-current-input-method-function 'ucs-input-help)
|
|
104 (quail-delete-overlays)
|
|
105 (if (eq (selected-window) (minibuffer-window))
|
|
106 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))
|
|
107 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t)
|
|
108 (set (make-local-variable 'input-method-function)
|
|
109 'ucs-input-method)))
|
|
110
|
|
111 (defun ucs-input-inactivate ()
|
|
112 "Inactivate UCS input method."
|
|
113 (interactive)
|
|
114 (ucs-input-activate -1))
|
|
115
|
|
116 (defun ucs-input-help ()
|
|
117 (interactive)
|
|
118 (with-output-to-temp-buffer "*Help*"
|
|
119 (princ "\
|
|
120 Input method: ucs (mode line indicator:U)
|
|
121
|
|
122 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number.")))
|
|
123
|
|
124 (register-input-method "ucs" "UTF-8" 'ucs-input-activate "U+"
|
|
125 "Unicode input as hex in the form Uxxxx.")
|
|
126
|
|
127 (provide 'uni-input)
|
|
128
|
|
129 ;;; uni-input.el ends here
|