*** empty log message ***
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'custom)
29 (require 'gnus)
30 (require 'gnus-sum)
31 (require 'gnus-spec)
32 (require 'gnus-int)
33 (require 'browse-url)
34
35 (defgroup article nil
36   "Article display."
37   :group 'gnus)
38
39 (defcustom gnus-ignored-headers
40   '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
41     "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
42     "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
43     "^Approved:" "^Sender:" "^Received:" "^Mail-from:") 
44   "All headers that match this regexp will be hidden.
45 This variable can also be a list of regexps of headers to be ignored.
46 If `gnus-visible-headers' is non-nil, this variable will be ignored."
47   :type '(choice :custom-show nil
48                  regexp
49                  (repeat regexp))
50   :group 'article)
51
52 (defcustom gnus-visible-headers 
53   "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-"
54   "All headers that do not match this regexp will be hidden.
55 This variable can also be a list of regexp of headers to remain visible.
56 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
57   :type '(repeat :value-to-internal (lambda (widget value)
58                                       (custom-split-regexp-maybe value))
59                  :match (lambda (widget value)
60                           (or (stringp value)
61                               (widget-editable-list-match widget value)))
62                  regexp)
63   :group 'article)
64
65 (defcustom gnus-sorted-header-list
66   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:"
67     "^Cc:" "^Date:" "^Organization:")
68   "This variable is a list of regular expressions.
69 If it is non-nil, headers that match the regular expressions will
70 be placed first in the article buffer in the sequence specified by
71 this list."
72   :type '(repeat regexp)
73   :group 'article)
74
75 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
76   "Headers that are only to be displayed if they have interesting data.
77 Possible values in this list are `empty', `newsgroups', `followup-to',
78 `reply-to', and `date'."
79   :type '(set (const :tag "Headers with no content." empty)
80               (const :tag "Newsgroups with only one group." newsgroups)
81               (const :tag "Followup-to identical to newsgroups." followup-to)
82               (const :tag "Reply-to identical to from." reply-to)
83               (const :tag "Date less than four days old." date))
84   :group 'article)
85
86 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
87   "Regexp matching signature separator.
88 This can also be a list of regexps.  In that case, it will be checked
89 from head to tail looking for a separator.  Searches will be done from
90 the end of the buffer."
91   :type '(repeat string)
92   :group 'article)
93
94 (defcustom gnus-signature-limit nil
95    "Provide a limit to what is considered a signature.
96 If it is a number, no signature may not be longer (in characters) than
97 that number.  If it is a floating point number, no signature may be
98 longer (in lines) than that number.  If it is a function, the function
99 will be called without any parameters, and if it returns nil, there is
100 no signature in the buffer.  If it is a string, it will be used as a
101 regexp.  If it matches, the text in question is not a signature."
102   :type '(choice integer number function regexp)
103   :group 'article)
104
105 (defcustom gnus-hidden-properties '(invisible t intangible t)
106   "Property list to use for hiding text."
107   :type 'sexp 
108   :group 'article)
109
110 (defcustom gnus-article-x-face-command
111   "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
112   "String or function to be executed to display an X-Face header.
113 If it is a string, the command will be executed in a sub-shell
114 asynchronously.  The compressed face will be piped to this command."
115   :type 'string                         ;Leave function case to Lisp.
116   :group 'article)
117
118 (defcustom gnus-article-x-face-too-ugly nil
119   "Regexp matching posters whose face shouldn't be shown automatically."
120   :type 'regexp
121   :group 'article)
122
123 (defcustom gnus-emphasis-alist
124   (let ((format
125          "\\(\\s-\\|^\\|[-\"\(]\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"\)]\\)")
126         (types
127          '(("_" "_" underline)
128            ("/" "/" italic)
129            ("\\*" "\\*" bold)
130            ("_/" "/_" underline-italic)
131            ("_\\*" "\\*_" underline-bold)
132            ("\\*/" "/\\*" bold-italic)
133            ("_\\*/" "/\\*_" underline-bold-italic))))
134     `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
135        2 3 gnus-emphasis-underline)
136       ,@(mapcar
137          (lambda (spec)
138            (list
139             (format format (car spec) (cadr spec))
140             2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
141          types)))
142   "Alist that says how to fontify certain phrases.
143 Each item looks like this:
144
145   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
146
147 The first element is a regular expression to be matched.  The second
148 is a number that says what regular expression grouping used to find
149 the entire emphasized word.  The third is a number that says what
150 regexp grouping should be displayed and highlighted.  The fourth
151 is the face used for highlighting."
152   :type '(repeat (list :value ("" 0 0 default)
153                        regexp
154                        (integer :tag "Match group")
155                        (integer :tag "Emphasize group")
156                        face))
157   :group 'article)
158
159 (defface gnus-emphasis-bold '((t (:bold t)))
160   "Face used for displaying strong emphasized text (*word*)."
161   :group 'article)
162
163 (defface gnus-emphasis-italic '((t (:italic t)))
164   "Face used for displaying italic emphasized text (/word/)."
165   :group 'article)
166
167 (defface gnus-emphasis-underline '((t (:underline t)))
168   "Face used for displaying underlined emphasized text (_word_)."
169   :group 'article)
170
171 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
172   "Face used for displaying underlined bold emphasized text (_*word*_)."
173   :group 'article)
174
175 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
176   "Face used for displaying underlined italic emphasized text (_*word*_)."
177   :group 'article)
178
179 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
180   "Face used for displaying bold italic emphasized text (/*word*/)."
181   :group 'article)
182
183 (defface gnus-emphasis-underline-bold-italic 
184   '((t (:bold t :italic t :underline t)))
185   "Face used for displaying underlined bold italic emphasized text (_/*word*/_)."
186   :group 'article)
187
188 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
189   "Format for display of Date headers in article bodies.
190 See `format-time-zone' for the possible values."
191   :type 'string
192   :group 'article)
193
194 (eval-and-compile
195   (autoload 'hexl-hex-string-to-integer "hexl")
196   (autoload 'timezone-make-date-arpa-standard "timezone")
197   (autoload 'mail-extract-address-components "mail-extr"))
198
199 (defcustom gnus-article-save-directory gnus-directory
200   "*Name of the directory articles will be saved in (default \"~/News\")."
201   :group 'article
202   :type 'directory)
203
204 (defcustom gnus-save-all-headers t
205   "*If non-nil, don't remove any headers before saving."
206   :group 'article
207   :type 'boolean)
208
209 (defcustom gnus-prompt-before-saving 'always
210   "*This variable says how much prompting is to be done when saving articles.
211 If it is nil, no prompting will be done, and the articles will be
212 saved to the default files.  If this variable is `always', each and
213 every article that is saved will be preceded by a prompt, even when
214 saving large batches of articles.  If this variable is neither nil not
215 `always', there the user will be prompted once for a file name for
216 each invocation of the saving commands."
217   :group 'article
218   :type '(choice (item always)
219                  (item :tag "never" nil)
220                  (sexp :tag "once" :format "%t")))
221
222 (defcustom gnus-saved-headers gnus-visible-headers
223   "Headers to keep if `gnus-save-all-headers' is nil.
224 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
225 If that variable is nil, however, all headers that match this regexp
226 will be kept while the rest will be deleted before saving."
227   :group 'article
228   :type '(repeat string))
229
230 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
231   "A function to save articles in your favourite format.
232 The function must be interactively callable (in other words, it must
233 be an Emacs command).
234
235 Gnus provides the following functions:
236
237 * gnus-summary-save-in-rmail (Rmail format)
238 * gnus-summary-save-in-mail (Unix mail format)
239 * gnus-summary-save-in-folder (MH folder)
240 * gnus-summary-save-in-file (article format)
241 * gnus-summary-save-in-vm (use VM's folder format)
242 * gnus-summary-write-to-file (article format -- overwrite)."
243   :group 'article
244   :type '(radio (function-item gnus-summary-save-in-rmail)
245                 (function-item gnus-summary-save-in-mail)
246                 (function-item gnus-summary-save-in-folder)
247                 (function-item gnus-summary-save-in-file)
248                 (function-item gnus-summary-save-in-vm)
249                 (function-item gnus-summary-write-to-file)))
250
251 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
252   "A function generating a file name to save articles in Rmail format.
253 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
254   :group 'article
255   :type 'function)
256
257 (defcustom gnus-mail-save-name 'gnus-plain-save-name
258   "A function generating a file name to save articles in Unix mail format.
259 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
260   :group 'article
261   :type 'function)
262
263 (defcustom gnus-folder-save-name 'gnus-folder-save-name
264   "A function generating a file name to save articles in MH folder.
265 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
266   :group 'article
267   :type 'function)
268
269 (defcustom gnus-file-save-name 'gnus-numeric-save-name
270   "A function generating a file name to save articles in article format.
271 The function is called with NEWSGROUP, HEADERS, and optional
272 LAST-FILE."
273   :group 'article
274   :type 'function)
275
276 (defcustom gnus-split-methods
277   '((gnus-article-archive-name))
278   "Variable used to suggest where articles are to be saved.
279 For instance, if you would like to save articles related to Gnus in
280 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
281 you could set this variable to something like:
282
283  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
284    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
285
286 This variable is an alist where the where the key is the match and the
287 value is a list of possible files to save in if the match is non-nil.
288
289 If the match is a string, it is used as a regexp match on the
290 article.  If the match is a symbol, that symbol will be funcalled
291 from the buffer of the article to be saved with the newsgroup as the
292 parameter.  If it is a list, it will be evaled in the same buffer.
293
294 If this form or function returns a string, this string will be used as
295 a possible file name; and if it returns a non-nil list, that list will
296 be used as possible file names."
297   :group 'article
298   :type '(repeat (choice (list function)
299                          (cons regexp (repeat string))
300                          sexp)))
301
302 (defcustom gnus-strict-mime t
303   "*If nil, MIME-decode even if there is no Mime-Version header."
304   :group 'article
305   :type 'boolean)
306
307 (defcustom gnus-show-mime-method 'metamail-buffer
308   "Function to process a MIME message.
309 The function is called from the article buffer."
310   :group 'article
311   :type 'function)
312
313 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
314   "*Function to decode MIME encoded words.
315 The function is called from the article buffer."
316   :group 'article
317   :type 'function)
318
319 (defcustom gnus-page-delimiter "^\^L"
320   "*Regexp describing what to use as article page delimiters.
321 The default value is \"^\^L\", which is a form linefeed at the
322 beginning of a line."
323   :type 'regexp
324   :group 'article)
325
326 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
327   "*The format specification for the article mode line.
328 See `gnus-summary-mode-line-format' for a closer description."
329   :type 'string
330   :group 'article)
331
332 (defcustom gnus-article-mode-hook nil
333   "*A hook for Gnus article mode."
334   :type 'hook
335   :group 'article)
336
337 (defcustom gnus-article-menu-hook nil
338   "*Hook run after the creation of the article mode menu."
339   :type 'hook
340   :group 'article)
341
342 (defcustom gnus-article-prepare-hook nil
343   "*A hook called after an article has been prepared in the article buffer.
344 If you want to run a special decoding program like nkf, use this hook."
345   :type 'hook
346   :group 'article)
347
348 (defcustom gnus-article-button-face 'bold
349   "Face used for highlighting buttons in the article buffer.
350
351 An article button is a piece of text that you can activate by pressing
352 `RET' or `mouse-2' above it."
353   :type 'face
354   :group 'article)
355
356 (defcustom gnus-article-mouse-face 'highlight
357   "Face used for mouse highlighting in the article buffer.
358
359 Article buttons will be displayed in this face when the cursor is
360 above them."
361   :type 'face
362   :group 'article)
363
364 (defcustom gnus-signature-face 'italic
365   "Face used for highlighting a signature in the article buffer."
366   :type 'face
367   :group 'article)
368
369 (defface gnus-header-from-face 
370   '((((class color)
371       (background dark))
372      (:foreground "light blue" :bold t :italic t))
373     (((class color)
374       (background light))
375      (:foreground "MidnightBlue" :bold t :italic t))
376     (t 
377      (:bold t :italic t)))
378   "Face used for displaying from headers."
379   :group 'article)
380
381 (defface gnus-header-subject-face 
382   '((((class color)
383       (background dark))
384      (:foreground "pink" :bold t :italic t))
385     (((class color)
386       (background light))
387      (:foreground "firebrick" :bold t :italic t))
388     (t 
389      (:bold t :italic t)))
390   "Face used for displaying subject headers."
391   :group 'article)
392
393 (defface gnus-header-newsgroups-face 
394   '((((class color)
395       (background dark))
396      (:foreground "yellow" :bold t :italic t))
397     (((class color)
398       (background light))
399      (:foreground "indianred" :bold t :italic t))
400     (t 
401      (:bold t :italic t)))
402   "Face used for displaying newsgroups headers."
403   :group 'article)
404
405 (defface gnus-header-name-face 
406   '((((class color)
407       (background dark))
408      (:foreground "cyan" :bold t))
409     (((class color)
410       (background light))
411      (:foreground "DarkGreen" :bold t))
412     (t 
413      (:bold t)))
414   "Face used for displaying header names."
415   :group 'article)
416
417 (defface gnus-header-content-face
418   '((((class color)
419       (background dark))
420      (:foreground "forest green" :italic t))
421     (((class color)
422       (background light))
423      (:foreground "DarkGreen" :italic t))
424     (t 
425      (:italic t)))  "Face used for displaying header content."
426   :group 'article)
427
428 (defcustom gnus-header-face-alist
429   '(("From" nil gnus-header-from-face)
430     ("Subject" nil gnus-header-subject-face)
431     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
432     ("" gnus-header-name-face gnus-header-content-face))
433   "Controls highlighting of article header.
434
435 An alist of the form (HEADER NAME CONTENT). 
436
437 HEADER is a regular expression which should match the name of an
438 header header and NAME and CONTENT are either face names or nil.
439
440 The name of each header field will be displayed using the face
441 specified by the first element in the list where HEADER match the
442 header name and NAME is non-nil.  Similarly, the content will be
443 displayed by the first non-nil matching CONTENT face."
444   :group 'article
445   :type '(repeat (list (regexp :tag "Header")
446                        (choice :tag "Name"
447                                (item :tag "skip" nil)
448                                (face :value default))
449                        (choice :tag "Content"
450                                (item :tag "skip" nil)
451                                (face :value default)))))
452
453 ;;; Internal variables
454
455 (defvar gnus-article-mode-syntax-table
456   (let ((table (copy-syntax-table text-mode-syntax-table)))
457     ;;(modify-syntax-entry ?_ "w" table)
458     table)
459   "Syntax table used in article mode buffers.
460 Initialized from `text-mode-syntax-table.")
461
462 (defvar gnus-save-article-buffer nil)
463
464 (defvar gnus-article-mode-line-format-alist
465     (nconc '((?w (gnus-article-wash-status) ?s))
466            gnus-summary-mode-line-format-alist))
467
468 (defvar gnus-number-of-articles-to-be-saved nil)
469
470 (defvar gnus-inhibit-hiding nil)
471 (defvar gnus-newsgroup-name)
472
473 (defsubst gnus-article-hide-text (b e props)
474   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
475   (add-text-properties b e props)
476   (when (memq 'intangible props)
477     (put-text-property 
478      (max (1- b) (point-min))
479      b 'intangible (cddr (memq 'intangible props)))))
480
481 (defsubst gnus-article-unhide-text (b e)
482   "Remove hidden text properties from region between B and E."
483   (remove-text-properties b e gnus-hidden-properties)
484   (when (memq 'intangible gnus-hidden-properties)
485     (put-text-property (max (1- b) (point-min))
486                        b 'intangible nil)))
487
488 (defun gnus-article-hide-text-type (b e type)
489   "Hide text of TYPE between B and E."
490   (gnus-article-hide-text
491    b e (cons 'article-type (cons type gnus-hidden-properties))))
492
493 (defun gnus-article-unhide-text-type (b e type)
494   "Hide text of TYPE between B and E."
495   (remove-text-properties
496    b e (cons 'article-type (cons type gnus-hidden-properties)))
497   (when (memq 'intangible gnus-hidden-properties)
498     (put-text-property (max (1- b) (point-min))
499                        b 'intangible nil)))
500
501 (defun gnus-article-hide-text-of-type (type)
502   "Hide text of TYPE in the current buffer."
503   (save-excursion
504     (let ((b (point-min))
505           (e (point-max)))
506       (while (setq b (text-property-any b e 'article-type type))
507         (add-text-properties b (incf b) gnus-hidden-properties)))))
508
509 (defun gnus-article-delete-text-of-type (type)
510   "Delete text of TYPE in the current buffer."
511   (save-excursion
512     (let ((b (point-min)))
513       (while (setq b (text-property-any b (point-max) 'article-type type))
514         (delete-region b (incf b))))))
515
516 (defun gnus-article-delete-invisible-text ()
517   "Delete all invisible text in the current buffer."
518   (save-excursion
519     (let ((b (point-min)))
520       (while (setq b (text-property-any b (point-max) 'invisible t))
521         (delete-region b (incf b))))))
522
523 (defun gnus-article-text-type-exists-p (type)
524   "Say whether any text of type TYPE exists in the buffer."
525   (text-property-any (point-min) (point-max) 'article-type type))
526
527 (defsubst gnus-article-header-rank ()
528   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
529   (let ((list gnus-sorted-header-list)
530         (i 0))
531     (while list
532       (when (looking-at (car list))
533         (setq list nil))
534       (setq list (cdr list))
535       (incf i))
536     i))
537
538 (defun article-hide-headers (&optional arg delete)
539   "Toggle whether to hide unwanted headers and possibly sort them as well.
540 If given a negative prefix, always show; if given a positive prefix,
541 always hide."
542   (interactive (gnus-article-hidden-arg))
543   (if (gnus-article-check-hidden-text 'headers arg)
544       ;; Show boring headers as well.
545       (gnus-article-show-hidden-text 'boring-headers)
546     ;; This function might be inhibited.
547     (unless gnus-inhibit-hiding
548       (save-excursion
549         (save-restriction
550           (let ((buffer-read-only nil)
551                 (props (nconc (list 'article-type 'headers)
552                               gnus-hidden-properties))
553                 (max (1+ (length gnus-sorted-header-list)))
554                 (ignored (when (not gnus-visible-headers)
555                            (cond ((stringp gnus-ignored-headers)
556                                   gnus-ignored-headers)
557                                  ((listp gnus-ignored-headers)
558                                   (mapconcat 'identity gnus-ignored-headers
559                                              "\\|")))))
560                 (visible
561                  (cond ((stringp gnus-visible-headers)
562                         gnus-visible-headers)
563                        ((and gnus-visible-headers
564                              (listp gnus-visible-headers))
565                         (mapconcat 'identity gnus-visible-headers "\\|"))))
566                 (inhibit-point-motion-hooks t)
567                 want-list beg)
568             ;; First we narrow to just the headers.
569             (widen)
570             (goto-char (point-min))
571             ;; Hide any "From " lines at the beginning of (mail) articles.
572             (while (looking-at "From ")
573               (forward-line 1))
574             (unless (bobp)
575               (if delete
576                   (delete-region (point-min) (point))
577                 (gnus-article-hide-text (point-min) (point) props)))
578             ;; Then treat the rest of the header lines.
579             (narrow-to-region
580              (point)
581              (if (search-forward "\n\n" nil t) ; if there's a body
582                  (progn (forward-line -1) (point))
583                (point-max)))
584             ;; Then we use the two regular expressions
585             ;; `gnus-ignored-headers' and `gnus-visible-headers' to
586             ;; select which header lines is to remain visible in the
587             ;; article buffer.
588             (goto-char (point-min))
589             (while (re-search-forward "^[^ \t]*:" nil t)
590               (beginning-of-line)
591               ;; Mark the rank of the header.
592               (put-text-property 
593                (point) (1+ (point)) 'message-rank
594                (if (or (and visible (looking-at visible))
595                        (and ignored
596                             (not (looking-at ignored))))
597                    (gnus-article-header-rank) 
598                  (+ 2 max)))
599               (forward-line 1))
600             (message-sort-headers-1)
601             (when (setq beg (text-property-any 
602                              (point-min) (point-max) 'message-rank (+ 2 max)))
603               ;; We make the unwanted headers invisible.
604               (if delete
605                   (delete-region beg (point-max))
606                 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
607                 (gnus-article-hide-text-type beg (point-max) 'headers))
608               ;; Work around XEmacs lossage.
609               (put-text-property (point-min) beg 'invisible nil))))))))
610
611 (defun article-hide-boring-headers (&optional arg)
612   "Toggle hiding of headers that aren't very interesting.
613 If given a negative prefix, always show; if given a positive prefix,
614 always hide."
615   (interactive (gnus-article-hidden-arg))
616   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
617              (not gnus-show-all-headers))
618     (save-excursion
619       (save-restriction
620         (let ((buffer-read-only nil)
621               (list gnus-boring-article-headers)
622               (inhibit-point-motion-hooks t)
623               elem)
624           (nnheader-narrow-to-headers)
625           (while list
626             (setq elem (pop list))
627             (goto-char (point-min))
628             (cond
629              ;; Hide empty headers.
630              ((eq elem 'empty)
631               (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
632                 (forward-line -1)
633                 (gnus-article-hide-text-type
634                  (progn (beginning-of-line) (point))
635                  (progn 
636                    (end-of-line)
637                    (if (re-search-forward "^[^ \t]" nil t)
638                        (match-beginning 0)
639                      (point-max)))
640                  'boring-headers)))
641              ;; Hide boring Newsgroups header.
642              ((eq elem 'newsgroups)
643               (when (equal (gnus-fetch-field "newsgroups")
644                            (gnus-group-real-name
645                             (if (boundp 'gnus-newsgroup-name)
646                                 gnus-newsgroup-name
647                               "")))
648                 (gnus-article-hide-header "newsgroups")))
649              ((eq elem 'followup-to)
650               (when (equal (message-fetch-field "followup-to")
651                            (message-fetch-field "newsgroups"))
652                 (gnus-article-hide-header "followup-to")))
653              ((eq elem 'reply-to)
654               (let ((from (message-fetch-field "from"))
655                     (reply-to (message-fetch-field "reply-to")))
656                 (when (and
657                        from reply-to
658                        (equal 
659                         (nth 1 (mail-extract-address-components from))
660                         (nth 1 (mail-extract-address-components reply-to))))
661                   (gnus-article-hide-header "reply-to"))))
662              ((eq elem 'date)
663               (let ((date (message-fetch-field "date")))
664                 (when (and date
665                            (< (gnus-days-between (current-time-string) date)
666                               4))
667                   (gnus-article-hide-header "date")))))))))))
668
669 (defun gnus-article-hide-header (header)
670   (save-excursion
671     (goto-char (point-min))
672     (when (re-search-forward (concat "^" header ":") nil t)
673       (gnus-article-hide-text-type
674        (progn (beginning-of-line) (point))
675        (progn 
676          (end-of-line)
677          (if (re-search-forward "^[^ \t]" nil t)
678              (match-beginning 0)
679            (point-max)))
680        'boring-headers))))
681
682 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
683 (defun article-treat-overstrike ()
684   "Translate overstrikes into bold text."
685   (interactive)
686   (save-excursion
687     (let ((buffer-read-only nil))
688       (while (search-forward "\b" nil t)
689         (let ((next (following-char))
690               (previous (char-after (- (point) 2))))
691           ;; We do the boldification/underlining by hiding the
692           ;; overstrikes and putting the proper text property
693           ;; on the letters.
694           (cond 
695            ((eq next previous)
696             (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
697             (put-text-property (point) (1+ (point)) 'face 'bold))
698            ((eq next ?_)
699             (gnus-article-hide-text-type (1- (point)) (1+ (point)) 'overstrike)
700             (put-text-property
701              (- (point) 2) (1- (point)) 'face 'underline))
702            ((eq previous ?_)
703             (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
704             (put-text-property
705              (point) (1+ (point)) 'face 'underline))))))))
706
707 (defun article-fill ()
708   "Format too long lines."
709   (interactive)
710   (save-excursion
711     (let ((buffer-read-only nil))
712       (widen)
713       (goto-char (point-min))
714       (search-forward "\n\n" nil t)
715       (end-of-line 1)
716       (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
717             (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
718             (adaptive-fill-mode t))
719         (while (not (eobp))
720           (and (>= (current-column) (min fill-column (window-width)))
721                (/= (preceding-char) ?:)
722                (fill-paragraph nil))
723           (end-of-line 2))))))
724
725 (defun article-remove-cr ()
726   "Remove carriage returns from an article."
727   (interactive)
728   (save-excursion
729     (let ((buffer-read-only nil))
730       (goto-char (point-min))
731       (while (search-forward "\r" nil t)
732         (replace-match "" t t)))))
733
734 (defun article-remove-trailing-blank-lines ()
735   "Remove all trailing blank lines from the article."
736   (interactive)
737   (save-excursion
738     (let ((buffer-read-only nil))
739       (goto-char (point-max))
740       (delete-region
741        (point)
742        (progn
743          (while (and (not (bobp))
744                      (looking-at "^[ \t]*$"))
745            (forward-line -1))
746          (forward-line 1)
747          (point))))))
748
749 (defun article-display-x-face (&optional force)
750   "Look for an X-Face header and display it if present."
751   (interactive (list 'force))
752   (save-excursion
753     ;; Delete the old process, if any.
754     (when (process-status "article-x-face")
755       (delete-process "article-x-face"))
756     (let ((inhibit-point-motion-hooks t)
757           (case-fold-search nil)
758           from)
759       (save-restriction
760         (nnheader-narrow-to-headers)
761         (setq from (message-fetch-field "from"))
762         (goto-char (point-min))
763         (when (and gnus-article-x-face-command
764                    (or force
765                        ;; Check whether this face is censored.
766                        (not gnus-article-x-face-too-ugly)
767                        (and gnus-article-x-face-too-ugly from
768                             (not (string-match gnus-article-x-face-too-ugly
769                                                from))))
770                    ;; Has to be present.
771                    (re-search-forward "^X-Face: " nil t))
772           ;; We now have the area of the buffer where the X-Face is stored.
773           (let ((beg (point))
774                 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
775             ;; We display the face.
776             (if (symbolp gnus-article-x-face-command)
777                 ;; The command is a lisp function, so we call it.
778                 (if (gnus-functionp gnus-article-x-face-command)
779                     (funcall gnus-article-x-face-command beg end)
780                   (error "%s is not a function" gnus-article-x-face-command))
781               ;; The command is a string, so we interpret the command
782               ;; as a, well, command, and fork it off.
783               (let ((process-connection-type nil))
784                 (process-kill-without-query
785                  (start-process
786                   "article-x-face" nil shell-file-name shell-command-switch
787                   gnus-article-x-face-command))
788                 (process-send-region "article-x-face" beg end)
789                 (process-send-eof "article-x-face")))))))))
790
791 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
792 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
793 (defun article-decode-rfc1522 ()
794   "Hack to remove QP encoding from headers."
795   (let ((case-fold-search t)
796         (inhibit-point-motion-hooks t)
797         (buffer-read-only nil)
798         string)
799     (save-restriction
800       (narrow-to-region
801        (goto-char (point-min))
802        (or (search-forward "\n\n" nil t) (point-max)))
803       (goto-char (point-min))
804       (while (re-search-forward 
805               "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
806         (setq string (match-string 1))
807         (save-restriction
808           (narrow-to-region (match-beginning 0) (match-end 0))
809           (delete-region (point-min) (point-max))
810           (insert string)
811           (article-mime-decode-quoted-printable 
812            (goto-char (point-min)) (point-max))
813           (subst-char-in-region (point-min) (point-max) ?_ ? )
814           (goto-char (point-max)))
815         (goto-char (point-min))))))
816
817 (defun article-de-quoted-unreadable (&optional force)
818   "Do a naive translation of a quoted-printable-encoded article.
819 This is in no way, shape or form meant as a replacement for real MIME
820 processing, but is simply a stop-gap measure until MIME support is
821 written.
822 If FORCE, decode the article whether it is marked as quoted-printable
823 or not."
824   (interactive (list 'force))
825   (save-excursion
826     (let ((case-fold-search t)
827           (buffer-read-only nil)
828           (type (gnus-fetch-field "content-transfer-encoding")))
829       (gnus-article-decode-rfc1522)
830       (when (or force
831                 (and type (string-match "quoted-printable" (downcase type))))
832         (goto-char (point-min))
833         (search-forward "\n\n" nil 'move)
834         (article-mime-decode-quoted-printable (point) (point-max))))))
835
836 (defun article-mime-decode-quoted-printable-buffer ()
837   "Decode Quoted-Printable in the current buffer."
838   (article-mime-decode-quoted-printable (point-min) (point-max)))
839   
840 (defun article-mime-decode-quoted-printable (from to)
841   "Decode Quoted-Printable in the region between FROM and TO."
842   (interactive "r")
843   (goto-char from)
844   (while (search-forward "=" to t)
845     (cond ((eq (following-char) ?\n)
846            (delete-char -1)
847            (delete-char 1))
848           ((looking-at "[0-9A-F][0-9A-F]")
849            (subst-char-in-region
850             (1- (point)) (point) ?=
851             (hexl-hex-string-to-integer
852              (buffer-substring (point) (+ 2 (point)))))
853            (delete-char 2))
854           ((looking-at "=")
855            (delete-char 1))
856           ((gnus-message 3 "Malformed MIME quoted-printable message")))))
857
858 (defun article-hide-pgp (&optional arg)
859   "Toggle hiding of any PGP headers and signatures in the current article.
860 If given a negative prefix, always show; if given a positive prefix,
861 always hide."
862   (interactive (gnus-article-hidden-arg))
863   (unless (gnus-article-check-hidden-text 'pgp arg)
864     (save-excursion
865       (let (buffer-read-only beg end)
866         (widen)
867         (goto-char (point-min))
868         ;; Hide the "header".
869         (and (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
870              (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
871         (setq beg (point))
872         ;; Hide the actual signature.
873         (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
874              (setq end (1+ (match-beginning 0)))
875              (gnus-article-hide-text-type
876               end
877               (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
878                   (match-end 0)
879                 ;; Perhaps we shouldn't hide to the end of the buffer
880                 ;; if there is no end to the signature?
881                 (point-max))
882               'pgp))
883         ;; Hide "- " PGP quotation markers.
884         (when (and beg end)
885           (narrow-to-region beg end)
886           (goto-char (point-min))
887           (while (re-search-forward "^- " nil t)
888             (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
889           (widen))))))
890
891 (defun article-hide-pem (&optional arg)
892   "Toggle hiding of any PEM headers and signatures in the current article.
893 If given a negative prefix, always show; if given a positive prefix,
894 always hide."
895   (interactive (gnus-article-hidden-arg))
896   (unless (gnus-article-check-hidden-text 'pem arg)
897     (save-excursion
898       (let (buffer-read-only end)
899         (widen)
900         (goto-char (point-min))
901         ;; hide the horrendously ugly "header".
902         (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
903                              nil
904                              t)
905              (setq end (1+ (match-beginning 0)))
906              (gnus-article-hide-text-type
907               end
908               (if (search-forward "\n\n" nil t)
909                   (match-end 0)
910                 (point-max))
911               'pem))
912         ;; hide the trailer as well
913         (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
914                              nil
915                              t)
916              (gnus-article-hide-text-type
917               (match-beginning 0) (match-end 0) 'pem))))))
918
919 (defun article-hide-signature (&optional arg)
920   "Hide the signature in the current article.
921 If given a negative prefix, always show; if given a positive prefix,
922 always hide."
923   (interactive (gnus-article-hidden-arg))
924   (unless (gnus-article-check-hidden-text 'signature arg)
925     (save-excursion
926       (save-restriction
927         (let ((buffer-read-only nil))
928           (when (gnus-article-narrow-to-signature)
929             (gnus-article-hide-text-type 
930              (point-min) (point-max) 'signature)))))))
931
932 (defun article-strip-leading-blank-lines ()
933   "Remove all blank lines from the beginning of the article."
934   (interactive)
935   (save-excursion
936     (let ((inhibit-point-motion-hooks t)
937           buffer-read-only)
938       (goto-char (point-min))
939       (when (search-forward "\n\n" nil t)
940         (while (and (not (eobp))
941                     (looking-at "[ \t]*$"))
942           (gnus-delete-line))))))
943
944 (defun article-strip-multiple-blank-lines ()
945   "Replace consecutive blank lines with one empty line."
946   (interactive)
947   (save-excursion
948     (let (buffer-read-only)
949       ;; First make all blank lines empty.
950       (goto-char (point-min))
951       (while (re-search-forward "^[ \t]+$" nil t)
952         (replace-match "" nil t))
953       ;; Then replace multiple empty lines with a single empty line.
954       (goto-char (point-min))
955       (while (re-search-forward "\n\n\n+" nil t)
956         (replace-match "\n\n" t t)))))
957
958 (defun article-strip-blank-lines ()
959   "Strip leading, trailing and multiple blank lines."
960   (interactive)
961   (article-strip-leading-blank-lines)
962   (article-remove-trailing-blank-lines)
963   (article-strip-multiple-blank-lines))
964
965 (defvar mime::preview/content-list)
966 (defvar mime::preview-content-info/point-min)
967 (defun gnus-article-narrow-to-signature ()
968   "Narrow to the signature; return t if a signature is found, else nil."
969   (widen)
970   (when (and (boundp 'mime::preview/content-list)
971              mime::preview/content-list)
972     ;; We have a MIMEish article, so we use the MIME data to narrow.
973     (let ((pcinfo (car (last mime::preview/content-list))))
974       (ignore-errors
975         (narrow-to-region
976          (funcall (intern "mime::preview-content-info/point-min") pcinfo)
977          (point-max)))))
978   
979   (when (gnus-article-search-signature)
980     (forward-line 1)
981     ;; Check whether we have some limits to what we consider
982     ;; to be a signature.
983     (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
984                     (list gnus-signature-limit)))
985           limit limited)
986       (while (setq limit (pop limits))
987         (if (or (and (integerp limit)
988                      (< (- (point-max) (point)) limit))
989                 (and (floatp limit)
990                      (< (count-lines (point) (point-max)) limit))
991                 (and (gnus-functionp limit)
992                      (funcall limit))
993                 (and (stringp limit)
994                      (not (re-search-forward limit nil t))))
995             ()                          ; This limit did not succeed.
996           (setq limited t
997                 limits nil)))
998       (unless limited
999         (narrow-to-region (point) (point-max))
1000         t))))
1001
1002 (defun gnus-article-search-signature ()
1003   "Search the current buffer for the signature separator.
1004 Put point at the beginning of the signature separator."
1005   (let ((cur (point)))
1006     (goto-char (point-max))
1007     (if (if (stringp gnus-signature-separator)
1008             (re-search-backward gnus-signature-separator nil t)
1009           (let ((seps gnus-signature-separator))
1010             (while (and seps
1011                         (not (re-search-backward (car seps) nil t)))
1012               (pop seps))
1013             seps))
1014         t
1015       (goto-char cur)
1016       nil)))
1017
1018 (defun gnus-article-hidden-arg ()
1019   "Return the current prefix arg as a number, or 0 if no prefix."
1020   (list (if current-prefix-arg
1021             (prefix-numeric-value current-prefix-arg)
1022           0)))
1023
1024 (defun gnus-article-check-hidden-text (type arg)
1025   "Return nil if hiding is necessary.
1026 Arg can be nil or a number.  Nil and positive means hide, negative
1027 means show, 0 means toggle."
1028   (save-excursion
1029     (let ((hide (gnus-article-hidden-text-p type)))
1030       (cond
1031        ((or (null arg)
1032             (> arg 0))
1033         nil)
1034        ((< arg 0)
1035         (gnus-article-show-hidden-text type))
1036        (t
1037         (if (eq hide 'hidden)
1038             (gnus-article-show-hidden-text type)
1039           nil))))))
1040
1041 (defun gnus-article-hidden-text-p (type)
1042   "Say whether the current buffer contains hidden text of type TYPE."
1043   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1044     (when pos
1045       (if (get-text-property pos 'invisible)
1046           'hidden
1047         'shown))))
1048
1049 (defun gnus-article-show-hidden-text (type &optional hide)
1050   "Show all hidden text of type TYPE.
1051 If HIDE, hide the text instead."
1052   (save-excursion
1053     (let ((buffer-read-only nil)
1054           (inhibit-point-motion-hooks t)
1055           (end (point-min))
1056           beg)
1057       (while (setq beg (text-property-any end (point-max) 'article-type type))
1058         (goto-char beg)
1059         (setq end (or
1060                    (text-property-not-all beg (point-max) 'article-type type)
1061                    (point-max)))
1062         (if hide
1063             (gnus-article-hide-text beg end gnus-hidden-properties)
1064           (gnus-article-unhide-text beg end))
1065         (goto-char end))
1066       t)))
1067
1068 (defconst article-time-units
1069   `((year . ,(* 365.25 24 60 60))
1070     (week . ,(* 7 24 60 60))
1071     (day . ,(* 24 60 60))
1072     (hour . ,(* 60 60))
1073     (minute . 60)
1074     (second . 1))
1075   "Mapping from time units to seconds.")
1076
1077 (defun article-date-ut (&optional type highlight header)
1078   "Convert DATE date to universal time in the current article.
1079 If TYPE is `local', convert to local time; if it is `lapsed', output
1080 how much time has lapsed since DATE."
1081   (interactive (list 'ut t))
1082   (let* ((header (or header 
1083                      (mail-header-date gnus-current-headers)
1084                      (message-fetch-field "date")
1085                      ""))
1086          (date (if (vectorp header) (mail-header-date header)
1087                  header))
1088          (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1089          (inhibit-point-motion-hooks t)
1090          bface eface)
1091     (when (and date (not (string= date "")))
1092       (save-excursion
1093         (save-restriction
1094           (nnheader-narrow-to-headers)
1095           (let ((buffer-read-only nil))
1096             ;; Delete any old Date headers.
1097             (if (re-search-forward date-regexp nil t)
1098                 (progn
1099                   (setq bface (get-text-property (gnus-point-at-bol) 'face)
1100                         eface (get-text-property (1- (gnus-point-at-eol))
1101                                                  'face))
1102                   (message-remove-header date-regexp t)
1103                   (beginning-of-line))
1104               (goto-char (point-max)))
1105             (insert (article-make-date-line date type))
1106             ;; Do highlighting.
1107             (forward-line -1)
1108             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1109               (put-text-property (match-beginning 1) (match-end 1)
1110                                  'face bface)
1111               (put-text-property (match-beginning 2) (match-end 2)
1112                                  'face eface))))))))
1113
1114 (defun article-make-date-line (date type)
1115   "Return a DATE line of TYPE."
1116   (cond
1117    ;; Convert to the local timezone.  We have to slap a
1118    ;; `condition-case' round the calls to the timezone
1119    ;; functions since they aren't particularly resistant to
1120    ;; buggy dates.
1121    ((eq type 'local)
1122     (concat "Date: " (condition-case ()
1123                          (timezone-make-date-arpa-standard date)
1124                        (error date))
1125             "\n"))
1126    ;; Convert to Universal Time.
1127    ((eq type 'ut)
1128     (concat "Date: "
1129             (condition-case ()
1130                 (timezone-make-date-arpa-standard date nil "UT")
1131               (error date))
1132             "\n"))
1133    ;; Get the original date from the article.
1134    ((eq type 'original)
1135     (concat "Date: " date "\n"))
1136    ;; Let the user define the format.
1137    ((eq type 'user)
1138     (format-time-string gnus-article-time-format
1139                         (ignore-errors
1140                           (gnus-encode-date
1141                            (timezone-make-date-arpa-standard
1142                             date nil "UT")))))
1143    ;; Do an X-Sent lapsed format.
1144    ((eq type 'lapsed)
1145     ;; If the date is seriously mangled, the timezone functions are
1146     ;; liable to bug out, so we ignore all errors.
1147     (let* ((now (current-time))
1148            (real-time
1149             (ignore-errors
1150               (gnus-time-minus
1151                (gnus-encode-date
1152                 (timezone-make-date-arpa-standard
1153                  (current-time-string now)
1154                  (current-time-zone now) "UT"))
1155                (gnus-encode-date
1156                 (timezone-make-date-arpa-standard
1157                  date nil "UT")))))
1158            (real-sec (and real-time
1159                           (+ (* (float (car real-time)) 65536)
1160                              (cadr real-time))))
1161            (sec (and real-time (abs real-sec)))
1162            num prev)
1163       (cond
1164        ((null real-time)
1165         "X-Sent: Unknown\n")
1166        ((zerop sec)
1167         "X-Sent: Now\n")
1168        (t
1169         (concat
1170          "X-Sent: "
1171          ;; This is a bit convoluted, but basically we go
1172          ;; through the time units for years, weeks, etc,
1173          ;; and divide things to see whether that results
1174          ;; in positive answers.
1175          (mapconcat
1176           (lambda (unit)
1177             (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1178                 ;; The (remaining) seconds are too few to
1179                 ;; be divided into this time unit.
1180                 ""
1181               ;; It's big enough, so we output it.
1182               (setq sec (- sec (* num (cdr unit))))
1183               (prog1
1184                   (concat (if prev ", " "") (int-to-string
1185                                              (floor num))
1186                           " " (symbol-name (car unit)) 
1187                           (if (> num 1) "s" ""))
1188                 (setq prev t))))
1189           article-time-units "")
1190          ;; If dates are odd, then it might appear like the
1191          ;; article was sent in the future.
1192          (if (> real-sec 0)
1193              " ago\n"
1194            " in the future\n"))))))
1195    (t
1196     (error "Unknown conversion type: %s" type))))
1197
1198 (defun article-date-local (&optional highlight)
1199   "Convert the current article date to the local timezone."
1200   (interactive (list t))
1201   (article-date-ut 'local highlight))
1202
1203 (defun article-date-original (&optional highlight)
1204   "Convert the current article date to what it was originally.
1205 This is only useful if you have used some other date conversion
1206 function and want to see what the date was before converting."
1207   (interactive (list t))
1208   (article-date-ut 'original highlight))
1209
1210 (defun article-date-lapsed (&optional highlight)
1211   "Convert the current article date to time lapsed since it was sent."
1212   (interactive (list t))
1213   (article-date-ut 'lapsed highlight))
1214
1215 (defun article-date-user (&optional highlight)
1216   "Convert the current article date to the user-defined format."
1217   (interactive (list t))
1218   (article-date-ut 'user highlight))
1219
1220 (defun article-show-all ()
1221   "Show all hidden text in the article buffer."
1222   (interactive)
1223   (save-excursion
1224     (let ((buffer-read-only nil))
1225       (gnus-article-unhide-text (point-min) (point-max)))))
1226
1227 (defun article-emphasize (&optional arg)
1228   "Emphasize text according to `gnus-emphasis-alist'."
1229   (interactive (gnus-article-hidden-arg))
1230   (unless (gnus-article-check-hidden-text 'emphasis arg)
1231     (save-excursion
1232       (let ((alist gnus-emphasis-alist)
1233             (buffer-read-only nil)
1234             (props (append '(article-type emphasis)
1235                            gnus-hidden-properties))
1236             regexp elem beg invisible visible face)
1237         (goto-char (point-min))
1238         (search-forward "\n\n" nil t)
1239         (setq beg (point))
1240         (while (setq elem (pop alist))
1241           (goto-char beg)
1242           (setq regexp (car elem)
1243                 invisible (nth 1 elem)
1244                 visible (nth 2 elem)
1245                 face (nth 3 elem))
1246           (while (re-search-forward regexp nil t)
1247             (when (and (match-beginning visible) (match-beginning invisible))
1248               (gnus-article-hide-text
1249                (match-beginning invisible) (match-end invisible) props)
1250               (gnus-article-unhide-text-type
1251                (match-beginning visible) (match-end visible) 'emphasis)
1252               (gnus-put-text-property-excluding-newlines
1253                (match-beginning visible) (match-end visible) 'face face)
1254               (goto-char (match-end invisible)))))))))
1255
1256 (defvar gnus-summary-article-menu)
1257 (defvar gnus-summary-post-menu)
1258
1259 ;;; Saving functions.
1260
1261 (defun gnus-article-save (save-buffer file &optional num)
1262   "Save the currently selected article."
1263   (unless gnus-save-all-headers
1264     ;; Remove headers according to `gnus-saved-headers'.
1265     (let ((gnus-visible-headers
1266            (or gnus-saved-headers gnus-visible-headers))
1267           (gnus-article-buffer save-buffer))
1268       (gnus-article-hide-headers 1 t)))
1269   (save-window-excursion
1270     (if (not gnus-default-article-saver)
1271         (error "No default saver is defined.")
1272       ;; !!! Magic!  The saving functions all save
1273       ;; `gnus-original-article-buffer' (or so they think), but we
1274       ;; bind that variable to our save-buffer.
1275       (set-buffer gnus-article-buffer)
1276       (let* ((gnus-save-article-buffer save-buffer)
1277              (filename
1278               (cond
1279                ((not gnus-prompt-before-saving) 'default)
1280                ((eq gnus-prompt-before-saving 'always) nil)
1281                (t file)))
1282              (gnus-number-of-articles-to-be-saved
1283               (when (eq gnus-prompt-before-saving t)
1284                 num)))                  ; Magic
1285         (set-buffer gnus-summary-buffer)
1286         (funcall gnus-default-article-saver filename))))) 
1287
1288 (defun gnus-read-save-file-name (prompt default-name &optional filename)
1289   (cond
1290    ((eq filename 'default)
1291     default-name)
1292    (filename filename)
1293    (t
1294     (let* ((split-name (gnus-get-split-value gnus-split-methods))
1295            (prompt
1296             (format prompt (if (and gnus-number-of-articles-to-be-saved
1297                                     (> gnus-number-of-articles-to-be-saved 1))
1298                                (format "these %d articles"
1299                                        gnus-number-of-articles-to-be-saved)
1300                              "this article")))
1301            (file
1302             ;; Let the split methods have their say.
1303             (cond
1304              ;; No split name was found.
1305              ((null split-name)
1306               (read-file-name
1307                (concat prompt " (default "
1308                        (file-name-nondirectory default-name) ") ")
1309                (file-name-directory default-name)
1310                default-name))
1311              ;; A single split name was found
1312              ((= 1 (length split-name))
1313               (let* ((name (car split-name))
1314                      (dir (cond ((file-directory-p name)
1315                                  (file-name-as-directory name))
1316                                 ((file-exists-p name) name)
1317                                 (t gnus-article-save-directory))))
1318                 (read-file-name
1319                  (concat prompt " (default " name ") ")
1320                  dir name)))
1321              ;; A list of splits was found.
1322              (t
1323               (setq split-name (nreverse split-name))
1324               (let (result)
1325                 (let ((file-name-history (nconc split-name file-name-history)))
1326                   (setq result
1327                         (expand-file-name
1328                          (read-file-name
1329                           (concat prompt " (`M-p' for defaults) ")
1330                           gnus-article-save-directory
1331                           (car split-name))
1332                          gnus-article-save-directory)))
1333                 (car (push result file-name-history)))))))
1334       ;; Create the directory.
1335       (gnus-make-directory (file-name-directory file))
1336       ;; If we have read a directory, we append the default file name.
1337       (when (file-directory-p file)
1338         (setq file (concat (file-name-as-directory file)
1339                            (file-name-nondirectory default-name))))
1340       ;; Possibly translate some characters.
1341       (nnheader-translate-file-chars file)))))
1342
1343 (defun gnus-article-archive-name (group)
1344   "Return the first instance of an \"Archive-name\" in the current buffer."
1345   (let ((case-fold-search t))
1346     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1347       (nnheader-concat gnus-article-save-directory
1348                        (match-string 1)))))
1349
1350 (defun gnus-summary-save-in-rmail (&optional filename)
1351   "Append this article to Rmail file.
1352 Optional argument FILENAME specifies file name.
1353 Directory to save to is default to `gnus-article-save-directory'."
1354   (interactive)
1355   (gnus-set-global-variables)
1356   (let ((default-name
1357           (funcall gnus-rmail-save-name gnus-newsgroup-name
1358                    gnus-current-headers gnus-newsgroup-last-rmail)))
1359     (setq filename (gnus-read-save-file-name
1360                     "Save %s in rmail file:" default-name filename))
1361     (gnus-make-directory (file-name-directory filename))
1362     (gnus-eval-in-buffer-window gnus-save-article-buffer
1363       (save-excursion
1364         (save-restriction
1365           (widen)
1366           (gnus-output-to-rmail filename))))
1367     ;; Remember the directory name to save articles
1368     (setq gnus-newsgroup-last-rmail filename)))
1369
1370 (defun gnus-summary-save-in-mail (&optional filename)
1371   "Append this article to Unix mail file.
1372 Optional argument FILENAME specifies file name.
1373 Directory to save to is default to `gnus-article-save-directory'."
1374   (interactive)
1375   (gnus-set-global-variables)
1376   (let ((default-name
1377           (funcall gnus-mail-save-name gnus-newsgroup-name
1378                    gnus-current-headers gnus-newsgroup-last-mail)))
1379     (setq filename (gnus-read-save-file-name
1380                     "Save %s in Unix mail file:" default-name filename))
1381     (setq filename
1382           (expand-file-name filename
1383                             (and default-name
1384                                  (file-name-directory default-name))))
1385     (gnus-make-directory (file-name-directory filename))
1386     (gnus-eval-in-buffer-window gnus-save-article-buffer
1387       (save-excursion
1388         (save-restriction
1389           (widen)
1390           (if (and (file-readable-p filename) (mail-file-babyl-p filename))
1391               (gnus-output-to-rmail filename)
1392             (let ((mail-use-rfc822 t))
1393               (rmail-output filename 1 t t))))))
1394     ;; Remember the directory name to save articles.
1395     (setq gnus-newsgroup-last-mail filename)))
1396
1397 (defun gnus-summary-save-in-file (&optional filename overwrite)
1398   "Append this article to file.
1399 Optional argument FILENAME specifies file name.
1400 Directory to save to is default to `gnus-article-save-directory'."
1401   (interactive)
1402   (gnus-set-global-variables)
1403   (let ((default-name
1404           (funcall gnus-file-save-name gnus-newsgroup-name
1405                    gnus-current-headers gnus-newsgroup-last-file)))
1406     (setq filename (gnus-read-save-file-name
1407                     "Save %s in file:" default-name filename))
1408     (gnus-make-directory (file-name-directory filename))
1409     (gnus-eval-in-buffer-window gnus-save-article-buffer
1410       (save-excursion
1411         (save-restriction
1412           (widen)
1413           (when (and overwrite
1414                      (file-exists-p filename))
1415             (delete-file filename))
1416           (gnus-output-to-file filename))))
1417     ;; Remember the directory name to save articles.
1418     (setq gnus-newsgroup-last-file filename)))
1419
1420 (defun gnus-summary-write-to-file (&optional filename)
1421   "Write this article to a file.
1422 Optional argument FILENAME specifies file name.
1423 The directory to save in defaults to `gnus-article-save-directory'."
1424   (interactive)
1425   (gnus-summary-save-in-file nil t))
1426
1427 (defun gnus-summary-save-body-in-file (&optional filename)
1428   "Append this article body to a file.
1429 Optional argument FILENAME specifies file name.
1430 The directory to save in defaults to `gnus-article-save-directory'."
1431   (interactive)
1432   (gnus-set-global-variables)
1433   (let ((default-name
1434           (funcall gnus-file-save-name gnus-newsgroup-name
1435                    gnus-current-headers gnus-newsgroup-last-file)))
1436     (setq filename (gnus-read-save-file-name
1437                     "Save %s body in file:" default-name filename))
1438     (gnus-make-directory (file-name-directory filename))
1439     (gnus-eval-in-buffer-window gnus-save-article-buffer
1440       (save-excursion
1441         (save-restriction
1442           (widen)
1443           (goto-char (point-min))
1444           (when (search-forward "\n\n" nil t)
1445             (narrow-to-region (point) (point-max)))
1446           (gnus-output-to-file filename))))
1447     ;; Remember the directory name to save articles.
1448     (setq gnus-newsgroup-last-file filename)))
1449
1450 (defun gnus-summary-save-in-pipe (&optional command)
1451   "Pipe this article to subprocess."
1452   (interactive)
1453   (gnus-set-global-variables)
1454   (setq command
1455         (cond ((eq command 'default)
1456                gnus-last-shell-command)
1457               (command command)
1458               (t (read-string 
1459                   (format
1460                    "Shell command on %s: "
1461                    (if (and gnus-number-of-articles-to-be-saved
1462                             (> gnus-number-of-articles-to-be-saved 1))
1463                        (format "these %d articles"
1464                                gnus-number-of-articles-to-be-saved)
1465                      "this article"))
1466                   gnus-last-shell-command))))
1467   (when (string-equal command "")
1468     (setq command gnus-last-shell-command))
1469   (gnus-eval-in-buffer-window gnus-article-buffer
1470     (save-restriction
1471       (widen)
1472       (shell-command-on-region (point-min) (point-max) command nil)))
1473   (setq gnus-last-shell-command command))
1474
1475 ;;; Article file names when saving.
1476
1477 (defun gnus-capitalize-newsgroup (newsgroup)
1478   "Capitalize NEWSGROUP name."
1479   (when (not (zerop (length newsgroup)))
1480     (concat (char-to-string (upcase (aref newsgroup 0)))
1481             (substring newsgroup 1))))
1482
1483 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1484   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1485 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1486 Otherwise, it is like ~/News/news/group/num."
1487   (let ((default
1488           (expand-file-name
1489            (concat (if (gnus-use-long-file-name 'not-save)
1490                        (gnus-capitalize-newsgroup newsgroup)
1491                      (gnus-newsgroup-directory-form newsgroup))
1492                    "/" (int-to-string (mail-header-number headers)))
1493            gnus-article-save-directory)))
1494     (if (and last-file
1495              (string-equal (file-name-directory default)
1496                            (file-name-directory last-file))
1497              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1498         default
1499       (or last-file default))))
1500
1501 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1502   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1503 If variable `gnus-use-long-file-name' is non-nil, it is
1504 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
1505   (let ((default
1506           (expand-file-name
1507            (concat (if (gnus-use-long-file-name 'not-save)
1508                        newsgroup
1509                      (gnus-newsgroup-directory-form newsgroup))
1510                    "/" (int-to-string (mail-header-number headers)))
1511            gnus-article-save-directory)))
1512     (if (and last-file
1513              (string-equal (file-name-directory default)
1514                            (file-name-directory last-file))
1515              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1516         default
1517       (or last-file default))))
1518
1519 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1520   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1521 If variable `gnus-use-long-file-name' is non-nil, it is
1522 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
1523   (or last-file
1524       (expand-file-name
1525        (if (gnus-use-long-file-name 'not-save)
1526            (gnus-capitalize-newsgroup newsgroup)
1527          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1528        gnus-article-save-directory)))
1529
1530 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1531   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1532 If variable `gnus-use-long-file-name' is non-nil, it is
1533 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
1534   (or last-file
1535       (expand-file-name
1536        (if (gnus-use-long-file-name 'not-save)
1537            newsgroup
1538          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1539        gnus-article-save-directory)))
1540
1541 (eval-and-compile
1542   (mapcar
1543    (lambda (func)
1544      (let (afunc gfunc)
1545        (if (consp func)
1546            (setq afunc (car func)
1547                  gfunc (cdr func))
1548          (setq afunc func
1549                gfunc (intern (format "gnus-%s" func))))
1550        (fset gfunc 
1551              (if (not (fboundp afunc))
1552                  nil
1553                `(lambda (&optional interactive &rest args)
1554                   ,(documentation afunc t)
1555                   (interactive (list t))
1556                   (save-excursion
1557                     (set-buffer gnus-article-buffer)
1558                     (if interactive
1559                         (call-interactively ',afunc)
1560                       (apply ',afunc args))))))))
1561    '(article-hide-headers
1562      article-hide-boring-headers
1563      article-treat-overstrike
1564      (article-fill . gnus-article-word-wrap)
1565      article-remove-cr
1566      article-display-x-face
1567      article-de-quoted-unreadable
1568      article-mime-decode-quoted-printable
1569      article-hide-pgp
1570      article-hide-pem
1571      article-hide-signature
1572      article-remove-trailing-blank-lines
1573      article-strip-leading-blank-lines
1574      article-strip-multiple-blank-lines
1575      article-strip-blank-lines
1576      article-date-local
1577      article-date-original
1578      article-date-ut
1579      article-date-user
1580      article-date-lapsed
1581      article-emphasize
1582      (article-show-all . gnus-article-show-all-headers))))
1583 \f
1584 ;;;
1585 ;;; Gnus article mode
1586 ;;;
1587
1588 (put 'gnus-article-mode 'mode-class 'special)
1589
1590 (when t
1591   (gnus-define-keys gnus-article-mode-map
1592     " " gnus-article-goto-next-page
1593     "\177" gnus-article-goto-prev-page
1594     [delete] gnus-article-goto-prev-page
1595     "\C-c^" gnus-article-refer-article
1596     "h" gnus-article-show-summary
1597     "s" gnus-article-show-summary
1598     "\C-c\C-m" gnus-article-mail
1599     "?" gnus-article-describe-briefly
1600     gnus-mouse-2 gnus-article-push-button
1601     "\r" gnus-article-press-button
1602     "\t" gnus-article-next-button
1603     "\M-\t" gnus-article-prev-button
1604     "e" gnus-article-edit
1605     "<" beginning-of-buffer
1606     ">" end-of-buffer
1607     "\C-c\C-i" gnus-info-find-node
1608     "\C-c\C-b" gnus-bug
1609
1610     "\C-d" gnus-article-read-summary-keys
1611     "\M-*" gnus-article-read-summary-keys
1612     "\M-g" gnus-article-read-summary-keys)
1613
1614   (substitute-key-definition
1615    'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1616
1617 (defun gnus-article-make-menu-bar ()
1618   (gnus-turn-off-edit-menu 'article)
1619   (unless (boundp 'gnus-article-article-menu)
1620     (easy-menu-define
1621      gnus-article-article-menu gnus-article-mode-map ""
1622      '("Article"
1623        ["Scroll forwards" gnus-article-goto-next-page t]
1624        ["Scroll backwards" gnus-article-goto-prev-page t]
1625        ["Show summary" gnus-article-show-summary t]
1626        ["Fetch Message-ID at point" gnus-article-refer-article t]
1627        ["Mail to address at point" gnus-article-mail t]))
1628
1629     (easy-menu-define
1630      gnus-article-treatment-menu gnus-article-mode-map ""
1631      '("Treatment"
1632        ["Hide headers" gnus-article-hide-headers t]
1633        ["Hide signature" gnus-article-hide-signature t]
1634        ["Hide citation" gnus-article-hide-citation t]
1635        ["Treat overstrike" gnus-article-treat-overstrike t]
1636        ["Remove carriage return" gnus-article-remove-cr t]
1637        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1638
1639     (when (boundp 'gnus-summary-article-menu)
1640       (define-key gnus-article-mode-map [menu-bar commands]
1641         (cons "Commands" gnus-summary-article-menu)))
1642
1643     (when (boundp 'gnus-summary-post-menu)
1644       (define-key gnus-article-mode-map [menu-bar post]
1645         (cons "Post" gnus-summary-post-menu)))
1646
1647     (run-hooks 'gnus-article-menu-hook)))
1648
1649 (defun gnus-article-mode ()
1650   "Major mode for displaying an article.
1651
1652 All normal editing commands are switched off.
1653
1654 The following commands are available in addition to all summary mode
1655 commands:
1656 \\<gnus-article-mode-map>
1657 \\[gnus-article-next-page]\t Scroll the article one page forwards
1658 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1659 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1660 \\[gnus-article-show-summary]\t Display the summary buffer
1661 \\[gnus-article-mail]\t Send a reply to the address near point
1662 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1663 \\[gnus-info-find-node]\t Go to the Gnus info node"
1664   (interactive)
1665   (when (gnus-visual-p 'article-menu 'menu)
1666     (gnus-article-make-menu-bar))
1667   (kill-all-local-variables)
1668   (gnus-simplify-mode-line)
1669   (setq mode-name "Article")
1670   (setq major-mode 'gnus-article-mode)
1671   (make-local-variable 'minor-mode-alist)
1672   (unless (assq 'gnus-show-mime minor-mode-alist)
1673     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1674   (use-local-map gnus-article-mode-map)
1675   (gnus-update-format-specifications nil 'article-mode)
1676   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1677   (gnus-set-default-directory)
1678   (buffer-disable-undo (current-buffer))
1679   (setq buffer-read-only t)
1680   (set-syntax-table gnus-article-mode-syntax-table)
1681   (run-hooks 'gnus-article-mode-hook))
1682
1683 (defun gnus-article-setup-buffer ()
1684   "Initialize the article buffer."
1685   (let* ((name (if gnus-single-article-buffer "*Article*"
1686                  (concat "*Article " gnus-newsgroup-name "*")))
1687          (original
1688           (progn (string-match "\\*Article" name)
1689                  (concat " *Original Article"
1690                          (substring name (match-end 0))))))
1691     (setq gnus-article-buffer name)
1692     (setq gnus-original-article-buffer original)
1693     ;; This might be a variable local to the summary buffer.
1694     (unless gnus-single-article-buffer
1695       (save-excursion
1696         (set-buffer gnus-summary-buffer)
1697         (setq gnus-article-buffer name)
1698         (setq gnus-original-article-buffer original)
1699         (gnus-set-global-variables)))
1700     ;; Init original article buffer.
1701     (save-excursion
1702       (set-buffer (get-buffer-create gnus-original-article-buffer))
1703       (buffer-disable-undo (current-buffer))
1704       (setq major-mode 'gnus-original-article-mode)
1705       (gnus-add-current-to-buffer-list)
1706       (make-local-variable 'gnus-original-article))
1707     (if (get-buffer name)
1708         (save-excursion
1709           (set-buffer name)
1710           (buffer-disable-undo (current-buffer))
1711           (setq buffer-read-only t)
1712           (gnus-add-current-to-buffer-list)
1713           (unless (eq major-mode 'gnus-article-mode)
1714             (gnus-article-mode))
1715           (current-buffer))
1716       (save-excursion
1717         (set-buffer (get-buffer-create name))
1718         (gnus-add-current-to-buffer-list)
1719         (gnus-article-mode)
1720         (make-local-variable 'gnus-summary-buffer)
1721         (current-buffer)))))
1722
1723 ;; Set article window start at LINE, where LINE is the number of lines
1724 ;; from the head of the article.
1725 (defun gnus-article-set-window-start (&optional line)
1726   (set-window-start
1727    (get-buffer-window gnus-article-buffer t)
1728    (save-excursion
1729      (set-buffer gnus-article-buffer)
1730      (goto-char (point-min))
1731      (if (not line)
1732          (point-min)
1733        (gnus-message 6 "Moved to bookmark")
1734        (search-forward "\n\n" nil t)
1735        (forward-line line)
1736        (point)))))
1737
1738 (defun gnus-article-prepare (article &optional all-headers header)
1739   "Prepare ARTICLE in article mode buffer.
1740 ARTICLE should either be an article number or a Message-ID.
1741 If ARTICLE is an id, HEADER should be the article headers.
1742 If ALL-HEADERS is non-nil, no headers are hidden."
1743   (save-excursion
1744     ;; Make sure we start in a summary buffer.
1745     (unless (eq major-mode 'gnus-summary-mode)
1746       (set-buffer gnus-summary-buffer))
1747     (setq gnus-summary-buffer (current-buffer))
1748     ;; Make sure the connection to the server is alive.
1749     (unless (gnus-server-opened
1750              (gnus-find-method-for-group gnus-newsgroup-name))
1751       (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1752       (gnus-request-group gnus-newsgroup-name t))
1753     (let* ((gnus-article (if header (mail-header-number header) article))
1754            (summary-buffer (current-buffer))
1755            (internal-hook gnus-article-internal-prepare-hook)
1756            (group gnus-newsgroup-name)
1757            result)
1758       (save-excursion
1759         (gnus-article-setup-buffer)
1760         (set-buffer gnus-article-buffer)
1761         ;; Deactivate active regions.
1762         (when (and (boundp 'transient-mark-mode)
1763                    transient-mark-mode)
1764           (setq mark-active nil))
1765         (if (not (setq result (let ((buffer-read-only nil))
1766                                 (gnus-request-article-this-buffer
1767                                  article group))))
1768             ;; There is no such article.
1769             (save-excursion
1770               (when (and (numberp article)
1771                          (not (memq article gnus-newsgroup-sparse)))
1772                 (setq gnus-article-current
1773                       (cons gnus-newsgroup-name article))
1774                 (set-buffer gnus-summary-buffer)
1775                 (setq gnus-current-article article)
1776                 (gnus-summary-mark-article article gnus-canceled-mark))
1777               (unless (memq article gnus-newsgroup-sparse)
1778                 (gnus-error
1779                  1 "No such article (may have expired or been canceled)")))
1780           (if (or (eq result 'pseudo) (eq result 'nneething))
1781               (progn
1782                 (save-excursion
1783                   (set-buffer summary-buffer)
1784                   (setq gnus-last-article gnus-current-article
1785                         gnus-newsgroup-history (cons gnus-current-article
1786                                                      gnus-newsgroup-history)
1787                         gnus-current-article 0
1788                         gnus-current-headers nil
1789                         gnus-article-current nil)
1790                   (if (eq result 'nneething)
1791                       (gnus-configure-windows 'summary)
1792                     (gnus-configure-windows 'article))
1793                   (gnus-set-global-variables))
1794                 (gnus-set-mode-line 'article))
1795             ;; The result from the `request' was an actual article -
1796             ;; or at least some text that is now displayed in the
1797             ;; article buffer.
1798             (when (and (numberp article)
1799                        (not (eq article gnus-current-article)))
1800               ;; Seems like a new article has been selected.
1801               ;; `gnus-current-article' must be an article number.
1802               (save-excursion
1803                 (set-buffer summary-buffer)
1804                 (setq gnus-last-article gnus-current-article
1805                       gnus-newsgroup-history (cons gnus-current-article
1806                                                    gnus-newsgroup-history)
1807                       gnus-current-article article
1808                       gnus-current-headers
1809                       (gnus-summary-article-header gnus-current-article)
1810                       gnus-article-current
1811                       (cons gnus-newsgroup-name gnus-current-article))
1812                 (unless (vectorp gnus-current-headers)
1813                   (setq gnus-current-headers nil))
1814                 (gnus-summary-show-thread)
1815                 (run-hooks 'gnus-mark-article-hook)
1816                 (gnus-set-mode-line 'summary)
1817                 (when (gnus-visual-p 'article-highlight 'highlight)
1818                   (run-hooks 'gnus-visual-mark-article-hook))
1819                 ;; Set the global newsgroup variables here.
1820                 ;; Suggested by Jim Sisolak
1821                 ;; <sisolak@trans4.neep.wisc.edu>.
1822                 (gnus-set-global-variables)
1823                 (setq gnus-have-all-headers
1824                       (or all-headers gnus-show-all-headers))
1825                 (and gnus-use-cache
1826                      (vectorp (gnus-summary-article-header article))
1827                      (gnus-cache-possibly-enter-article
1828                       group article
1829                       (gnus-summary-article-header article)
1830                       (memq article gnus-newsgroup-marked)
1831                       (memq article gnus-newsgroup-dormant)
1832                       (memq article gnus-newsgroup-unreads)))))
1833             (when (or (numberp article)
1834                       (stringp article))
1835               ;; Hooks for getting information from the article.
1836               ;; This hook must be called before being narrowed.
1837               (let (buffer-read-only)
1838                 (run-hooks 'internal-hook)
1839                 (run-hooks 'gnus-article-prepare-hook)
1840                 ;; Decode MIME message.
1841                 (when gnus-show-mime
1842                   (if (or (not gnus-strict-mime)
1843                           (gnus-fetch-field "Mime-Version"))
1844                       (funcall gnus-show-mime-method)
1845                     (funcall gnus-decode-encoded-word-method)))
1846                 ;; Perform the article display hooks.
1847                 (run-hooks 'gnus-article-display-hook))
1848               ;; Do page break.
1849               (goto-char (point-min))
1850               (when gnus-break-pages
1851                 (gnus-narrow-to-page)))
1852             (gnus-set-mode-line 'article)
1853             (gnus-configure-windows 'article)
1854             (goto-char (point-min))
1855             t))))))
1856
1857 (defun gnus-article-wash-status ()
1858   "Return a string which display status of article washing."
1859   (save-excursion
1860     (set-buffer gnus-article-buffer)
1861     (let ((cite (gnus-article-hidden-text-p 'cite))
1862           (headers (gnus-article-hidden-text-p 'headers))
1863           (boring (gnus-article-hidden-text-p 'boring-headers))
1864           (pgp (gnus-article-hidden-text-p 'pgp))
1865           (pem (gnus-article-hidden-text-p 'pem))
1866           (signature (gnus-article-hidden-text-p 'signature))
1867           (overstrike (gnus-article-hidden-text-p 'overstrike))
1868           (emphasis (gnus-article-hidden-text-p 'emphasis))
1869           (mime gnus-show-mime))
1870       (format "%c%c%c%c%c%c%c"
1871               (if cite ?c ? )
1872               (if (or headers boring) ?h ? )
1873               (if (or pgp pem) ?p ? )
1874               (if signature ?s ? )
1875               (if overstrike ?o ? )
1876               (if mime ?m ? )
1877               (if emphasis ?e ? )))))
1878
1879 (defun gnus-article-hide-headers-if-wanted ()
1880   "Hide unwanted headers if `gnus-have-all-headers' is nil.
1881 Provided for backwards compatibility."
1882   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
1883       gnus-inhibit-hiding
1884       (gnus-article-hide-headers)))
1885
1886 ;;; Article savers.
1887
1888 (defun gnus-output-to-rmail (file-name)
1889   "Append the current article to an Rmail file named FILE-NAME."
1890   (require 'rmail)
1891   ;; Most of these codes are borrowed from rmailout.el.
1892   (setq file-name (expand-file-name file-name))
1893   (setq rmail-default-rmail-file file-name)
1894   (let ((artbuf (current-buffer))
1895         (tmpbuf (get-buffer-create " *Gnus-output*")))
1896     (save-excursion
1897       (or (get-file-buffer file-name)
1898           (file-exists-p file-name)
1899           (if (gnus-yes-or-no-p
1900                (concat "\"" file-name "\" does not exist, create it? "))
1901               (let ((file-buffer (create-file-buffer file-name)))
1902                 (save-excursion
1903                   (set-buffer file-buffer)
1904                   (rmail-insert-rmail-file-header)
1905                   (let ((require-final-newline nil))
1906                     (gnus-write-buffer file-name)))
1907                 (kill-buffer file-buffer))
1908             (error "Output file does not exist")))
1909       (set-buffer tmpbuf)
1910       (buffer-disable-undo (current-buffer))
1911       (erase-buffer)
1912       (insert-buffer-substring artbuf)
1913       (gnus-convert-article-to-rmail)
1914       ;; Decide whether to append to a file or to an Emacs buffer.
1915       (let ((outbuf (get-file-buffer file-name)))
1916         (if (not outbuf)
1917             (append-to-file (point-min) (point-max) file-name)
1918           ;; File has been visited, in buffer OUTBUF.
1919           (set-buffer outbuf)
1920           (let ((buffer-read-only nil)
1921                 (msg (and (boundp 'rmail-current-message)
1922                           (symbol-value 'rmail-current-message))))
1923             ;; If MSG is non-nil, buffer is in RMAIL mode.
1924             (when msg
1925               (widen)
1926               (narrow-to-region (point-max) (point-max)))
1927             (insert-buffer-substring tmpbuf)
1928             (when msg
1929               (goto-char (point-min))
1930               (widen)
1931               (search-backward "\^_")
1932               (narrow-to-region (point) (point-max))
1933               (goto-char (1+ (point-min)))
1934               (rmail-count-new-messages t)
1935               (rmail-show-message msg))))))
1936     (kill-buffer tmpbuf)))
1937
1938 (defun gnus-output-to-file (file-name)
1939   "Append the current article to a file named FILE-NAME."
1940   (let ((artbuf (current-buffer)))
1941     (nnheader-temp-write nil
1942       (insert-buffer-substring artbuf)
1943       ;; Append newline at end of the buffer as separator, and then
1944       ;; save it to file.
1945       (goto-char (point-max))
1946       (insert "\n")
1947       (append-to-file (point-min) (point-max) file-name))))
1948
1949 (defun gnus-convert-article-to-rmail ()
1950   "Convert article in current buffer to Rmail message format."
1951   (let ((buffer-read-only nil))
1952     ;; Convert article directly into Babyl format.
1953     ;; Suggested by Rob Austein <sra@lcs.mit.edu>
1954     (goto-char (point-min))
1955     (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1956     (while (search-forward "\n\^_" nil t) ;single char
1957       (replace-match "\n^_" t t))       ;2 chars: "^" and "_"
1958     (goto-char (point-max))
1959     (insert "\^_")))
1960
1961 (defun gnus-narrow-to-page (&optional arg)
1962   "Narrow the article buffer to a page.
1963 If given a numerical ARG, move forward ARG pages."
1964   (interactive "P")
1965   (setq arg (if arg (prefix-numeric-value arg) 0))
1966   (save-excursion
1967     (set-buffer gnus-article-buffer)
1968     (goto-char (point-min))
1969     (widen)
1970     ;; Remove any old next/prev buttons.
1971     (when (gnus-visual-p 'page-marker)
1972       (let ((buffer-read-only nil))
1973         (gnus-remove-text-with-property 'gnus-prev)
1974         (gnus-remove-text-with-property 'gnus-next)))
1975     (when
1976         (cond ((< arg 0)
1977                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
1978               ((> arg 0)
1979                (re-search-forward page-delimiter nil 'move arg)))
1980       (goto-char (match-end 0)))
1981     (narrow-to-region
1982      (point)
1983      (if (re-search-forward page-delimiter nil 'move)
1984          (match-beginning 0)
1985        (point)))
1986     (when (and (gnus-visual-p 'page-marker)
1987                (not (= (point-min) 1)))
1988       (save-excursion
1989         (goto-char (point-min))
1990         (gnus-insert-prev-page-button)))
1991     (when (and (gnus-visual-p 'page-marker)
1992                (< (+ (point-max) 2) (buffer-size)))
1993       (save-excursion
1994         (goto-char (point-max))
1995         (gnus-insert-next-page-button)))))
1996
1997 ;; Article mode commands
1998
1999 (defun gnus-article-goto-next-page ()
2000   "Show the next page of the article."
2001   (interactive)
2002   (when (gnus-article-next-page)
2003     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2004
2005 (defun gnus-article-goto-prev-page ()
2006   "Show the next page of the article."
2007   (interactive)
2008   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
2009     (gnus-article-prev-page nil)))
2010
2011 (defun gnus-article-next-page (&optional lines)
2012   "Show the next page of the current article.
2013 If end of article, return non-nil.  Otherwise return nil.
2014 Argument LINES specifies lines to be scrolled up."
2015   (interactive "p")
2016   (move-to-window-line -1)
2017   (if (save-excursion
2018         (end-of-line)
2019         (and (pos-visible-in-window-p)  ;Not continuation line.
2020              (eobp)))
2021       ;; Nothing in this page.
2022       (if (or (not gnus-break-pages)
2023               (save-excursion
2024                 (save-restriction
2025                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2026           t                             ;Nothing more.
2027         (gnus-narrow-to-page 1)         ;Go to next page.
2028         nil)
2029     ;; More in this page.
2030     (let ((scroll-in-place nil))
2031       (condition-case ()
2032           (scroll-up lines)
2033         (end-of-buffer
2034          ;; Long lines may cause an end-of-buffer error.
2035          (goto-char (point-max)))))
2036     (move-to-window-line 0)
2037     nil))
2038
2039 (defun gnus-article-prev-page (&optional lines)
2040   "Show previous page of current article.
2041 Argument LINES specifies lines to be scrolled down."
2042   (interactive "p")
2043   (move-to-window-line 0)
2044   (if (and gnus-break-pages
2045            (bobp)
2046            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2047       (progn
2048         (gnus-narrow-to-page -1)        ;Go to previous page.
2049         (goto-char (point-max))
2050         (recenter -1))
2051     (let ((scroll-in-place nil))
2052       (prog1
2053           (ignore-errors
2054             (scroll-down lines))
2055         (move-to-window-line 0)))))
2056
2057 (defun gnus-article-refer-article ()
2058   "Read article specified by message-id around point."
2059   (interactive)
2060   (let ((point (point)))
2061     (search-forward ">" nil t)          ;Move point to end of "<....>".
2062     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2063         (let ((message-id (match-string 1)))
2064           (goto-char point)
2065           (set-buffer gnus-summary-buffer)
2066           (gnus-summary-refer-article message-id))
2067       (goto-char (point))
2068       (error "No references around point"))))
2069
2070 (defun gnus-article-show-summary ()
2071   "Reconfigure windows to show summary buffer."
2072   (interactive)
2073   (gnus-configure-windows 'article)
2074   (gnus-summary-goto-subject gnus-current-article))
2075
2076 (defun gnus-article-describe-briefly ()
2077   "Describe article mode commands briefly."
2078   (interactive)
2079   (gnus-message 6
2080                 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page     \\[gnus-article-goto-prev-page]:Prev page  \\[gnus-article-show-summary]:Show summary  \\[gnus-info-find-node]:Run Info  \\[gnus-article-describe-briefly]:This help")))
2081
2082 (defun gnus-article-summary-command ()
2083   "Execute the last keystroke in the summary buffer."
2084   (interactive)
2085   (let ((obuf (current-buffer))
2086         (owin (current-window-configuration))
2087         func)
2088     (switch-to-buffer gnus-summary-buffer 'norecord)
2089     (setq func (lookup-key (current-local-map) (this-command-keys)))
2090     (call-interactively func)
2091     (set-buffer obuf)
2092     (set-window-configuration owin)
2093     (set-window-point (get-buffer-window (current-buffer)) (point))))
2094
2095 (defun gnus-article-summary-command-nosave ()
2096   "Execute the last keystroke in the summary buffer."
2097   (interactive)
2098   (let (func)
2099     (pop-to-buffer gnus-summary-buffer 'norecord)
2100     (setq func (lookup-key (current-local-map) (this-command-keys)))
2101     (call-interactively func)))
2102
2103 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2104   "Read a summary buffer key sequence and execute it from the article buffer."
2105   (interactive "P")
2106   (let ((nosaves
2107          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
2108            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2109            "=" "^" "\M-^" "|"))
2110         (nosave-but-article
2111          '("A\r"))
2112         (nosave-in-article
2113          '("\C-d"))
2114         keys)
2115     (save-excursion
2116       (set-buffer gnus-summary-buffer)
2117       (push (or key last-command-event) unread-command-events)
2118       (setq keys (read-key-sequence nil)))
2119     (message "")
2120
2121     (if (or (member keys nosaves)
2122             (member keys nosave-but-article)
2123             (member keys nosave-in-article))
2124         (let (func)
2125           (save-window-excursion
2126             (pop-to-buffer gnus-summary-buffer 'norecord)
2127             (setq func (lookup-key (current-local-map) keys)))
2128           (if (not func)
2129               (ding)
2130             (unless (member keys nosave-in-article)
2131               (set-buffer gnus-summary-buffer))
2132             (call-interactively func))
2133           (when (member keys nosave-but-article)
2134             (pop-to-buffer gnus-article-buffer 'norecord)))
2135       ;; These commands should restore window configuration.
2136       (let ((obuf (current-buffer))
2137             (owin (current-window-configuration))
2138             (opoint (point))
2139             func in-buffer)
2140         (if not-restore-window
2141             (pop-to-buffer gnus-summary-buffer 'norecord)
2142           (switch-to-buffer gnus-summary-buffer 'norecord))
2143         (setq in-buffer (current-buffer))
2144         (if (setq func (lookup-key (current-local-map) keys))
2145             (call-interactively func)
2146           (ding))
2147         (when (eq in-buffer (current-buffer))
2148           (set-buffer obuf)
2149           (unless not-restore-window
2150             (set-window-configuration owin))
2151           (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2152
2153 (defun gnus-article-hide (&optional arg force)
2154   "Hide all the gruft in the current article.
2155 This means that PGP stuff, signatures, cited text and (some)
2156 headers will be hidden.
2157 If given a prefix, show the hidden text instead."
2158   (interactive (list current-prefix-arg 'force))
2159   (gnus-article-hide-headers arg)
2160   (gnus-article-hide-pgp arg)
2161   (gnus-article-hide-citation-maybe arg force)
2162   (gnus-article-hide-signature arg))
2163
2164 (defun gnus-article-maybe-highlight ()
2165   "Do some article highlighting if `article-visual' is non-nil."
2166   (when (gnus-visual-p 'article-highlight 'highlight)
2167     (gnus-article-highlight-some)))
2168
2169 (defun gnus-request-article-this-buffer (article group)
2170   "Get an article and insert it into this buffer."
2171   (let (do-update-line)
2172     (prog1
2173         (save-excursion
2174           (erase-buffer)
2175           (gnus-kill-all-overlays)
2176           (setq group (or group gnus-newsgroup-name))
2177
2178           ;; Open server if it has closed.
2179           (gnus-check-server (gnus-find-method-for-group group))
2180
2181           ;; Using `gnus-request-article' directly will insert the article into
2182           ;; `nntp-server-buffer' - so we'll save some time by not having to
2183           ;; copy it from the server buffer into the article buffer.
2184
2185           ;; We only request an article by message-id when we do not have the
2186           ;; headers for it, so we'll have to get those.
2187           (when (stringp article)
2188             (let ((gnus-override-method gnus-refer-article-method))
2189               (gnus-read-header article)))
2190
2191           ;; If the article number is negative, that means that this article
2192           ;; doesn't belong in this newsgroup (possibly), so we find its
2193           ;; message-id and request it by id instead of number.
2194           (when (and (numberp article)
2195                      gnus-summary-buffer
2196                      (get-buffer gnus-summary-buffer)
2197                      (buffer-name (get-buffer gnus-summary-buffer)))
2198             (save-excursion
2199               (set-buffer gnus-summary-buffer)
2200               (let ((header (gnus-summary-article-header article)))
2201                 (when (< article 0)
2202                   (cond 
2203                    ((memq article gnus-newsgroup-sparse)
2204                     ;; This is a sparse gap article.
2205                     (setq do-update-line article)
2206                     (setq article (mail-header-id header))
2207                     (let ((gnus-override-method gnus-refer-article-method))
2208                       (gnus-read-header article))
2209                     (setq gnus-newsgroup-sparse
2210                           (delq article gnus-newsgroup-sparse)))
2211                    ((vectorp header)
2212                     ;; It's a real article.
2213                     (setq article (mail-header-id header)))
2214                    (t
2215                     ;; It is an extracted pseudo-article.
2216                     (setq article 'pseudo)
2217                     (gnus-request-pseudo-article header))))
2218                 
2219                 (let ((method (gnus-find-method-for-group 
2220                                gnus-newsgroup-name)))
2221                   (if (not (eq (car method) 'nneething))
2222                       ()
2223                     (let ((dir (concat (file-name-as-directory (nth 1 method))
2224                                        (mail-header-subject header))))
2225                       (when (file-directory-p dir)
2226                         (setq article 'nneething)
2227                         (gnus-group-enter-directory dir))))))))
2228
2229           (cond
2230            ;; Refuse to select canceled articles.
2231            ((and (numberp article)
2232                  gnus-summary-buffer
2233                  (get-buffer gnus-summary-buffer)
2234                  (buffer-name (get-buffer gnus-summary-buffer))
2235                  (eq (cdr (save-excursion
2236                             (set-buffer gnus-summary-buffer)
2237                             (assq article gnus-newsgroup-reads)))
2238                      gnus-canceled-mark))
2239             nil)
2240            ;; We first check `gnus-original-article-buffer'.
2241            ((and (get-buffer gnus-original-article-buffer)
2242                  (numberp article)
2243                  (save-excursion
2244                    (set-buffer gnus-original-article-buffer)
2245                    (and (equal (car gnus-original-article) group)
2246                         (eq (cdr gnus-original-article) article))))
2247             (insert-buffer-substring gnus-original-article-buffer)
2248             'article)
2249            ;; Check the backlog.
2250            ((and gnus-keep-backlog
2251                  (gnus-backlog-request-article group article (current-buffer)))
2252             'article)
2253            ;; Check asynchronous pre-fetch.
2254            ((gnus-async-request-fetched-article group article (current-buffer))
2255             (gnus-async-prefetch-next group article gnus-summary-buffer)
2256             'article)
2257            ;; Check the cache.
2258            ((and gnus-use-cache
2259                  (numberp article)
2260                  (gnus-cache-request-article article group))
2261             'article)
2262            ;; Get the article and put into the article buffer.
2263            ((or (stringp article) (numberp article))
2264             (let ((gnus-override-method
2265                    (and (stringp article) gnus-refer-article-method))
2266                   (buffer-read-only nil))
2267               (erase-buffer)
2268               (gnus-kill-all-overlays)
2269               (when (gnus-request-article article group (current-buffer))
2270                 (when (numberp article)
2271                   (gnus-async-prefetch-next group article gnus-summary-buffer)
2272                   (when gnus-keep-backlog
2273                     (gnus-backlog-enter-article 
2274                      group article (current-buffer))))
2275                 'article)))
2276            ;; It was a pseudo.
2277            (t article)))
2278
2279       ;; Take the article from the original article buffer
2280       ;; and place it in the buffer it's supposed to be in.
2281       (when (and (get-buffer gnus-article-buffer)
2282                  ;;(numberp article)
2283                  (equal (buffer-name (current-buffer))
2284                         (buffer-name (get-buffer gnus-article-buffer))))
2285         (save-excursion
2286           (if (get-buffer gnus-original-article-buffer)
2287               (set-buffer (get-buffer gnus-original-article-buffer))
2288             (set-buffer (get-buffer-create gnus-original-article-buffer))
2289             (buffer-disable-undo (current-buffer))
2290             (setq major-mode 'gnus-original-article-mode)
2291             (setq buffer-read-only t)
2292             (gnus-add-current-to-buffer-list))
2293           (let (buffer-read-only)
2294             (erase-buffer)
2295             (insert-buffer-substring gnus-article-buffer))
2296           (setq gnus-original-article (cons group article))))
2297     
2298       ;; Update sparse articles.
2299       (when (and do-update-line
2300                  (or (numberp article)
2301                      (stringp article)))
2302         (let ((buf (current-buffer)))
2303           (set-buffer gnus-summary-buffer)
2304           (gnus-summary-update-article do-update-line)
2305           (gnus-summary-goto-subject do-update-line nil t)
2306           (set-window-point (get-buffer-window (current-buffer) t)
2307                             (point))
2308           (set-buffer buf))))))
2309
2310 ;;;
2311 ;;; Article editing
2312 ;;;
2313
2314 (defcustom gnus-article-edit-mode-hook nil
2315   "Hook run in article edit mode buffers."
2316   :group 'article
2317   :type 'hook)
2318
2319 (defvar gnus-article-edit-done-function nil)
2320
2321 (defvar gnus-article-edit-mode-map nil)
2322
2323 (unless gnus-article-edit-mode-map 
2324   (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2325
2326   (gnus-define-keys gnus-article-edit-mode-map
2327     "\C-c\C-c" gnus-article-edit-done
2328     "\C-c\C-k" gnus-article-edit-exit)
2329
2330   (gnus-define-keys (gnus-article-edit-wash-map
2331                      "\C-c\C-w" gnus-article-edit-mode-map)
2332     "f" gnus-article-edit-full-stops))
2333
2334 (defun gnus-article-edit-mode ()
2335   "Major mode for editing articles.
2336 This is an extended text-mode.
2337
2338 \\{gnus-article-edit-mode-map}"
2339   (interactive)
2340   (kill-all-local-variables)
2341   (setq major-mode 'gnus-article-edit-mode)
2342   (setq mode-name "Article Edit")
2343   (use-local-map gnus-article-edit-mode-map)
2344   (make-local-variable 'gnus-article-edit-done-function)
2345   (make-local-variable 'gnus-prev-winconf)
2346   (setq buffer-read-only nil)
2347   (buffer-enable-undo)
2348   (widen)
2349   (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2350
2351 (defun gnus-article-edit (&optional force)
2352   "Edit the current article.
2353 This will have permanent effect only in mail groups.
2354 If FORCE is non-nil, allow editing of articles even in read-only
2355 groups."
2356   (interactive "P")
2357   (when (and (not force)
2358              (gnus-group-read-only-p))
2359     (error "The current newsgroup does not support article editing."))
2360   (gnus-article-edit-article
2361    `(lambda ()
2362       (gnus-summary-edit-article-done
2363        ,(or (mail-header-references gnus-current-headers) "")
2364        ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2365
2366 (defun gnus-article-edit-article (exit-func)
2367   "Start editing the contents of the current article buffer."
2368   (let ((winconf (current-window-configuration)))
2369     (set-buffer gnus-article-buffer)
2370     (gnus-article-edit-mode)
2371     (set-text-properties (point-min) (point-max) nil)
2372     (gnus-configure-windows 'edit-article)
2373     (setq gnus-article-edit-done-function exit-func)
2374     (setq gnus-prev-winconf winconf)
2375     (gnus-message 6 "C-c C-c to end edits")))
2376
2377 (defun gnus-article-edit-done ()
2378   "Update the article edits and exit."
2379   (interactive)
2380   (let ((func gnus-article-edit-done-function)
2381         (buf (current-buffer))
2382         (start (window-start)))
2383     (gnus-article-edit-exit)
2384     (save-excursion
2385       (set-buffer buf)
2386       (let ((buffer-read-only nil))
2387         (funcall func)))
2388     (set-buffer buf)
2389     (set-window-start (get-buffer-window buf) start)
2390     (set-window-point (get-buffer-window buf) (point))))
2391
2392 (defun gnus-article-edit-exit ()
2393   "Exit the article editing without updating."
2394   (interactive)
2395   ;; We remove all text props from the article buffer.
2396   (let ((buf (format "%s" (buffer-string)))
2397         (curbuf (current-buffer))
2398         (p (point))
2399         (window-start (window-start)))
2400     (erase-buffer)
2401     (insert buf)
2402     (let ((winconf gnus-prev-winconf))
2403       (gnus-article-mode)
2404       ;; The cache and backlog have to be flushed somewhat.
2405       (when gnus-use-cache
2406         (gnus-cache-update-article      
2407          (car gnus-article-current) (cdr gnus-article-current)))
2408       (when gnus-keep-backlog
2409         (gnus-backlog-remove-article 
2410          (car gnus-article-current) (cdr gnus-article-current)))
2411       ;; Flush original article as well.
2412       (save-excursion
2413         (when (get-buffer gnus-original-article-buffer)
2414           (set-buffer gnus-original-article-buffer)
2415           (setq gnus-original-article nil)))
2416       (set-window-configuration winconf)
2417       ;; Tippy-toe some to make sure that point remains where it was.
2418       (let ((buf (current-buffer)))
2419         (set-buffer curbuf)
2420         (set-window-start (get-buffer-window (current-buffer)) window-start)
2421         (goto-char p)
2422         (set-buffer buf)))))
2423       
2424 (defun gnus-article-edit-full-stops ()
2425   "Interactively repair spacing at end of sentences."
2426   (interactive)
2427   (save-excursion
2428     (goto-char (point-min))
2429     (search-forward-regexp "^$" nil t)
2430     (let ((case-fold-search nil))
2431       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2432
2433 ;;; 
2434 ;;; Article highlights
2435 ;;;
2436
2437 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2438
2439 ;;; Internal Variables:
2440
2441 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)"
2442   "Regular expression that matches URLs."
2443   :group 'article
2444   :type 'regexp)
2445
2446 (defcustom gnus-button-alist 
2447   `(("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
2448      gnus-button-message-id 3)
2449     ("\\(<?\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>?\\)" 1 t
2450      gnus-button-fetch-group 4)
2451     ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 
2452      t gnus-button-message-id 3)
2453     ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-url-mailto 2)
2454     ;; This is how URLs _should_ be embedded in text...
2455     ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2456     ;; Raw URLs.
2457     (,gnus-button-url-regexp 0 t gnus-button-url 0))
2458   "Alist of regexps matching buttons in article bodies.
2459
2460 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2461 REGEXP: is the string matching text around the button,
2462 BUTTON: is the number of the regexp grouping actually matching the button,
2463 FORM: is a lisp expression which must eval to true for the button to
2464 be added, 
2465 CALLBACK: is the function to call when the user push this button, and each
2466 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2467
2468 CALLBACK can also be a variable, in that case the value of that
2469 variable it the real callback function."
2470   :group 'article
2471   :type '(repeat (list regexp 
2472                        (integer :tag "Button")
2473                        (sexp :tag "Form")
2474                        (function :tag "Callback")
2475                        (repeat :tag "Par"
2476                                :inline t
2477                                (integer :tag "Regexp group")))))
2478
2479 (defcustom gnus-header-button-alist 
2480   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2481      0 t gnus-button-message-id 0)
2482     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2483     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+" 
2484      0 t gnus-button-mailto 0)
2485     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2486     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2487     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2488      gnus-button-message-id 3))
2489   "Alist of headers and regexps to match buttons in article heads.
2490
2491 This alist is very similar to `gnus-button-alist', except that each
2492 alist has an additional HEADER element first in each entry:
2493
2494 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2495
2496 HEADER is a regexp to match a header.  For a fuller explanation, see
2497 `gnus-button-alist'."
2498   :group 'article
2499   :type '(repeat (list (regexp :tag "Header")
2500                        regexp 
2501                        (integer :tag "Button")
2502                        (sexp :tag "Form")
2503                        (function :tag "Callback")
2504                        (repeat :tag "Par"
2505                                :inline t
2506                                (integer :tag "Regexp group")))))
2507
2508 (defvar gnus-button-regexp nil)
2509 (defvar gnus-button-marker-list nil)
2510 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2511
2512 (defvar gnus-button-last nil)
2513 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2514
2515 ;;; Commands:
2516
2517 (defun gnus-article-push-button (event)
2518   "Check text under the mouse pointer for a callback function.
2519 If the text under the mouse pointer has a `gnus-callback' property,
2520 call it with the value of the `gnus-data' text property."
2521   (interactive "e")
2522   (set-buffer (window-buffer (posn-window (event-start event))))
2523   (let* ((pos (posn-point (event-start event)))
2524          (data (get-text-property pos 'gnus-data))
2525          (fun (get-text-property pos 'gnus-callback)))
2526     (when fun
2527       (funcall fun data))))
2528
2529 (defun gnus-article-press-button ()
2530   "Check text at point for a callback function.
2531 If the text at point has a `gnus-callback' property,
2532 call it with the value of the `gnus-data' text property."
2533   (interactive)
2534   (let* ((data (get-text-property (point) 'gnus-data))
2535          (fun (get-text-property (point) 'gnus-callback)))
2536     (when fun
2537       (funcall fun data))))
2538
2539 (defun gnus-article-prev-button (n)
2540   "Move point to N buttons backward.
2541 If N is negative, move forward instead."
2542   (interactive "p")
2543   (gnus-article-next-button (- n)))
2544
2545 (defun gnus-article-next-button (n)
2546   "Move point to N buttons forward.
2547 If N is negative, move backward instead."
2548   (interactive "p")
2549   (let ((function (if (< n 0) 'previous-single-property-change
2550                     'next-single-property-change))
2551         (inhibit-point-motion-hooks t)
2552         (backward (< n 0))
2553         (limit (if (< n 0) (point-min) (point-max))))
2554     (setq n (abs n))
2555     (while (and (not (= limit (point)))
2556                 (> n 0))
2557       ;; Skip past the current button.
2558       (when (get-text-property (point) 'gnus-callback)
2559         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2560       ;; Go to the next (or previous) button.
2561       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2562       ;; Put point at the start of the button.
2563       (when (and backward (not (get-text-property (point) 'gnus-callback)))
2564         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2565       ;; Skip past intangible buttons.
2566       (when (get-text-property (point) 'intangible)
2567         (incf n))
2568       (decf n))
2569     (unless (zerop n)
2570       (gnus-message 5 "No more buttons"))
2571     n))
2572
2573 (defun gnus-article-highlight (&optional force)
2574   "Highlight current article.
2575 This function calls `gnus-article-highlight-headers',
2576 `gnus-article-highlight-citation', 
2577 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2578 do the highlighting.  See the documentation for those functions."
2579   (interactive (list 'force))
2580   (gnus-article-highlight-headers)
2581   (gnus-article-highlight-citation force)
2582   (gnus-article-highlight-signature)
2583   (gnus-article-add-buttons force)
2584   (gnus-article-add-buttons-to-head))
2585
2586 (defun gnus-article-highlight-some (&optional force)
2587   "Highlight current article.
2588 This function calls `gnus-article-highlight-headers',
2589 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2590 do the highlighting.  See the documentation for those functions."
2591   (interactive (list 'force))
2592   (gnus-article-highlight-headers)
2593   (gnus-article-highlight-signature)
2594   (gnus-article-add-buttons))
2595
2596 (defun gnus-article-highlight-headers ()
2597   "Highlight article headers as specified by `gnus-header-face-alist'."
2598   (interactive)
2599   (save-excursion
2600     (set-buffer gnus-article-buffer)
2601     (save-restriction
2602       (let ((alist gnus-header-face-alist)
2603             (buffer-read-only nil)
2604             (case-fold-search t)
2605             (inhibit-point-motion-hooks t)
2606             entry regexp header-face field-face from hpoints fpoints)
2607         (goto-char (point-min))
2608         (when (search-forward "\n\n" nil t)
2609           (narrow-to-region (1- (point)) (point-min))
2610           (while (setq entry (pop alist))
2611             (goto-char (point-min))
2612             (setq regexp (concat "^\\("
2613                                  (if (string-equal "" (nth 0 entry))
2614                                      "[^\t ]"
2615                                    (nth 0 entry))
2616                                  "\\)")
2617                   header-face (nth 1 entry)
2618                   field-face (nth 2 entry))
2619             (while (and (re-search-forward regexp nil t)
2620                         (not (eobp)))
2621               (beginning-of-line)
2622               (setq from (point))
2623               (unless (search-forward ":" nil t)
2624                 (forward-char 1))
2625               (when (and header-face
2626                          (not (memq (point) hpoints)))
2627                 (push (point) hpoints)
2628                 (gnus-put-text-property from (point) 'face header-face))
2629               (when (and field-face
2630                          (not (memq (setq from (point)) fpoints)))
2631                 (push from fpoints)
2632                 (if (re-search-forward "^[^ \t]" nil t)
2633                     (forward-char -2)
2634                   (goto-char (point-max)))
2635                 (gnus-put-text-property from (point) 'face field-face)))))))))
2636
2637 (defun gnus-article-highlight-signature ()
2638   "Highlight the signature in an article.
2639 It does this by highlighting everything after
2640 `gnus-signature-separator' using `gnus-signature-face'." 
2641   (interactive)
2642   (save-excursion
2643     (set-buffer gnus-article-buffer)
2644     (let ((buffer-read-only nil)
2645           (inhibit-point-motion-hooks t))
2646       (save-restriction
2647         (when (and gnus-signature-face
2648                    (gnus-article-narrow-to-signature))
2649           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2650                             'face gnus-signature-face)
2651           (widen)
2652           (gnus-article-search-signature)
2653           (let ((start (match-beginning 0))
2654                 (end (set-marker (make-marker) (1+ (match-end 0)))))
2655             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2656                                      end)))))))
2657
2658 (defun gnus-article-add-buttons (&optional force)
2659   "Find external references in the article and make buttons of them.
2660 \"External references\" are things like Message-IDs and URLs, as
2661 specified by `gnus-button-alist'."
2662   (interactive (list 'force))
2663   (save-excursion
2664     (set-buffer gnus-article-buffer)
2665     ;; Remove all old markers.
2666     (while gnus-button-marker-list
2667       (set-marker (pop gnus-button-marker-list) nil))
2668     (let ((buffer-read-only nil)
2669           (inhibit-point-motion-hooks t)
2670           (case-fold-search t)
2671           (alist gnus-button-alist)
2672           beg entry regexp)
2673       (goto-char (point-min))
2674       ;; We skip the headers.
2675       (unless (search-forward "\n\n" nil t)
2676         (goto-char (point-max)))
2677       (setq beg (point))
2678       (while (setq entry (pop alist))
2679         (setq regexp (car entry))
2680         (goto-char beg)
2681         (while (re-search-forward regexp nil t)
2682           (let* ((start (and entry (match-beginning (nth 1 entry))))
2683                  (end (and entry (match-end (nth 1 entry))))
2684                  (from (match-beginning 0)))
2685             (when (and (or (eq t (nth 1 entry))
2686                            (eval (nth 1 entry)))
2687                        (not (get-text-property (point) 'gnus-callback)))
2688               ;; That optional form returned non-nil, so we add the
2689               ;; button. 
2690               (gnus-article-add-button 
2691                start end 'gnus-button-push 
2692                (car (push (set-marker (make-marker) from)
2693                           gnus-button-marker-list))))))))))
2694
2695 ;; Add buttons to the head of an article.
2696 (defun gnus-article-add-buttons-to-head ()
2697   "Add buttons to the head of the article."
2698   (interactive)
2699   (save-excursion
2700     (set-buffer gnus-article-buffer)
2701     (let ((buffer-read-only nil)
2702           (inhibit-point-motion-hooks t)
2703           (case-fold-search t)
2704           (alist gnus-header-button-alist)
2705           entry beg end)
2706       (nnheader-narrow-to-headers)
2707       (while alist
2708         ;; Each alist entry.
2709         (setq entry (car alist)
2710               alist (cdr alist))
2711         (goto-char (point-min))
2712         (while (re-search-forward (car entry) nil t)
2713           ;; Each header matching the entry.
2714           (setq beg (match-beginning 0))
2715           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2716                              (match-beginning 0))
2717                         (point-max)))
2718           (goto-char beg)
2719           (while (re-search-forward (nth 1 entry) end t)
2720             ;; Each match within a header.
2721             (let* ((entry (cdr entry))
2722                    (start (match-beginning (nth 1 entry)))
2723                    (end (match-end (nth 1 entry)))
2724                    (form (nth 2 entry)))
2725               (goto-char (match-end 0))
2726               (when (eval form)
2727                 (gnus-article-add-button 
2728                  start end (nth 3 entry)
2729                  (buffer-substring (match-beginning (nth 4 entry))
2730                                    (match-end (nth 4 entry)))))))
2731           (goto-char end))))
2732     (widen)))
2733
2734 ;;; External functions:
2735
2736 (defun gnus-article-add-button (from to fun &optional data)
2737   "Create a button between FROM and TO with callback FUN and data DATA."
2738   (when gnus-article-button-face
2739     (gnus-overlay-put (gnus-make-overlay from to)
2740                       'face gnus-article-button-face))
2741   (gnus-add-text-properties 
2742    from to
2743    (nconc (and gnus-article-mouse-face
2744                (list gnus-mouse-face-prop gnus-article-mouse-face))
2745           (list 'gnus-callback fun)
2746           (and data (list 'gnus-data data)))))
2747
2748 ;;; Internal functions:
2749
2750 (defun gnus-signature-toggle (end)
2751   (save-excursion
2752     (set-buffer gnus-article-buffer)
2753     (let ((buffer-read-only nil)
2754           (inhibit-point-motion-hooks t))
2755       (if (get-text-property end 'invisible)
2756           (gnus-article-unhide-text end (point-max))
2757         (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2758
2759 (defun gnus-button-entry ()
2760   ;; Return the first entry in `gnus-button-alist' matching this place.
2761   (let ((alist gnus-button-alist)
2762         (entry nil))
2763     (while alist
2764       (setq entry (pop alist))
2765       (if (looking-at (car entry))
2766           (setq alist nil)
2767         (setq entry nil)))
2768     entry))
2769
2770 (defun gnus-button-push (marker)
2771   ;; Push button starting at MARKER.
2772   (save-excursion
2773     (set-buffer gnus-article-buffer)
2774     (goto-char marker)
2775     (let* ((entry (gnus-button-entry))
2776            (inhibit-point-motion-hooks t)
2777            (fun (nth 3 entry))
2778            (args (mapcar (lambda (group)
2779                            (let ((string (match-string group)))
2780                              (gnus-set-text-properties
2781                               0 (length string) nil string)
2782                              string))
2783                          (nthcdr 4 entry))))
2784       (cond
2785        ((fboundp fun)
2786         (apply fun args))
2787        ((and (boundp fun)
2788              (fboundp (symbol-value fun)))
2789         (apply (symbol-value fun) args))
2790        (t
2791         (gnus-message 1 "You must define `%S' to use this button"
2792                       (cons fun args)))))))
2793
2794 (defun gnus-button-message-id (message-id)
2795   "Fetch MESSAGE-ID."
2796   (save-excursion
2797     (set-buffer gnus-summary-buffer)
2798     (gnus-summary-refer-article message-id)))
2799
2800 (defun gnus-button-fetch-group (address)
2801   "Fetch GROUP specified by ADDRESS."
2802   (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
2803       (error "Can't parse %s" address)
2804     (gnus-group-read-ephemeral-group
2805      (match-string 4 address)
2806      `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
2807             (nntp-port-number ,(if (match-end 3)
2808                                    (match-string 3 address)
2809                                  "nntp"))))))
2810
2811 (defun gnus-split-string (string pattern)
2812   "Return a list of substrings of STRING which are separated by PATTERN."
2813   (let (parts (start 0))
2814     (while (string-match pattern string start)
2815       (setq parts (cons (substring string start (match-beginning 0)) parts)
2816             start (match-end 0)))
2817     (nreverse (cons (substring string start) parts))))
2818  
2819 (defun gnus-url-parse-query-string (query &optional downcase)
2820   (let (retval pairs cur key val)
2821     (setq pairs (gnus-split-string query "&"))
2822     (while pairs
2823       (setq cur (car pairs)
2824             pairs (cdr pairs))
2825       (if (not (string-match "=" cur))
2826           nil                           ; Grace
2827         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2828               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2829         (if downcase
2830             (setq key (downcase key)))
2831         (setq cur (assoc key retval))
2832         (if cur
2833             (setcdr cur (cons val (cdr cur)))
2834           (setq retval (cons (list key val) retval)))))
2835     retval))
2836  
2837 (defun gnus-url-unhex (x)
2838   (if (> x ?9)
2839       (if (>= x ?a)
2840           (+ 10 (- x ?a))
2841         (+ 10 (- x ?A)))
2842     (- x ?0)))
2843  
2844 (defun gnus-url-unhex-string (str &optional allow-newlines)
2845   "Remove %XXX embedded spaces, etc in a url.
2846 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2847 decoding of carriage returns and line feeds in the string, which is normally
2848 forbidden in URL encoding."
2849   (setq str (or str ""))
2850   (let ((tmp "")
2851         (case-fold-search t))
2852     (while (string-match "%[0-9a-f][0-9a-f]" str)
2853       (let* ((start (match-beginning 0))
2854              (ch1 (gnus-url-unhex (elt str (+ start 1))))
2855              (code (+ (* 16 ch1)
2856                       (gnus-url-unhex (elt str (+ start 2))))))
2857         (setq tmp (concat 
2858                    tmp (substring str 0 start)
2859                    (cond
2860                     (allow-newlines
2861                      (char-to-string code))
2862                     ((or (= code ?\n) (= code ?\r))
2863                      " ")
2864                     (t (char-to-string code))))
2865               str (substring str (match-end 0)))))
2866     (setq tmp (concat tmp str))
2867     tmp))
2868  
2869 (defun gnus-url-mailto (url)
2870   ;; Send mail to someone
2871   (if (not (string-match "mailto:/*\\(.*\\)" url))
2872       (error "Malformed mailto link: %s" url))
2873   (setq url (substring url (match-beginning 1) nil))
2874   (let (to args source-url subject func)
2875     (if (string-match (regexp-quote "?") url)
2876         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2877               args (gnus-url-parse-query-string
2878                     (substring url (match-end 0) nil) t))
2879       (setq to (gnus-url-unhex-string url)))
2880     (setq args (cons (list "to" to) args)
2881           subject (cdr-safe (assoc "subject" args)))
2882     (message-mail)
2883     (while args
2884       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
2885       (if (fboundp func)
2886           (funcall func)
2887         (message-position-on-field (caar args)))
2888       (insert (mapconcat 'identity (cdar args) ", "))
2889       (setq args (cdr args)))
2890     (if subject
2891         (message-goto-body)
2892       (message-goto-subject))))
2893
2894 (defun gnus-button-mailto (address)
2895   ;; Mail to ADDRESS.
2896   (set-buffer (gnus-copy-article-buffer))
2897   (message-reply address))
2898
2899 (defun gnus-button-reply (address)
2900   ;; Reply to ADDRESS.
2901   (message-reply address))
2902
2903 (defun gnus-button-url (address)
2904   "Browse ADDRESS."
2905   (funcall browse-url-browser-function address))
2906
2907 (defun gnus-button-embedded-url (address)
2908   "Browse ADDRESS."
2909   (funcall browse-url-browser-function (gnus-strip-whitespace address)))
2910
2911 ;;; Next/prev buttons in the article buffer.
2912
2913 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
2914 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
2915
2916 (defvar gnus-prev-page-map nil)
2917 (unless gnus-prev-page-map
2918   (setq gnus-prev-page-map (make-sparse-keymap))
2919   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
2920   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
2921
2922 (defun gnus-insert-prev-page-button ()
2923   (let ((buffer-read-only nil))
2924     (gnus-eval-format 
2925      gnus-prev-page-line-format nil
2926      `(gnus-prev t local-map ,gnus-prev-page-map
2927                  gnus-callback gnus-article-button-prev-page))))
2928
2929 (defvar gnus-next-page-map nil)
2930 (unless gnus-next-page-map
2931   (setq gnus-next-page-map (make-keymap))
2932   (suppress-keymap gnus-prev-page-map)
2933   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
2934   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
2935
2936 (defun gnus-button-next-page ()
2937   "Go to the next page."
2938   (interactive)
2939   (let ((win (selected-window)))
2940     (select-window (get-buffer-window gnus-article-buffer t))
2941     (gnus-article-next-page)
2942     (select-window win)))
2943
2944 (defun gnus-button-prev-page ()
2945   "Go to the prev page."
2946   (interactive)
2947   (let ((win (selected-window)))
2948     (select-window (get-buffer-window gnus-article-buffer t))
2949     (gnus-article-prev-page)
2950     (select-window win)))
2951
2952 (defun gnus-insert-next-page-button ()
2953   (let ((buffer-read-only nil))
2954     (gnus-eval-format gnus-next-page-line-format nil
2955                       `(gnus-next t local-map ,gnus-next-page-map
2956                                   gnus-callback 
2957                                   gnus-article-button-next-page))))
2958
2959 (defun gnus-article-button-next-page (arg)
2960   "Go to the next page."
2961   (interactive "P")
2962   (let ((win (selected-window)))
2963     (select-window (get-buffer-window gnus-article-buffer t))
2964     (gnus-article-next-page)
2965     (select-window win)))
2966
2967 (defun gnus-article-button-prev-page (arg)
2968   "Go to the prev page."
2969   (interactive "P")
2970   (let ((win (selected-window)))
2971     (select-window (get-buffer-window gnus-article-buffer t))
2972     (gnus-article-prev-page)
2973     (select-window win))) 
2974
2975 (gnus-ems-redefine)
2976
2977 (provide 'gnus-art)
2978
2979 (run-hooks 'gnus-art-load-hook)
2980
2981 ;;; gnus-art.el ends here