*** empty log message ***
[gnus] / lisp / gnus-art.el
index 77edaa7..22c843f 100644 (file)
 
 ;;; Code:
 
-(require 'gnus-load)
+(require 'gnus)
 (require 'gnus-sum)
 (require 'article)
 (require 'gnus-spec)
 (require 'gnus-int)
 (require 'browse-url)
 
-(defvar gnus-article-save-directory gnus-directory
-  "*Name of the directory articles will be saved in (default \"~/News\").")
+(defcustom gnus-article-save-directory gnus-directory
+  "*Name of the directory articles will be saved in (default \"~/News\")."
+  :group 'article
+  :type 'directory)
 
-(defvar gnus-save-all-headers t
-  "*If non-nil, don't remove any headers before saving.")
+(defcustom gnus-save-all-headers t
+  "*If non-nil, don't remove any headers before saving."
+  :group 'article
+  :type 'boolean)
 
-(defvar gnus-prompt-before-saving 'always
+(defcustom gnus-prompt-before-saving 'always
   "*This variable says how much prompting is to be done when saving articles.
 If it is nil, no prompting will be done, and the articles will be
 saved to the default files.  If this variable is `always', each and
 every article that is saved will be preceded by a prompt, even when
 saving large batches of articles.  If this variable is neither nil not
 `always', there the user will be prompted once for a file name for
-each invocation of the saving commands.")
-
-(defvar gnus-saved-headers gnus-visible-headers
-  "*Headers to keep if `gnus-save-all-headers' is nil.
+each invocation of the saving commands."
+  :group 'article
+  :type '(choice (item always)
+                (item :tag "never" nil)
+                (sexp :tag "once" :format "%t")))
+
+(defcustom gnus-saved-headers gnus-visible-headers
+  "Headers to keep if `gnus-save-all-headers' is nil.
 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
 If that variable is nil, however, all headers that match this regexp
-will be kept while the rest will be deleted before saving.")
+will be kept while the rest will be deleted before saving."
+  :group 'article
+  :type '(repeat string))
 
-(defvar gnus-default-article-saver 'gnus-summary-save-in-rmail
-  "*A function to save articles in your favourite format.
+(defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
+  "A function to save articles in your favourite format.
 The function must be interactively callable (in other words, it must
 be an Emacs command).
 
@@ -63,29 +73,45 @@ Gnus provides the following functions:
 * gnus-summary-save-in-rmail (Rmail format)
 * gnus-summary-save-in-mail (Unix mail format)
 * gnus-summary-save-in-folder (MH folder)
-* gnus-summary-save-in-file (article format).
-* gnus-summary-save-in-vm (use VM's folder format).")
-
-(defvar gnus-rmail-save-name (function gnus-plain-save-name)
-  "*A function generating a file name to save articles in Rmail format.
-The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
-
-(defvar gnus-mail-save-name (function gnus-plain-save-name)
-  "*A function generating a file name to save articles in Unix mail format.
-The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
-
-(defvar gnus-folder-save-name (function gnus-folder-save-name)
-  "*A function generating a file name to save articles in MH folder.
-The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.")
-
-(defvar gnus-file-save-name (function gnus-numeric-save-name)
-  "*A function generating a file name to save articles in article format.
+* gnus-summary-save-in-file (article format)
+* gnus-summary-save-in-vm (use VM's folder format)
+* gnus-summary-write-to-file (article format -- overwrite)."
+  :group 'article
+  :type '(radio (function-item gnus-summary-save-in-rmail)
+               (function-item gnus-summary-save-in-mail)
+               (function-item gnus-summary-save-in-folder)
+               (function-item gnus-summary-save-in-file)
+               (function-item gnus-summary-save-in-vm)
+               (function-item gnus-summary-write-to-file)))
+
+(defcustom gnus-rmail-save-name 'gnus-plain-save-name
+  "A function generating a file name to save articles in Rmail format.
+The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
+  :group 'article
+  :type 'function)
+
+(defcustom gnus-mail-save-name 'gnus-plain-save-name
+  "A function generating a file name to save articles in Unix mail format.
+The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
+  :group 'article
+  :type 'function)
+
+(defcustom gnus-folder-save-name 'gnus-folder-save-name
+  "A function generating a file name to save articles in MH folder.
+The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
+  :group 'article
+  :type 'function)
+
+(defcustom gnus-file-save-name 'gnus-numeric-save-name
+  "A function generating a file name to save articles in article format.
 The function is called with NEWSGROUP, HEADERS, and optional
-LAST-FILE.")
+LAST-FILE."
+  :group 'article
+  :type 'function)
 
-(defvar gnus-split-methods
+(defcustom gnus-split-methods
   '((gnus-article-archive-name))
-  "*Variable used to suggest where articles are to be saved.
+  "Variable used to suggest where articles are to be saved.
 For instance, if you would like to save articles related to Gnus in
 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
 you could set this variable to something like:
@@ -103,109 +129,173 @@ parameter.  If it is a list, it will be evaled in the same buffer.
 
 If this form or function returns a string, this string will be used as
 a possible file name; and if it returns a non-nil list, that list will
-be used as possible file names.")
-
-(defvar gnus-strict-mime t
-  "*If nil, MIME-decode even if there is no Mime-Version header in the article.")
-
-(defvar gnus-show-mime-method 'metamail-buffer
-  "*Function to process a MIME message.
-The function is called from the article buffer.")
-
-(defvar gnus-decode-encoded-word-method (lambda ())
-  "*Function to decode a MIME encoded-words.
-The function is called from the article buffer.")
-
-(defvar gnus-page-delimiter "^\^L"
+be used as possible file names."
+  :group 'article
+  :type '(repeat (choice (list function)
+                        (cons regexp (repeat string))
+                        sexp)))
+
+(defcustom gnus-strict-mime t
+  "*If nil, MIME-decode even if there is no Mime-Version header."
+  :group 'article
+  :type 'boolean)
+
+(defcustom gnus-show-mime-method 'metamail-buffer
+  "Function to process a MIME message.
+The function is called from the article buffer."
+  :group 'article
+  :type 'function)
+
+(defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
+  "*Function to decode MIME encoded words.
+The function is called from the article buffer."
+  :group 'article
+  :type 'function)
+
+(defcustom gnus-page-delimiter "^\^L"
   "*Regexp describing what to use as article page delimiters.
 The default value is \"^\^L\", which is a form linefeed at the
-beginning of a line.")
+beginning of a line."
+  :type 'regexp
+  :group 'article)
 
-(defvar gnus-article-mode-line-format "Gnus: %%b %S"
+(defcustom gnus-article-mode-line-format "Gnus: %%b %S"
   "*The format specification for the article mode line.
-See `gnus-summary-mode-line-format' for a closer description.")
+See `gnus-summary-mode-line-format' for a closer description."
+  :type 'string
+  :group 'article)
 
-(defvar gnus-article-mode-hook nil
-  "*A hook for Gnus article mode.")
+(defcustom gnus-article-mode-hook nil
+  "*A hook for Gnus article mode."
+  :type 'hook
+  :group 'article)
 
-(defvar gnus-article-menu-hook nil
-  "*Hook run after the creation of the article mode menu.")
+(defcustom gnus-article-menu-hook nil
+  "*Hook run after the creation of the article mode menu."
+  :type 'hook
+  :group 'article)
 
-(defvar gnus-article-prepare-hook nil
+(defcustom gnus-article-prepare-hook nil
   "*A hook called after an article has been prepared in the article buffer.
-If you want to run a special decoding program like nkf, use this hook.")
+If you want to run a special decoding program like nkf, use this hook."
+  :type 'hook
+  :group 'article)
 
-(defvar gnus-article-button-face 'bold
+(defcustom gnus-article-button-face 'bold
   "Face used for highlighting buttons in the article buffer.
 
 An article button is a piece of text that you can activate by pressing
-`RET' or `mouse-2' above it.")
+`RET' or `mouse-2' above it."
+  :type 'face
+  :group 'article)
 
-(defvar gnus-article-mouse-face 'highlight
+(defcustom gnus-article-mouse-face 'highlight
   "Face used for mouse highlighting in the article buffer.
 
 Article buttons will be displayed in this face when the cursor is
-above them.")
-
-(defvar gnus-signature-face 'italic
-  "Face used for highlighting a signature in the article buffer.")
-
-(defvar gnus-header-face-alist
-  (cond 
-   ((not (eq gnus-display-type 'color))
-    '(("" bold italic)))
-   ((eq gnus-background-mode 'dark)
-    (list 
-     (list "From" nil 
-          (custom-face-lookup "light blue" nil nil t t nil))
-     (list "Subject" nil 
-          (custom-face-lookup "pink" nil nil t t nil))
-     (list "Newsgroups:.*," nil
-          (custom-face-lookup "yellow" nil nil t t nil))
-     (list 
-      "" 
-      (custom-face-lookup "cyan" nil nil t nil nil)
-      (custom-face-lookup "forestgreen" nil nil nil t 
-                         nil))))
-   (t
-    (list
-     (list "From" nil
-          (custom-face-lookup "MidnightBlue" nil nil t t nil))
-     (list "Subject" nil 
-          (custom-face-lookup "firebrick" nil nil t t nil))
-     (list "Newsgroups:.*," nil
-          (custom-face-lookup "indianred" nil nil t t nil))
-     (list ""
-          (custom-face-lookup 
-           "DarkGreen" nil nil t nil nil)
-          (custom-face-lookup "DarkGreen" nil nil
-                              nil t nil)))))
+above them."
+  :type 'face
+  :group 'article)
+
+(defcustom gnus-signature-face 'italic
+  "Face used for highlighting a signature in the article buffer."
+  :type 'face
+  :group 'article)
+
+(defface gnus-header-from-face 
+  '((((class color)
+      (background dark))
+     (:foreground "light blue" :bold t :italic t))
+    (((class color)
+      (background light))
+     (:foreground "MidnightBlue" :bold t :italic t))
+    (t 
+     (:bold t :italic t)))
+  "Face used for displaying from headers."
+  :group 'article)
+
+(defface gnus-header-subject-face 
+  '((((class color)
+      (background dark))
+     (:foreground "pink" :bold t :italic t))
+    (((class color)
+      (background light))
+     (:foreground "firebrick" :bold t :italic t))
+    (t 
+     (:bold t :italic t)))
+  "Face used for displaying subject headers."
+  :group 'article)
+
+(defface gnus-header-newsgroups-face 
+  '((((class color)
+      (background dark))
+     (:foreground "yellow" :bold t :italic t))
+    (((class color)
+      (background light))
+     (:foreground "indianred" :bold t :italic t))
+    (t 
+     (:bold t :italic t)))
+  "Face used for displaying newsgroups headers."
+  :group 'article)
+
+(defface gnus-header-name-face 
+  '((((class color)
+      (background dark))
+     (:foreground "cyan" :bold t))
+    (((class color)
+      (background light))
+     (:foreground "DarkGreen" :bold t))
+    (t 
+     (:bold t)))
+  "Face used for displaying header names."
+  :group 'article)
+
+(defface gnus-header-content-face
+  '((((class color)
+      (background dark))
+     (:foreground "forest green" :italic t))
+    (((class color)
+      (background light))
+     (:foreground "DarkGreen" :italic t))
+    (t 
+     (:italic t)))  "Face used for displaying header content."
+  :group 'article)
+
+(defcustom gnus-header-face-alist
+  '(("From" nil gnus-header-from-face)
+    ("Subject" nil gnus-header-subject-face)
+    ("Newsgroups:.*," nil gnus-header-newsgroups-face)
+    ("" gnus-header-name-face gnus-header-content-face))
   "Controls highlighting of article header.
 
-[ This needs to be rewritten in lisp-talk ]
+An alist of the form (HEADER NAME CONTENT). 
 
-Below is a list of article header names, and the faces used for
-displaying the name and content of the header.  The `Header' field
-should contain the name of the header.  The field actually contains a
-regular expression that should match the beginning of the header line,
-but if you don't know what a regular expression is, just write the
-name of the header.  The second field is the `Name' field, which
-determines how the header name (i. e., the part of the header left
-of the `:') is displayed.  The third field is the `Content' field,
-which determines how the content (i. e., the part of the header right of
-the `:') is displayed.  
+HEADER is a regular expression which should match the name of an
+header header and NAME and CONTENT are either face names or nil.
 
-If you leave the last `Header' field in the list empty, the `Name' and
-`Content' fields will determine how headers not listed above are
-displayed.  
+The name of each header field will be displayed using the face
+specified by the first element in the list where HEADER match the
+header name and NAME is non-nil.  Similarly, the content will be
+displayed by the first non-nil matching CONTENT face."
+  :group 'article
+  :type '(repeat (list (regexp :tag "Header")
+                      (choice :tag "Name"
+                              (item :tag "skip" nil)
+                              (face :value default))
+                      (choice :tag "Content"
+                              (item :tag "skip" nil)
+                              (face :value default)))))
 
-If you only want to change the display of the name part for a specific
-header, specify `None' in the `Content' field.  Similarly, specify
-`None' in the `Name' field if you only want to leave the name part
-alone.")
+;;; Internal variables
 
+(defvar gnus-article-mode-syntax-table
+  (let ((table (copy-syntax-table text-mode-syntax-table)))
+    ;;(modify-syntax-entry ?_ "w" table)
+    table)
+  "Syntax table used in article mode buffers.
+Initialized from `text-mode-syntax-table.")
 
-;;; Internal variables
+(defvar gnus-save-article-buffer nil)
 
 (defvar gnus-article-mode-line-format-alist
     (nconc '((?w (gnus-article-wash-status) ?s))
@@ -256,6 +346,8 @@ alone.")
 
 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
 
+(defvar gnus-summary-article-menu)
+
 ;;; Saving functions.
 
 (defun gnus-article-save (save-buffer file &optional num)
@@ -270,21 +362,20 @@ alone.")
     (if (not gnus-default-article-saver)
        (error "No default saver is defined.")
       ;; !!! Magic!  The saving functions all save
-      ;; `gnus-original-article-buffer' (or so they think),
-      ;; but we bind that variable to our save-buffer.
+      ;; `gnus-original-article-buffer' (or so they think), but we
+      ;; bind that variable to our save-buffer.
       (set-buffer gnus-article-buffer)
-      (let* ((gnus-original-article-buffer save-buffer)
+      (let* ((gnus-save-article-buffer save-buffer)
             (filename
              (cond
-              ((not gnus-prompt-before-saving)
-               'default)
-              ((eq gnus-prompt-before-saving 'always)
-               nil)
+              ((not gnus-prompt-before-saving) 'default)
+              ((eq gnus-prompt-before-saving 'always) nil)
               (t file)))
             (gnus-number-of-articles-to-be-saved
-             (when (eq gnus-prompt-before-saving t) num))) ; Magic
+             (when (eq gnus-prompt-before-saving t)
+               num)))                  ; Magic
        (set-buffer gnus-summary-buffer)
-       (funcall gnus-default-article-saver filename)))))
+       (funcall gnus-default-article-saver filename))))) 
 
 (defun gnus-read-save-file-name (prompt default-name &optional filename)
   (cond
@@ -358,7 +449,7 @@ Directory to save to is default to `gnus-article-save-directory'."
     (setq filename (gnus-read-save-file-name
                    "Save %s in rmail file:" default-name filename))
     (gnus-make-directory (file-name-directory filename))
-    (gnus-eval-in-buffer-window gnus-original-article-buffer
+    (gnus-eval-in-buffer-window gnus-save-article-buffer
       (save-excursion
        (save-restriction
          (widen)
@@ -382,7 +473,7 @@ Directory to save to is default to `gnus-article-save-directory'."
                            (and default-name
                                 (file-name-directory default-name))))
     (gnus-make-directory (file-name-directory filename))
-    (gnus-eval-in-buffer-window gnus-original-article-buffer
+    (gnus-eval-in-buffer-window gnus-save-article-buffer
       (save-excursion
        (save-restriction
          (widen)
@@ -393,7 +484,7 @@ Directory to save to is default to `gnus-article-save-directory'."
     ;; Remember the directory name to save articles.
     (setq gnus-newsgroup-last-mail filename)))
 
-(defun gnus-summary-save-in-file (&optional filename)
+(defun gnus-summary-save-in-file (&optional filename overwrite)
   "Append this article to file.
 Optional argument FILENAME specifies file name.
 Directory to save to is default to `gnus-article-save-directory'."
@@ -405,14 +496,24 @@ Directory to save to is default to `gnus-article-save-directory'."
     (setq filename (gnus-read-save-file-name
                    "Save %s in file:" default-name filename))
     (gnus-make-directory (file-name-directory filename))
-    (gnus-eval-in-buffer-window gnus-original-article-buffer
+    (gnus-eval-in-buffer-window gnus-save-article-buffer
       (save-excursion
        (save-restriction
          (widen)
+         (when (and overwrite
+                    (file-exists-p filename))
+           (delete-file filename))
          (gnus-output-to-file filename))))
     ;; Remember the directory name to save articles.
     (setq gnus-newsgroup-last-file filename)))
 
+(defun gnus-summary-write-to-file (&optional filename)
+  "Write this article to a file.
+Optional argument FILENAME specifies file name.
+The directory to save in defaults to `gnus-article-save-directory'."
+  (interactive)
+  (gnus-summary-save-in-file nil t))
+
 (defun gnus-summary-save-body-in-file (&optional filename)
   "Append this article body to a file.
 Optional argument FILENAME specifies file name.
@@ -425,13 +526,13 @@ The directory to save in defaults to `gnus-article-save-directory'."
     (setq filename (gnus-read-save-file-name
                    "Save %s body in file:" default-name filename))
     (gnus-make-directory (file-name-directory filename))
-    (gnus-eval-in-buffer-window gnus-original-article-buffer
+    (gnus-eval-in-buffer-window gnus-save-article-buffer
       (save-excursion
        (save-restriction
          (widen)
          (goto-char (point-min))
-         (and (search-forward "\n\n" nil t)
-              (narrow-to-region (point) (point-max)))
+         (when (search-forward "\n\n" nil t)
+           (narrow-to-region (point) (point-max)))
          (gnus-output-to-file filename))))
     ;; Remember the directory name to save articles.
     (setq gnus-newsgroup-last-file filename)))
@@ -446,8 +547,8 @@ The directory to save in defaults to `gnus-article-save-directory'."
              (command command)
              (t (read-string "Shell command on article: "
                              gnus-last-shell-command))))
-  (if (string-equal command "")
-      (setq command gnus-last-shell-command))
+  (when (string-equal command "")
+    (setq command gnus-last-shell-command))
   (gnus-eval-in-buffer-window gnus-article-buffer
     (save-restriction
       (widen)
@@ -458,9 +559,9 @@ The directory to save in defaults to `gnus-article-save-directory'."
 
 (defun gnus-capitalize-newsgroup (newsgroup)
   "Capitalize NEWSGROUP name."
-  (and (not (zerop (length newsgroup)))
-       (concat (char-to-string (upcase (aref newsgroup 0)))
-              (substring newsgroup 1))))
+  (when (not (zerop (length newsgroup)))
+    (concat (char-to-string (upcase (aref newsgroup 0)))
+           (substring newsgroup 1))))
 
 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
@@ -548,6 +649,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is
     "\C-c\C-b" gnus-bug
 
     "\C-d" gnus-article-read-summary-keys
+    "\M-*" gnus-article-read-summary-keys
     "\M-g" gnus-article-read-summary-keys)
 
   (substitute-key-definition
@@ -563,8 +665,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is
        ["Scroll backwards" gnus-article-goto-prev-page t]
        ["Show summary" gnus-article-show-summary t]
        ["Fetch Message-ID at point" gnus-article-refer-article t]
-       ["Mail to address at point" gnus-article-mail t]
-       ))
+       ["Mail to address at point" gnus-article-mail t]))
 
     (easy-menu-define
      gnus-article-treatment-menu gnus-article-mode-map ""
@@ -574,8 +675,11 @@ If variable `gnus-use-long-file-name' is non-nil, it is
        ["Hide citation" gnus-article-hide-citation t]
        ["Treat overstrike" gnus-article-treat-overstrike t]
        ["Remove carriage return" gnus-article-remove-cr t]
-       ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
-       ))
+       ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
+
+    (define-key rmail-mode-map [menu-bar commands]
+      (cons "Commands" gnus-summary-article-menu))
+
     (run-hooks 'gnus-article-menu-hook)))
 
 (defun gnus-article-mode ()
@@ -610,6 +714,7 @@ commands:
   (gnus-set-default-directory)
   (buffer-disable-undo (current-buffer))
   (setq buffer-read-only t)
+  (set-syntax-table gnus-article-mode-syntax-table)
   (run-hooks 'gnus-article-mode-hook))
 
 (defun gnus-article-setup-buffer ()
@@ -727,41 +832,41 @@ If ALL-HEADERS is non-nil, no headers are hidden."
            ;; The result from the `request' was an actual article -
            ;; or at least some text that is now displayed in the
            ;; article buffer.
-           (if (and (numberp article)
-                    (not (eq article gnus-current-article)))
-               ;; Seems like a new article has been selected.
-               ;; `gnus-current-article' must be an article number.
-               (save-excursion
-                 (set-buffer summary-buffer)
-                 (setq gnus-last-article gnus-current-article
-                       gnus-newsgroup-history (cons gnus-current-article
-                                                    gnus-newsgroup-history)
-                       gnus-current-article article
-                       gnus-current-headers
-                       (gnus-summary-article-header gnus-current-article)
-                       gnus-article-current
-                       (cons gnus-newsgroup-name gnus-current-article))
-                 (unless (vectorp gnus-current-headers)
-                   (setq gnus-current-headers nil))
-                 (gnus-summary-show-thread)
-                 (run-hooks 'gnus-mark-article-hook)
-                 (gnus-set-mode-line 'summary)
-                 (and (gnus-visual-p 'article-highlight 'highlight)
-                      (run-hooks 'gnus-visual-mark-article-hook))
-                 ;; Set the global newsgroup variables here.
-                 ;; Suggested by Jim Sisolak
-                 ;; <sisolak@trans4.neep.wisc.edu>.
-                 (gnus-set-global-variables)
-                 (setq gnus-have-all-headers
-                       (or all-headers gnus-show-all-headers))
-                 (and gnus-use-cache
-                      (vectorp (gnus-summary-article-header article))
-                      (gnus-cache-possibly-enter-article
-                       group article
-                       (gnus-summary-article-header article)
-                       (memq article gnus-newsgroup-marked)
-                       (memq article gnus-newsgroup-dormant)
-                       (memq article gnus-newsgroup-unreads)))))
+           (when (and (numberp article)
+                      (not (eq article gnus-current-article)))
+             ;; Seems like a new article has been selected.
+             ;; `gnus-current-article' must be an article number.
+             (save-excursion
+               (set-buffer summary-buffer)
+               (setq gnus-last-article gnus-current-article
+                     gnus-newsgroup-history (cons gnus-current-article
+                                                  gnus-newsgroup-history)
+                     gnus-current-article article
+                     gnus-current-headers
+                     (gnus-summary-article-header gnus-current-article)
+                     gnus-article-current
+                     (cons gnus-newsgroup-name gnus-current-article))
+               (unless (vectorp gnus-current-headers)
+                 (setq gnus-current-headers nil))
+               (gnus-summary-show-thread)
+               (run-hooks 'gnus-mark-article-hook)
+               (gnus-set-mode-line 'summary)
+               (when (gnus-visual-p 'article-highlight 'highlight)
+                 (run-hooks 'gnus-visual-mark-article-hook))
+               ;; Set the global newsgroup variables here.
+               ;; Suggested by Jim Sisolak
+               ;; <sisolak@trans4.neep.wisc.edu>.
+               (gnus-set-global-variables)
+               (setq gnus-have-all-headers
+                     (or all-headers gnus-show-all-headers))
+               (and gnus-use-cache
+                    (vectorp (gnus-summary-article-header article))
+                    (gnus-cache-possibly-enter-article
+                     group article
+                     (gnus-summary-article-header article)
+                     (memq article gnus-newsgroup-marked)
+                     (memq article gnus-newsgroup-dormant)
+                     (memq article gnus-newsgroup-unreads)))))
            (when (or (numberp article)
                      (stringp article))
              ;; Hooks for getting information from the article.
@@ -770,16 +875,17 @@ If ALL-HEADERS is non-nil, no headers are hidden."
                (run-hooks 'internal-hook)
                (run-hooks 'gnus-article-prepare-hook)
                ;; Decode MIME message.
-               (if gnus-show-mime
-                   (if (or (not gnus-strict-mime)
-                           (gnus-fetch-field "Mime-Version"))
-                       (funcall gnus-show-mime-method)
-                     (funcall gnus-decode-encoded-word-method)))
+               (when gnus-show-mime
+                 (if (or (not gnus-strict-mime)
+                         (gnus-fetch-field "Mime-Version"))
+                     (funcall gnus-show-mime-method)
+                   (funcall gnus-decode-encoded-word-method)))
                ;; Perform the article display hooks.
                (run-hooks 'gnus-article-display-hook))
              ;; Do page break.
              (goto-char (point-min))
-             (and gnus-break-pages (gnus-narrow-to-page)))
+             (when gnus-break-pages
+               (gnus-narrow-to-page)))
            (gnus-set-mode-line 'article)
            (gnus-configure-windows 'article)
            (goto-char (point-min))
@@ -834,7 +940,7 @@ Provided for backwards compatibility."
                  (set-buffer file-buffer)
                  (rmail-insert-rmail-file-header)
                  (let ((require-final-newline nil))
-                   (write-region (point-min) (point-max) file-name t 1)))
+                   (gnus-write-buffer file-name)))
                (kill-buffer file-buffer))
            (error "Output file does not exist")))
       (set-buffer tmpbuf)
@@ -852,19 +958,18 @@ Provided for backwards compatibility."
                (msg (and (boundp 'rmail-current-message)
                          (symbol-value 'rmail-current-message))))
            ;; If MSG is non-nil, buffer is in RMAIL mode.
-           (if msg
-               (progn (widen)
-                      (narrow-to-region (point-max) (point-max))))
+           (when msg
+             (widen)
+             (narrow-to-region (point-max) (point-max)))
            (insert-buffer-substring tmpbuf)
-           (if msg
-               (progn
-                 (goto-char (point-min))
-                 (widen)
-                 (search-backward "\^_")
-                 (narrow-to-region (point) (point-max))
-                 (goto-char (1+ (point-min)))
-                 (rmail-count-new-messages t)
-                 (rmail-show-message msg)))))))
+           (when msg
+             (goto-char (point-min))
+             (widen)
+             (search-backward "\^_")
+             (narrow-to-region (point) (point-max))
+             (goto-char (1+ (point-min)))
+             (rmail-count-new-messages t)
+             (rmail-show-message msg))))))
     (kill-buffer tmpbuf)))
 
 (defun gnus-output-to-file (file-name)
@@ -959,11 +1064,12 @@ Argument LINES specifies lines to be scrolled up."
        (gnus-narrow-to-page 1)         ;Go to next page.
        nil)
     ;; More in this page.
-    (condition-case ()
-       (scroll-up lines)
-      (end-of-buffer
-       ;; Long lines may cause an end-of-buffer error.
-       (goto-char (point-max))))
+    (let ((scroll-in-place nil))
+      (condition-case ()
+         (scroll-up lines)
+       (end-of-buffer
+        ;; Long lines may cause an end-of-buffer error.
+        (goto-char (point-max)))))
     (move-to-window-line 0)
     nil))
 
@@ -979,11 +1085,11 @@ Argument LINES specifies lines to be scrolled down."
        (gnus-narrow-to-page -1)        ;Go to previous page.
        (goto-char (point-max))
        (recenter -1))
-    (prog1
-       (condition-case ()
-           (scroll-down lines)
-         (error nil))
-      (move-to-window-line 0))))
+    (let ((scroll-in-place nil))
+      (prog1
+         (ignore-errors
+           (scroll-down lines))
+       (move-to-window-line 0)))))
 
 (defun gnus-article-refer-article ()
   "Read article specified by message-id around point."
@@ -1094,8 +1200,8 @@ If given a prefix, show the hidden text instead."
 
 (defun gnus-article-maybe-highlight ()
   "Do some article highlighting if `article-visual' is non-nil."
-  (if (gnus-visual-p 'article-highlight 'highlight)
-      (gnus-article-highlight-some)))
+  (when (gnus-visual-p 'article-highlight 'highlight)
+    (gnus-article-highlight-some)))
 
 (defun gnus-request-article-this-buffer (article group)
   "Get an article and insert it into this buffer."
@@ -1129,23 +1235,23 @@ If given a prefix, show the hidden text instead."
            (save-excursion
              (set-buffer gnus-summary-buffer)
              (let ((header (gnus-summary-article-header article)))
-               (if (< article 0)
-                   (cond 
-                    ((memq article gnus-newsgroup-sparse)
-                     ;; This is a sparse gap article.
-                     (setq do-update-line article)
-                     (setq article (mail-header-id header))
-                     (let ((gnus-override-method gnus-refer-article-method))
-                       (gnus-read-header article))
-                     (setq gnus-newsgroup-sparse
-                           (delq article gnus-newsgroup-sparse)))
-                    ((vectorp header)
-                     ;; It's a real article.
-                     (setq article (mail-header-id header)))
-                    (t
-                     ;; It is an extracted pseudo-article.
-                     (setq article 'pseudo)
-                     (gnus-request-pseudo-article header))))
+               (when (< article 0)
+                 (cond 
+                  ((memq article gnus-newsgroup-sparse)
+                   ;; This is a sparse gap article.
+                   (setq do-update-line article)
+                   (setq article (mail-header-id header))
+                   (let ((gnus-override-method gnus-refer-article-method))
+                     (gnus-read-header article))
+                   (setq gnus-newsgroup-sparse
+                         (delq article gnus-newsgroup-sparse)))
+                  ((vectorp header)
+                   ;; It's a real article.
+                   (setq article (mail-header-id header)))
+                  (t
+                   ;; It is an extracted pseudo-article.
+                   (setq article 'pseudo)
+                   (gnus-request-pseudo-article header))))
                
                (let ((method (gnus-find-method-for-group 
                               gnus-newsgroup-name)))
@@ -1153,10 +1259,9 @@ If given a prefix, show the hidden text instead."
                      ()
                    (let ((dir (concat (file-name-as-directory (nth 1 method))
                                       (mail-header-subject header))))
-                     (if (file-directory-p dir)
-                         (progn
-                           (setq article 'nneething)
-                           (gnus-group-enter-directory dir)))))))))
+                     (when (file-directory-p dir)
+                       (setq article 'nneething)
+                       (gnus-group-enter-directory dir))))))))
 
          (cond
           ;; Refuse to select canceled articles.
@@ -1253,8 +1358,10 @@ how much time has lapsed since DATE."
 ;;; Article editing
 ;;;
 
-(defvar gnus-article-edit-mode-hook nil
-  "*Hook run in article edit mode buffers.")
+(defcustom gnus-article-edit-mode-hook nil
+  "Hook run in article edit mode buffers."
+  :group 'article
+  :type 'hook)
 
 (defvar gnus-article-edit-done-function nil)
 
@@ -1378,17 +1485,19 @@ groups."
 
 ;;; Internal Variables:
 
-(defvar gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-\\wa-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]*[-\\wa-zA-Z0-9_=#$@~`%&*+|\\/]"
-  "*Regular expression that matches URLs.")
+(defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-\\wa-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]*[-\\wa-zA-Z0-9_=#$@~`%&*+|\\/]"
+  "Regular expression that matches URLs."
+  :group 'article
+  :type 'regexp)
 
-(defvar gnus-button-alist 
+(defcustom gnus-button-alist 
   `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 
      t gnus-button-message-id 3)
     ("\\(<?\\(url: ?\\)?news://\\([^>\n\t ]*\\)>?\\)" 1 t
      gnus-button-fetch-group 3)
     ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
      gnus-button-message-id 3)
-    ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-button-reply 2)
+    ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-url-mailto 2)
     ;; This is how URLs _should_ be embedded in text...
     ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
     ;; Next regexp stolen from highlight-headers.el.
@@ -1405,9 +1514,17 @@ CALLBACK: is the function to call when the user push this button, and each
 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
 
 CALLBACK can also be a variable, in that case the value of that
-variable it the real callback function.")
-
-(defvar gnus-header-button-alist 
+variable it the real callback function."
+  :group 'article
+  :type '(repeat (list regexp 
+                      (integer :tag "Button")
+                      (sexp :tag "Form")
+                      (function :tag "Callback")
+                      (repeat :tag "Par"
+                              :inline t
+                              (integer :tag "Regexp group")))))
+
+(defcustom gnus-header-button-alist 
   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
      0 t gnus-button-message-id 0)
     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
@@ -1425,7 +1542,16 @@ alist has an additional HEADER element first in each entry:
 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
 
 HEADER is a regexp to match a header.  For a fuller explanation, see
-`gnus-button-alist'.")
+`gnus-button-alist'."
+  :group 'article
+  :type '(repeat (list (regexp :tag "Header")
+                      regexp 
+                      (integer :tag "Button")
+                      (sexp :tag "Form")
+                      (function :tag "Callback")
+                      (repeat :tag "Par"
+                              :inline t
+                              (integer :tag "Regexp group")))))
 
 (defvar gnus-button-regexp nil)
 (defvar gnus-button-marker-list nil)
@@ -1445,7 +1571,8 @@ call it with the value of the `gnus-data' text property."
   (let* ((pos (posn-point (event-start event)))
          (data (get-text-property pos 'gnus-data))
         (fun (get-text-property pos 'gnus-callback)))
-    (if fun (funcall fun data))))
+    (when fun
+      (funcall fun data))))
 
 (defun gnus-article-press-button ()
   "Check text at point for a callback function.
@@ -1454,7 +1581,8 @@ call it with the value of the `gnus-data' text property."
   (interactive)
   (let* ((data (get-text-property (point) 'gnus-data))
         (fun (get-text-property (point) 'gnus-callback)))
-    (if fun (funcall fun data))))
+    (when fun
+      (funcall fun data))))
 
 (defun gnus-article-prev-button (n)
   "Move point to N buttons backward.
@@ -1540,8 +1668,8 @@ do the highlighting.  See the documentation for those functions."
                        (not (eobp)))
              (beginning-of-line)
              (setq from (point))
-             (or (search-forward ":" nil t)
-                 (forward-char 1))
+             (unless (search-forward ":" nil t)
+               (forward-char 1))
              (when (and header-face
                         (not (memq (point) hpoints)))
                (push (point) hpoints)
@@ -1642,11 +1770,11 @@ specified by `gnus-button-alist'."
                   (end (match-end (nth 1 entry)))
                   (form (nth 2 entry)))
              (goto-char (match-end 0))
-             (and (eval form)
-                  (gnus-article-add-button 
-                   start end (nth 3 entry)
-                   (buffer-substring (match-beginning (nth 4 entry))
-                                     (match-end (nth 4 entry)))))))
+             (when (eval form)
+               (gnus-article-add-button 
+                start end (nth 3 entry)
+                (buffer-substring (match-beginning (nth 4 entry))
+                                  (match-end (nth 4 entry)))))))
          (goto-char end))))
     (widen)))
 
@@ -1654,9 +1782,9 @@ specified by `gnus-button-alist'."
 
 (defun gnus-article-add-button (from to fun &optional data)
   "Create a button between FROM and TO with callback FUN and data DATA."
-  (and gnus-article-button-face
-       (gnus-overlay-put (gnus-make-overlay from to)
-                        'face gnus-article-button-face))
+  (when gnus-article-button-face
+    (gnus-overlay-put (gnus-make-overlay from to)
+                     'face gnus-article-button-face))
   (gnus-add-text-properties 
    from to
    (nconc (and gnus-article-mouse-face
@@ -1694,7 +1822,7 @@ specified by `gnus-button-alist'."
     (let* ((entry (gnus-button-entry))
           (inhibit-point-motion-hooks t)
           (fun (nth 3 entry))
-          (args (mapcar (lambda (group) 
+          (args (mapcar (lambda (group)
                           (let ((string (buffer-substring
                                          (match-beginning group)
                                          (match-end group))))
@@ -1729,6 +1857,89 @@ specified by `gnus-button-alist'."
                                   (match-string 3 address)
                                 "nntp"))))))
 
+(defun gnus-split-string (string pattern)
+  "Return a list of substrings of STRING which are separated by PATTERN."
+  (let (parts (start 0))
+    (while (string-match pattern string start)
+      (setq parts (cons (substring string start (match-beginning 0)) parts)
+           start (match-end 0)))
+    (nreverse (cons (substring string start) parts))))
+(defun gnus-url-parse-query-string (query &optional downcase)
+  (let (retval pairs cur key val)
+    (setq pairs (gnus-split-string query "&"))
+    (while pairs
+      (setq cur (car pairs)
+            pairs (cdr pairs))
+      (if (not (string-match "=" cur))
+          nil                           ; Grace
+        (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
+              val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
+        (if downcase
+            (setq key (downcase key)))
+        (setq cur (assoc key retval))
+        (if cur
+            (setcdr cur (cons val (cdr cur)))
+          (setq retval (cons (list key val) retval)))))
+    retval))
+(defun gnus-url-unhex (x)
+  (if (> x ?9)
+      (if (>= x ?a)
+          (+ 10 (- x ?a))
+        (+ 10 (- x ?A)))
+    (- x ?0)))
+(defun gnus-url-unhex-string (str &optional allow-newlines)
+  "Remove %XXX embedded spaces, etc in a url.
+If optional second argument ALLOW-NEWLINES is non-nil, then allow the
+decoding of carriage returns and line feeds in the string, which is normally
+forbidden in URL encoding."
+  (setq str (or str ""))
+  (let ((tmp "")
+        (case-fold-search t))
+    (while (string-match "%[0-9a-f][0-9a-f]" str)
+      (let* ((start (match-beginning 0))
+             (ch1 (gnus-url-unhex (elt str (+ start 1))))
+             (code (+ (* 16 ch1)
+                      (gnus-url-unhex (elt str (+ start 2))))))
+        (setq tmp (concat 
+                   tmp (substring str 0 start)
+                   (cond
+                    (allow-newlines
+                     (char-to-string code))
+                    ((or (= code ?\n) (= code ?\r))
+                     " ")
+                    (t (char-to-string code))))
+              str (substring str (match-end 0)))))
+    (setq tmp (concat tmp str))
+    tmp))
+(defun gnus-url-mailto (url)
+  ;; Send mail to someone
+  (if (not (string-match "mailto:/*\\(.*\\)" url))
+      (error "Malformed mailto link: %s" url))
+  (setq url (substring url (match-beginning 1) nil))
+  (let (to args source-url subject func)
+    (if (string-match (regexp-quote "?") url)
+        (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
+              args (gnus-url-parse-query-string
+                    (substring url (match-end 0) nil) t))
+      (setq to (gnus-url-unhex-string url)))
+    (setq args (cons (list "to" to) args)
+          subject (cdr-safe (assoc "subject" args)))
+    (message-mail)
+    (while args
+      (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
+      (if (fboundp func)
+          (funcall func)
+        (message-position-on-field (caar args)))
+      (insert (mapconcat 'identity (cdar args) ", "))
+      (setq args (cdr args)))
+    (if subject
+        (message-goto-body)
+      (message-goto-subject))))
+
 (defun gnus-button-mailto (address)
   ;; Mail to ADDRESS.
   (set-buffer (gnus-copy-article-buffer))
@@ -1804,8 +2015,10 @@ specified by `gnus-button-alist'."
   (let ((win (selected-window)))
     (select-window (get-buffer-window gnus-article-buffer t))
     (gnus-article-prev-page)
-    (select-window win)))
+    (select-window win))) 
 
 (provide 'gnus-art)
 
+(run-hooks 'gnus-art-load-hook)
+
 ;;; gnus-art.el ends here