comparison lisp/gnus/mm-util.el @ 41494:933ab100fb4a

2001-11-25 ShengHuo ZHU <zsh@cs.rochester.edu> * gnus-util.el (gnus-directory-sep-char-regexp): New. * gnus-score.el (gnus-score-find-bnews): Sync with Gnus CVS. * mm-util.el: Sync. * gnus-sum.el (gnus-summary-limit-to-subject): An exclusion version. (gnus-summary-limit-to-author): Ditto. (gnus-summary-limit-to-extra): Ditto. (gnus-summary-find-matching): Support not-matching argument. * message.el (message-wash-subject): Use `insert' rather than `insert-string', which is deprecated. From Kai Gro,A_(Bjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE>
author ShengHuo ZHU <zsh@cs.rochester.edu>
date Sun, 25 Nov 2001 15:17:24 +0000
parents 11741b5b7d18
children 0f4506820432
comparison
equal deleted inserted replaced
41493:d85992144288 41494:933ab100fb4a
161 ((mm-coding-system-p 'escape-quoted) 'escape-quoted) 161 ((mm-coding-system-p 'escape-quoted) 'escape-quoted)
162 (t mm-binary-coding-system)) 162 (t mm-binary-coding-system))
163 "Coding system of auto save file.") 163 "Coding system of auto save file.")
164 164
165 (defvar mm-universal-coding-system mm-auto-save-coding-system 165 (defvar mm-universal-coding-system mm-auto-save-coding-system
166 "The universal Coding system.") 166 "The universal coding system.")
167 167
168 ;; Fixme: some of the cars here aren't valid MIME charsets. That 168 ;; Fixme: some of the cars here aren't valid MIME charsets. That
169 ;; should only matter with XEmacs, though. 169 ;; should only matter with XEmacs, though.
170 (defvar mm-mime-mule-charset-alist 170 (defvar mm-mime-mule-charset-alist
171 `((us-ascii ascii) 171 `((us-ascii ascii)
236 (list (cons (coding-system-get cs 'mime-charset) 236 (list (cons (coding-system-get cs 'mime-charset)
237 (delq 'ascii 237 (delq 'ascii
238 (coding-system-get cs 'safe-charsets)))))) 238 (coding-system-get cs 'safe-charsets))))))
239 (sort-coding-systems (coding-system-list 'base-only)))))) 239 (sort-coding-systems (coding-system-list 'base-only))))))
240 240
241 (defvar mm-hack-charsets '(iso-8859-15 iso-2022-jp-2)
242 "A list of special charsets.
243 Valid elements include:
244 `iso-8859-15' convert ISO-8859-1, -9 to ISO-8859-15 if ISO-8859-15 exists.
245 `iso-2022-jp-2' convert ISO-2022-jp to ISO-2022-jp-2 if ISO-2022-jp-2 exists."
246 )
247
248 (defvar mm-iso-8859-15-compatible
249 '((iso-8859-1 "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE")
250 (iso-8859-9 "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE\xD0\xDD\xDE\xF0\xFD\xFE"))
251 "ISO-8859-15 exchangeable coding systems and inconvertible characters.")
252
253 (defvar mm-iso-8859-x-to-15-table
254 (and (fboundp 'coding-system-p)
255 (mm-coding-system-p 'iso-8859-15)
256 (mapcar
257 (lambda (cs)
258 (if (mm-coding-system-p (car cs))
259 (let ((c (string-to-char
260 (decode-coding-string "\341" (car cs)))))
261 (cons (char-charset c)
262 (cons
263 (- (string-to-char
264 (decode-coding-string "\341" 'iso-8859-15)) c)
265 (string-to-list (decode-coding-string (car (cdr cs))
266 (car cs))))))
267 '(gnus-charset 0)))
268 mm-iso-8859-15-compatible))
269 "A table of the difference character between ISO-8859-X and ISO-8859-15.")
270
271 (defvar mm-coding-system-priorities nil
272 "Preferred coding systems for encoding outgoing mails.
273
274 More than one suitable coding systems may be found for some texts. By
275 default, a coding system with the highest priority is used to encode
276 outgoing mails (see `sort-coding-systems'). If this variable is set,
277 it overrides the default priority. For example, Japanese users may
278 prefer iso-2022-jp to japanese-shift-jis:
279
280 \(setq mm-coding-system-priorities
281 '(iso-2022-jp iso-2022-jp-2 japanese-shift-jis utf-8))
282 ")
283
241 ;;; Internal variables: 284 ;;; Internal variables:
242 285
243 ;;; Functions: 286 ;;; Functions:
244 287
245 (defun mm-mule-charset-to-mime-charset (charset) 288 (defun mm-mule-charset-to-mime-charset (charset)
268 (when (stringp charset) 311 (when (stringp charset)
269 (setq charset (intern (downcase charset)))) 312 (setq charset (intern (downcase charset))))
270 (when lbt 313 (when lbt
271 (setq charset (intern (format "%s-%s" charset lbt)))) 314 (setq charset (intern (format "%s-%s" charset lbt))))
272 (cond 315 (cond
316 ((null charset)
317 charset)
273 ;; Running in a non-MULE environment. 318 ;; Running in a non-MULE environment.
274 ((null (mm-get-coding-system-list)) 319 ((null (mm-get-coding-system-list))
275 charset) 320 charset)
276 ;; ascii 321 ;; ascii
277 ((eq charset 'us-ascii) 322 ((eq charset 'us-ascii)
346 (set-buffer-multibyte nil)) 391 (set-buffer-multibyte nil))
347 (defalias 'mm-disable-multibyte-mule4 'ignore))) 392 (defalias 'mm-disable-multibyte-mule4 'ignore)))
348 393
349 (defun mm-preferred-coding-system (charset) 394 (defun mm-preferred-coding-system (charset)
350 ;; A typo in some Emacs versions. 395 ;; A typo in some Emacs versions.
351 (or (get-charset-property charset 'prefered-coding-system) 396 (or (get-charset-property charset 'preferred-coding-system)
352 (get-charset-property charset 'preferred-coding-system))) 397 (get-charset-property charset 'prefered-coding-system)))
353 398
354 (defun mm-charset-after (&optional pos) 399 (defun mm-charset-after (&optional pos)
355 "Return charset of a character in current buffer at position POS. 400 "Return charset of a character in current buffer at position POS.
356 If POS is nil, it defauls to the current point. 401 If POS is nil, it defauls to the current point.
357 If POS is out of range, the value is nil. 402 If POS is out of range, the value is nil.
418 (if (and (not (featurep 'xemacs)) 463 (if (and (not (featurep 'xemacs))
419 (boundp 'enable-multibyte-characters)) 464 (boundp 'enable-multibyte-characters))
420 enable-multibyte-characters 465 enable-multibyte-characters
421 (featurep 'mule))) 466 (featurep 'mule)))
422 467
423 (defun mm-find-mime-charset-region (b e) 468 (defun mm-iso-8859-x-to-15-region (&optional b e)
469 (if (fboundp 'char-charset)
470 (let (charset item c inconvertible)
471 (save-restriction
472 (if e (narrow-to-region b e))
473 (goto-char (point-min))
474 (skip-chars-forward "\0-\177")
475 (while (not (eobp))
476 (cond
477 ((not (setq item (assq (char-charset (setq c (char-after)))
478 mm-iso-8859-x-to-15-table)))
479 (forward-char))
480 ((memq c (cdr (cdr item)))
481 (setq inconvertible t)
482 (forward-char))
483 (t
484 (insert (prog1 (+ c (car (cdr item))) (delete-char 1))))
485 (skip-chars-forward "\0-\177"))))
486 (not inconvertible))))
487
488 (defun mm-sort-coding-systems-predicate (a b)
489 (> (length (memq a mm-coding-system-priorities))
490 (length (memq b mm-coding-system-priorities))))
491
492 (defun mm-find-mime-charset-region (b e &optional hack-charsets)
424 "Return the MIME charsets needed to encode the region between B and E. 493 "Return the MIME charsets needed to encode the region between B and E.
425 Nil means ASCII, a single-element list represents an appropriate MIME 494 Nil means ASCII, a single-element list represents an appropriate MIME
426 charset, and a longer list means no appropriate charset." 495 charset, and a longer list means no appropriate charset."
427 ;; The return possibilities of this function are a mess... 496 (let (charsets)
428 (or (and 497 ;; The return possibilities of this function are a mess...
429 (mm-multibyte-p) 498 (or (and (mm-multibyte-p)
430 (fboundp 'find-coding-systems-region) 499 (fboundp 'find-coding-systems-region)
431 ;; Find the mime-charset of the most preferred coding 500 ;; Find the mime-charset of the most preferred coding
432 ;; system that has one. 501 ;; system that has one.
433 (let ((systems (find-coding-systems-region b e)) 502 (let ((systems (find-coding-systems-region b e)))
434 result) 503 (when mm-coding-system-priorities
435 ;; Fixme: The `mime-charset' (`x-ctext') of `compound-text' 504 (setq systems
436 ;; is not in the IANA list. 505 (sort systems 'mm-sort-coding-systems-predicate)))
437 (setq systems (delq 'compound-text systems)) 506 ;; Fixme: The `mime-charset' (`x-ctext') of `compound-text'
438 (unless (equal systems '(undecided)) 507 ;; is not in the IANA list.
439 (while systems 508 (setq systems (delq 'compound-text systems))
440 (let ((cs (coding-system-get (pop systems) 'mime-charset))) 509 (unless (equal systems '(undecided))
441 (if cs 510 (while systems
442 (setq systems nil 511 (let ((cs (coding-system-get (pop systems) 'mime-charset)))
443 result (list cs)))))) 512 (if cs
444 result)) 513 (setq systems nil
445 ;; Otherwise we're not multibyte, XEmacs or a single coding 514 charsets (list cs))))))
446 ;; system won't cover it. 515 charsets))
447 (let ((charsets 516 ;; Otherwise we're not multibyte, XEmacs or a single coding
448 (mm-delete-duplicates 517 ;; system won't cover it.
449 (mapcar 'mm-mime-charset 518 (setq charsets
450 (delq 'ascii 519 (mm-delete-duplicates
451 (mm-find-charset-region b e)))))) 520 (mapcar 'mm-mime-charset
452 (if (memq 'iso-2022-jp-2 charsets) 521 (delq 'ascii
453 (delq 'iso-2022-jp charsets) 522 (mm-find-charset-region b e))))))
454 charsets)))) 523 (if (and (memq 'iso-8859-15 charsets)
524 (memq 'iso-8859-15 hack-charsets)
525 (save-excursion (mm-iso-8859-x-to-15-region b e)))
526 (mapcar (lambda (x) (setq charsets (delq (car x) charsets)))
527 mm-iso-8859-15-compatible))
528 (if (and (memq 'iso-2022-jp-2 charsets)
529 (memq 'iso-2022-jp-2 hack-charsets))
530 (setq charsets (delq 'iso-2022-jp charsets)))
531 charsets))
455 532
456 (defmacro mm-with-unibyte-buffer (&rest forms) 533 (defmacro mm-with-unibyte-buffer (&rest forms)
457 "Create a temporary buffer, and evaluate FORMS there like `progn'. 534 "Create a temporary buffer, and evaluate FORMS there like `progn'.
458 Use unibyte mode for this." 535 Use unibyte mode for this."
459 `(let (default-enable-multibyte-characters) 536 `(let (default-enable-multibyte-characters)