+(defun nnheader-ms-strip-cr ()
+ "Strip ^M from the end of all lines."
+ (save-excursion
+ (nnheader-remove-cr-followed-by-lf)))
+
+(defun nnheader-file-size (file)
+ "Return the file size of FILE or 0."
+ (or (nth 7 (file-attributes file)) 0))
+
+(defun nnheader-find-etc-directory (package &optional file first)
+ "Go through `load-path' and find the \"../etc/PACKAGE\" directory.
+This function will look in the parent directory of each `load-path'
+entry, and look for the \"etc\" directory there.
+If FILE, find the \".../etc/PACKAGE\" file instead.
+If FIRST is non-nil, return the directory or the file found at the
+first. Otherwise, find the newest one, though it may take a time."
+ (let ((path load-path)
+ dir results)
+ ;; We try to find the dir by looking at the load path,
+ ;; stripping away the last component and adding "etc/".
+ (while path
+ (if (and (car path)
+ (file-exists-p
+ (setq dir (concat
+ (file-name-directory
+ (directory-file-name (car path)))
+ "etc/" package
+ (if file "" "/"))))
+ (or file (file-directory-p dir)))
+ (progn
+ (or (member dir results)
+ (push dir results))
+ (setq path (if first nil (cdr path))))
+ (setq path (cdr path))))
+ (if (or first (not (cdr results)))
+ (car results)
+ (car (sort results 'file-newer-than-file-p)))))
+
+(defvar ange-ftp-path-format)
+(defvar efs-path-regexp)
+(defun nnheader-re-read-dir (path)
+ "Re-read directory PATH if PATH is on a remote system."
+ (if (and (fboundp 'efs-re-read-dir) (boundp 'efs-path-regexp))
+ (when (string-match efs-path-regexp path)
+ (efs-re-read-dir path))
+ (when (and (fboundp 'ange-ftp-re-read-dir) (boundp 'ange-ftp-path-format))
+ (when (string-match (car ange-ftp-path-format) path)
+ (ange-ftp-re-read-dir path)))))
+
+(defvar nnheader-file-coding-system 'raw-text
+ "Coding system used in file backends of Gnus.")
+
+(defun nnheader-insert-file-contents (filename &optional visit beg end replace)
+ "Like `insert-file-contents', q.v., 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.
+ This function ensures that none of these modifications will take place."
+ (let ((coding-system-for-read nnheader-file-coding-system))
+ (mm-insert-file-contents filename visit beg end replace)))
+
+(defun nnheader-insert-nov-file (file first)
+ (let ((size (nth 7 (file-attributes file)))
+ (cutoff (* 32 1024)))
+ (when size
+ (if (< size cutoff)
+ ;; If the file is small, we just load it.
+ (nnheader-insert-file-contents file)
+ ;; We start on the assumption that FIRST is pretty recent. If
+ ;; not, we just insert the rest of the file as well.
+ (let (current)
+ (nnheader-insert-file-contents file nil (- size cutoff) size)
+ (goto-char (point-min))
+ (delete-region (point) (or (search-forward "\n" nil 'move) (point)))
+ (setq current (ignore-errors (read (current-buffer))))
+ (if (and (numberp current)
+ (< current first))
+ t
+ (delete-region (point-min) (point-max))
+ (nnheader-insert-file-contents file)))))))
+
+(defun nnheader-find-file-noselect (&rest args)
+ "Open a file with some variables bound.
+See `find-file-noselect' for the arguments."
+ (let* ((format-alist nil)
+ (auto-mode-alist (mm-auto-mode-alist))
+ (default-major-mode 'fundamental-mode)
+ (enable-local-variables nil)
+ (after-insert-file-functions nil)
+ (enable-local-eval nil)
+ (coding-system-for-read nnheader-file-coding-system)
+ (version-control 'never)
+ (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 args)
+ (set ffh val))))
+
+(defun nnheader-directory-regular-files (dir)
+ "Return a list of all regular files in DIR."
+ (let ((files (directory-files dir t))
+ out)
+ (while files
+ (when (file-regular-p (car files))
+ (push (car files) out))
+ (pop files))
+ (nreverse out)))
+
+(defun nnheader-directory-files (&rest args)
+ "Same as `directory-files', but prune \".\" and \"..\"."
+ (let ((files (apply 'directory-files args))
+ out)
+ (while files
+ (unless (member (file-name-nondirectory (car files)) '("." ".."))
+ (push (car files) out))
+ (pop files))
+ (nreverse out)))
+
+(defmacro nnheader-skeleton-replace (from &optional to regexp)
+ `(let ((new (generate-new-buffer " *nnheader replace*"))
+ (cur (current-buffer))
+ (start (point-min)))
+ (set-buffer cur)
+ (goto-char (point-min))
+ (while (,(if regexp 're-search-forward 'search-forward)
+ ,from nil t)
+ (insert-buffer-substring
+ cur start (prog1 (match-beginning 0) (set-buffer new)))
+ (goto-char (point-max))
+ ,(when to `(insert ,to))
+ (set-buffer cur)
+ (setq start (point)))
+ (insert-buffer-substring
+ cur start (prog1 (point-max) (set-buffer new)))
+ (copy-to-buffer cur (point-min) (point-max))
+ (kill-buffer (current-buffer))
+ (set-buffer cur)))
+
+(defun nnheader-replace-string (from to)
+ "Do a fast replacement of FROM to TO from point to `point-max'."
+ (nnheader-skeleton-replace from to))
+
+(defun nnheader-replace-regexp (from to)
+ "Do a fast regexp replacement of FROM to TO from point to `point-max'."
+ (nnheader-skeleton-replace from to t))
+
+(defun nnheader-strip-cr ()
+ "Strip all \r's from the current buffer."
+ (nnheader-skeleton-replace "\r"))
+
+(defalias 'nnheader-cancel-timer 'cancel-timer)
+(defalias 'nnheader-cancel-function-timers 'cancel-function-timers)
+(defalias 'nnheader-string-as-multibyte 'string-as-multibyte)
+
+(defun nnheader-accept-process-output (process)
+ (accept-process-output
+ process
+ (truncate nnheader-read-timeout)
+ (truncate (* (- nnheader-read-timeout
+ (truncate nnheader-read-timeout))
+ 1000))))
+
+(when (featurep 'xemacs)
+ (require 'nnheaderxm))