Synch to No Gnus 200601131944.
[elisp/gnus.git-] / lisp / nnheader.el
index 4528d1d..193bcbf 100644 (file)
@@ -1,8 +1,8 @@
 ;;; nnheader.el --- header access macros for Semi-gnus and its backends
 
-;; Copyright (C) 1987, 1988, 1989, 1990, 1993, 1994, 1995, 1996,
-;;        1997, 1998, 2000, 2001, 2002, 2003, 2004
-;;        Free Software Foundation, Inc.
+;; Copyright (C) 1987, 1988, 1989, 1990, 1993, 1994,
+;;   1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003,
+;;   2004, 2005 Free Software Foundation, Inc.
 
 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
 ;;     Lars Magne Ingebrigtsen <larsi@gnus.org>
@@ -24,8 +24,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -34,6 +34,8 @@
 (eval-when-compile (require 'cl))
 (eval-when-compile (require 'static))
 
+(defvar nnmail-extra-headers)
+
 ;; Requiring `gnus-util' at compile time creates a circular
 ;; dependency between nnheader.el and gnus-util.el.
 ;;(eval-when-compile (require 'gnus-util))
@@ -147,6 +149,8 @@ This variable is a substitute for `mm-text-coding-system-for-write'.")
   (autoload 'gnus-buffer-live-p "gnus-util"))
 
 ;; mm-util stuff.
+(defvar mm-emacs-mule t "True in Emacs with Mule.")
+
 (unless (featurep 'mm-util)
   ;; Should keep track of `mm-image-load-path' in mm-util.el.
   (defun nnheader-image-load-path (&optional package)
@@ -170,6 +174,9 @@ This variable is a substitute for `mm-text-coding-system-for-write'.")
       'ignore))
   (defalias 'mm-encode-coding-string 'encode-coding-string)
   (defalias 'mm-decode-coding-string 'decode-coding-string)
+  (defalias 'mm-encode-coding-region 'encode-coding-region)
+  (defalias 'mm-decode-coding-region 'decode-coding-region)
+  (defalias 'mm-set-buffer-file-coding-system 'set-buffer-file-coding-system)
 
   ;; Should keep track of `mm-detect-coding-region' in mm-util.el.
   (defun nnheader-detect-coding-region (start end)
@@ -199,6 +206,18 @@ Use unibyte mode for this."
   (put 'mm-with-unibyte-buffer 'edebug-form-spec '(body))
   (defalias 'mm-with-unibyte-buffer 'nnheader-with-unibyte-buffer)
 
+  ;; Should keep track of `mm-with-multibyte-buffer' in mm-util.el.
+  (defmacro nnheader-with-multibyte-buffer (&rest forms)
+    "Create a temporary buffer, and evaluate FORMS there like `progn'.
+Use multibyte mode for this."
+    `(let ((default-enable-multibyte-characters t))
+       (with-temp-buffer ,@forms)))
+  (put 'nnheader-with-multibyte-buffer 'lisp-indent-function 0)
+  (put 'nnheader-with-multibyte-buffer 'edebug-form-spec '(body))
+  (put 'mm-with-multibyte-buffer 'lisp-indent-function 0)
+  (put 'mm-with-multibyte-buffer 'edebug-form-spec '(body))
+  (defalias 'mm-with-multibyte-buffer 'nnheader-with-multibyte-buffer)
+
   ;; Should keep track of `mm-with-unibyte-current-buffer' in mm-util.el.
   (defmacro nnheader-with-unibyte-current-buffer (&rest forms)
     "Evaluate FORMS with current current buffer temporarily made unibyte.
@@ -317,7 +336,24 @@ nil, ."
     (cond
      ((fboundp 'char-or-char-int-p) 'char-or-char-int-p)
      ((fboundp 'char-valid-p) 'char-valid-p)
-     (t 'identity))))
+     (t 'identity)))
+
+  ;; Should keep track of the same function in mm-util.el.
+  (if (fboundp 'delete-dups)
+      (defalias 'mm-delete-duplicates 'delete-dups)
+    (defun mm-delete-duplicates (list)
+      "Destructively remove `equal' duplicates from LIST.
+Store the result in LIST and return it.  LIST must be a proper list.
+Of several `equal' occurrences of an element in LIST, the first
+one is kept.
+
+This is a compatibility function for Emacsen without `delete-dups'."
+      ;; Code from `subr.el' in Emacs 22:
+      (let ((tail list))
+       (while tail
+         (setcdr tail (delete (car tail) (cdr tail)))
+         (setq tail (cdr tail))))
+      list)))
 
 ;; mail-parse stuff.
 (unless (featurep 'mail-parse)
@@ -575,7 +611,10 @@ given, the return value will not contain the last newline."
   (mime-find-field-decoder 'From 'nov))
 
 (defalias 'mail-header-extra 'mime-gnus-entity-extra-internal)
-(defalias 'mail-header-set-extra 'mime-gnus-entity-set-extra-internal)
+
+(defun mail-header-set-extra (header extra)
+  "Set the extra headers in HEADER to EXTRA."
+  (mime-gnus-entity-set-extra-internal header extra))
 
 (defun nnheader-decode-field-body (field-body field-name
                                              &optional mode max-column)
@@ -1295,9 +1334,9 @@ list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
 (defsubst nnheader-file-to-number (file)
   "Take a FILE name and return the article number."
   (if (string= nnheader-numerical-short-files "^[0-9]+$")
-      (string-to-int file)
+      (string-to-number file)
     (string-match nnheader-numerical-short-files file)
-    (string-to-int (match-string 0 file))))
+    (string-to-number (match-string 0 file))))
 
 (defvar nnheader-directory-files-is-safe
   (or (eq system-type 'windows-nt)
@@ -1550,15 +1589,21 @@ 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.
   This function ensures that none of these modifications will take place."
-  (let ((format-alist nil)
-       (auto-mode-alist (nnheader-auto-mode-alist))
-       (default-major-mode 'fundamental-mode)
-       (enable-local-variables nil)
-       (after-insert-file-functions nil)
-       (enable-local-eval nil)
-       (find-file-hooks nil))
-    (insert-file-contents-as-coding-system
-     nnheader-file-coding-system filename visit beg end replace)))
+  (let* ((format-alist nil)
+        (auto-mode-alist (nnheader-auto-mode-alist))
+        (default-major-mode 'fundamental-mode)
+        (enable-local-variables nil)
+        (after-insert-file-functions nil)
+        (enable-local-eval nil)
+        (ffh (if (boundp 'find-file-hook)
+                 'find-file-hook
+               'find-file-hooks))
+        (val (symbol-value ffh)))
+    (set ffh nil)
+    (unwind-protect
+       (insert-file-contents-as-coding-system
+        nnheader-file-coding-system filename visit beg end replace)
+      (set ffh val))))
 
 (defun nnheader-insert-nov-file (file first)
   (let ((size (nth 7 (file-attributes file)))
@@ -1581,15 +1626,23 @@ find-file-hooks, etc.
             (nnheader-insert-file-contents file)))))))
 
 (defun nnheader-find-file-noselect (&rest args)
-  (let ((format-alist nil)
-       (auto-mode-alist (nnheader-auto-mode-alist))
-       (default-major-mode 'fundamental-mode)
-       (enable-local-variables nil)
-       (after-insert-file-functions nil)
-       (enable-local-eval nil)
-       (find-file-hooks nil))
-    (apply 'find-file-noselect-as-coding-system
-          nnheader-file-coding-system args)))
+  "Open a file with some variables bound.
+See `find-file-noselect' for the arguments."
+  (let* ((format-alist nil)
+        (auto-mode-alist (nnheader-auto-mode-alist))
+        (default-major-mode 'fundamental-mode)
+        (enable-local-variables nil)
+        (after-insert-file-functions nil)
+        (enable-local-eval nil)
+        (ffh (if (boundp 'find-file-hook)
+                 'find-file-hook
+               'find-file-hooks))
+        (val (symbol-value ffh)))
+    (set ffh nil)
+    (unwind-protect
+       (apply 'find-file-noselect-as-coding-system
+              nnheader-file-coding-system args)
+      (set ffh val))))
 
 (defun nnheader-auto-mode-alist ()
   "Return an `auto-mode-alist' with only the .gz (etc) thingies."