Mercurial > emacs
annotate leim/quail/uni-input.el @ 91121:1805a65e7746
(read1): Undo the previous change.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 21 Nov 2007 12:12:06 +0000 |
parents | f55f9811f5d7 |
children | 606f2d163a64 |
rev | line source |
---|---|
40712 | 1 ;;; uni-input.el --- Hex Unicode input method |
2 | |
75253
f5f322eb227f
Update copyright for years from Emacs 21 to present.
Glenn Morris <rgm@gnu.org>
parents:
75203
diff
changeset
|
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
f5f322eb227f
Update copyright for years from Emacs 21 to present.
Glenn Morris <rgm@gnu.org>
parents:
75203
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
f5f322eb227f
Update copyright for years from Emacs 21 to present.
Glenn Morris <rgm@gnu.org>
parents:
75203
diff
changeset
|
5 ;; Copyright (C) 2004, 2005, 2006, 2007 |
67657 | 6 ;; National Institute of Advanced Industrial Science and Technology (AIST) |
7 ;; Registration Number H14PRO021 | |
40712 | 8 |
9 ;; Author: Dave Love <fx@gnu.org> | |
10 ;; Keywords: i18n | |
11 | |
42320 | 12 ;; This file is part of GNU Emacs. |
13 | |
40712 | 14 ;; This file is free software; you can redistribute it and/or modify |
15 ;; it under the terms of the GNU General Public License as published by | |
78308
126deea128b3
Restore comma mistakenly removed in last change.
Glenn Morris <rgm@gnu.org>
parents:
78303
diff
changeset
|
16 ;; the Free Software Foundation; either version 3, or (at your option) |
40712 | 17 ;; any later version. |
18 | |
19 ;; This file 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. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
25 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
64083 | 26 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27 ;; Boston, MA 02110-1301, USA. | |
40712 | 28 |
29 ;;; Commentary: | |
30 | |
31 ;; Provides an input method for entering characters by hex unicode in | |
32 ;; the form `uxxxx', similarly to the Yudit editor. | |
33 | |
34 ;; This is not really a Quail method, but uses some Quail functions. | |
35 ;; There is probably A Better Way. | |
36 | |
88785 | 37 ;; You can get a similar effect by using C-q with |
38 ;; `read-quoted-char-radix' set to 16. | |
40712 | 39 |
89384 | 40 ;; Note that this only allows you to enter BMP values unless someone |
41 ;; extends it to use variable numbers of digits. | |
40712 | 42 |
43 ;;; Code: | |
44 | |
45 (require 'quail) | |
46 | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
47 (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
|
48 (insert char) |
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
49 (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
|
50 |
40712 | 51 (defun ucs-input-method (key) |
52 (if (or buffer-read-only | |
53 (and (/= key ?U) (/= key ?u))) | |
54 (list key) | |
55 (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
|
56 (ucs-input-insert-char key) |
40712 | 57 (let ((modified-p (buffer-modified-p)) |
58 (buffer-undo-list t) | |
59 (input-method-function nil) | |
60 (echo-keystrokes 0) | |
61 (help-char nil) | |
62 (events (list key)) | |
63 (str " ")) | |
64 (unwind-protect | |
65 (catch 'non-digit | |
66 (progn | |
67 (dotimes (i 4) | |
68 (let ((seq (read-key-sequence nil)) | |
69 key) | |
70 (if (and (stringp seq) | |
71 (= 1 (length seq)) | |
72 (setq key (aref seq 0)) | |
73 (memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a | |
88785 | 74 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F))) |
40712 | 75 (progn |
76 (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
|
77 (ucs-input-insert-char key)) |
40712 | 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 | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
101 (quail-hide-guidance) |
40712 | 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 (set (make-local-variable 'input-method-function) | |
111 'ucs-input-method))) | |
112 | |
113 (defun ucs-input-inactivate () | |
114 "Inactivate UCS input method." | |
115 (interactive) | |
116 (ucs-input-activate -1)) | |
117 | |
118 (defun ucs-input-help () | |
119 (interactive) | |
120 (with-output-to-temp-buffer "*Help*" | |
121 (princ "\ | |
74538
dc4eb942b3a5
(ucs-input-help): Fix title of ucs input method.
Juanma Barranquero <lekktu@gmail.com>
parents:
72860
diff
changeset
|
122 Input method: ucs (mode line indicator:U+) |
40712 | 123 |
124 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number."))) | |
125 | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
126 ;; 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
|
127 ;; (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
|
128 ;; "Unicode input as hex in the form Uxxxx.") |
40712 | 129 |
130 (provide 'uni-input) | |
131 | |
52401 | 132 ;;; arch-tag: e0d91c7c-19a1-43d3-8f2b-28c0e031efaa |
40712 | 133 ;;; uni-input.el ends here |