1 ;;; unicode.el --- for UNICODE special features
3 ;; Copyright (C) 1997-2001 Miyashita Hisashi
5 ;; Keywords: mule, multilingual,
6 ;; character set, coding-system, ISO10646, Unicode
8 ;; This file is part of Mule-UCS
10 ;; Mule-UCS 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)
15 ;; Mule-UCS 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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
26 ;; This module supports unicode translations.
33 ;;; ucs-generic character elisp representation
34 ;; (1) ... a simple number.
35 ;; (2) ... a string that shows a number in c-format.
37 ;; If any other representations are converted to elisp
38 ;; representation, normalize it to (1) form.
39 ;; Why introduce (2)? Because there is no compatible format
40 ;; on hexadecimal literal between Emacs20 and XEmacs...x_x;
42 (defun ucs-generic-elisp-representation (x)
46 (c-notated-string-to-number x)
47 (error "Invalid ucs-generic represenation:%S" x))))
50 ;;; UCS generic type definition.
54 (function ucs-generic-elisp-representation)
58 ;;; translation generator
59 ;;; (work in progress...)
62 ;;; en/decode-char backends.
65 (defun ucs-representation-encoding-backend (char representation restriction)
66 (logior (lsh (charset-id (char-charset char)) 16)
67 (char-codepoint char))
68 (mucs-convert 'emacs-char-to-ucs-codepoint-conversion
71 (defun ucs-representation-decoding-backend (representation object restriction)
73 (mucs-convert 'ucs-codepoint-to-emacs-char-conversion
75 (signal 'wrong-type-argument
76 (list 'numberp object))))
78 (mucs-register-representation-encoding-backend
80 (function ucs-representation-encoding-backend))
82 (mucs-register-representation-decoding-backend
84 (function ucs-representation-decoding-backend))
87 ;;; Unicode or its transformation format support function.
88 ;;; (obsoleted by encode-char/decode-char)
91 (defun ucs-to-char (codepoint)
92 "Convert Unicode codepoint to an XEmacs character.
93 CODE should be a non-negative integer.
95 If `codepoint' cannot be represented as an XEmacs character--that is,
96 Mule-UCS doesn't know about any registered translation from it to some
97 character in the multiple-character-set non-Unified Mule model, return nil.
98 Beware that *many* Unicode codepoints have no representation in the Mule
99 model, and since the Mule-UCS coding systems have the same backend as does
100 this function, they will tend to trash data. "
101 (ucs-representation-decoding-backend 'ucs codepoint nil))
103 (defun char-to-ucs (char)
104 "Convert character to Unicode codepoint. "
105 (ucs-representation-encoding-backend char 'ucs nil))
108 ;;; Commands for editing.
111 (defun insert-ucs-character (codepoint)
112 "Insert character which is converted from give UCS codepoint."
113 (interactive "nUCS codepoint:")
114 (insert (or (ucs-representation-decoding-backend 'ucs codepoint nil)
115 (error "Invalid or cannot translate:U+%X"
118 (provide 'mule-ucs-unicode)
120 ;;; unicode.el ends here.