Mercurial > emacs
annotate lisp/international/mule-util.el @ 89352:ffa18ef18e45
(x_set_font, x_create_tip_frame): Adjusted to the change
of x_new_fontset.
(Fx_create_frame): Don't call x_new_fontset here. Just use
x_list_fonts to check the existence of fonts.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 10 Jan 2003 07:20:25 +0000 |
parents | 438e610d8d06 |
children | 2f877ed80fa6 |
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. |
88810 | 5 ;; Copyright (C) 2002 Free Software Foundation, Inc. |
17052 | 6 |
7 ;; Keywords: mule, multilingual | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
17071 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
17052 | 25 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29354
diff
changeset
|
26 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29354
diff
changeset
|
27 |
17052 | 28 ;;; Code: |
29 | |
30 ;;; String manipulations while paying attention to multibyte | |
31 ;;; characters. | |
32 | |
33 ;;;###autoload | |
34 (defun string-to-sequence (string type) | |
35 "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
|
36 TYPE should be `list' or `vector'." |
28458 | 37 ;;; (let ((len (length string)) |
38 ;;; (i 0) | |
39 ;;; val) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
40 (cond ((eq type 'list) |
28458 | 41 ;; Applicable post-Emacs 20.2 and asymptotically ~10 times |
42 ;; faster than the code below: | |
43 (append string nil)) | |
44 ;;; (setq val (make-list len 0)) | |
45 ;;; (let ((l val)) | |
46 ;;; (while (< i len) | |
47 ;;; (setcar l (aref string i)) | |
48 ;;; (setq l (cdr l) i (1+ i)))))) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
49 ((eq type 'vector) |
28458 | 50 ;; As above. |
51 (vconcat string)) | |
52 ;;; (setq val (make-vector len 0)) | |
53 ;;; (while (< i len) | |
54 ;;; (aset val i (aref string i)) | |
55 ;;; (setq i (1+ i)))) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
56 (t |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
57 (error "Invalid type: %s" type))) |
28458 | 58 ;;; val) |
59 ) | |
41232
43e756c38f4f
(string-to-sequence): Make it obsolete.
Richard M. Stallman <rms@gnu.org>
parents:
38414
diff
changeset
|
60 (make-obsolete 'string-to-sequence |
43e756c38f4f
(string-to-sequence): Make it obsolete.
Richard M. Stallman <rms@gnu.org>
parents:
38414
diff
changeset
|
61 "Use `string-to-list' or `string-to-vector'" |
43e756c38f4f
(string-to-sequence): Make it obsolete.
Richard M. Stallman <rms@gnu.org>
parents:
38414
diff
changeset
|
62 "21.3") |
17052 | 63 |
64 ;;;###autoload | |
65 (defsubst string-to-list (string) | |
66 "Return a list of characters in STRING." | |
41232
43e756c38f4f
(string-to-sequence): Make it obsolete.
Richard M. Stallman <rms@gnu.org>
parents:
38414
diff
changeset
|
67 (append string nil)) |
17052 | 68 |
69 ;;;###autoload | |
70 (defsubst string-to-vector (string) | |
71 "Return a vector of characters in STRING." | |
41232
43e756c38f4f
(string-to-sequence): Make it obsolete.
Richard M. Stallman <rms@gnu.org>
parents:
38414
diff
changeset
|
72 (vconcat string)) |
17052 | 73 |
74 ;;;###autoload | |
75 (defun store-substring (string idx obj) | |
76 "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
|
77 (if (integerp obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
78 (aset string idx obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
79 (let ((len1 (length obj)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
80 (len2 (length string)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
81 (i 0)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
82 (while (< i len1) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
83 (aset string (+ idx i) (aref obj i)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
84 (setq i (1+ i))))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
85 string) |
17052 | 86 |
87 ;;;###autoload | |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
88 (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
|
89 "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
|
90 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
|
91 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
|
92 columns START-COLUMN ... END-COLUMN of STR. |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
93 |
26691
1f573e26070a
(truncate-string-to-width): Docsting fixed.
Gerd Moellmann <gerd@gnu.org>
parents:
24866
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
100 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
|
101 the resulting string may be narrower than END-COLUMN." |
17052 | 102 (or start-column |
103 (setq start-column 0)) | |
104 (let ((len (length str)) | |
105 (idx 0) | |
106 (column 0) | |
107 (head-padding "") (tail-padding "") | |
108 ch last-column last-idx from-idx) | |
109 (condition-case nil | |
110 (while (< column start-column) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
111 (setq ch (aref str idx) |
17052 | 112 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
113 idx (1+ idx))) |
17052 | 114 (args-out-of-range (setq idx len))) |
115 (if (< column start-column) | |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
116 (if padding (make-string end-column padding) "") |
17052 | 117 (if (and padding (> column start-column)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
118 (setq head-padding (make-string (- column start-column) padding))) |
17052 | 119 (setq from-idx idx) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
120 (if (< end-column column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
121 (setq idx from-idx) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
122 (condition-case nil |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
123 (while (< column end-column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
124 (setq last-column column |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
125 last-idx idx |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
126 ch (aref str idx) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
127 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
128 idx (1+ idx))) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
129 (args-out-of-range (setq idx len))) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
130 (if (> column end-column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
131 (setq column last-column idx last-idx)) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
132 (if (and padding (< column end-column)) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
133 (setq tail-padding (make-string (- end-column column) padding)))) |
17052 | 134 (setq str (substring str from-idx idx)) |
135 (if padding | |
136 (concat head-padding str tail-padding) | |
137 str)))) | |
138 | |
23196 | 139 ;;; For backward compatibility ... |
17052 | 140 ;;;###autoload |
141 (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
|
142 (make-obsolete 'truncate-string 'truncate-string-to-width "20.1") |
17052 | 143 |
144 ;;; Nested alist handler. Nested alist is alist whose elements are | |
145 ;;; also nested alist. | |
146 | |
147 ;;;###autoload | |
148 (defsubst nested-alist-p (obj) | |
23196 | 149 "Return t if OBJ is a nested alist. |
17052 | 150 |
151 Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is | |
152 any Lisp object, and BRANCHES is a list of cons cells of the form | |
153 (KEY-ELEMENT . NESTED-ALIST). | |
154 | |
155 You can use a nested alist to store any Lisp object (ENTRY) for a key | |
156 sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ | |
157 can be a string, a vector, or a list." | |
158 (and obj (listp obj) (listp (cdr obj)))) | |
159 | |
160 ;;;###autoload | |
161 (defun set-nested-alist (keyseq entry alist &optional len branches) | |
162 "Set ENTRY for KEYSEQ in a nested alist ALIST. | |
23196 | 163 Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ |
17052 | 164 is considered. |
165 Optional argument BRANCHES if non-nil is branches for a keyseq | |
166 longer than KEYSEQ. | |
167 See the documentation of `nested-alist-p' for more detail." | |
168 (or (nested-alist-p alist) | |
23196 | 169 (error "Invalid argument %s" alist)) |
17052 | 170 (let ((islist (listp keyseq)) |
171 (len (or len (length keyseq))) | |
172 (i 0) | |
173 key-elt slot) | |
174 (while (< i len) | |
175 (if (null (nested-alist-p alist)) | |
176 (error "Keyseq %s is too long for this nested alist" keyseq)) | |
177 (setq key-elt (if islist (nth i keyseq) (aref keyseq i))) | |
178 (setq slot (assoc key-elt (cdr alist))) | |
179 (if (null slot) | |
180 (progn | |
181 (setq slot (cons key-elt (list t))) | |
182 (setcdr alist (cons slot (cdr alist))))) | |
183 (setq alist (cdr slot)) | |
184 (setq i (1+ i))) | |
185 (setcar alist entry) | |
186 (if branches | |
26890
4cd9407a4683
(set-nested-alist): Set BRANCHES (if
Kenichi Handa <handa@m17n.org>
parents:
26691
diff
changeset
|
187 (setcdr (last alist) branches)))) |
17052 | 188 |
189 ;;;###autoload | |
190 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long) | |
191 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition. | |
192 Optional 1st argument LEN specifies the length of KEYSEQ. | |
193 Optional 2nd argument START specifies index of the starting key. | |
194 The returned value is normally a nested alist of which | |
195 car part is the entry for KEYSEQ. | |
196 If ALIST is not deep enough for KEYSEQ, return number which is | |
197 how many key elements at the front of KEYSEQ it takes | |
198 to reach a leaf in ALIST. | |
199 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil | |
200 even if ALIST is not deep enough." | |
201 (or (nested-alist-p alist) | |
28458 | 202 (error "Invalid argument %s" alist)) |
17052 | 203 (or len |
204 (setq len (length keyseq))) | |
205 (let ((i (or start 0))) | |
206 (if (catch 'lookup-nested-alist-tag | |
207 (if (listp keyseq) | |
208 (while (< i len) | |
209 (if (setq alist (cdr (assoc (nth i keyseq) (cdr alist)))) | |
210 (setq i (1+ i)) | |
211 (throw 'lookup-nested-alist-tag t)))) | |
212 (while (< i len) | |
213 (if (setq alist (cdr (assoc (aref keyseq i) (cdr alist)))) | |
214 (setq i (1+ i)) | |
215 (throw 'lookup-nested-alist-tag t)))) | |
216 ;; KEYSEQ is too long. | |
217 (if nil-for-too-long nil i) | |
218 alist))) | |
219 | |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
220 |
17052 | 221 ;; Coding system related functions. |
222 | |
223 ;;;###autoload | |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
224 (defun coding-system-eol-type-mnemonic (coding-system) |
24866
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
225 "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
|
226 (let* ((eol-type (coding-system-eol-type coding-system)) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
227 (val (cond ((vectorp eol-type) eol-mnemonic-undecided) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
228 ((eq eol-type 0) eol-mnemonic-unix) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
229 ((eq eol-type 1) eol-mnemonic-dos) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
230 ((eq eol-type 2) eol-mnemonic-mac) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
231 (t "-")))) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
232 (if (stringp val) |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
233 val |
84d705e026b4
(coding-system-eol-type-mnemonic):
Kenichi Handa <handa@m17n.org>
parents:
24485
diff
changeset
|
234 (char-to-string val)))) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
235 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
236 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
237 (defun coding-system-post-read-conversion (coding-system) |
42049 | 238 "Return the value of CODING-SYSTEM's `post-read-conversion' property." |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
239 (coding-system-get coding-system :post-read-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
240 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
241 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
242 (defun coding-system-pre-write-conversion (coding-system) |
42049 | 243 "Return the value of CODING-SYSTEM's `pre-write-conversion' property." |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
244 (coding-system-get coding-system :pre-write-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
245 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
246 ;;;###autoload |
22126
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
247 (defun coding-system-translation-table-for-decode (coding-system) |
42049 | 248 "Return the value of CODING-SYSTEM's `translation-table-for-decode' property." |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
249 (coding-system-get coding-system :decode-translation-table)) |
19455
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
250 |
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
251 ;;;###autoload |
22126
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
252 (defun coding-system-translation-table-for-encode (coding-system) |
42049 | 253 "Return the value of CODING-SYSTEM's `translation-table-for-encode' property." |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
254 (coding-system-get coding-system :encode-translation-table)) |
17052 | 255 |
18299
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-equal (coding-system-1 coding-system-2) |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
258 "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
|
259 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
|
260 or one is an alias of the other." |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
261 (or (eq coding-system-1 coding-system-2) |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
262 (and (equal (coding-system-plist coding-system-1) |
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
263 (coding-system-plist coding-system-2)) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
264 (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
|
265 (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
|
266 (or (eq eol-type-1 eol-type-2) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
267 (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
|
268 |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
269 ;;;###autoload |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
270 (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
|
271 "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
|
272 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
|
273 coding systems ordered by priority." |
88867
438e610d8d06
(detect-coding-with-priority): Fix the place of using `,' marker in
Kenichi Handa <handa@m17n.org>
parents:
88842
diff
changeset
|
274 `(with-coding-priority (mapcar #'cdr ,priority-list) |
88810 | 275 (detect-coding-region ,from ,to))) |
276 (make-obsolete 'detect-coding-with-priority | |
277 "Use with-coding-priority and detect-coding-region" "22.1") | |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
278 |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
279 ;;;###autoload |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
280 (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
|
281 "Detect a coding system of the text between FROM and TO with LANG-ENV. |
23196 | 282 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
|
283 language environment LANG-ENV." |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
284 (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
|
285 (if coding-priority |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
286 (with-coding-priority coding-priority |
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
287 (detect-coding-region from to))))) |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
288 |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
289 ;;;###autoload |
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
290 (defmacro with-coding-priority (coding-systems &rest body) |
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
291 "Execute BODY like `progn' with CODING-SYSTEMS at the front of priority list. |
88842 | 292 CODING-SYSTEMS is a list of coding systems. See |
293 `set-coding-priority'. This affects the implicit sorting of lists of | |
294 coding sysems returned by operations such as `find-coding-systems-region'." | |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
295 (let ((current (make-symbol "current"))) |
88842 | 296 `(let ((,current (coding-system-priority-list))) |
297 (apply #'set-coding-system-priority ,coding-systems) | |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
298 (unwind-protect |
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
299 (progn ,@body) |
88842 | 300 (apply #'set-coding-system-priority ,current))))) |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
301 (put 'with-coding-priority 'lisp-indent-function 1) |
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
302 (put 'with-coding-priority 'edebug-form-spec t) |
17052 | 303 |
28458 | 304 (provide 'mule-util) |
305 | |
26890
4cd9407a4683
(set-nested-alist): Set BRANCHES (if
Kenichi Handa <handa@m17n.org>
parents:
26691
diff
changeset
|
306 ;;; mule-util.el ends here |