Mercurial > emacs
annotate lisp/international/mule-util.el @ 21623:6c7a46148dd4
* lastfile.c (_my_endbss, my_endbss_static): New variables.
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Fri, 17 Apr 1998 05:25:35 +0000 |
parents | 90119d523093 |
children | 97cf1cae1971 |
rev | line source |
---|---|
17052 | 1 ;;; mule-util.el --- Utility functions for mulitilingual environment (mule) |
2 | |
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
18377
8b4a66c66dd6
Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
18313
diff
changeset
|
4 ;; Licensed to the Free Software Foundation. |
17052 | 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'." |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
34 (let ((len (length string)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
35 (i 0) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
36 val) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
37 (cond ((eq type 'list) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
38 (setq val (make-list len 0)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
39 (let ((l val)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
40 (while (< i len) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
41 (setcar l (aref string i)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
42 (setq l (cdr l) i (1+ i))))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
43 ((eq type 'vector) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
44 (setq val (make-vector len 0)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
45 (while (< i len) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
46 (aset val i (aref string i)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
47 (setq i (1+ i)))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
48 (t |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
49 (error "Invalid type: %s" type))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
50 val)) |
17052 | 51 |
52 ;;;###autoload | |
53 (defsubst string-to-list (string) | |
54 "Return a list of characters in STRING." | |
55 (string-to-sequence string 'list)) | |
56 | |
57 ;;;###autoload | |
58 (defsubst string-to-vector (string) | |
59 "Return a vector of characters in STRING." | |
60 (string-to-sequence string 'vector)) | |
61 | |
62 ;;;###autoload | |
63 (defun store-substring (string idx obj) | |
64 "Embed OBJ (string or character) at index IDX of STRING." | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
65 (if (integerp obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
66 (aset string idx obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
67 (let ((len1 (length obj)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
68 (len2 (length string)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
69 (i 0)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
70 (while (< i len1) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
71 (aset string (+ idx i) (aref obj i)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
72 (setq i (1+ i))))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
73 string) |
17052 | 74 |
75 ;;;###autoload | |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
76 (defun truncate-string-to-width (str end-column &optional start-column padding) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
77 "Truncate string STR to end at column END-COLUMN. |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
78 The optional 2nd arg START-COLUMN, if non-nil, specifies |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
79 the starting column; that means to return the characters occupying |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
80 columns START-COLUMN ... END-COLUMN of STR. |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
81 |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
82 The optional 3rd arg PADDING, if non-nil, specifies a padding character |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
83 to add at the end of the result if STR doesn't reach column END-COLUMN, |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
84 or if END-COLUMN comes in the middle of a character in STR. |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
85 PADDING is also added at the beginning of the result |
19928
7e4718c779b2
(truncate-string-to-width): Doc typo fix.
Richard M. Stallman <rms@gnu.org>
parents:
19916
diff
changeset
|
86 if column START-COLUMN appears in the middle of a character in STR. |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
87 |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
88 If PADDING is nil, no padding is added in these cases, so |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
89 the resulting string may be narrower than END-COLUMN." |
17052 | 90 (or start-column |
91 (setq start-column 0)) | |
92 (let ((len (length str)) | |
93 (idx 0) | |
94 (column 0) | |
95 (head-padding "") (tail-padding "") | |
96 ch last-column last-idx from-idx) | |
97 (condition-case nil | |
98 (while (< column start-column) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
99 (setq ch (aref str idx) |
17052 | 100 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
101 idx (1+ idx))) |
17052 | 102 (args-out-of-range (setq idx len))) |
103 (if (< column start-column) | |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
104 (if padding (make-string end-column padding) "") |
17052 | 105 (if (and padding (> column start-column)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
106 (setq head-padding (make-string (- column start-column) padding))) |
17052 | 107 (setq from-idx idx) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
108 (if (< end-column column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
109 (setq idx from-idx) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
110 (condition-case nil |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
111 (while (< column end-column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
112 (setq last-column column |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
113 last-idx idx |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
114 ch (aref str idx) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
115 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
116 idx (1+ idx))) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
117 (args-out-of-range (setq idx len))) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
118 (if (> column end-column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
119 (setq column last-column idx last-idx)) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
120 (if (and padding (< column end-column)) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
121 (setq tail-padding (make-string (- end-column column) padding)))) |
17052 | 122 (setq str (substring str from-idx idx)) |
123 (if padding | |
124 (concat head-padding str tail-padding) | |
125 str)))) | |
126 | |
127 ;;; For backward compatiblity ... | |
128 ;;;###autoload | |
129 (defalias 'truncate-string 'truncate-string-to-width) | |
130 (make-obsolete 'truncate-string 'truncate-string-to-width) | |
131 | |
132 ;;; Nested alist handler. Nested alist is alist whose elements are | |
133 ;;; also nested alist. | |
134 | |
135 ;;;###autoload | |
136 (defsubst nested-alist-p (obj) | |
137 "Return t if OBJ is a nesetd alist. | |
138 | |
139 Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is | |
140 any Lisp object, and BRANCHES is a list of cons cells of the form | |
141 (KEY-ELEMENT . NESTED-ALIST). | |
142 | |
143 You can use a nested alist to store any Lisp object (ENTRY) for a key | |
144 sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ | |
145 can be a string, a vector, or a list." | |
146 (and obj (listp obj) (listp (cdr obj)))) | |
147 | |
148 ;;;###autoload | |
149 (defun set-nested-alist (keyseq entry alist &optional len branches) | |
150 "Set ENTRY for KEYSEQ in a nested alist ALIST. | |
151 Optional 4th arg LEN non-nil means the firlst LEN elements in KEYSEQ | |
152 is considered. | |
153 Optional argument BRANCHES if non-nil is branches for a keyseq | |
154 longer than KEYSEQ. | |
155 See the documentation of `nested-alist-p' for more detail." | |
156 (or (nested-alist-p alist) | |
157 (error "Invalid arguement %s" alist)) | |
158 (let ((islist (listp keyseq)) | |
159 (len (or len (length keyseq))) | |
160 (i 0) | |
161 key-elt slot) | |
162 (while (< i len) | |
163 (if (null (nested-alist-p alist)) | |
164 (error "Keyseq %s is too long for this nested alist" keyseq)) | |
165 (setq key-elt (if islist (nth i keyseq) (aref keyseq i))) | |
166 (setq slot (assoc key-elt (cdr alist))) | |
167 (if (null slot) | |
168 (progn | |
169 (setq slot (cons key-elt (list t))) | |
170 (setcdr alist (cons slot (cdr alist))))) | |
171 (setq alist (cdr slot)) | |
172 (setq i (1+ i))) | |
173 (setcar alist entry) | |
174 (if branches | |
175 (if (cdr alist) | |
176 (error "Can't set branches for keyseq %s" keyseq) | |
177 (setcdr alist branches))))) | |
178 | |
179 ;;;###autoload | |
180 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long) | |
181 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition. | |
182 Optional 1st argument LEN specifies the length of KEYSEQ. | |
183 Optional 2nd argument START specifies index of the starting key. | |
184 The returned value is normally a nested alist of which | |
185 car part is the entry for KEYSEQ. | |
186 If ALIST is not deep enough for KEYSEQ, return number which is | |
187 how many key elements at the front of KEYSEQ it takes | |
188 to reach a leaf in ALIST. | |
189 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil | |
190 even if ALIST is not deep enough." | |
191 (or (nested-alist-p alist) | |
192 (error "invalid arguement %s" alist)) | |
193 (or len | |
194 (setq len (length keyseq))) | |
195 (let ((i (or start 0))) | |
196 (if (catch 'lookup-nested-alist-tag | |
197 (if (listp keyseq) | |
198 (while (< i len) | |
199 (if (setq alist (cdr (assoc (nth i keyseq) (cdr alist)))) | |
200 (setq i (1+ i)) | |
201 (throw 'lookup-nested-alist-tag t)))) | |
202 (while (< i len) | |
203 (if (setq alist (cdr (assoc (aref keyseq i) (cdr alist)))) | |
204 (setq i (1+ i)) | |
205 (throw 'lookup-nested-alist-tag t)))) | |
206 ;; KEYSEQ is too long. | |
207 (if nil-for-too-long nil i) | |
208 alist))) | |
209 | |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
210 |
17052 | 211 ;; Coding system related functions. |
212 | |
213 ;;;###autoload | |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
214 (defun coding-system-eol-type-mnemonic (coding-system) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
215 "Return mnemonic letter of eol-type of CODING-SYSTEM." |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
216 (let ((eol-type (coding-system-eol-type coding-system))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
217 (cond ((vectorp eol-type) eol-mnemonic-undecided) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
218 ((eq eol-type 0) eol-mnemonic-unix) |
21488
2c0815a83862
(coding-system-eol-type-mnemonic): Return correct eol-type mnemonics
Eli Zaretskii <eliz@gnu.org>
parents:
20841
diff
changeset
|
219 ((eq eol-type 1) eol-mnemonic-dos) |
2c0815a83862
(coding-system-eol-type-mnemonic): Return correct eol-type mnemonics
Eli Zaretskii <eliz@gnu.org>
parents:
20841
diff
changeset
|
220 ((eq eol-type 2) eol-mnemonic-mac) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
221 (t ?-)))) |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
222 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
223 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
224 (defun coding-system-post-read-conversion (coding-system) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
225 "Return the value of CODING-SYSTEM's post-read-conversion property." |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
226 (coding-system-get coding-system 'post-read-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
227 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
228 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
229 (defun coding-system-pre-write-conversion (coding-system) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
230 "Return the value of CODING-SYSTEM's pre-write-conversion property." |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
231 (coding-system-get coding-system 'pre-write-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
232 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
233 ;;;###autoload |
19455
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
234 (defun coding-system-unification-table-for-decode (coding-system) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
235 "Return the value of CODING-SYSTEM's unification-table-for-decode property." |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
236 (coding-system-get coding-system 'character-unification-table-for-decode)) |
19455
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
237 |
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
238 ;;;###autoload |
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
239 (defun coding-system-unification-table-for-encode (coding-system) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
240 "Return the value of CODING-SYSTEM's unification-table-for-encode property." |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
241 (coding-system-get coding-system 'character-unification-table-for-encode)) |
17052 | 242 |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
243 (defun coding-system-lessp (x y) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
244 (cond ((eq x 'no-conversion) t) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
245 ((eq y 'no-conversion) nil) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
246 ((eq x 'emacs-mule) t) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
247 ((eq y 'emacs-mule) nil) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
248 ((eq x 'undecided) t) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
249 ((eq y 'undecided) nil) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
250 (t (let ((c1 (coding-system-mnemonic x)) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
251 (c2 (coding-system-mnemonic y))) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
252 (or (< (downcase c1) (downcase c2)) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
253 (and (not (> (downcase c1) (downcase c2))) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
254 (< c1 c2))))))) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
255 |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
256 ;;;###autoload |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
257 (defun coding-system-list (&optional base-only) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
258 "Return a list of all existing coding systems. |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
259 If optional arg BASE-ONLY is non-nil, only base coding systems are listed." |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
260 (let* ((codings (sort (copy-sequence coding-system-list) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
261 'coding-system-lessp)) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
262 (tail (cons nil codings))) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
263 ;; Remove subsidiary coding systems (eol variants) and alias |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
264 ;; coding systems (if necessary). |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
265 (while (cdr tail) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
266 (let* ((coding (car (cdr tail))) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
267 (aliases (coding-system-get coding 'alias-coding-systems))) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
268 (if (or |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
269 ;; CODING is an eol varinant if not in ALIASES. |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
270 (not (memq coding aliases)) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
271 ;; CODING is an alias if it is not car of ALISES. |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
272 (and base-only (not (eq coding (car aliases))))) |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
273 (setcdr tail (cdr (cdr tail))) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
274 (setq tail (cdr tail))))) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
275 codings)) |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
276 |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
277 ;;;###autoload |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
278 (defun coding-system-equal (coding-system-1 coding-system-2) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
279 "Return t if and only if CODING-SYSTEM-1 and CODING-SYSTEM-2 are identical. |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
280 Two coding systems are identical if two symbols are equal |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
281 or one is an alias of the other." |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
282 (or (eq coding-system-1 coding-system-2) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
283 (and (equal (coding-system-spec coding-system-1) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
284 (coding-system-spec coding-system-2)) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
285 (let ((eol-type-1 (coding-system-eol-type coding-system-1)) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
286 (eol-type-2 (coding-system-eol-type coding-system-2))) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
287 (or (eq eol-type-1 eol-type-2) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
288 (and (vectorp eol-type-1) (vectorp eol-type-2))))))) |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
289 |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
290 ;;;###autoload |
21554
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
291 (defun coding-system-change-eol-conversion (coding-system eol-type) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
292 "Return a coding system which differs from CODING-SYSTEM in eol conversion. |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
293 The returned coding system converts end-of-line by EOL-TYPE |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
294 but text as the same way as CODING-SYSTEM. |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
295 EOL-TYPE should be `unix', `dos', `mac', or nil. |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
296 If EOL-TYPE is nil, the returned coding system detects |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
297 how end-of-line is formatted automatically while decoding." |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
298 (let ((eol-type (cond ((eq eol-type 'unix) 0) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
299 ((eq eol-type 'dos) 1) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
300 ((eq eol-type 'mac) 2) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
301 (t eol-type))) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
302 (orig-eol-type (coding-system-eol-type coding-system))) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
303 (if (vectorp orig-eol-type) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
304 (if (not eol-type) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
305 coding-system |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
306 (aref orig-eol-type eol-type)) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
307 (let ((base (coding-system-base coding-system))) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
308 (if (not eol-type) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
309 base |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
310 (if (= eol-type orig-eol-type) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
311 coding-system |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
312 (setq orig-eol-type (coding-system-eol-type base)) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
313 (if (vectorp orig-eol-type) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
314 (aref orig-eol-type eol-type)))))))) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
315 |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
316 ;;;###autoload |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
317 (defun coding-system-change-text-conversion (coding-system coding) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
318 "Return a coding system which differs from CODING-SYSTEM in text conversion. |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
319 The returned coding system converts text by CODING |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
320 but end-of-line as the same way as CODING-SYSTEM. |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
321 If CODING is nil, the returned coding system detects |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
322 how text is formatted automatically while decoding." |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
323 (if (not coding) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
324 (coding-system-base coding-system) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
325 (let ((eol-type (coding-system-eol-type coding-system))) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
326 (coding-system-change-eol-conversion |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
327 coding |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
328 (if (numberp eol-type) (aref [unix dos mac] eol-type)))))) |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
329 |
90119d523093
(coding-system-change-eol-coding): New function.
Kenichi Handa <handa@m17n.org>
parents:
21488
diff
changeset
|
330 ;;;###autoload |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
331 (defmacro detect-coding-with-priority (from to priority-list) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
332 "Detect a coding system of the text between FROM and TO with PRIORITY-LIST. |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
333 PRIORITY-LIST is an alist of coding categories vs the corresponding |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
334 coding systems ordered by priority." |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
335 `(let* ((prio-list ,priority-list) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
336 (coding-category-list coding-category-list) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
337 ,@(mapcar (function (lambda (x) (list x x))) coding-category-list)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
338 (mapcar (function (lambda (x) (set (car x) (cdr x)))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
339 prio-list) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
340 (set-coding-priority (mapcar (function (lambda (x) (car x))) prio-list)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
341 (detect-coding-region ,from ,to))) |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
342 |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
343 ;;;###autoload |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
344 (defun detect-coding-with-language-environment (from to lang-env) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
345 "Detect a coding system of the text between FROM and TO with LANG-ENV. |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
346 The detection takes into accont the coding system priorities for the |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
347 language environment LANG-ENV." |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
348 (let ((coding-priority (get-language-info lang-env 'coding-priority))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
349 (if coding-priority |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
350 (detect-coding-with-priority |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
351 from to |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
352 (mapcar (function (lambda (x) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
353 (cons (coding-system-get x 'coding-category) x))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
354 coding-priority)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
355 (detect-coding-region from to)))) |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
356 |
17052 | 357 |
358 ;;; Composite charcater manipulations. | |
359 | |
360 ;;;###autoload | |
361 (defun compose-region (start end) | |
362 "Compose all characters in the current region into one composite character. | |
363 When called from a program, expects two arguments, | |
364 positions (integers or markers) specifying the region." | |
365 (interactive "r") | |
366 (save-excursion | |
367 (let ((str (buffer-substring start end))) | |
368 (goto-char start) | |
369 (delete-region start end) | |
370 (insert (compose-string str))))) | |
371 | |
372 ;;;###autoload | |
373 (defun decompose-region (start end) | |
374 "Decompose all composite characters in the current region. | |
375 Composite characters are broken up into individual components. | |
376 When called from a program, expects two arguments, | |
377 positions (integers or markers) specifying the region." | |
378 (interactive "r") | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
379 (save-excursion |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
380 (save-restriction |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
381 (narrow-to-region start end) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
382 (goto-char (point-min)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
383 (while (not (eobp)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
384 (let ((ch (following-char))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
385 (if (>= ch min-composite-char) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
386 (progn |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
387 (delete-char 1) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
388 (insert (decompose-composite-char ch))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
389 (forward-char 1))))))) |
17052 | 390 |
391 ;;;###autoload | |
19264
6122dbba797f
(prefer-coding-system): Moved to mule-util.el.
Kenichi Handa <handa@m17n.org>
parents:
19056
diff
changeset
|
392 (defun decompose-string (string) |
6122dbba797f
(prefer-coding-system): Moved to mule-util.el.
Kenichi Handa <handa@m17n.org>
parents:
19056
diff
changeset
|
393 "Decompose all composite characters in STRING." |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
394 (let ((len (length string)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
395 (idx 0) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
396 (i 0) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
397 (str-list nil) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
398 ch) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
399 (while (< idx len) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
400 (setq ch (aref string idx)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
401 (if (>= ch min-composite-char) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
402 (progn |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
403 (if (> idx i) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
404 (setq str-list (cons (substring string i idx) str-list))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
405 (setq str-list (cons (decompose-composite-char ch) str-list)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
406 (setq i (1+ idx)))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
407 (setq idx (1+ idx))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
408 (if (not str-list) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
409 (copy-sequence string) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
410 (if (> idx i) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
411 (setq str-list (cons (substring string i idx) str-list))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
412 (apply 'concat (nreverse str-list))))) |
19264
6122dbba797f
(prefer-coding-system): Moved to mule-util.el.
Kenichi Handa <handa@m17n.org>
parents:
19056
diff
changeset
|
413 |
6122dbba797f
(prefer-coding-system): Moved to mule-util.el.
Kenichi Handa <handa@m17n.org>
parents:
19056
diff
changeset
|
414 ;;;###autoload |
17052 | 415 (defconst reference-point-alist |
416 '((tl . 0) (tc . 1) (tr . 2) | |
417 (ml . 3) (mc . 4) (mr . 5) | |
418 (bl . 6) (bc . 7) (br . 8) | |
419 (top-left . 0) (top-center . 1) (top-right . 2) | |
420 (mid-left . 3) (mid-center . 4) (mid-right . 5) | |
421 (bottom-left . 6) (bottom-center . 7) (bottom-right . 8) | |
422 (0 . 0) (1 . 1) (2 . 2) | |
423 (3 . 3) (4 . 4) (5 . 5) | |
424 (6 . 6) (7 . 7) (8 . 8)) | |
425 "Alist of reference point symbols vs reference point codes. | |
19048
65112b3cc989
(reference-point-alist): Doc-string modified.
Kenichi Handa <handa@m17n.org>
parents:
19016
diff
changeset
|
426 A reference point symbol is to be used to specify a composition rule |
65112b3cc989
(reference-point-alist): Doc-string modified.
Kenichi Handa <handa@m17n.org>
parents:
19016
diff
changeset
|
427 while making a composite character by the function `compose-chars' |
65112b3cc989
(reference-point-alist): Doc-string modified.
Kenichi Handa <handa@m17n.org>
parents:
19016
diff
changeset
|
428 (which see). |
65112b3cc989
(reference-point-alist): Doc-string modified.
Kenichi Handa <handa@m17n.org>
parents:
19016
diff
changeset
|
429 |
17052 | 430 Meanings of reference point codes are as follows: |
431 | |
432 0----1----2 <-- ascent 0:tl or top-left | |
433 | | 1:tc or top-center | |
434 | | 2:tr or top-right | |
435 | | 3:ml or mid-left | |
436 | 4 <--+---- center 4:mc or mid-center | |
437 | | 5:mr or mid-right | |
438 --- 3 5 <-- baseline 6:bl or bottom-left | |
439 | | 7:bc or bottom-center | |
440 6----7----8 <-- descent 8:br or bottom-right | |
441 | |
442 Reference point symbols are to be used to specify composition rule of | |
443 the form \(GLOBAL-REF-POINT . NEW-REF-POINT), where GLOBAL-REF-POINT | |
444 is a reference point in the overall glyphs already composed, and | |
445 NEW-REF-POINT is a reference point in the new glyph to be added. | |
446 | |
447 For instance, if GLOBAL-REF-POINT is 8 and NEW-REF-POINT is 1, the | |
448 overall glyph is updated as follows: | |
449 | |
450 +-------+--+ <--- new ascent | |
451 | | | | |
452 | global| | | |
453 | glyph | | | |
454 --- | | | <--- baseline (doesn't change) | |
455 +----+--+--+ | |
456 | | new | | |
457 | |glyph| | |
458 +----+-----+ <--- new descent | |
459 ") | |
460 | |
461 ;; Return a string for char CH to be embedded in multibyte form of | |
462 ;; composite character. | |
463 (defun compose-chars-component (ch) | |
464 (if (< ch 128) | |
465 (format "\240%c" (+ ch 128)) | |
20841
ef5fd882ca63
(compose-chars-component): Return
Kenichi Handa <handa@m17n.org>
parents:
20730
diff
changeset
|
466 (let ((str (string-as-unibyte (char-to-string ch)))) |
17052 | 467 (if (cmpcharp ch) |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
468 (substring str (if (= (aref str 1) ?\xFF) 2 1)) |
17052 | 469 (aset str 0 (+ (aref str 0) ?\x20)) |
470 str)))) | |
471 | |
472 ;; Return a string for composition rule RULE to be embedded in | |
473 ;; multibyte form of composite character. | |
474 (defsubst compose-chars-rule (rule) | |
475 (char-to-string (+ ?\xA0 | |
476 (* (cdr (assq (car rule) reference-point-alist)) 9) | |
477 (cdr (assq (cdr rule) reference-point-alist))))) | |
478 | |
479 ;;;###autoload | |
480 (defun compose-chars (first-component &rest args) | |
481 "Return one char string composed from the arguments. | |
482 Each argument is a character (including a composite chararacter) | |
483 or a composition rule. | |
484 A composition rule has the form \(GLOBAL-REF-POINT . NEW-REF-POINT). | |
485 See the documentation of `reference-point-alist' for more detail." | |
486 (if (= (length args) 0) | |
487 (char-to-string first-component) | |
488 (let* ((with-rule (consp (car args))) | |
489 (str (if with-rule (concat (vector leading-code-composition ?\xFF)) | |
490 (char-to-string leading-code-composition)))) | |
491 (setq str (concat str (compose-chars-component first-component))) | |
492 (while args | |
493 (if with-rule | |
494 (progn | |
495 (if (not (consp (car args))) | |
496 (error "Invalid composition rule: %s" (car args))) | |
497 (setq str (concat str (compose-chars-rule (car args)) | |
498 (compose-chars-component (car (cdr args)))) | |
499 args (cdr (cdr args)))) | |
500 (setq str (concat str (compose-chars-component (car args))) | |
501 args (cdr args)))) | |
20841
ef5fd882ca63
(compose-chars-component): Return
Kenichi Handa <handa@m17n.org>
parents:
20730
diff
changeset
|
502 (string-as-multibyte str)))) |
17052 | 503 |
504 ;;;###autoload | |
505 (defun decompose-composite-char (char &optional type with-composition-rule) | |
20841
ef5fd882ca63
(compose-chars-component): Return
Kenichi Handa <handa@m17n.org>
parents:
20730
diff
changeset
|
506 "Convert composite character CHAR to a sequence of the components. |
17052 | 507 Optional 1st arg TYPE specifies the type of sequence returned. |
508 It should be `string' (default), `list', or `vector'. | |
509 Optional 2nd arg WITH-COMPOSITION-RULE non-nil means the returned | |
510 sequence contains embedded composition rules if any. In this case, the | |
511 order of elements in the sequence is the same as arguments for | |
512 `compose-chars' to create CHAR. | |
513 If TYPE is omitted or is `string', composition rules are omitted | |
514 even if WITH-COMPOSITION-RULE is t." | |
515 (or type | |
516 (setq type 'string)) | |
517 (let* ((len (composite-char-component-count char)) | |
518 (i (1- len)) | |
519 l) | |
520 (setq with-composition-rule (and with-composition-rule | |
521 (not (eq type 'string)) | |
522 (composite-char-composition-rule-p char))) | |
523 (while (> i 0) | |
524 (setq l (cons (composite-char-component char i) l)) | |
525 (if with-composition-rule | |
526 (let ((rule (- (composite-char-composition-rule char i) ?\xA0))) | |
527 (setq l (cons (cons (/ rule 9) (% rule 9)) l)))) | |
528 (setq i (1- i))) | |
529 (setq l (cons (composite-char-component char 0) l)) | |
530 (cond ((eq type 'string) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
531 (apply 'string l)) |
17052 | 532 ((eq type 'list) |
533 l) | |
534 (t ; i.e. TYPE is vector | |
535 (vconcat l))))) | |
536 | |
537 ;;; mule-util.el ends here |