aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa1998-04-06 05:07:36 +0000
committerKenichi Handa1998-04-06 05:07:36 +0000
commit3fc7dfe527f861a0409fd605fe4ec054f752d5a6 (patch)
tree28049759990f3ee69493c9638be0921499d7a840
parent533d3a6f5a0043af3f66b72c3c9299b89e8106b3 (diff)
downloademacs-3fc7dfe527f861a0409fd605fe4ec054f752d5a6.tar.gz
emacs-3fc7dfe527f861a0409fd605fe4ec054f752d5a6.zip
(subset-p): Renamed from
find-safe-coding-system-list-subset-p. (find-coding-systems-region, find-coding-systems-string): New functions. (find-coding-systems-for-charsets): Renamed from find-safe-coding-system. This is now a helper function of the above two. (select-safe-coding-system): Adjusted for the above changes.
-rw-r--r--lisp/international/mule-cmds.el90
1 files changed, 50 insertions, 40 deletions
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index 509672cee6d..a6526ff0160 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -228,7 +228,7 @@ This also sets the following values:
228 base coding-system)) 228 base coding-system))
229 (set-default-coding-systems (or base coding-system)))) 229 (set-default-coding-systems (or base coding-system))))
230 230
231(defun find-safe-coding-system-list-subset-p (list1 list2) 231(defun subset-p (list1 list2)
232 "Return non-nil if all elements in LIST1 are included in LIST2. 232 "Return non-nil if all elements in LIST1 are included in LIST2.
233Comparison done with EQ." 233Comparison done with EQ."
234 (catch 'tag 234 (catch 'tag
@@ -238,50 +238,58 @@ Comparison done with EQ."
238 (setq list1 (cdr list1))) 238 (setq list1 (cdr list1)))
239 t)) 239 t))
240 240
241(defun find-safe-coding-system (from to) 241(defun find-coding-systems-region (from to)
242 "Return a list of proper coding systems to encode a text between FROM and TO. 242 "Return a list of proper coding systems to encode a text between FROM and TO.
243All coding systems in the list can safely encode any multibyte characters 243All coding systems in the list can safely encode any multibyte characters
244in the text. 244in the text.
245 245
246If the text contains no multibyte charcters, return a list of a single 246If the text contains no multibyte charcters, return a list of a single
247element `undecided'. 247element `undecided'."
248 (find-coding-systems-for-charsets (find-charset-region from to)))
248 249
249Kludgy feature: if FROM is a string, the string is the target text, 250(defun find-coding-systems-string (string)
250and TO is ignored." 251 "Return a list of proper coding systems to encode STRING.
251 (let ((charset-list (if (stringp from) (find-charset-string from) 252All coding systems in the list can safely encode any multibyte characters
252 (find-charset-region from to)))) 253in STRING.
253 (if (or (null charset-list) 254
254 (and (= (length charset-list) 1) 255If STRING contains no multibyte charcters, return a list of a single
255 (eq 'ascii (car charset-list)))) 256element `undecided'."
256 '(undecided) 257 (find-coding-systems-for-charsets (find-charset-string string)))
257 (let ((l coding-system-list) 258
258 (prefered-codings 259(defun find-coding-systems-for-charsets (charsets)
259 (mapcar (function 260 "Return a list of proper coding systems to encode characters of CHARSETS.
260 (lambda (x) 261CHARSETS is a list of character sets."
261 (get-charset-property x 'prefered-coding-system))) 262 (if (or (null charsets)
262 charset-list)) 263 (and (= (length charsets) 1)
263 codings coding safe) 264 (eq 'ascii (car charsets))))
264 (while l 265 '(undecided)
265 (setq coding (car l) l (cdr l)) 266 (let ((l coding-system-list)
266 (if (and (eq coding (coding-system-base coding)) 267 (prefered-codings
267 (setq safe (coding-system-get coding 'safe-charsets)) 268 (mapcar (function
268 (or (eq safe t) 269 (lambda (x)
269 (find-safe-coding-system-list-subset-p 270 (get-charset-property x 'prefered-coding-system)))
270 charset-list safe))) 271 charsets))
271 ;; We put the higher priority to coding systems included 272 codings coding safe)
272 ;; in PREFERED-CODINGS, and within them, put the higher 273 (while l
273 ;; priority to coding systems which support smaller 274 (setq coding (car l) l (cdr l))
274 ;; number of charsets. 275 (if (and (eq coding (coding-system-base coding))
275 (let ((priority 276 (setq safe (coding-system-get coding 'safe-charsets))
276 (logior (if (coding-system-get coding 'mime-charset) 277 (or (eq safe t)
277 256 0) 278 (subset-p charsets safe)))
278 (if (memq coding prefered-codings) 128 0) 279 ;; We put the higher priority to coding systems included
279 (if (> (coding-system-type coding) 0) 64 0) 280 ;; in PREFERED-CODINGS, and within them, put the higher
280 (if (consp safe) (- 64 (length safe)) 0)))) 281 ;; priority to coding systems which support smaller
281 (setq codings (cons (cons priority coding) codings))))) 282 ;; number of charsets.
282 (mapcar 'cdr 283 (let ((priority
283 (sort codings (function (lambda (x y) (> (car x) (car y)))))) 284 (logior (if (coding-system-get coding 'mime-charset)
284 )))) 285 256 0)
286 (if (memq coding prefered-codings) 128 0)
287 (if (> (coding-system-type coding) 0) 64 0)
288 (if (consp safe) (- 64 (length safe)) 0))))
289 (setq codings (cons (cons priority coding) codings)))))
290 (mapcar 'cdr
291 (sort codings (function (lambda (x y) (> (car x) (car y))))))
292 )))
285 293
286(defun select-safe-coding-system (from to &optional default-coding-system) 294(defun select-safe-coding-system (from to &optional default-coding-system)
287 "Ask a user to select a safe coding system from candidates. 295 "Ask a user to select a safe coding system from candidates.
@@ -299,7 +307,9 @@ Kludgy feature: if FROM is a string, the string is the target text,
299and TO is ignored." 307and TO is ignored."
300 (or default-coding-system 308 (or default-coding-system
301 (setq default-coding-system buffer-file-coding-system)) 309 (setq default-coding-system buffer-file-coding-system))
302 (let ((safe-coding-systems (find-safe-coding-system from to))) 310 (let ((safe-coding-systems (if (stringp from)
311 (find-coding-systems-string from)
312 (find-coding-systems-region from to))))
303 (if (or (eq (car safe-coding-systems) 'undecided) 313 (if (or (eq (car safe-coding-systems) 'undecided)
304 (and default-coding-system 314 (and default-coding-system
305 (memq (coding-system-base default-coding-system) 315 (memq (coding-system-base default-coding-system)