annotate lisp/mule/mule-util.el @ 165:5a88923fcbfe r20-3b9

Import from CVS: tag r20-3b9
author cvs
date Mon, 13 Aug 2007 09:44:42 +0200
parents
children 85ec50267440
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
1 ;;; mule-util.el --- Utility functions for mulitilingual environment (mule)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
2
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
6
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
7 ;; Keywords: mule, multilingual
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
8
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
10
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
14 ;; any later version.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
15
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
19 ;; General Public License for more details.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
20
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
24 ;; 02111-1307, USA.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
25
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
26 ;;; Code:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
27
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
28 ;;; String manipulations while paying attention to multibyte
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
29 ;;; characters.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
30
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
31 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
32 (defsubst string-to-sequence (string type)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
33 "Convert STRING to a sequence of TYPE which contains characters in STRING.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
34 TYPE should be `list' or `vector'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
35 Multibyte characters are conserned."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
36 (map type (function identity) string))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
37
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
38 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
39 (defsubst string-to-list (string)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
40 "Return a list of characters in STRING."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
41 (mapcar (function identity) string))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
42
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
43 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
44 (defsubst string-to-vector (string)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
45 "Return a vector of characters in STRING."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
46 (string-to-sequence string 'vector))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
47
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
48 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
49 (defun store-substring (string idx obj)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
50 "Embed OBJ (string or character) at index IDX of STRING."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
51 (let* ((str (cond ((stringp obj) obj)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
52 ((characterp obj) (char-to-string obj))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
53 (t (error
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
54 "Invalid argument (should be string or character): %s"
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
55 obj))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
56 (string-len (length string))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
57 (len (length str))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
58 (i 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
59 (while (and (< i len) (< idx string-len))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
60 (aset string idx (aref str i))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
61 (setq idx (1+ idx) i (1+ i)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
62 string))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
63
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
64 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
65 (defun truncate-string-to-width (str width &optional start-column padding)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
66 "Truncate string STR to fit in WIDTH columns.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
67 Optional 1st arg START-COLUMN if non-nil specifies the starting column.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
68 Optional 2nd arg PADDING if non-nil is a padding character to be padded at
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
69 the head and tail of the resulting string to fit in WIDTH if necessary.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
70 If PADDING is nil, the resulting string may be narrower than WIDTH."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
71 (or start-column
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
72 (setq start-column 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
73 (let ((len (length str))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
74 (idx 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
75 (column 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
76 (head-padding "") (tail-padding "")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
77 ch last-column last-idx from-idx)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
78 (condition-case nil
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
79 (while (< column start-column)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
80 (setq ch (sref str idx)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
81 column (+ column (char-width ch))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
82 idx (+ idx (char-bytes ch))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
83 (args-out-of-range (setq idx len)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
84 (if (< column start-column)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
85 (if padding (make-string width padding) "")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
86 (if (and padding (> column start-column))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
87 (setq head-padding (make-string (- column start-column) ?\ )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
88 (setq from-idx idx)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
89 (condition-case nil
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
90 (while (< column width)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
91 (setq last-column column
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
92 last-idx idx
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
93 ch (sref str idx)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
94 column (+ column (char-width ch))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
95 idx (+ idx (char-bytes ch))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
96 (args-out-of-range (setq idx len)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
97 (if (> column width)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
98 (setq column last-column idx last-idx))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
99 (if (and padding (< column width))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
100 (setq tail-padding (make-string (- width column) padding)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
101 (setq str (substring str from-idx idx))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
102 (if padding
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
103 (concat head-padding str tail-padding)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
104 str))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
105
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
106 ;;; For backward compatiblity ...
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
107 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
108 (defalias 'truncate-string 'truncate-string-to-width)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
109 (make-obsolete 'truncate-string 'truncate-string-to-width)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
110
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
111 ;;; Nested alist handler. Nested alist is alist whose elements are
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
112 ;;; also nested alist.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
113
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
114 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
115 (defsubst nested-alist-p (obj)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
116 "Return t if OBJ is a nesetd alist.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
117
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
118 Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
119 any Lisp object, and BRANCHES is a list of cons cells of the form
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
120 (KEY-ELEMENT . NESTED-ALIST).
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
121
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
122 You can use a nested alist to store any Lisp object (ENTRY) for a key
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
123 sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
124 can be a string, a vector, or a list."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
125 (and obj (listp obj) (listp (cdr obj))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
126
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
127 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
128 (defun set-nested-alist (keyseq entry alist &optional len branches)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
129 "Set ENTRY for KEYSEQ in a nested alist ALIST.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
130 Optional 4th arg LEN non-nil means the firlst LEN elements in KEYSEQ
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
131 is considered.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
132 Optional argument BRANCHES if non-nil is branches for a keyseq
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
133 longer than KEYSEQ.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
134 See the documentation of `nested-alist-p' for more detail."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
135 (or (nested-alist-p alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
136 (error "Invalid arguement %s" alist))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
137 (let ((islist (listp keyseq))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
138 (len (or len (length keyseq)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
139 (i 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
140 key-elt slot)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
141 (while (< i len)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
142 (if (null (nested-alist-p alist))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
143 (error "Keyseq %s is too long for this nested alist" keyseq))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
144 (setq key-elt (if islist (nth i keyseq) (aref keyseq i)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
145 (setq slot (assoc key-elt (cdr alist)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
146 (if (null slot)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
147 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
148 (setq slot (cons key-elt (list t)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
149 (setcdr alist (cons slot (cdr alist)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
150 (setq alist (cdr slot))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
151 (setq i (1+ i)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
152 (setcar alist entry)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
153 (if branches
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
154 (if (cdr alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
155 (error "Can't set branches for keyseq %s" keyseq)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
156 (setcdr alist branches)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
157
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
158 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
159 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
160 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
161 Optional 1st argument LEN specifies the length of KEYSEQ.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
162 Optional 2nd argument START specifies index of the starting key.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
163 The returned value is normally a nested alist of which
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
164 car part is the entry for KEYSEQ.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
165 If ALIST is not deep enough for KEYSEQ, return number which is
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
166 how many key elements at the front of KEYSEQ it takes
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
167 to reach a leaf in ALIST.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
168 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
169 even if ALIST is not deep enough."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
170 (or (nested-alist-p alist)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
171 (error "invalid arguement %s" alist))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
172 (or len
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
173 (setq len (length keyseq)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
174 (let ((i (or start 0)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
175 (if (catch 'lookup-nested-alist-tag
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
176 (if (listp keyseq)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
177 (while (< i len)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
178 (if (setq alist (cdr (assoc (nth i keyseq) (cdr alist))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
179 (setq i (1+ i))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
180 (throw 'lookup-nested-alist-tag t))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
181 (while (< i len)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
182 (if (setq alist (cdr (assoc (aref keyseq i) (cdr alist))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
183 (setq i (1+ i))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
184 (throw 'lookup-nested-alist-tag t))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
185 ;; KEYSEQ is too long.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
186 (if nil-for-too-long nil i)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
187 alist)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
188
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
189 ;; Coding system related functions.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
190
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
191 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
192 (defun set-coding-system-alist (target-type regexp coding-system
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
193 &optional operation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
194 "Update `coding-system-alist' according to the arguments.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
195 TARGET-TYPE specifies a type of the target: `file', `process', or `network'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
196 TARGET-TYPE tells which slots of coding-system-alist should be affected.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
197 If `file', it affects slots for insert-file-contents and write-region.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
198 If `process', it affects slots for call-process, call-process-region, and
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
199 start-process.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
200 If `network', it affects a slot for open-network-process.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
201 REGEXP is a regular expression matching a target of I/O operation.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
202 CODING-SYSTEM is a coding system to perform code conversion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
203 on the I/O operation, or a cons of coding systems for decoding and
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
204 encoding respectively, or a function symbol which returns the cons.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
205 Optional arg OPERATION if non-nil specifies directly one of slots above.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
206 The valid value is: insert-file-contents, write-region,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
207 call-process, call-process-region, start-process, or open-network-stream.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
208 If OPERATION is specified, TARGET-TYPE is ignored.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
209 See the documentation of `coding-system-alist' for more detail."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
210 (or (stringp regexp)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
211 (error "Invalid regular expression: %s" regexp))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
212 (or (memq target-type '(file process network))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
213 (error "Invalid target type: %s" target-type))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
214 (if (symbolp coding-system)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
215 (if (not (fboundp coding-system))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
216 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
217 (check-coding-system coding-system)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
218 (setq coding-system (cons coding-system coding-system))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
219 (check-coding-system (car coding-system))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
220 (check-coding-system (cdr coding-system)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
221 (let ((op-list (if operation (list operation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
222 (cond ((eq target-type 'file)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
223 '(insert-file-contents write-region))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
224 ((eq target-type 'process)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
225 '(call-process call-process-region start-process))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
226 (t ; i.e. (eq target-type network)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
227 '(open-network-stream)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
228 slot)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
229 (while op-list
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
230 (setq slot (assq (car op-list) coding-system-alist))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
231 (if slot
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
232 (let ((chain (cdr slot)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
233 (if (catch 'tag
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
234 (while chain
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
235 (if (string= regexp (car (car chain)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
236 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
237 (setcdr (car chain) coding-system)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
238 (throw 'tag nil)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
239 (setq chain (cdr chain)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
240 t)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
241 (setcdr slot (cons (cons regexp coding-system) (cdr slot)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
242 (setq coding-system-alist
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
243 (cons (cons (car op-list) (list (cons regexp coding-system)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
244 coding-system-alist)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
245 (setq op-list (cdr op-list)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
246
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
247
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
248 ;;; Composite charcater manipulations.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
249
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
250 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
251 (defun compose-region (start end &optional buffer)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
252 "Compose characters in the current region into one composite character.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
253 From a Lisp program, pass two arguments, START to END.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
254 The composite character replaces the composed characters.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
255 BUFFER defaults to the current buffer if omitted."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
256 (interactive "r")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
257 (let ((ch (make-composite-char (buffer-substring start end buffer))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
258 (delete-region start end buffer)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
259 (insert-char ch nil nil buffer)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
260
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
261 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
262 (defun decompose-region (start end &optional buffer)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
263 "Decompose any composite characters in the current region.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
264 From a Lisp program, pass two arguments, START to END.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
265 This converts each composite character into one or more characters,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
266 the individual characters out of which the composite character was formed.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
267 Non-composite characters are left as-is. BUFFER defaults to the current
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
268 buffer if omitted."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
269 (interactive "r")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
270 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
271 (set-buffer buffer)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
272 (save-restriction
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
273 (narrow-to-region start end)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
274 (goto-char (point-min))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
275 (let ((compcharset (get-charset 'composite)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
276 (while (< (point) (point-max))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
277 (let ((ch (char-after (point))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
278 (if (eq compcharset (char-charset ch))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
279 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
280 (delete-char 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
281 (insert (composite-char-string ch))))))))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
282
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
283 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
284 (defconst reference-point-alist
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
285 '((tl . 0) (tc . 1) (tr . 2)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
286 (ml . 3) (mc . 4) (mr . 5)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
287 (bl . 6) (bc . 7) (br . 8)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
288 (top-left . 0) (top-center . 1) (top-right . 2)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
289 (mid-left . 3) (mid-center . 4) (mid-right . 5)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
290 (bottom-left . 6) (bottom-center . 7) (bottom-right . 8)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
291 (0 . 0) (1 . 1) (2 . 2)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
292 (3 . 3) (4 . 4) (5 . 5)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
293 (6 . 6) (7 . 7) (8 . 8))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
294 "Alist of reference point symbols vs reference point codes.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
295 Meanings of reference point codes are as follows:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
296
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
297 0----1----2 <-- ascent 0:tl or top-left
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
298 | | 1:tc or top-center
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
299 | | 2:tr or top-right
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
300 | | 3:ml or mid-left
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
301 | 4 <--+---- center 4:mc or mid-center
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
302 | | 5:mr or mid-right
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
303 --- 3 5 <-- baseline 6:bl or bottom-left
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
304 | | 7:bc or bottom-center
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
305 6----7----8 <-- descent 8:br or bottom-right
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
306
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
307 Reference point symbols are to be used to specify composition rule of
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
308 the form \(GLOBAL-REF-POINT . NEW-REF-POINT), where GLOBAL-REF-POINT
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
309 is a reference point in the overall glyphs already composed, and
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
310 NEW-REF-POINT is a reference point in the new glyph to be added.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
311
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
312 For instance, if GLOBAL-REF-POINT is 8 and NEW-REF-POINT is 1, the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
313 overall glyph is updated as follows:
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
314
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
315 +-------+--+ <--- new ascent
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
316 | | |
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
317 | global| |
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
318 | glyph | |
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
319 --- | | | <--- baseline (doesn't change)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
320 +----+--+--+
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
321 | | new |
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
322 | |glyph|
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
323 +----+-----+ <--- new descent
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
324 ")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
325
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
326 ;; Return a string for char CH to be embedded in multibyte form of
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
327 ;; composite character.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
328 (defun compose-chars-component (ch)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
329 (if (< ch 128)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
330 (format "\240%c" (+ ch 128))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
331 (let ((str (char-to-string ch)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
332 (if (cmpcharp ch)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
333 (if (/= (aref str 1) ?\xFF)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
334 (error "Char %c can't be composed" ch)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
335 (substring str 2))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
336 (aset str 0 (+ (aref str 0) ?\x20))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
337 str))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
338
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
339 ;; Return a string for composition rule RULE to be embedded in
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
340 ;; multibyte form of composite character.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
341 (defsubst compose-chars-rule (rule)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
342 (char-to-string (+ ?\xA0
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
343 (* (cdr (assq (car rule) reference-point-alist)) 9)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
344 (cdr (assq (cdr rule) reference-point-alist)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
345
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
346 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
347 (defun compose-chars (first-component &rest args)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
348 "Return one char string composed from the arguments.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
349 Each argument is a character (including a composite chararacter)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
350 or a composition rule.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
351 A composition rule has the form \(GLOBAL-REF-POINT . NEW-REF-POINT).
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
352 See the documentation of `reference-point-alist' for more detail."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
353 (if (= (length args) 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
354 (char-to-string first-component)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
355 (let* ((with-rule (consp (car args)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
356 (str (if with-rule (concat (vector leading-code-composition ?\xFF))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
357 (char-to-string leading-code-composition))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
358 (setq str (concat str (compose-chars-component first-component)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
359 (while args
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
360 (if with-rule
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
361 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
362 (if (not (consp (car args)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
363 (error "Invalid composition rule: %s" (car args)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
364 (setq str (concat str (compose-chars-rule (car args))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
365 (compose-chars-component (car (cdr args))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
366 args (cdr (cdr args))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
367 (setq str (concat str (compose-chars-component (car args)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
368 args (cdr args))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
369 str)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
370
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
371 ;;;###autoload
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
372 (defun decompose-composite-char (char &optional type with-composition-rule)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
373 "Convert composite character CHAR to a string containing components of CHAR.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
374 Optional 1st arg TYPE specifies the type of sequence returned.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
375 It should be `string' (default), `list', or `vector'.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
376 Optional 2nd arg WITH-COMPOSITION-RULE non-nil means the returned
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
377 sequence contains embedded composition rules if any. In this case, the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
378 order of elements in the sequence is the same as arguments for
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
379 `compose-chars' to create CHAR.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
380 If TYPE is omitted or is `string', composition rules are omitted
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
381 even if WITH-COMPOSITION-RULE is t."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
382 (or type
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
383 (setq type 'string))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
384 (let* ((len (composite-char-component-count char))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
385 (i (1- len))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
386 l)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
387 (setq with-composition-rule (and with-composition-rule
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
388 (not (eq type 'string))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
389 (composite-char-composition-rule-p char)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
390 (while (> i 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
391 (setq l (cons (composite-char-component char i) l))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
392 (if with-composition-rule
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
393 (let ((rule (- (composite-char-composition-rule char i) ?\xA0)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
394 (setq l (cons (cons (/ rule 9) (% rule 9)) l))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
395 (setq i (1- i)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
396 (setq l (cons (composite-char-component char 0) l))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
397 (cond ((eq type 'string)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
398 (apply 'concat-chars l))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
399 ((eq type 'list)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
400 l)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
401 (t ; i.e. TYPE is vector
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
402 (vconcat l)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
403
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
404 ;;; mule-util.el ends here