annotate lisp/international/mule-util.el @ 88790:18d2236f972b

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