Mercurial > emacs
annotate leim/quail/uni-input.el @ 90168:60394801794e
While running cpp on junk.c, include
-DHAVE_UNIDATA in CPPFLAGS if admin/unidata/UnicodeData.txt
exists.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 11 May 2005 12:16:42 +0000 |
parents | 0b158db81c28 |
children | f9a65d7ebd29 |
rev | line source |
---|---|
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. | |
40712 | 38 |
39 ;;; Code: | |
40 | |
41 (require 'quail) | |
42 | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
43 (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
|
44 (insert char) |
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
45 (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
|
46 |
40712 | 47 (defun ucs-input-method (key) |
48 (if (or buffer-read-only | |
49 (and (/= key ?U) (/= key ?u))) | |
50 (list key) | |
51 (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
|
52 (ucs-input-insert-char key) |
40712 | 53 (let ((modified-p (buffer-modified-p)) |
54 (buffer-undo-list t) | |
55 (input-method-function nil) | |
56 (echo-keystrokes 0) | |
57 (help-char nil) | |
58 (events (list key)) | |
59 (str " ")) | |
60 (unwind-protect | |
61 (catch 'non-digit | |
62 (progn | |
63 (dotimes (i 4) | |
64 (let ((seq (read-key-sequence nil)) | |
65 key) | |
66 (if (and (stringp seq) | |
67 (= 1 (length seq)) | |
68 (setq key (aref seq 0)) | |
69 (memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a | |
88785 | 70 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F))) |
40712 | 71 (progn |
72 (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
|
73 (ucs-input-insert-char key)) |
40712 | 74 (let ((last-command-char key) |
75 (current-prefix-arg)) | |
57212
fddea2c62003
(ucs-input-method): Add error clause to
Kenichi Handa <handa@m17n.org>
parents:
57180
diff
changeset
|
76 (condition-case err |
fddea2c62003
(ucs-input-method): Add error clause to
Kenichi Handa <handa@m17n.org>
parents:
57180
diff
changeset
|
77 (call-interactively (key-binding seq)) |
fddea2c62003
(ucs-input-method): Add error clause to
Kenichi Handa <handa@m17n.org>
parents:
57180
diff
changeset
|
78 (quail-error (message "%s" (cdr err)) (beep)))) |
40712 | 79 (quail-delete-region) |
80 (throw 'non-digit (append (reverse events) | |
81 (listify-key-sequence seq)))))) | |
82 (quail-delete-region) | |
88785 | 83 (let ((n (string-to-number (apply 'string |
84 (cdr (nreverse events))) | |
85 16))) | |
86 (if (characterp n) | |
87 (list n))))) | |
40712 | 88 (quail-delete-overlays) |
89 (set-buffer-modified-p modified-p) | |
90 (run-hooks 'input-method-after-insert-chunk-hook))))) | |
91 | |
92 (defun ucs-input-activate (&optional arg) | |
93 "Activate UCS input method. | |
94 With arg, activate UCS input method if and only if arg is positive. | |
95 | |
96 While this input method is active, the variable | |
97 `input-method-function' is bound to the function `ucs-input-method'." | |
98 (if (and arg | |
99 (< (prefix-numeric-value arg) 0)) | |
100 (unwind-protect | |
101 (progn | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
102 (quail-hide-guidance) |
40712 | 103 (quail-delete-overlays) |
104 (setq describe-current-input-method-function nil)) | |
105 (kill-local-variable 'input-method-function)) | |
106 (setq inactivate-current-input-method-function 'ucs-input-inactivate) | |
107 (setq describe-current-input-method-function 'ucs-input-help) | |
108 (quail-delete-overlays) | |
109 (if (eq (selected-window) (minibuffer-window)) | |
110 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)) | |
111 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t) | |
112 (set (make-local-variable 'input-method-function) | |
113 'ucs-input-method))) | |
114 | |
115 (defun ucs-input-inactivate () | |
116 "Inactivate UCS input method." | |
117 (interactive) | |
118 (ucs-input-activate -1)) | |
119 | |
120 (defun ucs-input-help () | |
121 (interactive) | |
122 (with-output-to-temp-buffer "*Help*" | |
123 (princ "\ | |
124 Input method: ucs (mode line indicator:U) | |
125 | |
126 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number."))) | |
127 | |
57180
5afba9a35578
Move the call of register-input-method to leim-ext.el.
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
128 ;; 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
|
129 ;; (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
|
130 ;; "Unicode input as hex in the form Uxxxx.") |
40712 | 131 |
132 (provide 'uni-input) | |
133 | |
52401 | 134 ;;; arch-tag: e0d91c7c-19a1-43d3-8f2b-28c0e031efaa |
40712 | 135 ;;; uni-input.el ends here |