Mercurial > emacs
annotate lisp/international/mule-util.el @ 89697:e3cedd99e51a
(FACE_FOR_CHAR): New args POS and OBJECT.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 13 Jan 2004 01:34:56 +0000 |
parents | e8de75a86fbc |
children | 68c22ea6027c |
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. | |
89483 | 4 ;; Licensed to the Free Software Foundation. |
88810 | 5 ;; Copyright (C) 2002 Free Software Foundation, Inc. |
89483 | 6 ;; Copyright (C) 2003 |
7 ;; National Institute of Advanced Industrial Science and Technology (AIST) | |
8 ;; Registration Number H13PRO009 | |
9 | |
17052 | 10 |
11 ;; Keywords: mule, multilingual | |
12 | |
13 ;; This file is part of GNU Emacs. | |
14 | |
15 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
16 ;; it under the terms of the GNU General Public License as published by | |
17 ;; the Free Software Foundation; either version 2, or (at your option) | |
18 ;; any later version. | |
19 | |
20 ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 ;; GNU General Public License for more details. | |
24 | |
25 ;; You should have received a copy of the GNU General Public License | |
17071 | 26 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
28 ;; Boston, MA 02111-1307, USA. | |
17052 | 29 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29354
diff
changeset
|
30 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29354
diff
changeset
|
31 |
17052 | 32 ;;; Code: |
33 | |
34 ;;; String manipulations while paying attention to multibyte | |
35 ;;; characters. | |
36 | |
37 ;;;###autoload | |
38 (defun string-to-sequence (string type) | |
39 "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
|
40 TYPE should be `list' or `vector'." |
28458 | 41 ;;; (let ((len (length string)) |
42 ;;; (i 0) | |
43 ;;; val) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
44 (cond ((eq type 'list) |
28458 | 45 ;; Applicable post-Emacs 20.2 and asymptotically ~10 times |
46 ;; faster than the code below: | |
47 (append string nil)) | |
48 ;;; (setq val (make-list len 0)) | |
49 ;;; (let ((l val)) | |
50 ;;; (while (< i len) | |
51 ;;; (setcar l (aref string i)) | |
52 ;;; (setq l (cdr l) i (1+ i)))))) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
53 ((eq type 'vector) |
28458 | 54 ;; As above. |
55 (vconcat string)) | |
56 ;;; (setq val (make-vector len 0)) | |
57 ;;; (while (< i len) | |
58 ;;; (aset val i (aref string i)) | |
59 ;;; (setq i (1+ i)))) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
60 (t |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
61 (error "Invalid type: %s" type))) |
28458 | 62 ;;; val) |
63 ) | |
46511
f44beb42c7c1
(string-to-sequence, truncate-string): Add autoload cookie.
Juanma Barranquero <lekktu@gmail.com>
parents:
46051
diff
changeset
|
64 |
f44beb42c7c1
(string-to-sequence, truncate-string): Add autoload cookie.
Juanma Barranquero <lekktu@gmail.com>
parents:
46051
diff
changeset
|
65 ;;;###autoload |
41232
43e756c38f4f
(string-to-sequence): Make it obsolete.
Richard M. Stallman <rms@gnu.org>
parents:
38414
diff
changeset
|
66 (make-obsolete 'string-to-sequence |
46051
990c78360ef5
(string-to-sequence): Fix obsolescence declaration.
Juanma Barranquero <lekktu@gmail.com>
parents:
45908
diff
changeset
|
67 "use `string-to-list' or `string-to-vector'." |
990c78360ef5
(string-to-sequence): Fix obsolescence declaration.
Juanma Barranquero <lekktu@gmail.com>
parents:
45908
diff
changeset
|
68 "21.4") |
17052 | 69 |
70 ;;;###autoload | |
71 (defsubst string-to-list (string) | |
72 "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
|
73 (append string nil)) |
17052 | 74 |
75 ;;;###autoload | |
76 (defsubst string-to-vector (string) | |
77 "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
|
78 (vconcat string)) |
17052 | 79 |
80 ;;;###autoload | |
81 (defun store-substring (string idx obj) | |
82 "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
|
83 (if (integerp obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
84 (aset string idx obj) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
85 (let ((len1 (length obj)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
86 (len2 (length string)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
87 (i 0)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
88 (while (< i len1) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
89 (aset string (+ idx i) (aref obj i)) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
90 (setq i (1+ i))))) |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
91 string) |
17052 | 92 |
93 ;;;###autoload | |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
94 (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
|
95 &optional start-column padding ellipsis) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
96 "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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 buffer; see also `char-width'. |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
102 |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 middle of a character in STR. |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
109 |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
110 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
|
111 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
|
112 |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 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
|
117 defaults to \"...\"." |
17052 | 118 (or start-column |
119 (setq start-column 0)) | |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
120 (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
|
121 (setq ellipsis "...")) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
122 (let ((str-len (length str)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
123 (str-width (string-width str)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
124 (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
|
125 (ellipsis-width (if ellipsis (string-width ellipsis) 0)) |
17052 | 126 (idx 0) |
127 (column 0) | |
128 (head-padding "") (tail-padding "") | |
129 ch last-column last-idx from-idx) | |
130 (condition-case nil | |
131 (while (< column start-column) | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
132 (setq ch (aref str idx) |
17052 | 133 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
134 idx (1+ idx))) |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
135 (args-out-of-range (setq idx str-len))) |
17052 | 136 (if (< column start-column) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
137 (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
|
138 (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
|
139 (setq head-padding (make-string (- column start-column) padding))) |
17052 | 140 (setq from-idx idx) |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
141 (when (>= end-column column) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
142 (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
|
143 (> str-width ellipsis-width)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
144 (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
|
145 (setq ellipsis "")) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
146 (condition-case nil |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
147 (while (< column end-column) |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
148 (setq last-column column |
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
149 last-idx idx |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
150 ch (aref str idx) |
19916
f43513081277
(truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents:
19745
diff
changeset
|
151 column (+ column (char-width ch)) |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
152 idx (1+ idx))) |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
153 (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
|
154 (when (> column end-column) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
155 (setq column last-column |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
156 idx last-idx)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
157 (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
|
158 (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
|
159 (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
|
160 tail-padding ellipsis)))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
161 |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
162 ;;; 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
|
163 ;; (dolist (test '((("" 0) . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
164 ;; (("x" 1) . "x") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
165 ;; (("xy" 1) . "x") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
166 ;; (("xy" 2 1) . "y") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
167 ;; (("xy" 0) . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
168 ;; (("xy" 3) . "xy") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
169 ;; (("$AVP(B" 0) . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
170 ;; (("$AVP(B" 1) . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
171 ;; (("$AVP(B" 2) . "$AVP(B") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
172 ;; (("$AVP(B" 1 nil ? ) . " ") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
173 ;; (("$AVPND(B" 3 1 ? ) . " ") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
174 ;; (("x$AVP(Bx" 2) . "x") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
175 ;; (("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
|
176 ;; (("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
|
177 ;; (("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
|
178 ;; (("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
|
179 ;; (("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
|
180 ;; (("" 0 nil nil "...") . "") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
181 ;; (("x" 3 nil nil "...") . "x") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
182 ;; (("$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
|
183 ;; (("foo" 3 nil nil "...") . "foo") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
184 ;; (("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
|
185 ;; (("foobar" 6 0 nil "...") . "foobar") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
186 ;; (("foobarbaz" 6 nil nil "...") . "foo...") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
187 ;; (("foobarbaz" 7 2 nil "...") . "ob...") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
188 ;; (("foobarbaz" 9 3 nil "...") . "barbaz") |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
189 ;; (("$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
|
190 ;; (("$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
|
191 ;; (("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
|
192 ;; (("$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
|
193 ;; (("$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
|
194 ;; (("$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
|
195 ;; (("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
|
196 ;; (("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
|
197 ;; (("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
|
198 ;; (("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
|
199 ;; (("$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
|
200 ;; (("$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
|
201 ;; )) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
202 ;; (let (ret) |
48156
5701c670b676
(coding-system-eol-type-mnemonic): Move to mule.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
46511
diff
changeset
|
203 ;; (condition-case e |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
204 ;; (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
|
205 ;; (error (setq ret e))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
206 ;; (unless (equal ret (cdr test)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
207 ;; (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
|
208 ;; (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
|
209 ;; (prin1-to-string (cdr test)) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
210 ;; (if (consp ret) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
211 ;; (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
|
212 ;; (prin1-to-string (cdr ret))) |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
213 ;; (prin1-to-string ret)))))) |
17052 | 214 |
23196 | 215 ;;; For backward compatibility ... |
17052 | 216 ;;;###autoload |
217 (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
|
218 |
f44beb42c7c1
(string-to-sequence, truncate-string): Add autoload cookie.
Juanma Barranquero <lekktu@gmail.com>
parents:
46051
diff
changeset
|
219 ;;;###autoload |
29354
4ed4a700358b
Update calls to make-obsolete with a WHEN argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29058
diff
changeset
|
220 (make-obsolete 'truncate-string 'truncate-string-to-width "20.1") |
17052 | 221 |
222 ;;; Nested alist handler. Nested alist is alist whose elements are | |
223 ;;; also nested alist. | |
224 | |
225 ;;;###autoload | |
226 (defsubst nested-alist-p (obj) | |
23196 | 227 "Return t if OBJ is a nested alist. |
17052 | 228 |
229 Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is | |
230 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
|
231 \(KEY-ELEMENT . NESTED-ALIST). |
17052 | 232 |
233 You can use a nested alist to store any Lisp object (ENTRY) for a key | |
234 sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ | |
235 can be a string, a vector, or a list." | |
236 (and obj (listp obj) (listp (cdr obj)))) | |
237 | |
238 ;;;###autoload | |
239 (defun set-nested-alist (keyseq entry alist &optional len branches) | |
240 "Set ENTRY for KEYSEQ in a nested alist ALIST. | |
23196 | 241 Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ |
17052 | 242 is considered. |
243 Optional argument BRANCHES if non-nil is branches for a keyseq | |
244 longer than KEYSEQ. | |
245 See the documentation of `nested-alist-p' for more detail." | |
246 (or (nested-alist-p alist) | |
23196 | 247 (error "Invalid argument %s" alist)) |
17052 | 248 (let ((islist (listp keyseq)) |
249 (len (or len (length keyseq))) | |
250 (i 0) | |
251 key-elt slot) | |
252 (while (< i len) | |
253 (if (null (nested-alist-p alist)) | |
254 (error "Keyseq %s is too long for this nested alist" keyseq)) | |
255 (setq key-elt (if islist (nth i keyseq) (aref keyseq i))) | |
256 (setq slot (assoc key-elt (cdr alist))) | |
257 (if (null slot) | |
258 (progn | |
259 (setq slot (cons key-elt (list t))) | |
260 (setcdr alist (cons slot (cdr alist))))) | |
261 (setq alist (cdr slot)) | |
262 (setq i (1+ i))) | |
263 (setcar alist entry) | |
264 (if branches | |
26890
4cd9407a4683
(set-nested-alist): Set BRANCHES (if
Kenichi Handa <handa@m17n.org>
parents:
26691
diff
changeset
|
265 (setcdr (last alist) branches)))) |
17052 | 266 |
267 ;;;###autoload | |
268 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long) | |
269 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition. | |
270 Optional 1st argument LEN specifies the length of KEYSEQ. | |
271 Optional 2nd argument START specifies index of the starting key. | |
272 The returned value is normally a nested alist of which | |
273 car part is the entry for KEYSEQ. | |
274 If ALIST is not deep enough for KEYSEQ, return number which is | |
275 how many key elements at the front of KEYSEQ it takes | |
276 to reach a leaf in ALIST. | |
277 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil | |
278 even if ALIST is not deep enough." | |
279 (or (nested-alist-p alist) | |
28458 | 280 (error "Invalid argument %s" alist)) |
17052 | 281 (or len |
282 (setq len (length keyseq))) | |
283 (let ((i (or start 0))) | |
284 (if (catch 'lookup-nested-alist-tag | |
285 (if (listp keyseq) | |
286 (while (< i len) | |
287 (if (setq alist (cdr (assoc (nth i keyseq) (cdr alist)))) | |
288 (setq i (1+ i)) | |
289 (throw 'lookup-nested-alist-tag t)))) | |
290 (while (< i len) | |
291 (if (setq alist (cdr (assoc (aref keyseq i) (cdr alist)))) | |
292 (setq i (1+ i)) | |
293 (throw 'lookup-nested-alist-tag t)))) | |
294 ;; KEYSEQ is too long. | |
295 (if nil-for-too-long nil i) | |
296 alist))) | |
297 | |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
298 |
17052 | 299 ;; Coding system related functions. |
300 | |
301 ;;;###autoload | |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
302 (defun coding-system-post-read-conversion (coding-system) |
42049 | 303 "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
|
304 (coding-system-get coding-system :post-read-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
305 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
306 ;;;###autoload |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
307 (defun coding-system-pre-write-conversion (coding-system) |
42049 | 308 "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
|
309 (coding-system-get coding-system :pre-write-conversion)) |
18200
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
310 |
c913160e34a7
(set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents:
17092
diff
changeset
|
311 ;;;###autoload |
22126
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
312 (defun coding-system-translation-table-for-decode (coding-system) |
89483 | 313 "Return the value of CODING-SYSTEM's `decode-translation-table' property." |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
314 (coding-system-get coding-system :decode-translation-table)) |
19455
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
315 |
7cf3d42a6fd7
(coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents:
19264
diff
changeset
|
316 ;;;###autoload |
22126
97cf1cae1971
Change term unification to
Kenichi Handa <handa@m17n.org>
parents:
21554
diff
changeset
|
317 (defun coding-system-translation-table-for-encode (coding-system) |
89483 | 318 "Return the value of CODING-SYSTEM's `encode-translation-table' property." |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
319 (coding-system-get coding-system :encode-translation-table)) |
17052 | 320 |
18299
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
321 ;;;###autoload |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
322 (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
|
323 "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
|
324 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
|
325 or one is an alias of the other." |
c6f35cac24b4
(coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents:
18200
diff
changeset
|
326 (or (eq coding-system-1 coding-system-2) |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
327 (and (equal (coding-system-plist coding-system-1) |
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
328 (coding-system-plist coding-system-2)) |
20113
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
329 (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
|
330 (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
|
331 (or (eq eol-type-1 eol-type-2) |
00ca5f419c16
(coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents:
19932
diff
changeset
|
332 (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
|
333 |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
334 ;;;###autoload |
89483 | 335 (defmacro with-coding-priority (coding-systems &rest body) |
336 "Execute BODY like `progn' with CODING-SYSTEMS at the front of priority list. | |
337 CODING-SYSTEMS is a list of coding systems. See | |
338 `set-coding-priority'. This affects the implicit sorting of lists of | |
339 coding sysems returned by operations such as `find-coding-systems-region'." | |
340 (let ((current (make-symbol "current"))) | |
341 `(let ((,current (coding-system-priority-list))) | |
342 (apply #'set-coding-system-priority ,coding-systems) | |
343 (unwind-protect | |
344 (progn ,@body) | |
345 (apply #'set-coding-system-priority ,current))))) | |
346 (put 'with-coding-priority 'lisp-indent-function 1) | |
347 (put 'with-coding-priority 'edebug-form-spec t) | |
348 | |
349 ;;;###autoload | |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
350 (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
|
351 "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
|
352 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
|
353 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
|
354 `(with-coding-priority (mapcar #'cdr ,priority-list) |
88810 | 355 (detect-coding-region ,from ,to))) |
356 (make-obsolete 'detect-coding-with-priority | |
357 "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
|
358 |
20730
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
359 ;;;###autoload |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
360 (defun detect-coding-with-language-environment (from to lang-env) |
89500
e8de75a86fbc
(detect-coding-with-language-environment): Doc fix.
Dave Love <fx@gnu.org>
parents:
89483
diff
changeset
|
361 "Detect a coding system for the text between FROM and TO with LANG-ENV. |
23196 | 362 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
|
363 language environment LANG-ENV." |
42d729244a85
(find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents:
20162
diff
changeset
|
364 (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
|
365 (if coding-priority |
88652
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
366 (with-coding-priority coding-priority |
8b4e3bbe01d4
(coding-system-post-read-conversion)
Dave Love <fx@gnu.org>
parents:
42049
diff
changeset
|
367 (detect-coding-region from to))))) |
20162
dc6f12ef4d47
(find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents:
20113
diff
changeset
|
368 |
17052 | 369 |
28458 | 370 (provide 'mule-util) |
371 | |
45453
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
372 ;; Local Variables: |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
373 ;; coding: iso-2022-7bit |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
374 ;; End: |
05d77f58ead5
(truncate-string-to-width): New optional argument `ellipsis'. Add
Colin Walters <walters@gnu.org>
parents:
42049
diff
changeset
|
375 |
26890
4cd9407a4683
(set-nested-alist): Set BRANCHES (if
Kenichi Handa <handa@m17n.org>
parents:
26691
diff
changeset
|
376 ;;; mule-util.el ends here |