Mercurial > emacs
annotate lisp/international/mule-util.el @ 18208:5b68d05ff026 gnumach-release-1-1-2 gnumach-release-1-1-3 hurd-release-0-2 libc-970610 libc-970611 libc-970612 libc-970613 libc-970614 libc-970615 libc-970616 libc-970617 libc-970618 libc-970619 libc-970620 libc-970621 libc-970622
Fix previous change.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 10 Jun 1997 04:18:36 +0000 |
parents | c913160e34a7 |
children | c6f35cac24b4 |
rev | line source |
---|---|
17052 | 1 ;;; mule-util.el --- Utility functions for mulitilingual environment (mule) |
2 | |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
5 | |
6 ;; Keywords: mule, multilingual | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
17071 | 21 ;; along with GNU Emacs; 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. | |
17052 | 24 |
25 ;;; Code: | |
26 | |
27 ;;; String manipulations while paying attention to multibyte | |
28 ;;; characters. | |
29 | |
30 ;;;###autoload | |
31 (defun string-to-sequence (string type) | |
32 "Convert STRING to a sequence of TYPE which contains characters in STRING. | |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
33 TYPE should be `list' or `vector'." |
17052 | 34 (or (eq type 'list) (eq type 'vector) |
35 (error "Invalid type: %s" type)) | |
36 (let* ((len (length string)) | |
37 (i 0) | |
38 l ch) | |
39 (while (< i len) | |
40 (setq ch (sref string i)) | |
41 (setq l (cons ch l)) | |
42 (setq i (+ i (char-bytes ch)))) | |
43 (setq l (nreverse l)) | |
44 (if (eq type 'list) | |
45 l | |
46 (vconcat l)))) | |
47 | |
48 ;;;###autoload | |
49 (defsubst string-to-list (string) | |
50 "Return a list of characters in STRING." | |
51 (string-to-sequence string 'list)) | |
52 | |
53 ;;;###autoload | |
54 (defsubst string-to-vector (string) | |
55 "Return a vector of characters in STRING." | |
56 (string-to-sequence string 'vector)) | |
57 | |
58 ;;;###autoload | |
59 (defun store-substring (string idx obj) | |
60 "Embed OBJ (string or character) at index IDX of STRING." | |
61 (let* ((str (cond ((stringp obj) obj) | |
62 ((integerp obj) (char-to-string obj)) | |
63 (t (error | |
64 "Invalid argument (should be string or character): %s" | |
65 obj)))) | |
66 (string-len (length string)) | |
67 (len (length str)) | |
68 (i 0)) | |
69 (while (and (< i len) (< idx string-len)) | |
70 (aset string idx (aref str i)) | |
71 (setq idx (1+ idx) i (1+ i))) | |
72 string)) | |
73 | |
74 ;;;###autoload | |
75 (defun truncate-string-to-width (str width &optional start-column padding) | |
76 "Truncate string STR to fit in WIDTH columns. | |
77 Optional 1st arg START-COLUMN if non-nil specifies the starting column. | |
17092
e7920fdc4948
(truncate-string-to-width): Argument PADDING can be a padding character.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
78 Optional 2nd arg PADDING if non-nil is a padding character to be padded at |
17052 | 79 the head and tail of the resulting string to fit in WIDTH if necessary. |
80 If PADDING is nil, the resulting string may be narrower than WIDTH." | |
81 (or start-column | |
82 (setq start-column 0)) | |
83 (let ((len (length str)) | |
84 (idx 0) | |
85 (column 0) | |
86 (head-padding "") (tail-padding "") | |
87 ch last-column last-idx from-idx) | |
88 (condition-case nil | |
89 (while (< column start-column) | |
90 (setq ch (sref str idx) | |
91 column (+ column (char-width ch)) | |
92 idx (+ idx (char-bytes ch)))) | |
93 (args-out-of-range (setq idx len))) | |
94 (if (< column start-column) | |
17092
e7920fdc4948
(truncate-string-to-width): Argument PADDING can be a padding character.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
95 (if padding (make-string width padding) "") |
17052 | 96 (if (and padding (> column start-column)) |
97 (setq head-padding (make-string (- column start-column) ?\ ))) | |
98 (setq from-idx idx) | |
99 (condition-case nil | |
100 (while (< column width) | |
101 (setq last-column column | |
102 last-idx idx | |
103 ch (sref str idx) | |
104 column (+ column (char-width ch)) | |
105 idx (+ idx (char-bytes ch)))) | |
106 (args-out-of-range (setq idx len))) | |
107 (if (> column width) | |
108 (setq column last-column idx last-idx)) | |
109 (if (and padding (< column width)) | |
17092
e7920fdc4948
(truncate-string-to-width): Argument PADDING can be a padding character.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
110 (setq tail-padding (make-string (- width column) padding))) |
17052 | 111 (setq str (substring str from-idx idx)) |
112 (if padding | |
113 (concat head-padding str tail-padding) | |
114 str)))) | |
115 | |
116 ;;; For backward compatiblity ... | |
117 ;;;###autoload | |
118 (defalias 'truncate-string 'truncate-string-to-width) | |
119 (make-obsolete 'truncate-string 'truncate-string-to-width) | |
120 | |
121 ;;; Nested alist handler. Nested alist is alist whose elements are | |
122 ;;; also nested alist. | |
123 | |
124 ;;;###autoload | |
125 (defsubst nested-alist-p (obj) | |
126 "Return t if OBJ is a nesetd alist. | |
127 | |
128 Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is | |
129 any Lisp object, and BRANCHES is a list of cons cells of the form | |
130 (KEY-ELEMENT . NESTED-ALIST). | |
131 | |
132 You can use a nested alist to store any Lisp object (ENTRY) for a key | |
133 sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ | |
134 can be a string, a vector, or a list." | |
135 (and obj (listp obj) (listp (cdr obj)))) | |
136 | |
137 ;;;###autoload | |
138 (defun set-nested-alist (keyseq entry alist &optional len branches) | |
139 "Set ENTRY for KEYSEQ in a nested alist ALIST. | |
140 Optional 4th arg LEN non-nil means the firlst LEN elements in KEYSEQ | |
141 is considered. | |
142 Optional argument BRANCHES if non-nil is branches for a keyseq | |
143 longer than KEYSEQ. | |
144 See the documentation of `nested-alist-p' for more detail." | |
145 (or (nested-alist-p alist) | |
146 (error "Invalid arguement %s" alist)) | |
147 (let ((islist (listp keyseq)) | |
148 (len (or len (length keyseq))) | |
149 (i 0) | |
150 key-elt slot) | |
151 (while (< i len) | |
152 (if (null (nested-alist-p alist)) | |
153 (error "Keyseq %s is too long for this nested alist" keyseq)) | |
154 (setq key-elt (if islist (nth i keyseq) (aref keyseq i))) | |
155 (setq slot (assoc key-elt (cdr alist))) | |
156 (if (null slot) | |
157 (progn | |
158 (setq slot (cons key-elt (list t))) | |
159 (setcdr alist (cons slot (cdr alist))))) | |
160 (setq alist (cdr slot)) | |
161 (setq i (1+ i))) | |
162 (setcar alist entry) | |
163 (if branches | |
164 (if (cdr alist) | |
165 (error "Can't set branches for keyseq %s" keyseq) | |
166 (setcdr alist branches))))) | |
167 | |
168 ;;;###autoload | |
169 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long) | |
170 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition. | |
171 Optional 1st argument LEN specifies the length of KEYSEQ. | |
172 Optional 2nd argument START specifies index of the starting key. | |
173 The returned value is normally a nested alist of which | |
174 car part is the entry for KEYSEQ. | |
175 If ALIST is not deep enough for KEYSEQ, return number which is | |
176 how many key elements at the front of KEYSEQ it takes | |
177 to reach a leaf in ALIST. | |
178 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil | |
179 even if ALIST is not deep enough." | |
180 (or (nested-alist-p alist) | |
181 (error "invalid arguement %s" alist)) | |
182 (or len | |
183 (setq len (length keyseq))) | |
184 (let ((i (or start 0))) | |
185 (if (catch 'lookup-nested-alist-tag | |
186 (if (listp keyseq) | |
187 (while (< i len) | |
188 (if (setq alist (cdr (assoc (nth i keyseq) (cdr alist)))) | |
189 (setq i (1+ i)) | |
190 (throw 'lookup-nested-alist-tag t)))) | |
191 (while (< i len) | |
192 (if (setq alist (cdr (assoc (aref keyseq i) (cdr alist)))) | |
193 (setq i (1+ i)) | |
194 (throw 'lookup-nested-alist-tag t)))) | |
195 ;; KEYSEQ is too long. | |
196 (if nil-for-too-long nil i) | |
197 alist))) | |
198 | |
199 ;; Coding system related functions. | |
200 | |
201 ;;;###autoload | |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
202 (defun coding-system-list (&optional base-only) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
203 "Return a list of all existing coding systems. |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
204 If optional arg BASE-ONLY is non-nil, each element of the list |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
205 is a base coding system or a list of coding systems. |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
206 In the latter case, the first element is a base coding system, |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
207 and the remainings are aliases of it." |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
208 (let (l) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
209 (mapatoms (lambda (x) (if (get x 'coding-system) (setq l (cons x l))))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
210 (if (not base-only) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
211 l |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
212 (let* ((codings (sort l (function |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
213 (lambda (x y) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
214 (<= (coding-system-mnemonic x) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
215 (coding-system-mnemonic y)))))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
216 (tail (cons nil codings)) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
217 (aliases nil) ; ((BASE ALIAS ...) ...) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
218 base coding) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
219 ;; At first, remove subsidiary coding systems (eol variants) and |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
220 ;; move alias coding systems to ALIASES. |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
221 (while (cdr tail) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
222 (setq coding (car (cdr tail))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
223 (if (get coding 'eol-variant) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
224 (setcdr tail (cdr (cdr tail))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
225 (setq base (coding-system-base coding)) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
226 (if (and (not (eq coding base)) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
227 (coding-system-equal coding base)) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
228 (let ((slot (memq base aliases))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
229 (setcdr tail (cdr (cdr tail))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
230 (if slot |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
231 (setcdr slot (cons coding (cdr slot))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
232 (setq aliases (cons (list base coding) aliases)))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
233 (setq tail (cdr tail))))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
234 ;; Then, replace a coding system who has aliases with a list. |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
235 (setq tail codings) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
236 (while tail |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
237 (let ((alias (assq (car tail) aliases))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
238 (if alias |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
239 (setcar tail alias))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
240 (setq tail (cdr tail))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
241 codings)))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
242 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
243 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
244 (defun coding-system-base (coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
245 "Return a base of CODING-SYSTEM. |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
246 The base is a coding system of which coding-system property is a |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
247 coding-spec (see the function `make-coding-system')." |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
248 (let ((coding-spec (get coding-system 'coding-system))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
249 (if (vectorp coding-spec) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
250 coding-system |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
251 (coding-system-base coding-spec)))) |
17052 | 252 |
253 ;;;###autoload | |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
254 (defun coding-system-plist (coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
255 "Return property list of CODING-SYSTEM." |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
256 (let ((found nil) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
257 coding-spec eol-type |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
258 post-read-conversion pre-write-conversion |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
259 unification-table) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
260 (while (not found) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
261 (or eol-type |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
262 (setq eol-type (get coding-system 'eol-type))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
263 (or post-read-conversion |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
264 (setq post-read-conversion |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
265 (get coding-system 'post-read-conversion))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
266 (or pre-write-conversion |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
267 (setq pre-write-conversion |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
268 (get coding-system 'pre-write-conversion))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
269 (or unification-table |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
270 (setq unification-table |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
271 (get coding-system 'unification-table))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
272 (setq coding-spec (get coding-system 'coding-system)) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
273 (if (and coding-spec (symbolp coding-spec)) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
274 (setq coding-system coding-spec) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
275 (setq found t))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
276 (if (not coding-spec) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
277 (error "Invalid coding system: %s" coding-system)) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
278 (list 'coding-spec coding-spec |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
279 'eol-type eol-type |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
280 'post-read-conversion post-read-conversion |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
281 'pre-write-conversion pre-write-conversion |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
282 'unification-table unification-table))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
283 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
284 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
285 (defun coding-system-equal (coding-system-1 coding-system-2) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
286 "Return t if and only of CODING-SYSTEM-1 and CODING-SYSTEM-2 are identical. |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
287 Two coding systems are identical if two symbols are equal |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
288 or one is an alias of the other." |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
289 (equal (coding-system-plist coding-system-1) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
290 (coding-system-plist coding-system-2))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
291 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
292 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
293 (defun coding-system-eol-type-mnemonic (coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
294 "Return mnemonic letter of eol-type of CODING-SYSTEM." |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
295 (let ((eol-type (coding-system-eol-type coding-system))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
296 (cond ((vectorp eol-type) eol-mnemonic-undecided) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
297 ((eq eol-type 0) eol-mnemonic-unix) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
298 ((eq eol-type 1) eol-mnemonic-unix) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
299 ((eq eol-type 2) eol-mnemonic-unix) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
300 (t ?-)))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
301 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
302 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
303 (defun coding-system-post-read-conversion (coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
304 "Return post-read-conversion property of CODING-SYSTEM." |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
305 (and coding-system |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
306 (symbolp coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
307 (or (get coding-system 'post-read-conversion) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
308 (coding-system-post-read-conversion |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
309 (get coding-system 'coding-system))))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
310 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
311 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
312 (defun coding-system-pre-write-conversion (coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
313 "Return pre-write-conversion property of CODING-SYSTEM." |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
314 (and coding-system |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
315 (symbolp coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
316 (or (get coding-system 'pre-write-conversion) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
317 (coding-system-pre-write-conversion |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
318 (get coding-system 'coding-system))))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
319 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
320 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
321 (defun coding-system-unification-table (coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
322 "Return unification-table property of CODING-SYSTEM." |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
323 (and coding-system |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
324 (symbolp coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
325 (or (get coding-system 'unification-table) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
326 (coding-system-unification-table |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
327 (get coding-system 'coding-system))))) |
17052 | 328 |
329 | |
330 ;;; Composite charcater manipulations. | |
331 | |
332 ;;;###autoload | |
333 (defun compose-region (start end) | |
334 "Compose all characters in the current region into one composite character. | |
335 When called from a program, expects two arguments, | |
336 positions (integers or markers) specifying the region." | |
337 (interactive "r") | |
338 (save-excursion | |
339 (let ((str (buffer-substring start end))) | |
340 (goto-char start) | |
341 (delete-region start end) | |
342 (insert (compose-string str))))) | |
343 | |
344 ;;;###autoload | |
345 (defun decompose-region (start end) | |
346 "Decompose all composite characters in the current region. | |
347 Composite characters are broken up into individual components. | |
348 When called from a program, expects two arguments, | |
349 positions (integers or markers) specifying the region." | |
350 (interactive "r") | |
351 (save-restriction | |
352 (narrow-to-region start end) | |
353 (goto-char (point-min)) | |
354 (let ((enable-multibyte-characters nil) | |
355 ;; This matches the whole bytes of single composite character. | |
356 (re-cmpchar "\200[\240-\377]+") | |
357 p ch str) | |
358 (while (re-search-forward re-cmpchar nil t) | |
359 (setq str (buffer-substring (match-beginning 0) (match-end 0))) | |
360 (delete-region (match-beginning 0) (match-end 0)) | |
361 (insert (decompose-composite-char (string-to-char str))))))) | |
362 | |
363 ;;;###autoload | |
364 (defconst reference-point-alist | |
365 '((tl . 0) (tc . 1) (tr . 2) | |
366 (ml . 3) (mc . 4) (mr . 5) | |
367 (bl . 6) (bc . 7) (br . 8) | |
368 (top-left . 0) (top-center . 1) (top-right . 2) | |
369 (mid-left . 3) (mid-center . 4) (mid-right . 5) | |
370 (bottom-left . 6) (bottom-center . 7) (bottom-right . 8) | |
371 (0 . 0) (1 . 1) (2 . 2) | |
372 (3 . 3) (4 . 4) (5 . 5) | |
373 (6 . 6) (7 . 7) (8 . 8)) | |
374 "Alist of reference point symbols vs reference point codes. | |
375 Meanings of reference point codes are as follows: | |
376 | |
377 0----1----2 <-- ascent 0:tl or top-left | |
378 | | 1:tc or top-center | |
379 | | 2:tr or top-right | |
380 | | 3:ml or mid-left | |
381 | 4 <--+---- center 4:mc or mid-center | |
382 | | 5:mr or mid-right | |
383 --- 3 5 <-- baseline 6:bl or bottom-left | |
384 | | 7:bc or bottom-center | |
385 6----7----8 <-- descent 8:br or bottom-right | |
386 | |
387 Reference point symbols are to be used to specify composition rule of | |
388 the form \(GLOBAL-REF-POINT . NEW-REF-POINT), where GLOBAL-REF-POINT | |
389 is a reference point in the overall glyphs already composed, and | |
390 NEW-REF-POINT is a reference point in the new glyph to be added. | |
391 | |
392 For instance, if GLOBAL-REF-POINT is 8 and NEW-REF-POINT is 1, the | |
393 overall glyph is updated as follows: | |
394 | |
395 +-------+--+ <--- new ascent | |
396 | | | | |
397 | global| | | |
398 | glyph | | | |
399 --- | | | <--- baseline (doesn't change) | |
400 +----+--+--+ | |
401 | | new | | |
402 | |glyph| | |
403 +----+-----+ <--- new descent | |
404 ") | |
405 | |
406 ;; Return a string for char CH to be embedded in multibyte form of | |
407 ;; composite character. | |
408 (defun compose-chars-component (ch) | |
409 (if (< ch 128) | |
410 (format "\240%c" (+ ch 128)) | |
411 (let ((str (char-to-string ch))) | |
412 (if (cmpcharp ch) | |
413 (if (/= (aref str 1) ?\xFF) | |
414 (error "Char %c can't be composed" ch) | |
415 (substring str 2)) | |
416 (aset str 0 (+ (aref str 0) ?\x20)) | |
417 str)))) | |
418 | |
419 ;; Return a string for composition rule RULE to be embedded in | |
420 ;; multibyte form of composite character. | |
421 (defsubst compose-chars-rule (rule) | |
422 (char-to-string (+ ?\xA0 | |
423 (* (cdr (assq (car rule) reference-point-alist)) 9) | |
424 (cdr (assq (cdr rule) reference-point-alist))))) | |
425 | |
426 ;;;###autoload | |
427 (defun compose-chars (first-component &rest args) | |
428 "Return one char string composed from the arguments. | |
429 Each argument is a character (including a composite chararacter) | |
430 or a composition rule. | |
431 A composition rule has the form \(GLOBAL-REF-POINT . NEW-REF-POINT). | |
432 See the documentation of `reference-point-alist' for more detail." | |
433 (if (= (length args) 0) | |
434 (char-to-string first-component) | |
435 (let* ((with-rule (consp (car args))) | |
436 (str (if with-rule (concat (vector leading-code-composition ?\xFF)) | |
437 (char-to-string leading-code-composition)))) | |
438 (setq str (concat str (compose-chars-component first-component))) | |
439 (while args | |
440 (if with-rule | |
441 (progn | |
442 (if (not (consp (car args))) | |
443 (error "Invalid composition rule: %s" (car args))) | |
444 (setq str (concat str (compose-chars-rule (car args)) | |
445 (compose-chars-component (car (cdr args)))) | |
446 args (cdr (cdr args)))) | |
447 (setq str (concat str (compose-chars-component (car args))) | |
448 args (cdr args)))) | |
449 str))) | |
450 | |
451 ;;;###autoload | |
452 (defun decompose-composite-char (char &optional type with-composition-rule) | |
453 "Convert composite character CHAR to a string containing components of CHAR. | |
454 Optional 1st arg TYPE specifies the type of sequence returned. | |
455 It should be `string' (default), `list', or `vector'. | |
456 Optional 2nd arg WITH-COMPOSITION-RULE non-nil means the returned | |
457 sequence contains embedded composition rules if any. In this case, the | |
458 order of elements in the sequence is the same as arguments for | |
459 `compose-chars' to create CHAR. | |
460 If TYPE is omitted or is `string', composition rules are omitted | |
461 even if WITH-COMPOSITION-RULE is t." | |
462 (or type | |
463 (setq type 'string)) | |
464 (let* ((len (composite-char-component-count char)) | |
465 (i (1- len)) | |
466 l) | |
467 (setq with-composition-rule (and with-composition-rule | |
468 (not (eq type 'string)) | |
469 (composite-char-composition-rule-p char))) | |
470 (while (> i 0) | |
471 (setq l (cons (composite-char-component char i) l)) | |
472 (if with-composition-rule | |
473 (let ((rule (- (composite-char-composition-rule char i) ?\xA0))) | |
474 (setq l (cons (cons (/ rule 9) (% rule 9)) l)))) | |
475 (setq i (1- i))) | |
476 (setq l (cons (composite-char-component char 0) l)) | |
477 (cond ((eq type 'string) | |
478 (apply 'concat-chars l)) | |
479 ((eq type 'list) | |
480 l) | |
481 (t ; i.e. TYPE is vector | |
482 (vconcat l))))) | |
483 | |
484 ;;; mule-util.el ends here |