annotate leim/quail/uni-input.el @ 55516:d43c6081f39c

Add edg examples and remove redundant ultrix examples.
author Daniel Pfeiffer <occitan@esperanto.org>
date Mon, 10 May 2004 21:09:51 +0000
parents 695cf19ef79e
children 5afba9a35578 375f2633d815
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40712
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
1 ;;; uni-input.el --- Hex Unicode input method
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
2
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 2001 Free Software Foundation, Inc.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
4
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
5 ;; Author: Dave Love <fx@gnu.org>
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Keywords: i18n
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
7
42320
44b4a14ae7fc Fix Lisp headers.
Pavel Janík <Pavel@Janik.cz>
parents: 40712
diff changeset
8 ;; This file is part of GNU Emacs.
44b4a14ae7fc Fix Lisp headers.
Pavel Janík <Pavel@Janik.cz>
parents: 40712
diff changeset
9
40712
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
10 ;; This file is free software; you can redistribute it and/or modify
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; any later version.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
14
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
15 ;; This file is distributed in the hope that it will be useful,
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
19
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
24
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
26
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
27 ;; Provides an input method for entering characters by hex unicode in
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;; the form `uxxxx', similarly to the Yudit editor.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
29
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
30 ;; This is not really a Quail method, but uses some Quail functions.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; There is probably A Better Way.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
32
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
33 ;; Compare `ucs-insert', which explicitly inserts a unicoded character
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
34 ;; rather than supplying an input method.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
35
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
36 ;;; Code:
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
37
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
38 (require 'quail)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
39
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
40 ;; Maybe stolen from Mule-UCS -- I don't remember.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
41 (define-ccl-program utf-8-ccl-encode
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
42 `(4 (if (r0 < ?\x80)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
43 ((write r0))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
44 (if (r0 < #x800)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
45 ((write ((r0 >> 6) | ?\xC0))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
46 (write ((r0 & ?\x3F) | ?\x80)))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
47 (if (r0 < #x10000)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
48 ((write ((r0 >> 12) | ?\xE0))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
49 (write (((r0 >> 6) & ?\x3F) | ?\x80))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
50 (write ((r0 & ?\x3F) | ?\x80)))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
51 (if (r0 < #x200000)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
52 ((write ((r0 >> 18) | ?\xF0))
49793
3994dfe96c97 (utf-8-ccl-encode): Fix use of character constants.
Juanma Barranquero <lekktu@gmail.com>
parents: 42320
diff changeset
53 (write (((r0 >> 12) & ?\x3F) | ?\x80))
40712
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
54 (write (((r0 >> 6) & ?\x3F) | ?\x80))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
55 (write ((r0 & ?\x3F) | ?\x80)))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
56 (if (r0 < #x4000000)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
57 ((write ((r0 >> 24) | ?\xF8))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
58 (write (((r0 >> 18) & ?\x3F) | ?\x80))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
59 (write (((r0 >> 12) & ?\x3F) | ?\x80))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
60 (write (((r0 >> 6) & ?\x3F) | ?\x80))
49793
3994dfe96c97 (utf-8-ccl-encode): Fix use of character constants.
Juanma Barranquero <lekktu@gmail.com>
parents: 42320
diff changeset
61 (write ((r0 & ?\x3F) | ?\x80)))
40712
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
62 ((write ((r0 >> 30) | ?\xFC))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
63 (write (((r0 >> 24) & ?\x3F) | ?\x80))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
64 (write (((r0 >> 18) & ?\x3F) | ?\x80))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
65 (write (((r0 >> 12) & ?\x3F) | ?\x80))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
66 (write (((r0 >> 6) & ?\x3F) | ?\x80))
49793
3994dfe96c97 (utf-8-ccl-encode): Fix use of character constants.
Juanma Barranquero <lekktu@gmail.com>
parents: 42320
diff changeset
67 (write ((r0 & ?\x3F) | ?\x80))))))))))
40712
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
68
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
69 (defun ucs-input-method (key)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
70 (if (or buffer-read-only
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
71 (and (/= key ?U) (/= key ?u)))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
72 (list key)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
73 (quail-setup-overlays nil)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
74 (let ((current-prefix-arg)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
75 (last-command-char key))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
76 (call-interactively 'self-insert-command))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
77 (let ((modified-p (buffer-modified-p))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
78 (buffer-undo-list t)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
79 (input-method-function nil)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
80 (echo-keystrokes 0)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
81 (help-char nil)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
82 (events (list key))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
83 (str " "))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
84 (unwind-protect
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
85 (catch 'non-digit
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
86 (progn
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
87 (dotimes (i 4)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
88 (let ((seq (read-key-sequence nil))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
89 key)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
90 (if (and (stringp seq)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
91 (= 1 (length seq))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
92 (setq key (aref seq 0))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
93 (memq key '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?a
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
94 ?b ?c ?d ?e ?f ?A ?B ?C ?D ?E ?F)))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
95 (progn
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
96 (push key events)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
97 (let ((last-command-char key)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
98 (current-prefix-arg))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
99 (call-interactively 'self-insert-command)))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
100 (let ((last-command-char key)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
101 (current-prefix-arg))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
102 (condition-case nil
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
103 (call-interactively (key-binding seq))))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
104 (quail-delete-region)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
105 (throw 'non-digit (append (reverse events)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
106 (listify-key-sequence seq))))))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
107 (quail-delete-region)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
108 (let* ((n (string-to-number (apply 'string
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
109 (cdr (nreverse events)))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
110 16))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
111 (c (decode-char 'ucs n))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
112 (status (make-vector 9 nil)))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
113 (if c
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
114 (list c)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
115 (aset status 0 n)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
116 (string-to-list (ccl-execute-on-string
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
117 'utf-8-ccl-encode status ""))))))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
118 (quail-delete-overlays)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
119 (set-buffer-modified-p modified-p)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
120 (run-hooks 'input-method-after-insert-chunk-hook)))))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
121
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
122 (defun ucs-input-activate (&optional arg)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
123 "Activate UCS input method.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
124 With arg, activate UCS input method if and only if arg is positive.
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
125
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
126 While this input method is active, the variable
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
127 `input-method-function' is bound to the function `ucs-input-method'."
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
128 (if (and arg
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
129 (< (prefix-numeric-value arg) 0))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
130 (unwind-protect
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
131 (progn
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
132 (quail-hide-guidance-buf)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
133 (quail-delete-overlays)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
134 (setq describe-current-input-method-function nil))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
135 (kill-local-variable 'input-method-function))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
136 (setq inactivate-current-input-method-function 'ucs-input-inactivate)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
137 (setq describe-current-input-method-function 'ucs-input-help)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
138 (quail-delete-overlays)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
139 (if (eq (selected-window) (minibuffer-window))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
140 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
141 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
142 (set (make-local-variable 'input-method-function)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
143 'ucs-input-method)))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
144
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
145 (defun ucs-input-inactivate ()
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
146 "Inactivate UCS input method."
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
147 (interactive)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
148 (ucs-input-activate -1))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
149
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
150 (defun ucs-input-help ()
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
151 (interactive)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
152 (with-output-to-temp-buffer "*Help*"
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
153 (princ "\
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
154 Input method: ucs (mode line indicator:U)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
155
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
156 Input as Unicode: U<hex> or u<hex>, where <hex> is a four-digit hex number.")))
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
157
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
158 (register-input-method "ucs" "UTF-8" 'ucs-input-activate "U+"
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
159 "Unicode input as hex in the form Uxxxx.")
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
160
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
161 (provide 'uni-input)
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
162
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49793
diff changeset
163 ;;; arch-tag: e0d91c7c-19a1-43d3-8f2b-28c0e031efaa
40712
31101867e6bf *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
164 ;;; uni-input.el ends here