annotate lisp/mule/mule-util.el @ 177:6075d714658b r20-3b15

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