Mercurial > emacs
annotate leim/quail/uni-input.el @ 90473:9c75458ea910
(xftfont_open): For generating a name, start from
96-byte buffer.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 19 Jun 2006 01:32:49 +0000 |
parents | 72dea2ff0142 |
children | a1a25ac6c88a |
rev | line source |
---|---|
40712 | 1 ;;; uni-input.el --- Hex Unicode input method |
2 | |
90385
72dea2ff0142
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-57
Miles Bader <miles@gnu.org>
diff
changeset
|
3 ;; Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. |
67657 | 4 ;; Copyright (C) 2004 |
5 ;; National Institute of Advanced Industrial Science and Technology (AIST) | |
6 ;; Registration Number H14PRO021 | |
40712 | 7 |
8 ;; Author: Dave Love <fx@gnu.org> | |
9 ;; Keywords: i18n | |
10 | |
42320 | 11 ;; This file is part of GNU Emacs. |
12 | |
40712 | 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) | |
16 ;; any later version. | |
17 | |
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. | |
22 | |
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 | |
64083 | 25 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
40712 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; Provides an input method for entering characters by hex unicode in | |
31 ;; the form `uxxxx', similarly to the Yudit editor. | |
32 | |
33 ;; This is not really a Quail method, but uses some Quail functions. | |
34 ;; There is probably A Better Way. | |
35 | |
88785 | 36 ;; You can get a similar effect by using C-q with |
37 ;; `read-quoted-char-radix' set to 16. | |
40712 | 38 |
89384 | 39 ;; Note that this only allows you to enter BMP values unless someone |
40 ;; extends it to use variable numbers of digits. | |
40712 | 41 |
42 ;;; Code: | |
43 | |
44 (require 'quail) | |
45 | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
46 (defun ucs-input-insert-char (char) |
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
47 (insert char) |
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
48 (move-overlay quail-overlay (overlay-start quail-overlay) (point))) |
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
49 |
40712 | 50 (defun ucs-input-method (key) |
51 (if (or buffer-read-only | |
52 (and (/= key ?U) (/= key ?u))) | |
53 (list key) | |
54 (quail-setup-overlays nil) | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
55 (ucs-input-insert-char key) |
40712 | 56 (let ((modified-p (buffer-modified-p)) |
57 (buffer-undo-list t) | |
58 (input-method-function nil) | |
59 (echo-keystrokes 0) | |
60 (help-char nil) | |
61 (events (list key)) | |
62 (str " ")) | |
63 (unwind-protect | |
64 (catch 'non-digit | |
65 (progn | |
66 (dotimes (i 4) | |
67 (let ((seq (read-key-sequence nil)) | |
68 key) | |
69 (if (and (stringp seq) | |
70 (= 1 (length seq)) | |
71 (setq key (aref seq 0)) | |
72 (memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a | |
88785 | 73 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F))) |
40712 | 74 (progn |
75 (push key events) | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
76 (ucs-input-insert-char key)) |
40712 | 77 (let ((last-command-char key) |
78 (current-prefix-arg)) | |
57212
fddea2c62003
(ucs-input-method): Add error clause to
Kenichi Handa <handa@m17n.org>
parents:
57180
diff
changeset
|
79 (condition-case err |
fddea2c62003
(ucs-input-method): Add error clause to
Kenichi Handa <handa@m17n.org>
parents:
57180
diff
changeset
|
80 (call-interactively (key-binding seq)) |
fddea2c62003
(ucs-input-method): Add error clause to
Kenichi Handa <handa@m17n.org>
parents:
57180
diff
changeset
|
81 (quail-error (message "%s" (cdr err)) (beep)))) |
40712 | 82 (quail-delete-region) |
83 (throw 'non-digit (append (reverse events) | |
84 (listify-key-sequence seq)))))) | |
85 (quail-delete-region) | |
88785 | 86 (let ((n (string-to-number (apply 'string |
87 (cdr (nreverse events))) | |
88 16))) | |
89 (if (characterp n) | |
90 (list n))))) | |
40712 | 91 (quail-delete-overlays) |
92 (set-buffer-modified-p modified-p) | |
93 (run-hooks 'input-method-after-insert-chunk-hook))))) | |
94 | |
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. | |
98 | |
99 While this input method is active, the variable | |
100 `input-method-function' is bound to the function `ucs-input-method'." | |
101 (if (and arg | |
102 (< (prefix-numeric-value arg) 0)) | |
103 (unwind-protect | |
104 (progn | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
105 (quail-hide-guidance) |
40712 | 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) | |
115 'ucs-input-method))) | |
116 | |
117 (defun ucs-input-inactivate () | |
118 "Inactivate UCS input method." | |
119 (interactive) | |
120 (ucs-input-activate -1)) | |
121 | |
122 (defun ucs-input-help () | |
123 (interactive) | |
124 (with-output-to-temp-buffer "*Help*" | |
125 (princ "\ | |
126 Input method: ucs (mode line indicator:U) | |
127 | |
128 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number."))) | |
129 | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
130 ;; The file ../leim-ext.el contains the following call. |
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
131 ;; (register-input-method "ucs" "UTF-8" 'ucs-input-activate "U+" |
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
132 ;; "Unicode input as hex in the form Uxxxx.") |
40712 | 133 |
134 (provide 'uni-input) | |
135 | |
52401 | 136 ;;; arch-tag: e0d91c7c-19a1-43d3-8f2b-28c0e031efaa |
40712 | 137 ;;; uni-input.el ends here |