Fix last commit.
[gnus] / lisp / mm-util.el
index 7631e5e..50a0ee5 100644 (file)
      ((fboundp 'char-valid-p) 'char-valid-p)
      (t 'identity))))
 
+;; Fixme:  This seems always to be used to read a MIME charset, so it
+;; should be re-named and fixed (in Emacs) to offer completion only on
+;; proper charset names (base coding systems which have a
+;; mime-charset defined).  XEmacs doesn't believe in mime-charset;
+;; test with
+;;   `(or (coding-system-get 'iso-8859-1 'mime-charset)
+;;        (coding-system-get 'iso-8859-1 :mime-charset))'
+;; Actually, there should be an `mm-coding-system-mime-charset'.
 (eval-and-compile
   (defalias 'mm-read-coding-system
     (cond
   (or mm-coding-system-list
       (setq mm-coding-system-list (mm-coding-system-list))))
 
-(defun mm-coding-system-p (sym)
-  "Return non-nil if SYM is a coding system."
-  (if (fboundp 'coding-system-p)
-      (coding-system-p sym)
-    (memq sym (mm-get-coding-system-list))))
+(defun mm-coding-system-p (cs)
+  "Return non-nil if CS is a symbol naming a coding system.
+In XEmacs, also return non-nil if CS is a coding system object."
+  (if (fboundp 'find-coding-system)
+      (find-coding-system cs)
+    (if (fboundp 'coding-system-p)
+       (coding-system-p cs)
+      ;; Is this branch ever actually useful?
+      (memq cs (mm-get-coding-system-list)))))
 
 (defvar mm-charset-synonym-alist
   `(
@@ -296,12 +308,12 @@ Valid elements include:
               ;; Japanese users may prefer iso-2022-jp to shift-jis.
               '(iso-2022-jp iso-2022-jp-2 japanese-shift-jis
                             iso-latin-1 utf-8)))))
-  "Preferred coding systems for encoding outgoing mails.
+  "Preferred coding systems for encoding outgoing messages.
 
-More than one suitable coding system may be found for some text.  By
-default, the coding system with the highest priority is used to encode
-outgoing mails (see `sort-coding-systems').  If this variable is set,
-it overrides the default priority."
+More than one suitable coding system may be found for some text.
+By default, the coding system with the highest priority is used
+to encode outgoing messages (see `sort-coding-systems').  If this
+variable is set, it overrides the default priority."
   :type '(repeat (symbol :tag "Coding system"))
   :group 'mime)
 
@@ -480,6 +492,8 @@ If the charset is `composition', return the actual one."
       (setq result (cons head result)))
     (nreverse result)))
 
+;; Fixme:  This is used in places when it should be testing the
+;; default multibyteness.  See mm-default-multibyte-p.
 (eval-and-compile
   (if (and (not (featurep 'xemacs))
           (boundp 'enable-multibyte-characters))
@@ -488,6 +502,14 @@ If the charset is `composition', return the actual one."
        enable-multibyte-characters)
     (defun mm-multibyte-p () (featurep 'mule))))
 
+(defun mm-default-multibyte-p ()
+  "Return non-nil if the session is multibyte.
+This affects whether coding conversion should be attempted generally."
+  (if (featurep 'mule)
+      (if (boundp 'default-enable-multibyte-characters)
+         default-enable-multibyte-characters
+       t)))
+
 (defun mm-iso-8859-x-to-15-region (&optional b e)
   (if (fboundp 'char-charset)
       (let (charset item c inconvertible)
@@ -543,16 +565,24 @@ charset, and a longer list means no appropriate charset."
                     ;; `compound-text' is not in the IANA list.  We
                     ;; shouldn't normally use anything here with a
                     ;; mime-charset having an `x-' prefix.
-                    ;; Fixme:  allow this to be overridden, since
+                    ;; Fixme:  Allow this to be overridden, since
                     ;; there is existing use of x-ctext.
                     ;; Also people apparently need the coding system
-                    ;; `iso-2022-jp-3', which Mule-UCS defines.
+                    ;; `iso-2022-jp-3' (which Mule-UCS defines with
+                    ;; mime-charset, though it's not valid).
                     (if (and cs
-                             (not (string-match "^[Xx]-" (symbol-name cs))))
+                             (not (string-match "^[Xx]-" (symbol-name cs)))
+                             ;; UTF-16 of any variety is invalid for
+                             ;; text parts and, unfortunately, has
+                             ;; mime-charset defined both in Mule-UCS
+                             ;; and versions of Emacs.  (The name
+                             ;; might be `mule-utf-16...'  or
+                             ;; `utf-16...'.)
+                             (not (string-match "utf-16" (symbol-name cs))))
                         (setq systems nil
                               charsets (list cs))))))
               charsets))
-       ;; Otherwise we're not multibyte, we're XEmacs or a single
+       ;; Otherwise we're not multibyte, we're XEmacs, or a single
        ;; coding system won't cover it.
        (setq charsets
              (mm-delete-duplicates
@@ -670,10 +700,10 @@ Equivalent to `progn' in XEmacs"
 
 (defun mm-insert-file-contents (filename &optional visit beg end replace
                                         inhibit)
-  "Like `insert-file-contents', q.v., but only reads in the file.
+  "Like `insert-file-contents', but only reads in the file.
 A buffer may be modified in several ways after reading into the buffer due
 to advanced Emacs features, such as file-name-handlers, format decoding,
-find-file-hooks, etc.
+`find-file-hooks', etc.
 If INHIBIT is non-nil, inhibit `mm-inhibit-file-name-handlers'.
   This function ensures that none of these modifications will take place."
   (let ((format-alist nil)
@@ -712,7 +742,8 @@ If INHIBIT is non-nil, inhibit `mm-inhibit-file-name-handlers'."
             (append mm-inhibit-file-name-handlers
                     inhibit-file-name-handlers)
           inhibit-file-name-handlers)))
-    (append-to-file start end filename)))
+    (write-region start end filename t 'no-message)
+    (message "Appended to %s" filename)))
 
 (defun mm-write-region (start end filename &optional append visit lockname
                              coding-system inhibit)
@@ -768,30 +799,6 @@ If INHIBIT is non-nil, inhibit `mm-inhibit-file-name-handlers'."
     (let ((cs (mm-detect-coding-region start end)))
       cs)))
 
-(defun mm-guess-mime-charset ()
-  "Guess the default MIME charset from the language environment."
-  (let ((language-info
-        (and (boundp 'current-language-environment)
-             (assoc current-language-environment
-                    language-info-alist)))
-       item)
-    (cond
-     ((null language-info)
-      'iso-8859-1)
-     ((setq item
-           (cadr
-            (or (assq 'coding-priority language-info)
-                (assq 'coding-system language-info))))
-      (if (fboundp 'coding-system-get)
-         (or (coding-system-get item 'mime-charset)
-             item)
-       item))
-     ((setq item (car (last (assq 'charset language-info))))
-      (if (eq item 'ascii)
-         'iso-8859-1
-       (mm-mime-charset item)))
-     (t
-      'iso-8859-1))))
 
 (provide 'mm-util)