Mercurial > emacs
annotate lisp/international/mule-util.el @ 41109:0bcf2d7f0112
(values, values-list, multiple-value-list, multiple-value-apply, nth-value):
Use defsubst rather than defalias, to get better doc strings.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 15 Nov 2001 23:57:43 +0000 |
parents | 67b464da13ec |
children | 43e756c38f4f |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29354
diff
changeset
|
1 ;;; mule-util.el --- utility functions for mulitilingual environment (mule) |
17052 | 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 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29354
diff
changeset
|
25 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29354
diff
changeset
|
26 |
17052 | 27 ;;; Code: |
28 | |
29 ;;; String manipulations while paying attention to multibyte | |
30 ;;; characters. | |
31 | |
32 ;;;###autoload | |
33 (defun string-to-sequence (string type) | |
34 "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
|
35 TYPE should be `list' or `vector'." |
28458 | 36 ;;; (let ((len (length string)) |
37 ;;; (i 0) | |
38 ;;; val) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
39 (cond ((eq type 'list) |
28458 | 40 ;; Applicable post-Emacs 20.2 and asymptotically ~10 times |
41 ;; faster than the code below: | |
42 (append string nil)) | |
43 ;;; (setq val (make-list len 0)) | |
44 ;;; (let ((l val)) | |
45 ;;; (while (< i len) | |
46 ;;; (setcar l (aref string i)) | |
47 ;;; (setq l (cdr l) i (1+ i)))))) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
48 ((eq type 'vector) |
28458 | 49 ;; As above. |
50 (vconcat string)) | |
51 ;;; (setq val (make-vector len 0)) | |
52 ;;; (while (< i len) | |
53 ;;; (aset val i (aref string i)) | |
54 ;;; (setq i (1+ i)))) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
55 (t |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
56 (error "Invalid type: %s" type))) |
28458 | 57 ;;; val) |
58 ) | |
17052 | 59 |
60 ;;;###autoload | |
61 (defsubst string-to-list (string) | |
62 "Return a list of characters in STRING." | |
63 (string-to-sequence string 'list)) | |
64 | |
65 ;;;###autoload | |
66 (defsubst string-to-vector (string) | |
67 "Return a vector of characters in STRING." | |
68 (string-to-sequence string 'vector)) | |
69 | |
70 ;;;###autoload | |
71 (defun store-substring (string idx obj) | |
72 "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
|
73 (if (integerp obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
74 (aset string idx obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
75 (let ((len1 (length obj)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
76 (len2 (length string)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
77 (i 0)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
78 (while (< i len1) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
79 (aset string (+ idx i) (aref obj i)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
80 (setq i (1+ i))))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
81 string) |
17052 | 82 |
83 ;;;###autoload | |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
84 (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
|
85 "Truncate string STR to end at column END-COLUMN. |
26691
1f573e26070a
(truncate-string-to-width): Docsting fixed.
Gerd Moellmann <gerd@gnu.org>
parents:
24866
diff
changeset
|
86 The optional 3rd arg START-COLUMN, if non-nil, specifies |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
87 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
|
88 columns START-COLUMN ... END-COLUMN of STR. |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
89 |
26691
1f573e26070a
(truncate-string-to-width): Docsting fixed.
Gerd Moellmann <gerd@gnu.org>
parents:
24866
diff
changeset
|
90 The optional 4th arg PADDING, if non-nil, specifies a padding character |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 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
|
95 |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
96 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
|
97 the resulting string may be narrower than END-COLUMN." |
17052 | 98 (or start-column |
99 (setq start-column 0)) | |
100 (let ((len (length str)) | |
101 (idx 0) | |
102 (column 0) | |
103 (head-padding "") (tail-padding "") | |
104 ch last-column last-idx from-idx) | |
105 (condition-case nil | |
106 (while (< column start-column) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
107 (setq ch (aref str idx) |
17052 | 108 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
109 idx (1+ idx))) |
17052 | 110 (args-out-of-range (setq idx len))) |
111 (if (< column start-column) | |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
112 (if padding (make-string end-column padding) "") |
17052 | 113 (if (and padding (> column start-column)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
114 (setq head-padding (make-string (- column start-column) padding))) |
17052 | 115 (setq from-idx idx) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
116 (if (< end-column column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
117 (setq idx from-idx) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
118 (condition-case nil |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
119 (while (< column end-column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
120 (setq last-column column |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
121 last-idx idx |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
122 ch (aref str idx) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
123 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
124 idx (1+ idx))) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
125 (args-out-of-range (setq idx len))) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
126 (if (> column end-column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
127 (setq column last-column idx last-idx)) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
128 (if (and padding (< column end-column)) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
129 (setq tail-padding (make-string (- end-column column) padding)))) |
17052 | 130 (setq str (substring str from-idx idx)) |
131 (if padding | |
132 (concat head-padding str tail-padding) | |
133 str)))) | |
134 | |
23196 | 135 ;;; For backward compatibility ... |
17052 | 136 ;;;###autoload |
137 (defalias 'truncate-string 'truncate-string-to-width) | |
29354
4ed4a700358b
Update calls to make-obsolete with a WHEN argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29058
diff
changeset
|
138 (make-obsolete 'truncate-string 'truncate-string-to-width "20.1") |
17052 | 139 |
140 ;;; Nested alist handler. Nested alist is alist whose elements are | |
141 ;;; also nested alist. | |
142 | |
143 ;;;###autoload | |
144 (defsubst nested-alist-p (obj) | |
23196 | 145 "Return t if OBJ is a nested alist. |
17052 | 146 |
147 Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is | |
148 any Lisp object, and BRANCHES is a list of cons cells of the form | |
149 (KEY-ELEMENT . NESTED-ALIST). | |
150 | |
151 You can use a nested alist to store any Lisp object (ENTRY) for a key | |
152 sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ | |
153 can be a string, a vector, or a list." | |
154 (and obj (listp obj) (listp (cdr obj)))) | |
155 | |
156 ;;;###autoload | |
157 (defun set-nested-alist (keyseq entry alist &optional len branches) | |
158 "Set ENTRY for KEYSEQ in a nested alist ALIST. | |
23196 | 159 Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ |
17052 | 160 is considered. |
161 Optional argument BRANCHES if non-nil is branches for a keyseq | |
162 longer than KEYSEQ. | |
163 See the documentation of `nested-alist-p' for more detail." | |
164 (or (nested-alist-p alist) | |
23196 | 165 (error "Invalid argument %s" alist)) |
17052 | 166 (let ((islist (listp keyseq)) |
167 (len (or len (length keyseq))) | |
168 (i 0) | |
169 key-elt slot) | |
170 (while (< i len) | |
171 (if (null (nested-alist-p alist)) | |
172 (error "Keyseq %s is too long for this nested alist" keyseq)) | |
173 (setq key-elt (if islist (nth i keyseq) (aref keyseq i))) | |
174 (setq slot (assoc key-elt (cdr alist))) | |
175 (if (null slot) | |
176 (progn | |
177 (setq slot (cons key-elt (list t))) | |
178 (setcdr alist (cons slot (cdr alist))))) | |
179 (setq alist (cdr slot)) | |
180 (setq i (1+ i))) | |
181 (setcar alist entry) | |
182 (if branches | |
26890
4cd9407a4683
(set-nested-alist): Set BRANCHES (if
Kenichi Handa <handa@m17n.org>
parents:
26691
diff
changeset
|
183 (setcdr (last alist) branches)))) |
17052 | 184 |
185 ;;;###autoload | |
186 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long) | |
187 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition. | |
188 Optional 1st argument LEN specifies the length of KEYSEQ. | |
189 Optional 2nd argument START specifies index of the starting key. | |
190 The returned value is normally a nested alist of which | |
191 car part is the entry for KEYSEQ. | |
192 If ALIST is not deep enough for KEYSEQ, return number which is | |
193 how many key elements at the front of KEYSEQ it takes | |
194 to reach a leaf in ALIST. | |
195 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil | |
196 even if ALIST is not deep enough." | |
197 (or (nested-alist-p alist) | |
28458 | 198 (error "Invalid argument %s" alist)) |
17052 | 199 (or len |
200 (setq len (length keyseq))) | |
201 (let ((i (or start 0))) | |
202 (if (catch 'lookup-nested-alist-tag | |
203 (if (listp keyseq) | |
204 (while (< i len) | |
205 (if (setq alist (cdr (assoc (nth i keyseq) (cdr alist)))) | |
206 (setq i (1+ i)) | |
207 (throw 'lookup-nested-alist-tag t)))) | |
208 (while (< i len) | |
209 (if (setq alist (cdr (assoc (aref keyseq i) (cdr alist)))) | |
210 (setq i (1+ i)) | |
211 (throw 'lookup-nested-alist-tag t)))) | |
212 ;; KEYSEQ is too long. | |
213 (if nil-for-too-long nil i) | |
214 alist))) | |
215 | |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
216 |
17052 | 217 ;; Coding system related functions. |
218 | |
219 ;;;###autoload | |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
220 (defun coding-system-eol-type-mnemonic (coding-system) |
24866
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
221 "Return the string indicating end-of-line format of CODING-SYSTEM." |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
222 (let* ((eol-type (coding-system-eol-type coding-system)) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
223 (val (cond ((vectorp eol-type) eol-mnemonic-undecided) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
224 ((eq eol-type 0) eol-mnemonic-unix) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
225 ((eq eol-type 1) eol-mnemonic-dos) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
226 ((eq eol-type 2) eol-mnemonic-mac) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
227 (t "-")))) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
228 (if (stringp val) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
229 val |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
230 (char-to-string val)))) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
231 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
232 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
233 (defun coding-system-post-read-conversion (coding-system) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
234 "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
|
235 (coding-system-get coding-system 'post-read-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
236 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
237 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
238 (defun coding-system-pre-write-conversion (coding-system) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
239 "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
|
240 (coding-system-get coding-system 'pre-write-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
241 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
242 ;;;###autoload |
22126
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
243 (defun coding-system-translation-table-for-decode (coding-system) |
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
244 "Return the value of CODING-SYSTEM's translation-table-for-decode property." |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22126
diff
changeset
|
245 (coding-system-get coding-system 'translation-table-for-decode)) |
19455
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
246 |
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
247 ;;;###autoload |
22126
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
248 (defun coding-system-translation-table-for-encode (coding-system) |
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
249 "Return the value of CODING-SYSTEM's translation-table-for-encode property." |
22186
fc4aaf1b1772
Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents:
22126
diff
changeset
|
250 (coding-system-get coding-system 'translation-table-for-encode)) |
17052 | 251 |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
252 ;;;###autoload |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
253 (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
|
254 "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
|
255 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
|
256 or one is an alias of the other." |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
257 (or (eq coding-system-1 coding-system-2) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
258 (and (equal (coding-system-spec coding-system-1) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
259 (coding-system-spec coding-system-2)) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
260 (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
|
261 (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
|
262 (or (eq eol-type-1 eol-type-2) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
263 (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
|
264 |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
265 ;;;###autoload |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
266 (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
|
267 "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
|
268 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
|
269 coding systems ordered by priority." |
24485
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
270 `(unwind-protect |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
271 (let* ((prio-list ,priority-list) |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
272 (coding-category-list coding-category-list) |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
273 ,@(mapcar (function (lambda (x) (list x x))) |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
274 coding-category-list)) |
29058
39b69af53e85
(detect-coding-with-priority): Use mapc. Remove redundant lambda.
Dave Love <fx@gnu.org>
parents:
28458
diff
changeset
|
275 (mapc (function (lambda (x) (set (car x) (cdr x)))) |
39b69af53e85
(detect-coding-with-priority): Use mapc. Remove redundant lambda.
Dave Love <fx@gnu.org>
parents:
28458
diff
changeset
|
276 prio-list) |
39b69af53e85
(detect-coding-with-priority): Use mapc. Remove redundant lambda.
Dave Love <fx@gnu.org>
parents:
28458
diff
changeset
|
277 (set-coding-priority (mapcar #'car prio-list)) |
24485
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
278 (detect-coding-region ,from ,to)) |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
279 ;; We must restore the internal database. |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
280 (set-coding-priority coding-category-list) |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
281 (update-coding-systems-internal))) |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
282 |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
283 ;;;###autoload |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
284 (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
|
285 "Detect a coding system of the text between FROM and TO with LANG-ENV. |
23196 | 286 The detection takes into account the coding system priorities for the |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
287 language environment LANG-ENV." |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
288 (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
|
289 (if coding-priority |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
290 (detect-coding-with-priority |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
291 from to |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
292 (mapcar (function (lambda (x) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
293 (cons (coding-system-get x 'coding-category) x))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
294 coding-priority)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
295 (detect-coding-region from to)))) |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
296 |
17052 | 297 |
28458 | 298 (provide 'mule-util) |
299 | |
26890
4cd9407a4683
(set-nested-alist): Set BRANCHES (if
Kenichi Handa <handa@m17n.org>
parents:
26691
diff
changeset
|
300 ;;; mule-util.el ends here |