Mercurial > emacs
annotate lisp/international/mule-util.el @ 53482:7528710ec1a4
(Creating Symbols): Add anchor.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Sat, 03 Jan 2004 16:47:05 +0000 |
parents | be9e6be9d6d7 |
children | 4860d5ef0587 375f2633d815 |
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. |
52403 | 5 ;; Copyright (C) 2000, 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 ) | |
46511
f44beb42c7c1
(string-to-sequence, truncate-string): Add autoload cookie.
Juanma Barranquero <lekktu@gmail.com>
parents:
46051
diff
changeset
|
60 |
f44beb42c7c1
(string-to-sequence, truncate-string): Add autoload cookie.
Juanma Barranquero <lekktu@gmail.com>
parents:
46051
diff
changeset
|
61 ;;;###autoload |
41232
43e756c38f4f
(string-to-sequence): Make it obsolete.
Richard M. Stallman <rms@gnu.org>
parents:
38414
diff
changeset
|
62 (make-obsolete 'string-to-sequence |
46051
990c78360ef5
(string-to-sequence): Fix obsolescence declaration.
Juanma Barranquero <lekktu@gmail.com>
parents:
45908
diff
changeset
|
63 "use `string-to-list' or `string-to-vector'." |
990c78360ef5
(string-to-sequence): Fix obsolescence declaration.
Juanma Barranquero <lekktu@gmail.com>
parents:
45908
diff
changeset
|
64 "21.4") |
17052 | 65 |
66 ;;;###autoload | |
67 (defsubst string-to-list (string) | |
68 "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
|
69 (append string nil)) |
17052 | 70 |
71 ;;;###autoload | |
72 (defsubst string-to-vector (string) | |
73 "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
|
74 (vconcat string)) |
17052 | 75 |
76 ;;;###autoload | |
77 (defun store-substring (string idx obj) | |
78 "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
|
79 (if (integerp obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
80 (aset string idx obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
81 (let ((len1 (length obj)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
82 (len2 (length string)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
83 (i 0)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
84 (while (< i len1) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
85 (aset string (+ idx i) (aref obj i)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
86 (setq i (1+ i))))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
87 string) |
17052 | 88 |
89 ;;;###autoload | |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
90 (defun truncate-string-to-width (str end-column |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
91 &optional start-column padding ellipsis) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
92 "Truncate string STR to end at column END-COLUMN. |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
93 The optional 3rd arg START-COLUMN, if non-nil, specifies the starting |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
94 column; that means to return the characters occupying columns |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
95 START-COLUMN ... END-COLUMN of STR. Both END-COLUMN and START-COLUMN |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
96 are specified in terms of character display width in the current |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
97 buffer; see also `char-width'. |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
98 |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
99 The optional 4th arg PADDING, if non-nil, specifies a padding |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
100 character (which should have a display width of 1) to add at the end |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
101 of the result if STR doesn't reach column END-COLUMN, or if END-COLUMN |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
102 comes in the middle of a character in STR. PADDING is also added at |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
103 the beginning of the result if column START-COLUMN appears in the |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
104 middle of a character in STR. |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
105 |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
106 If PADDING is nil, no padding is added in these cases, so |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
107 the resulting string may be narrower than END-COLUMN. |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
108 |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
109 If ELLIPSIS is non-nil, it should be a string which will replace the |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
110 end of STR (including any padding) if it extends beyond END-COLUMN, |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
111 unless the display width of STR is equal to or less than the display |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
112 width of ELLIPSIS. If it is non-nil and not a string, then ELLIPSIS |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
113 defaults to \"...\"." |
17052 | 114 (or start-column |
115 (setq start-column 0)) | |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
116 (when (and ellipsis (not (stringp ellipsis))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
117 (setq ellipsis "...")) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
118 (let ((str-len (length str)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
119 (str-width (string-width str)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
120 (ellipsis-len (if ellipsis (length ellipsis) 0)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
121 (ellipsis-width (if ellipsis (string-width ellipsis) 0)) |
17052 | 122 (idx 0) |
123 (column 0) | |
124 (head-padding "") (tail-padding "") | |
125 ch last-column last-idx from-idx) | |
126 (condition-case nil | |
127 (while (< column start-column) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
128 (setq ch (aref str idx) |
17052 | 129 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
130 idx (1+ idx))) |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
131 (args-out-of-range (setq idx str-len))) |
17052 | 132 (if (< column start-column) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
133 (if padding (make-string end-column padding) "") |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
134 (when (and padding (> column start-column)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
135 (setq head-padding (make-string (- column start-column) padding))) |
17052 | 136 (setq from-idx idx) |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
137 (when (>= end-column column) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
138 (if (and (< end-column str-width) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
139 (> str-width ellipsis-width)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
140 (setq end-column (- end-column ellipsis-width)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
141 (setq ellipsis "")) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
142 (condition-case nil |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
143 (while (< column end-column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
144 (setq last-column column |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
145 last-idx idx |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
146 ch (aref str idx) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
147 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
148 idx (1+ idx))) |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
149 (args-out-of-range (setq idx str-len))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
150 (when (> column end-column) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
151 (setq column last-column |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
152 idx last-idx)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
153 (when (and padding (< column end-column)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
154 (setq tail-padding (make-string (- end-column column) padding)))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
155 (concat head-padding (substring str from-idx idx) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
156 tail-padding ellipsis)))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
157 |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
158 ;;; Test suite for truncate-string-to-width |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
159 ;; (dolist (test '((("" 0) . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
160 ;; (("x" 1) . "x") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
161 ;; (("xy" 1) . "x") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
162 ;; (("xy" 2 1) . "y") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
163 ;; (("xy" 0) . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
164 ;; (("xy" 3) . "xy") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
165 ;; (("$AVP(B" 0) . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
166 ;; (("$AVP(B" 1) . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
167 ;; (("$AVP(B" 2) . "$AVP(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
168 ;; (("$AVP(B" 1 nil ? ) . " ") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
169 ;; (("$AVPND(B" 3 1 ? ) . " ") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
170 ;; (("x$AVP(Bx" 2) . "x") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
171 ;; (("x$AVP(Bx" 3) . "x$AVP(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
172 ;; (("x$AVP(Bx" 3) . "x$AVP(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
173 ;; (("x$AVP(Bx" 4 1) . "$AVP(Bx") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
174 ;; (("kor$(CGQ(Be$(C1[(Ban" 8 1 ? ) . "or$(CGQ(Be$(C1[(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
175 ;; (("kor$(CGQ(Be$(C1[(Ban" 7 2 ? ) . "r$(CGQ(Be ") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
176 ;; (("" 0 nil nil "...") . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
177 ;; (("x" 3 nil nil "...") . "x") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
178 ;; (("$AVP(B" 3 nil nil "...") . "$AVP(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
179 ;; (("foo" 3 nil nil "...") . "foo") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
180 ;; (("foo" 2 nil nil "...") . "fo") ;; XEmacs failure? |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
181 ;; (("foobar" 6 0 nil "...") . "foobar") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
182 ;; (("foobarbaz" 6 nil nil "...") . "foo...") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
183 ;; (("foobarbaz" 7 2 nil "...") . "ob...") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
184 ;; (("foobarbaz" 9 3 nil "...") . "barbaz") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
185 ;; (("$B$3(Bh$B$s(Be$B$K(Bl$B$A(Bl$B$O(Bo" 15 1 ? t) . " h$B$s(Be$B$K(Bl$B$A(Bl$B$O(Bo") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
186 ;; (("$B$3(Bh$B$s(Be$B$K(Bl$B$A(Bl$B$O(Bo" 14 1 ? t) . " h$B$s(Be$B$K(Bl$B$A(B...") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
187 ;; (("x" 3 nil nil "$(0GnM$(B") . "x") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
188 ;; (("$AVP(B" 2 nil nil "$(0GnM$(B") . "$AVP(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
189 ;; (("$AVP(B" 1 nil ?x "$(0GnM$(B") . "x") ;; XEmacs error |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
190 ;; (("$AVPND(B" 3 nil ? "$(0GnM$(B") . "$AVP(B ") ;; XEmacs error |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
191 ;; (("foobarbaz" 4 nil nil "$(0GnM$(B") . "$(0GnM$(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
192 ;; (("foobarbaz" 5 nil nil "$(0GnM$(B") . "f$(0GnM$(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
193 ;; (("foobarbaz" 6 nil nil "$(0GnM$(B") . "fo$(0GnM$(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
194 ;; (("foobarbaz" 8 3 nil "$(0GnM$(B") . "b$(0GnM$(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
195 ;; (("$B$3(Bh$B$s(Be$B$K(Bl$B$A(Bl$B$O(Bo" 14 4 ?x "$BF|K\8l(B") . "xe$B$KF|K\8l(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
196 ;; (("$B$3(Bh$B$s(Be$B$K(Bl$B$A(Bl$B$O(Bo" 13 4 ?x "$BF|K\8l(B") . "xex$BF|K\8l(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
197 ;; )) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
198 ;; (let (ret) |
48156
5701c670b676
(coding-system-eol-type-mnemonic): Move to mule.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
46511
diff
changeset
|
199 ;; (condition-case e |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
200 ;; (setq ret (apply #'truncate-string-to-width (car test))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
201 ;; (error (setq ret e))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
202 ;; (unless (equal ret (cdr test)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
203 ;; (error "%s: expected %s, got %s" |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
204 ;; (prin1-to-string (cons 'truncate-string-to-width (car test))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
205 ;; (prin1-to-string (cdr test)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
206 ;; (if (consp ret) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
207 ;; (format "error: %s: %s" (car ret) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
208 ;; (prin1-to-string (cdr ret))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
209 ;; (prin1-to-string ret)))))) |
17052 | 210 |
23196 | 211 ;;; For backward compatibility ... |
17052 | 212 ;;;###autoload |
213 (defalias 'truncate-string 'truncate-string-to-width) | |
46511
f44beb42c7c1
(string-to-sequence, truncate-string): Add autoload cookie.
Juanma Barranquero <lekktu@gmail.com>
parents:
46051
diff
changeset
|
214 |
f44beb42c7c1
(string-to-sequence, truncate-string): Add autoload cookie.
Juanma Barranquero <lekktu@gmail.com>
parents:
46051
diff
changeset
|
215 ;;;###autoload |
29354
4ed4a700358b
Update calls to make-obsolete with a WHEN argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29058
diff
changeset
|
216 (make-obsolete 'truncate-string 'truncate-string-to-width "20.1") |
17052 | 217 |
218 ;;; Nested alist handler. Nested alist is alist whose elements are | |
219 ;;; also nested alist. | |
220 | |
221 ;;;###autoload | |
222 (defsubst nested-alist-p (obj) | |
23196 | 223 "Return t if OBJ is a nested alist. |
17052 | 224 |
225 Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is | |
226 any Lisp object, and BRANCHES is a list of cons cells of the form | |
45908
bb8152219329
open-paren-in-column-0 in dosctring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45453
diff
changeset
|
227 \(KEY-ELEMENT . NESTED-ALIST). |
17052 | 228 |
229 You can use a nested alist to store any Lisp object (ENTRY) for a key | |
230 sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ | |
231 can be a string, a vector, or a list." | |
232 (and obj (listp obj) (listp (cdr obj)))) | |
233 | |
234 ;;;###autoload | |
235 (defun set-nested-alist (keyseq entry alist &optional len branches) | |
236 "Set ENTRY for KEYSEQ in a nested alist ALIST. | |
23196 | 237 Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ |
17052 | 238 is considered. |
239 Optional argument BRANCHES if non-nil is branches for a keyseq | |
240 longer than KEYSEQ. | |
241 See the documentation of `nested-alist-p' for more detail." | |
242 (or (nested-alist-p alist) | |
23196 | 243 (error "Invalid argument %s" alist)) |
17052 | 244 (let ((islist (listp keyseq)) |
245 (len (or len (length keyseq))) | |
246 (i 0) | |
247 key-elt slot) | |
248 (while (< i len) | |
249 (if (null (nested-alist-p alist)) | |
250 (error "Keyseq %s is too long for this nested alist" keyseq)) | |
251 (setq key-elt (if islist (nth i keyseq) (aref keyseq i))) | |
252 (setq slot (assoc key-elt (cdr alist))) | |
253 (if (null slot) | |
254 (progn | |
255 (setq slot (cons key-elt (list t))) | |
256 (setcdr alist (cons slot (cdr alist))))) | |
257 (setq alist (cdr slot)) | |
258 (setq i (1+ i))) | |
259 (setcar alist entry) | |
260 (if branches | |
26890
4cd9407a4683
(set-nested-alist): Set BRANCHES (if
Kenichi Handa <handa@m17n.org>
parents:
26691
diff
changeset
|
261 (setcdr (last alist) branches)))) |
17052 | 262 |
263 ;;;###autoload | |
264 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long) | |
265 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition. | |
266 Optional 1st argument LEN specifies the length of KEYSEQ. | |
267 Optional 2nd argument START specifies index of the starting key. | |
268 The returned value is normally a nested alist of which | |
269 car part is the entry for KEYSEQ. | |
270 If ALIST is not deep enough for KEYSEQ, return number which is | |
271 how many key elements at the front of KEYSEQ it takes | |
272 to reach a leaf in ALIST. | |
273 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil | |
274 even if ALIST is not deep enough." | |
275 (or (nested-alist-p alist) | |
28458 | 276 (error "Invalid argument %s" alist)) |
17052 | 277 (or len |
278 (setq len (length keyseq))) | |
279 (let ((i (or start 0))) | |
280 (if (catch 'lookup-nested-alist-tag | |
281 (if (listp keyseq) | |
282 (while (< i len) | |
283 (if (setq alist (cdr (assoc (nth i keyseq) (cdr alist)))) | |
284 (setq i (1+ i)) | |
285 (throw 'lookup-nested-alist-tag t)))) | |
286 (while (< i len) | |
287 (if (setq alist (cdr (assoc (aref keyseq i) (cdr alist)))) | |
288 (setq i (1+ i)) | |
289 (throw 'lookup-nested-alist-tag t)))) | |
290 ;; KEYSEQ is too long. | |
291 (if nil-for-too-long nil i) | |
292 alist))) | |
293 | |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
294 |
17052 | 295 ;; Coding system related functions. |
296 | |
297 ;;;###autoload | |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
298 (defun coding-system-post-read-conversion (coding-system) |
42049 | 299 "Return the value of CODING-SYSTEM's `post-read-conversion' property." |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
300 (coding-system-get coding-system 'post-read-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
301 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
302 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
303 (defun coding-system-pre-write-conversion (coding-system) |
42049 | 304 "Return the value of CODING-SYSTEM's `pre-write-conversion' property." |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
305 (coding-system-get coding-system 'pre-write-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
306 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
307 ;;;###autoload |
22126
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
308 (defun coding-system-translation-table-for-decode (coding-system) |
42049 | 309 "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
|
310 (coding-system-get coding-system 'translation-table-for-decode)) |
19455
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
311 |
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
312 ;;;###autoload |
22126
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
313 (defun coding-system-translation-table-for-encode (coding-system) |
42049 | 314 "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
|
315 (coding-system-get coding-system 'translation-table-for-encode)) |
17052 | 316 |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
317 ;;;###autoload |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
318 (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
|
319 "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
|
320 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
|
321 or one is an alias of the other." |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
322 (or (eq coding-system-1 coding-system-2) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
323 (and (equal (coding-system-spec coding-system-1) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
324 (coding-system-spec coding-system-2)) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
325 (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
|
326 (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
|
327 (or (eq eol-type-1 eol-type-2) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
328 (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
|
329 |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
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." |
24485
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
335 `(unwind-protect |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
336 (let* ((prio-list ,priority-list) |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
337 (coding-category-list coding-category-list) |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
338 ,@(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
|
339 coding-category-list)) |
29058
39b69af53e85
(detect-coding-with-priority): Use mapc. Remove redundant lambda.
Dave Love <fx@gnu.org>
parents:
28458
diff
changeset
|
340 (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
|
341 prio-list) |
39b69af53e85
(detect-coding-with-priority): Use mapc. Remove redundant lambda.
Dave Love <fx@gnu.org>
parents:
28458
diff
changeset
|
342 (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
|
343 (detect-coding-region ,from ,to)) |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
344 ;; We must restore the internal database. |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
345 (set-coding-priority coding-category-list) |
ab39ea2168e7
(detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents:
24346
diff
changeset
|
346 (update-coding-systems-internal))) |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
347 |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
348 ;;;###autoload |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
349 (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
|
350 "Detect a coding system of the text between FROM and TO with LANG-ENV. |
23196 | 351 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
|
352 language environment LANG-ENV." |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
353 (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
|
354 (if coding-priority |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
355 (detect-coding-with-priority |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
356 from to |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
357 (mapcar (function (lambda (x) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
358 (cons (coding-system-get x 'coding-category) x))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
359 coding-priority)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
360 (detect-coding-region from to)))) |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
361 |
52403 | 362 ;;;###autoload |
363 (defun char-displayable-p (char) | |
364 "Return non-nil if we should be able to display CHAR. | |
365 On a multi-font display, the test is only whether there is an | |
366 appropriate font from the selected frame's fontset to display CHAR's | |
367 charset in general. Since fonts may be specified on a per-character | |
368 basis, this may not be accurate." | |
369 (cond ((< char 256) | |
370 ;; Single byte characters are always displayable. | |
371 t) | |
372 ((display-multi-font-p) | |
373 ;; On a window system, a character is displayable if we have | |
374 ;; a font for that character in the default face of the | |
375 ;; currently selected frame. | |
376 (let ((fontset (frame-parameter (selected-frame) 'font)) | |
377 font-pattern) | |
378 (if (query-fontset fontset) | |
379 (setq font-pattern (fontset-font fontset char))) | |
380 (or font-pattern | |
381 (setq font-pattern (fontset-font "fontset-default" char))) | |
382 (if font-pattern | |
383 (progn | |
384 ;; Now FONT-PATTERN is a string or a cons of family | |
385 ;; field pattern and registry field pattern. | |
386 (or (stringp font-pattern) | |
387 (setq font-pattern (concat "-" | |
388 (or (car font-pattern) "*") | |
389 "-*-" | |
390 (cdr font-pattern)))) | |
391 (x-list-fonts font-pattern 'default (selected-frame) 1))))) | |
392 (t | |
393 (let ((coding (terminal-coding-system))) | |
394 (if coding | |
395 (let ((safe-chars (coding-system-get coding 'safe-chars)) | |
396 (safe-charsets (coding-system-get coding 'safe-charsets))) | |
397 (or (and safe-chars | |
398 (aref safe-chars char)) | |
399 (and safe-charsets | |
400 (memq (char-charset char) safe-charsets))))))))) | |
17052 | 401 |
28458 | 402 (provide 'mule-util) |
403 | |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
404 ;; Local Variables: |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
405 ;; coding: iso-2022-7bit |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
406 ;; End: |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
407 |
52401 | 408 ;;; arch-tag: 5bdb52b6-a3a5-4529-b7a0-37d01b0e570b |
26890
4cd9407a4683
(set-nested-alist): Set BRANCHES (if
Kenichi Handa <handa@m17n.org>
parents:
26691
diff
changeset
|
409 ;;; mule-util.el ends here |