*** 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                        (ignore-errors
659                          (equal 
660                           (nth 1 (mail-extract-address-components from))
661                           (nth 1 (mail-extract-address-components reply-to)))))
662                   (gnus-article-hide-header "reply-to"))))
663              ((eq elem 'date)
664               (let ((date (message-fetch-field "date")))
665                 (when (and date
666                            (< (gnus-days-between (current-time-string) date)
667                               4))
668                   (gnus-article-hide-header "date")))))))))))
669
670 (defun gnus-article-hide-header (header)
671   (save-excursion
672     (goto-char (point-min))
673     (when (re-search-forward (concat "^" header ":") nil t)
674       (gnus-article-hide-text-type
675        (progn (beginning-of-line) (point))
676        (progn 
677          (end-of-line)
678          (if (re-search-forward "^[^ \t]" nil t)
679              (match-beginning 0)
680            (point-max)))
681        'boring-headers))))
682
683 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
684 (defun article-treat-overstrike ()
685   "Translate overstrikes into bold text."
686   (interactive)
687   (save-excursion
688     (let ((buffer-read-only nil))
689       (while (search-forward "\b" nil t)
690         (let ((next (following-char))
691               (previous (char-after (- (point) 2))))
692           ;; We do the boldification/underlining by hiding the
693           ;; overstrikes and putting the proper text property
694           ;; on the letters.
695           (cond 
696            ((eq next previous)
697             (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
698             (put-text-property (point) (1+ (point)) 'face 'bold))
699            ((eq next ?_)
700             (gnus-article-hide-text-type (1- (point)) (1+ (point)) 'overstrike)
701             (put-text-property
702              (- (point) 2) (1- (point)) 'face 'underline))
703            ((eq previous ?_)
704             (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
705             (put-text-property
706              (point) (1+ (point)) 'face 'underline))))))))
707
708 (defun article-fill ()
709   "Format too long lines."
710   (interactive)
711   (save-excursion
712     (let ((buffer-read-only nil))
713       (widen)
714       (goto-char (point-min))
715       (search-forward "\n\n" nil t)
716       (end-of-line 1)
717       (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
718             (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
719             (adaptive-fill-mode t))
720         (while (not (eobp))
721           (and (>= (current-column) (min fill-column (window-width)))
722                (/= (preceding-char) ?:)
723                (fill-paragraph nil))
724           (end-of-line 2))))))
725
726 (defun article-remove-cr ()
727   "Remove carriage returns from an article."
728   (interactive)
729   (save-excursion
730     (let ((buffer-read-only nil))
731       (goto-char (point-min))
732       (while (search-forward "\r" nil t)
733         (replace-match "" t t)))))
734
735 (defun article-remove-trailing-blank-lines ()
736   "Remove all trailing blank lines from the article."
737   (interactive)
738   (save-excursion
739     (let ((buffer-read-only nil))
740       (goto-char (point-max))
741       (delete-region
742        (point)
743        (progn
744          (while (and (not (bobp))
745                      (looking-at "^[ \t]*$"))
746            (forward-line -1))
747          (forward-line 1)
748          (point))))))
749
750 (defun article-display-x-face (&optional force)
751   "Look for an X-Face header and display it if present."
752   (interactive (list 'force))
753   (save-excursion
754     ;; Delete the old process, if any.
755     (when (process-status "article-x-face")
756       (delete-process "article-x-face"))
757     (let ((inhibit-point-motion-hooks t)
758           (case-fold-search nil)
759           from)
760       (save-restriction
761         (nnheader-narrow-to-headers)
762         (setq from (message-fetch-field "from"))
763         (goto-char (point-min))
764         (when (and gnus-article-x-face-command
765                    (or force
766                        ;; Check whether this face is censored.
767                        (not gnus-article-x-face-too-ugly)
768                        (and gnus-article-x-face-too-ugly from
769                             (not (string-match gnus-article-x-face-too-ugly
770                                                from))))
771                    ;; Has to be present.
772                    (re-search-forward "^X-Face: " nil t))
773           ;; We now have the area of the buffer where the X-Face is stored.
774           (let ((beg (point))
775                 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
776             ;; We display the face.
777             (if (symbolp gnus-article-x-face-command)
778                 ;; The command is a lisp function, so we call it.
779                 (if (gnus-functionp gnus-article-x-face-command)
780                     (funcall gnus-article-x-face-command beg end)
781                   (error "%s is not a function" gnus-article-x-face-command))
782               ;; The command is a string, so we interpret the command
783               ;; as a, well, command, and fork it off.
784               (let ((process-connection-type nil))
785                 (process-kill-without-query
786                  (start-process
787                   "article-x-face" nil shell-file-name shell-command-switch
788                   gnus-article-x-face-command))
789                 (process-send-region "article-x-face" beg end)
790                 (process-send-eof "article-x-face")))))))))
791
792 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
793 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
794 (defun article-decode-rfc1522 ()
795   "Hack to remove QP encoding from headers."
796   (let ((case-fold-search t)
797         (inhibit-point-motion-hooks t)
798         (buffer-read-only nil)
799         string)
800     (save-restriction
801       (narrow-to-region
802        (goto-char (point-min))
803        (or (search-forward "\n\n" nil t) (point-max)))
804       (goto-char (point-min))
805       (while (re-search-forward 
806               "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
807         (setq string (match-string 1))
808         (save-restriction
809           (narrow-to-region (match-beginning 0) (match-end 0))
810           (delete-region (point-min) (point-max))
811           (insert string)
812           (article-mime-decode-quoted-printable 
813            (goto-char (point-min)) (point-max))
814           (subst-char-in-region (point-min) (point-max) ?_ ? )
815           (goto-char (point-max)))
816         (goto-char (point-min))))))
817
818 (defun article-de-quoted-unreadable (&optional force)
819   "Do a naive translation of a quoted-printable-encoded article.
820 This is in no way, shape or form meant as a replacement for real MIME
821 processing, but is simply a stop-gap measure until MIME support is
822 written.
823 If FORCE, decode the article whether it is marked as quoted-printable
824 or not."
825   (interactive (list 'force))
826   (save-excursion
827     (let ((case-fold-search t)
828           (buffer-read-only nil)
829           (type (gnus-fetch-field "content-transfer-encoding")))
830       (gnus-article-decode-rfc1522)
831       (when (or force
832                 (and type (string-match "quoted-printable" (downcase type))))
833         (goto-char (point-min))
834         (search-forward "\n\n" nil 'move)
835         (article-mime-decode-quoted-printable (point) (point-max))))))
836
837 (defun article-mime-decode-quoted-printable-buffer ()
838   "Decode Quoted-Printable in the current buffer."
839   (article-mime-decode-quoted-printable (point-min) (point-max)))
840   
841 (defun article-mime-decode-quoted-printable (from to)
842   "Decode Quoted-Printable in the region between FROM and TO."
843   (interactive "r")
844   (goto-char from)
845   (while (search-forward "=" to t)
846     (cond ((eq (following-char) ?\n)
847            (delete-char -1)
848            (delete-char 1))
849           ((looking-at "[0-9A-F][0-9A-F]")
850            (subst-char-in-region
851             (1- (point)) (point) ?=
852             (hexl-hex-string-to-integer
853              (buffer-substring (point) (+ 2 (point)))))
854            (delete-char 2))
855           ((looking-at "=")
856            (delete-char 1))
857           ((gnus-message 3 "Malformed MIME quoted-printable message")))))
858
859 (defun article-hide-pgp (&optional arg)
860   "Toggle hiding of any PGP headers and signatures in the current article.
861 If given a negative prefix, always show; if given a positive prefix,
862 always hide."
863   (interactive (gnus-article-hidden-arg))
864   (unless (gnus-article-check-hidden-text 'pgp arg)
865     (save-excursion
866       (let (buffer-read-only beg end)
867         (widen)
868         (goto-char (point-min))
869         ;; Hide the "header".
870         (and (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
871              (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
872         (setq beg (point))
873         ;; Hide the actual signature.
874         (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
875              (setq end (1+ (match-beginning 0)))
876              (gnus-article-hide-text-type
877               end
878               (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
879                   (match-end 0)
880                 ;; Perhaps we shouldn't hide to the end of the buffer
881                 ;; if there is no end to the signature?
882                 (point-max))
883               'pgp))
884         ;; Hide "- " PGP quotation markers.
885         (when (and beg end)
886           (narrow-to-region beg end)
887           (goto-char (point-min))
888           (while (re-search-forward "^- " nil t)
889             (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
890           (widen))))))
891
892 (defun article-hide-pem (&optional arg)
893   "Toggle hiding of any PEM headers and signatures in the current article.
894 If given a negative prefix, always show; if given a positive prefix,
895 always hide."
896   (interactive (gnus-article-hidden-arg))
897   (unless (gnus-article-check-hidden-text 'pem arg)
898     (save-excursion
899       (let (buffer-read-only end)
900         (widen)
901         (goto-char (point-min))
902         ;; hide the horrendously ugly "header".
903         (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
904                              nil
905                              t)
906              (setq end (1+ (match-beginning 0)))
907              (gnus-article-hide-text-type
908               end
909               (if (search-forward "\n\n" nil t)
910                   (match-end 0)
911                 (point-max))
912               'pem))
913         ;; hide the trailer as well
914         (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
915                              nil
916                              t)
917              (gnus-article-hide-text-type
918               (match-beginning 0) (match-end 0) 'pem))))))
919
920 (defun article-hide-signature (&optional arg)
921   "Hide the signature in the current article.
922 If given a negative prefix, always show; if given a positive prefix,
923 always hide."
924   (interactive (gnus-article-hidden-arg))
925   (unless (gnus-article-check-hidden-text 'signature arg)
926     (save-excursion
927       (save-restriction
928         (let ((buffer-read-only nil))
929           (when (gnus-article-narrow-to-signature)
930             (gnus-article-hide-text-type 
931              (point-min) (point-max) 'signature)))))))
932
933 (defun article-strip-leading-blank-lines ()
934   "Remove all blank lines from the beginning of the article."
935   (interactive)
936   (save-excursion
937     (let ((inhibit-point-motion-hooks t)
938           buffer-read-only)
939       (goto-char (point-min))
940       (when (search-forward "\n\n" nil t)
941         (while (and (not (eobp))
942                     (looking-at "[ \t]*$"))
943           (gnus-delete-line))))))
944
945 (defun article-strip-multiple-blank-lines ()
946   "Replace consecutive blank lines with one empty line."
947   (interactive)
948   (save-excursion
949     (let (buffer-read-only)
950       ;; First make all blank lines empty.
951       (goto-char (point-min))
952       (while (re-search-forward "^[ \t]+$" nil t)
953         (replace-match "" nil t))
954       ;; Then replace multiple empty lines with a single empty line.
955       (goto-char (point-min))
956       (while (re-search-forward "\n\n\n+" nil t)
957         (replace-match "\n\n" t t)))))
958
959 (defun article-strip-blank-lines ()
960   "Strip leading, trailing and multiple blank lines."
961   (interactive)
962   (article-strip-leading-blank-lines)
963   (article-remove-trailing-blank-lines)
964   (article-strip-multiple-blank-lines))
965
966 (defvar mime::preview/content-list)
967 (defvar mime::preview-content-info/point-min)
968 (defun gnus-article-narrow-to-signature ()
969   "Narrow to the signature; return t if a signature is found, else nil."
970   (widen)
971   (when (and (boundp 'mime::preview/content-list)
972              mime::preview/content-list)
973     ;; We have a MIMEish article, so we use the MIME data to narrow.
974     (let ((pcinfo (car (last mime::preview/content-list))))
975       (ignore-errors
976         (narrow-to-region
977          (funcall (intern "mime::preview-content-info/point-min") pcinfo)
978          (point-max)))))
979   
980   (when (gnus-article-search-signature)
981     (forward-line 1)
982     ;; Check whether we have some limits to what we consider
983     ;; to be a signature.
984     (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
985                     (list gnus-signature-limit)))
986           limit limited)
987       (while (setq limit (pop limits))
988         (if (or (and (integerp limit)
989                      (< (- (point-max) (point)) limit))
990                 (and (floatp limit)
991                      (< (count-lines (point) (point-max)) limit))
992                 (and (gnus-functionp limit)
993                      (funcall limit))
994                 (and (stringp limit)
995                      (not (re-search-forward limit nil t))))
996             ()                          ; This limit did not succeed.
997           (setq limited t
998                 limits nil)))
999       (unless limited
1000         (narrow-to-region (point) (point-max))
1001         t))))
1002
1003 (defun gnus-article-search-signature ()
1004   "Search the current buffer for the signature separator.
1005 Put point at the beginning of the signature separator."
1006   (let ((cur (point)))
1007     (goto-char (point-max))
1008     (if (if (stringp gnus-signature-separator)
1009             (re-search-backward gnus-signature-separator nil t)
1010           (let ((seps gnus-signature-separator))
1011             (while (and seps
1012                         (not (re-search-backward (car seps) nil t)))
1013               (pop seps))
1014             seps))
1015         t
1016       (goto-char cur)
1017       nil)))
1018
1019 (defun gnus-article-hidden-arg ()
1020   "Return the current prefix arg as a number, or 0 if no prefix."
1021   (list (if current-prefix-arg
1022             (prefix-numeric-value current-prefix-arg)
1023           0)))
1024
1025 (defun gnus-article-check-hidden-text (type arg)
1026   "Return nil if hiding is necessary.
1027 Arg can be nil or a number.  Nil and positive means hide, negative
1028 means show, 0 means toggle."
1029   (save-excursion
1030     (let ((hide (gnus-article-hidden-text-p type)))
1031       (cond
1032        ((or (null arg)
1033             (> arg 0))
1034         nil)
1035        ((< arg 0)
1036         (gnus-article-show-hidden-text type))
1037        (t
1038         (if (eq hide 'hidden)
1039             (gnus-article-show-hidden-text type)
1040           nil))))))
1041
1042 (defun gnus-article-hidden-text-p (type)
1043   "Say whether the current buffer contains hidden text of type TYPE."
1044   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1045     (when pos
1046       (if (get-text-property pos 'invisible)
1047           'hidden
1048         'shown))))
1049
1050 (defun gnus-article-show-hidden-text (type &optional hide)
1051   "Show all hidden text of type TYPE.
1052 If HIDE, hide the text instead."
1053   (save-excursion
1054     (let ((buffer-read-only nil)
1055           (inhibit-point-motion-hooks t)
1056           (end (point-min))
1057           beg)
1058       (while (setq beg (text-property-any end (point-max) 'article-type type))
1059         (goto-char beg)
1060         (setq end (or
1061                    (text-property-not-all beg (point-max) 'article-type type)
1062                    (point-max)))
1063         (if hide
1064             (gnus-article-hide-text beg end gnus-hidden-properties)
1065           (gnus-article-unhide-text beg end))
1066         (goto-char end))
1067       t)))
1068
1069 (defconst article-time-units
1070   `((year . ,(* 365.25 24 60 60))
1071     (week . ,(* 7 24 60 60))
1072     (day . ,(* 24 60 60))
1073     (hour . ,(* 60 60))
1074     (minute . 60)
1075     (second . 1))
1076   "Mapping from time units to seconds.")
1077
1078 (defun article-date-ut (&optional type highlight header)
1079   "Convert DATE date to universal time in the current article.
1080 If TYPE is `local', convert to local time; if it is `lapsed', output
1081 how much time has lapsed since DATE."
1082   (interactive (list 'ut t))
1083   (let* ((header (or header 
1084                      (mail-header-date gnus-current-headers)
1085                      (message-fetch-field "date")
1086                      ""))
1087          (date (if (vectorp header) (mail-header-date header)
1088                  header))
1089          (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1090          (inhibit-point-motion-hooks t)
1091          bface eface)
1092     (when (and date (not (string= date "")))
1093       (save-excursion
1094         (save-restriction
1095           (nnheader-narrow-to-headers)
1096           (let ((buffer-read-only nil))
1097             ;; Delete any old Date headers.
1098             (if (re-search-forward date-regexp nil t)
1099                 (progn
1100                   (setq bface (get-text-property (gnus-point-at-bol) 'face)
1101                         eface (get-text-property (1- (gnus-point-at-eol))
1102                                                  'face))
1103                   (message-remove-header date-regexp t)
1104                   (beginning-of-line))
1105               (goto-char (point-max)))
1106             (insert (article-make-date-line date type))
1107             ;; Do highlighting.
1108             (forward-line -1)
1109             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1110               (put-text-property (match-beginning 1) (match-end 1)
1111                                  'face bface)
1112               (put-text-property (match-beginning 2) (match-end 2)
1113                                  'face eface))))))))
1114
1115 (defun article-make-date-line (date type)
1116   "Return a DATE line of TYPE."
1117   (cond
1118    ;; Convert to the local timezone.  We have to slap a
1119    ;; `condition-case' round the calls to the timezone
1120    ;; functions since they aren't particularly resistant to
1121    ;; buggy dates.
1122    ((eq type 'local)
1123     (concat "Date: " (condition-case ()
1124                          (timezone-make-date-arpa-standard date)
1125                        (error date))
1126             "\n"))
1127    ;; Convert to Universal Time.
1128    ((eq type 'ut)
1129     (concat "Date: "
1130             (condition-case ()
1131                 (timezone-make-date-arpa-standard date nil "UT")
1132               (error date))
1133             "\n"))
1134    ;; Get the original date from the article.
1135    ((eq type 'original)
1136     (concat "Date: " date "\n"))
1137    ;; Let the user define the format.
1138    ((eq type 'user)
1139     (format-time-string gnus-article-time-format
1140                         (ignore-errors
1141                           (gnus-encode-date
1142                            (timezone-make-date-arpa-standard
1143                             date nil "UT")))))
1144    ;; Do an X-Sent lapsed format.
1145    ((eq type 'lapsed)
1146     ;; If the date is seriously mangled, the timezone functions are
1147     ;; liable to bug out, so we ignore all errors.
1148     (let* ((now (current-time))
1149            (real-time
1150             (ignore-errors
1151               (gnus-time-minus
1152                (gnus-encode-date
1153                 (timezone-make-date-arpa-standard
1154                  (current-time-string now)
1155                  (current-time-zone now) "UT"))
1156                (gnus-encode-date
1157                 (timezone-make-date-arpa-standard
1158                  date nil "UT")))))
1159            (real-sec (and real-time
1160                           (+ (* (float (car real-time)) 65536)
1161                              (cadr real-time))))
1162            (sec (and real-time (abs real-sec)))
1163            num prev)
1164       (cond
1165        ((null real-time)
1166         "X-Sent: Unknown\n")
1167        ((zerop sec)
1168         "X-Sent: Now\n")
1169        (t
1170         (concat
1171          "X-Sent: "
1172          ;; This is a bit convoluted, but basically we go
1173          ;; through the time units for years, weeks, etc,
1174          ;; and divide things to see whether that results
1175          ;; in positive answers.
1176          (mapconcat
1177           (lambda (unit)
1178             (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1179                 ;; The (remaining) seconds are too few to
1180                 ;; be divided into this time unit.
1181                 ""
1182               ;; It's big enough, so we output it.
1183               (setq sec (- sec (* num (cdr unit))))
1184               (prog1
1185                   (concat (if prev ", " "") (int-to-string
1186                                              (floor num))
1187                           " " (symbol-name (car unit)) 
1188                           (if (> num 1) "s" ""))
1189                 (setq prev t))))
1190           article-time-units "")
1191          ;; If dates are odd, then it might appear like the
1192          ;; article was sent in the future.
1193          (if (> real-sec 0)
1194              " ago\n"
1195            " in the future\n"))))))
1196    (t
1197     (error "Unknown conversion type: %s" type))))
1198
1199 (defun article-date-local (&optional highlight)
1200   "Convert the current article date to the local timezone."
1201   (interactive (list t))
1202   (article-date-ut 'local highlight))
1203
1204 (defun article-date-original (&optional highlight)
1205   "Convert the current article date to what it was originally.
1206 This is only useful if you have used some other date conversion
1207 function and want to see what the date was before converting."
1208   (interactive (list t))
1209   (article-date-ut 'original highlight))
1210
1211 (defun article-date-lapsed (&optional highlight)
1212   "Convert the current article date to time lapsed since it was sent."
1213   (interactive (list t))
1214   (article-date-ut 'lapsed highlight))
1215
1216 (defun article-date-user (&optional highlight)
1217   "Convert the current article date to the user-defined format."
1218   (interactive (list t))
1219   (article-date-ut 'user highlight))
1220
1221 (defun article-show-all ()
1222   "Show all hidden text in the article buffer."
1223   (interactive)
1224   (save-excursion
1225     (let ((buffer-read-only nil))
1226       (gnus-article-unhide-text (point-min) (point-max)))))
1227
1228 (defun article-emphasize (&optional arg)
1229   "Emphasize text according to `gnus-emphasis-alist'."
1230   (interactive (gnus-article-hidden-arg))
1231   (unless (gnus-article-check-hidden-text 'emphasis arg)
1232     (save-excursion
1233       (let ((alist gnus-emphasis-alist)
1234             (buffer-read-only nil)
1235             (props (append '(article-type emphasis)
1236                            gnus-hidden-properties))
1237             regexp elem beg invisible visible face)
1238         (goto-char (point-min))
1239         (search-forward "\n\n" nil t)
1240         (setq beg (point))
1241         (while (setq elem (pop alist))
1242           (goto-char beg)
1243           (setq regexp (car elem)
1244                 invisible (nth 1 elem)
1245                 visible (nth 2 elem)
1246                 face (nth 3 elem))
1247           (while (re-search-forward regexp nil t)
1248             (when (and (match-beginning visible) (match-beginning invisible))
1249               (gnus-article-hide-text
1250                (match-beginning invisible) (match-end invisible) props)
1251               (gnus-article-unhide-text-type
1252                (match-beginning visible) (match-end visible) 'emphasis)
1253               (gnus-put-text-property-excluding-newlines
1254                (match-beginning visible) (match-end visible) 'face face)
1255               (goto-char (match-end invisible)))))))))
1256
1257 (defvar gnus-summary-article-menu)
1258 (defvar gnus-summary-post-menu)
1259
1260 ;;; Saving functions.
1261
1262 (defun gnus-article-save (save-buffer file &optional num)
1263   "Save the currently selected article."
1264   (unless gnus-save-all-headers
1265     ;; Remove headers according to `gnus-saved-headers'.
1266     (let ((gnus-visible-headers
1267            (or gnus-saved-headers gnus-visible-headers))
1268           (gnus-article-buffer save-buffer))
1269       (gnus-article-hide-headers 1 t)))
1270   (save-window-excursion
1271     (if (not gnus-default-article-saver)
1272         (error "No default saver is defined.")
1273       ;; !!! Magic!  The saving functions all save
1274       ;; `gnus-original-article-buffer' (or so they think), but we
1275       ;; bind that variable to our save-buffer.
1276       (set-buffer gnus-article-buffer)
1277       (let* ((gnus-save-article-buffer save-buffer)
1278              (filename
1279               (cond
1280                ((not gnus-prompt-before-saving) 'default)
1281                ((eq gnus-prompt-before-saving 'always) nil)
1282                (t file)))
1283              (gnus-number-of-articles-to-be-saved
1284               (when (eq gnus-prompt-before-saving t)
1285                 num)))                  ; Magic
1286         (set-buffer gnus-summary-buffer)
1287         (funcall gnus-default-article-saver filename))))) 
1288
1289 (defun gnus-read-save-file-name (prompt default-name &optional filename)
1290   (cond
1291    ((eq filename 'default)
1292     default-name)
1293    (filename filename)
1294    (t
1295     (let* ((split-name (gnus-get-split-value gnus-split-methods))
1296            (prompt
1297             (format prompt (if (and gnus-number-of-articles-to-be-saved
1298                                     (> gnus-number-of-articles-to-be-saved 1))
1299                                (format "these %d articles"
1300                                        gnus-number-of-articles-to-be-saved)
1301                              "this article")))
1302            (file
1303             ;; Let the split methods have their say.
1304             (cond
1305              ;; No split name was found.
1306              ((null split-name)
1307               (read-file-name
1308                (concat prompt " (default "
1309                        (file-name-nondirectory default-name) ") ")
1310                (file-name-directory default-name)
1311                default-name))
1312              ;; A single split name was found
1313              ((= 1 (length split-name))
1314               (let* ((name (car split-name))
1315                      (dir (cond ((file-directory-p name)
1316                                  (file-name-as-directory name))
1317                                 ((file-exists-p name) name)
1318                                 (t gnus-article-save-directory))))
1319                 (read-file-name
1320                  (concat prompt " (default " name ") ")
1321                  dir name)))
1322              ;; A list of splits was found.
1323              (t
1324               (setq split-name (nreverse split-name))
1325               (let (result)
1326                 (let ((file-name-history (nconc split-name file-name-history)))
1327                   (setq result
1328                         (expand-file-name
1329                          (read-file-name
1330                           (concat prompt " (`M-p' for defaults) ")
1331                           gnus-article-save-directory
1332                           (car split-name))
1333                          gnus-article-save-directory)))
1334                 (car (push result file-name-history)))))))
1335       ;; Create the directory.
1336       (gnus-make-directory (file-name-directory file))
1337       ;; If we have read a directory, we append the default file name.
1338       (when (file-directory-p file)
1339         (setq file (concat (file-name-as-directory file)
1340                            (file-name-nondirectory default-name))))
1341       ;; Possibly translate some characters.
1342       (nnheader-translate-file-chars file)))))
1343
1344 (defun gnus-article-archive-name (group)
1345   "Return the first instance of an \"Archive-name\" in the current buffer."
1346   (let ((case-fold-search t))
1347     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1348       (nnheader-concat gnus-article-save-directory
1349                        (match-string 1)))))
1350
1351 (defun gnus-summary-save-in-rmail (&optional filename)
1352   "Append this article to Rmail file.
1353 Optional argument FILENAME specifies file name.
1354 Directory to save to is default to `gnus-article-save-directory'."
1355   (interactive)
1356   (gnus-set-global-variables)
1357   (let ((default-name
1358           (funcall gnus-rmail-save-name gnus-newsgroup-name
1359                    gnus-current-headers gnus-newsgroup-last-rmail)))
1360     (setq filename (gnus-read-save-file-name
1361                     "Save %s in rmail file:" default-name filename))
1362     (gnus-make-directory (file-name-directory filename))
1363     (gnus-eval-in-buffer-window gnus-save-article-buffer
1364       (save-excursion
1365         (save-restriction
1366           (widen)
1367           (gnus-output-to-rmail filename))))
1368     ;; Remember the directory name to save articles
1369     (setq gnus-newsgroup-last-rmail filename)))
1370
1371 (defun gnus-summary-save-in-mail (&optional filename)
1372   "Append this article to Unix mail file.
1373 Optional argument FILENAME specifies file name.
1374 Directory to save to is default to `gnus-article-save-directory'."
1375   (interactive)
1376   (gnus-set-global-variables)
1377   (let ((default-name
1378           (funcall gnus-mail-save-name gnus-newsgroup-name
1379                    gnus-current-headers gnus-newsgroup-last-mail)))
1380     (setq filename (gnus-read-save-file-name
1381                     "Save %s in Unix mail file:" default-name filename))
1382     (setq filename
1383           (expand-file-name filename
1384                             (and default-name
1385                                  (file-name-directory default-name))))
1386     (gnus-make-directory (file-name-directory filename))
1387     (gnus-eval-in-buffer-window gnus-save-article-buffer
1388       (save-excursion
1389         (save-restriction
1390           (widen)
1391           (if (and (file-readable-p filename) (mail-file-babyl-p filename))
1392               (gnus-output-to-rmail filename)
1393             (let ((mail-use-rfc822 t))
1394               (rmail-output filename 1 t t))))))
1395     ;; Remember the directory name to save articles.
1396     (setq gnus-newsgroup-last-mail filename)))
1397
1398 (defun gnus-summary-save-in-file (&optional filename overwrite)
1399   "Append this article to file.
1400 Optional argument FILENAME specifies file name.
1401 Directory to save to is default to `gnus-article-save-directory'."
1402   (interactive)
1403   (gnus-set-global-variables)
1404   (let ((default-name
1405           (funcall gnus-file-save-name gnus-newsgroup-name
1406                    gnus-current-headers gnus-newsgroup-last-file)))
1407     (setq filename (gnus-read-save-file-name
1408                     "Save %s in file:" default-name filename))
1409     (gnus-make-directory (file-name-directory filename))
1410     (gnus-eval-in-buffer-window gnus-save-article-buffer
1411       (save-excursion
1412         (save-restriction
1413           (widen)
1414           (when (and overwrite
1415                      (file-exists-p filename))
1416             (delete-file filename))
1417           (gnus-output-to-file filename))))
1418     ;; Remember the directory name to save articles.
1419     (setq gnus-newsgroup-last-file filename)))
1420
1421 (defun gnus-summary-write-to-file (&optional filename)
1422   "Write this article to a file.
1423 Optional argument FILENAME specifies file name.
1424 The directory to save in defaults to `gnus-article-save-directory'."
1425   (interactive)
1426   (gnus-summary-save-in-file nil t))
1427
1428 (defun gnus-summary-save-body-in-file (&optional filename)
1429   "Append this article body to a file.
1430 Optional argument FILENAME specifies file name.
1431 The directory to save in defaults to `gnus-article-save-directory'."
1432   (interactive)
1433   (gnus-set-global-variables)
1434   (let ((default-name
1435           (funcall gnus-file-save-name gnus-newsgroup-name
1436                    gnus-current-headers gnus-newsgroup-last-file)))
1437     (setq filename (gnus-read-save-file-name
1438                     "Save %s body in file:" default-name filename))
1439     (gnus-make-directory (file-name-directory filename))
1440     (gnus-eval-in-buffer-window gnus-save-article-buffer
1441       (save-excursion
1442         (save-restriction
1443           (widen)
1444           (goto-char (point-min))
1445           (when (search-forward "\n\n" nil t)
1446             (narrow-to-region (point) (point-max)))
1447           (gnus-output-to-file filename))))
1448     ;; Remember the directory name to save articles.
1449     (setq gnus-newsgroup-last-file filename)))
1450
1451 (defun gnus-summary-save-in-pipe (&optional command)
1452   "Pipe this article to subprocess."
1453   (interactive)
1454   (gnus-set-global-variables)
1455   (setq command
1456         (cond ((eq command 'default)
1457                gnus-last-shell-command)
1458               (command command)
1459               (t (read-string 
1460                   (format
1461                    "Shell command on %s: "
1462                    (if (and gnus-number-of-articles-to-be-saved
1463                             (> gnus-number-of-articles-to-be-saved 1))
1464                        (format "these %d articles"
1465                                gnus-number-of-articles-to-be-saved)
1466                      "this article"))
1467                   gnus-last-shell-command))))
1468   (when (string-equal command "")
1469     (setq command gnus-last-shell-command))
1470   (gnus-eval-in-buffer-window gnus-article-buffer
1471     (save-restriction
1472       (widen)
1473       (shell-command-on-region (point-min) (point-max) command nil)))
1474   (setq gnus-last-shell-command command))
1475
1476 ;;; Article file names when saving.
1477
1478 (defun gnus-capitalize-newsgroup (newsgroup)
1479   "Capitalize NEWSGROUP name."
1480   (when (not (zerop (length newsgroup)))
1481     (concat (char-to-string (upcase (aref newsgroup 0)))
1482             (substring newsgroup 1))))
1483
1484 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1485   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1486 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1487 Otherwise, it is like ~/News/news/group/num."
1488   (let ((default
1489           (expand-file-name
1490            (concat (if (gnus-use-long-file-name 'not-save)
1491                        (gnus-capitalize-newsgroup newsgroup)
1492                      (gnus-newsgroup-directory-form newsgroup))
1493                    "/" (int-to-string (mail-header-number headers)))
1494            gnus-article-save-directory)))
1495     (if (and last-file
1496              (string-equal (file-name-directory default)
1497                            (file-name-directory last-file))
1498              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1499         default
1500       (or last-file default))))
1501
1502 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1503   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1504 If variable `gnus-use-long-file-name' is non-nil, it is
1505 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
1506   (let ((default
1507           (expand-file-name
1508            (concat (if (gnus-use-long-file-name 'not-save)
1509                        newsgroup
1510                      (gnus-newsgroup-directory-form newsgroup))
1511                    "/" (int-to-string (mail-header-number headers)))
1512            gnus-article-save-directory)))
1513     (if (and last-file
1514              (string-equal (file-name-directory default)
1515                            (file-name-directory last-file))
1516              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1517         default
1518       (or last-file default))))
1519
1520 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1521   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1522 If variable `gnus-use-long-file-name' is non-nil, it is
1523 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
1524   (or last-file
1525       (expand-file-name
1526        (if (gnus-use-long-file-name 'not-save)
1527            (gnus-capitalize-newsgroup newsgroup)
1528          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1529        gnus-article-save-directory)))
1530
1531 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1532   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1533 If variable `gnus-use-long-file-name' is non-nil, it is
1534 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
1535   (or last-file
1536       (expand-file-name
1537        (if (gnus-use-long-file-name 'not-save)
1538            newsgroup
1539          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1540        gnus-article-save-directory)))
1541
1542 (eval-and-compile
1543   (mapcar
1544    (lambda (func)
1545      (let (afunc gfunc)
1546        (if (consp func)
1547            (setq afunc (car func)
1548                  gfunc (cdr func))
1549          (setq afunc func
1550                gfunc (intern (format "gnus-%s" func))))
1551        (fset gfunc 
1552              (if (not (fboundp afunc))
1553                  nil
1554                `(lambda (&optional interactive &rest args)
1555                   ,(documentation afunc t)
1556                   (interactive (list t))
1557                   (save-excursion
1558                     (set-buffer gnus-article-buffer)
1559                     (if interactive
1560                         (call-interactively ',afunc)
1561                       (apply ',afunc args))))))))
1562    '(article-hide-headers
1563      article-hide-boring-headers
1564      article-treat-overstrike
1565      (article-fill . gnus-article-word-wrap)
1566      article-remove-cr
1567      article-display-x-face
1568      article-de-quoted-unreadable
1569      article-mime-decode-quoted-printable
1570      article-hide-pgp
1571      article-hide-pem
1572      article-hide-signature
1573      article-remove-trailing-blank-lines
1574      article-strip-leading-blank-lines
1575      article-strip-multiple-blank-lines
1576      article-strip-blank-lines
1577      article-date-local
1578      article-date-original
1579      article-date-ut
1580      article-date-user
1581      article-date-lapsed
1582      article-emphasize
1583      (article-show-all . gnus-article-show-all-headers))))
1584 \f
1585 ;;;
1586 ;;; Gnus article mode
1587 ;;;
1588
1589 (put 'gnus-article-mode 'mode-class 'special)
1590
1591 (when t
1592   (gnus-define-keys gnus-article-mode-map
1593     " " gnus-article-goto-next-page
1594     "\177" gnus-article-goto-prev-page
1595     [delete] gnus-article-goto-prev-page
1596     "\C-c^" gnus-article-refer-article
1597     "h" gnus-article-show-summary
1598     "s" gnus-article-show-summary
1599     "\C-c\C-m" gnus-article-mail
1600     "?" gnus-article-describe-briefly
1601     gnus-mouse-2 gnus-article-push-button
1602     "\r" gnus-article-press-button
1603     "\t" gnus-article-next-button
1604     "\M-\t" gnus-article-prev-button
1605     "e" gnus-article-edit
1606     "<" beginning-of-buffer
1607     ">" end-of-buffer
1608     "\C-c\C-i" gnus-info-find-node
1609     "\C-c\C-b" gnus-bug
1610
1611     "\C-d" gnus-article-read-summary-keys
1612     "\M-*" gnus-article-read-summary-keys
1613     "\M-g" gnus-article-read-summary-keys)
1614
1615   (substitute-key-definition
1616    'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1617
1618 (defun gnus-article-make-menu-bar ()
1619   (gnus-turn-off-edit-menu 'article)
1620   (unless (boundp 'gnus-article-article-menu)
1621     (easy-menu-define
1622      gnus-article-article-menu gnus-article-mode-map ""
1623      '("Article"
1624        ["Scroll forwards" gnus-article-goto-next-page t]
1625        ["Scroll backwards" gnus-article-goto-prev-page t]
1626        ["Show summary" gnus-article-show-summary t]
1627        ["Fetch Message-ID at point" gnus-article-refer-article t]
1628        ["Mail to address at point" gnus-article-mail t]))
1629
1630     (easy-menu-define
1631      gnus-article-treatment-menu gnus-article-mode-map ""
1632      '("Treatment"
1633        ["Hide headers" gnus-article-hide-headers t]
1634        ["Hide signature" gnus-article-hide-signature t]
1635        ["Hide citation" gnus-article-hide-citation t]
1636        ["Treat overstrike" gnus-article-treat-overstrike t]
1637        ["Remove carriage return" gnus-article-remove-cr t]
1638        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1639
1640     (when (boundp 'gnus-summary-article-menu)
1641       (define-key gnus-article-mode-map [menu-bar commands]
1642         (cons "Commands" gnus-summary-article-menu)))
1643
1644     (when (boundp 'gnus-summary-post-menu)
1645       (define-key gnus-article-mode-map [menu-bar post]
1646         (cons "Post" gnus-summary-post-menu)))
1647
1648     (run-hooks 'gnus-article-menu-hook)))
1649
1650 (defun gnus-article-mode ()
1651   "Major mode for displaying an article.
1652
1653 All normal editing commands are switched off.
1654
1655 The following commands are available in addition to all summary mode
1656 commands:
1657 \\<gnus-article-mode-map>
1658 \\[gnus-article-next-page]\t Scroll the article one page forwards
1659 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1660 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1661 \\[gnus-article-show-summary]\t Display the summary buffer
1662 \\[gnus-article-mail]\t Send a reply to the address near point
1663 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1664 \\[gnus-info-find-node]\t Go to the Gnus info node"
1665   (interactive)
1666   (when (gnus-visual-p 'article-menu 'menu)
1667     (gnus-article-make-menu-bar))
1668   (kill-all-local-variables)
1669   (gnus-simplify-mode-line)
1670   (setq mode-name "Article")
1671   (setq major-mode 'gnus-article-mode)
1672   (make-local-variable 'minor-mode-alist)
1673   (unless (assq 'gnus-show-mime minor-mode-alist)
1674     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1675   (use-local-map gnus-article-mode-map)
1676   (gnus-update-format-specifications nil 'article-mode)
1677   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1678   (gnus-set-default-directory)
1679   (buffer-disable-undo (current-buffer))
1680   (setq buffer-read-only t)
1681   (set-syntax-table gnus-article-mode-syntax-table)
1682   (run-hooks 'gnus-article-mode-hook))
1683
1684 (defun gnus-article-setup-buffer ()
1685   "Initialize the article buffer."
1686   (let* ((name (if gnus-single-article-buffer "*Article*"
1687                  (concat "*Article " gnus-newsgroup-name "*")))
1688          (original
1689           (progn (string-match "\\*Article" name)
1690                  (concat " *Original Article"
1691                          (substring name (match-end 0))))))
1692     (setq gnus-article-buffer name)
1693     (setq gnus-original-article-buffer original)
1694     ;; This might be a variable local to the summary buffer.
1695     (unless gnus-single-article-buffer
1696       (save-excursion
1697         (set-buffer gnus-summary-buffer)
1698         (setq gnus-article-buffer name)
1699         (setq gnus-original-article-buffer original)
1700         (gnus-set-global-variables)))
1701     ;; Init original article buffer.
1702     (save-excursion
1703       (set-buffer (get-buffer-create gnus-original-article-buffer))
1704       (buffer-disable-undo (current-buffer))
1705       (setq major-mode 'gnus-original-article-mode)
1706       (gnus-add-current-to-buffer-list)
1707       (make-local-variable 'gnus-original-article))
1708     (if (get-buffer name)
1709         (save-excursion
1710           (set-buffer name)
1711           (buffer-disable-undo (current-buffer))
1712           (setq buffer-read-only t)
1713           (gnus-add-current-to-buffer-list)
1714           (unless (eq major-mode 'gnus-article-mode)
1715             (gnus-article-mode))
1716           (current-buffer))
1717       (save-excursion
1718         (set-buffer (get-buffer-create name))
1719         (gnus-add-current-to-buffer-list)
1720         (gnus-article-mode)
1721         (make-local-variable 'gnus-summary-buffer)
1722         (current-buffer)))))
1723
1724 ;; Set article window start at LINE, where LINE is the number of lines
1725 ;; from the head of the article.
1726 (defun gnus-article-set-window-start (&optional line)
1727   (set-window-start
1728    (get-buffer-window gnus-article-buffer t)
1729    (save-excursion
1730      (set-buffer gnus-article-buffer)
1731      (goto-char (point-min))
1732      (if (not line)
1733          (point-min)
1734        (gnus-message 6 "Moved to bookmark")
1735        (search-forward "\n\n" nil t)
1736        (forward-line line)
1737        (point)))))
1738
1739 (defun gnus-article-prepare (article &optional all-headers header)
1740   "Prepare ARTICLE in article mode buffer.
1741 ARTICLE should either be an article number or a Message-ID.
1742 If ARTICLE is an id, HEADER should be the article headers.
1743 If ALL-HEADERS is non-nil, no headers are hidden."
1744   (save-excursion
1745     ;; Make sure we start in a summary buffer.
1746     (unless (eq major-mode 'gnus-summary-mode)
1747       (set-buffer gnus-summary-buffer))
1748     (setq gnus-summary-buffer (current-buffer))
1749     ;; Make sure the connection to the server is alive.
1750     (unless (gnus-server-opened
1751              (gnus-find-method-for-group gnus-newsgroup-name))
1752       (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1753       (gnus-request-group gnus-newsgroup-name t))
1754     (let* ((gnus-article (if header (mail-header-number header) article))
1755            (summary-buffer (current-buffer))
1756            (internal-hook gnus-article-internal-prepare-hook)
1757            (group gnus-newsgroup-name)
1758            result)
1759       (save-excursion
1760         (gnus-article-setup-buffer)
1761         (set-buffer gnus-article-buffer)
1762         ;; Deactivate active regions.
1763         (when (and (boundp 'transient-mark-mode)
1764                    transient-mark-mode)
1765           (setq mark-active nil))
1766         (if (not (setq result (let ((buffer-read-only nil))
1767                                 (gnus-request-article-this-buffer
1768                                  article group))))
1769             ;; There is no such article.
1770             (save-excursion
1771               (when (and (numberp article)
1772                          (not (memq article gnus-newsgroup-sparse)))
1773                 (setq gnus-article-current
1774                       (cons gnus-newsgroup-name article))
1775                 (set-buffer gnus-summary-buffer)
1776                 (setq gnus-current-article article)
1777                 (gnus-summary-mark-article article gnus-canceled-mark))
1778               (unless (memq article gnus-newsgroup-sparse)
1779                 (gnus-error
1780                  1 "No such article (may have expired or been canceled)")))
1781           (if (or (eq result 'pseudo) (eq result 'nneething))
1782               (progn
1783                 (save-excursion
1784                   (set-buffer summary-buffer)
1785                   (setq gnus-last-article gnus-current-article
1786                         gnus-newsgroup-history (cons gnus-current-article
1787                                                      gnus-newsgroup-history)
1788                         gnus-current-article 0
1789                         gnus-current-headers nil
1790                         gnus-article-current nil)
1791                   (if (eq result 'nneething)
1792                       (gnus-configure-windows 'summary)
1793                     (gnus-configure-windows 'article))
1794                   (gnus-set-global-variables))
1795                 (gnus-set-mode-line 'article))
1796             ;; The result from the `request' was an actual article -
1797             ;; or at least some text that is now displayed in the
1798             ;; article buffer.
1799             (when (and (numberp article)
1800                        (not (eq article gnus-current-article)))
1801               ;; Seems like a new article has been selected.
1802               ;; `gnus-current-article' must be an article number.
1803               (save-excursion
1804                 (set-buffer summary-buffer)
1805                 (setq gnus-last-article gnus-current-article
1806                       gnus-newsgroup-history (cons gnus-current-article
1807                                                    gnus-newsgroup-history)
1808                       gnus-current-article article
1809                       gnus-current-headers
1810                       (gnus-summary-article-header gnus-current-article)
1811                       gnus-article-current
1812                       (cons gnus-newsgroup-name gnus-current-article))
1813                 (unless (vectorp gnus-current-headers)
1814                   (setq gnus-current-headers nil))
1815                 (gnus-summary-show-thread)
1816                 (run-hooks 'gnus-mark-article-hook)
1817                 (gnus-set-mode-line 'summary)
1818                 (when (gnus-visual-p 'article-highlight 'highlight)
1819                   (run-hooks 'gnus-visual-mark-article-hook))
1820                 ;; Set the global newsgroup variables here.
1821                 ;; Suggested by Jim Sisolak
1822                 ;; <sisolak@trans4.neep.wisc.edu>.
1823                 (gnus-set-global-variables)
1824                 (setq gnus-have-all-headers
1825                       (or all-headers gnus-show-all-headers))
1826                 (and gnus-use-cache
1827                      (vectorp (gnus-summary-article-header article))
1828                      (gnus-cache-possibly-enter-article
1829                       group article
1830                       (gnus-summary-article-header article)
1831                       (memq article gnus-newsgroup-marked)
1832                       (memq article gnus-newsgroup-dormant)
1833                       (memq article gnus-newsgroup-unreads)))))
1834             (when (or (numberp article)
1835                       (stringp article))
1836               ;; Hooks for getting information from the article.
1837               ;; This hook must be called before being narrowed.
1838               (let (buffer-read-only)
1839                 (run-hooks 'internal-hook)
1840                 (run-hooks 'gnus-article-prepare-hook)
1841                 ;; Decode MIME message.
1842                 (when gnus-show-mime
1843                   (if (or (not gnus-strict-mime)
1844                           (gnus-fetch-field "Mime-Version"))
1845                       (funcall gnus-show-mime-method)
1846                     (funcall gnus-decode-encoded-word-method)))
1847                 ;; Perform the article display hooks.
1848                 (run-hooks 'gnus-article-display-hook))
1849               ;; Do page break.
1850               (goto-char (point-min))
1851               (when gnus-break-pages
1852                 (gnus-narrow-to-page)))
1853             (gnus-set-mode-line 'article)
1854             (gnus-configure-windows 'article)
1855             (goto-char (point-min))
1856             t))))))
1857
1858 (defun gnus-article-wash-status ()
1859   "Return a string which display status of article washing."
1860   (save-excursion
1861     (set-buffer gnus-article-buffer)
1862     (let ((cite (gnus-article-hidden-text-p 'cite))
1863           (headers (gnus-article-hidden-text-p 'headers))
1864           (boring (gnus-article-hidden-text-p 'boring-headers))
1865           (pgp (gnus-article-hidden-text-p 'pgp))
1866           (pem (gnus-article-hidden-text-p 'pem))
1867           (signature (gnus-article-hidden-text-p 'signature))
1868           (overstrike (gnus-article-hidden-text-p 'overstrike))
1869           (emphasis (gnus-article-hidden-text-p 'emphasis))
1870           (mime gnus-show-mime))
1871       (format "%c%c%c%c%c%c%c"
1872               (if cite ?c ? )
1873               (if (or headers boring) ?h ? )
1874               (if (or pgp pem) ?p ? )
1875               (if signature ?s ? )
1876               (if overstrike ?o ? )
1877               (if mime ?m ? )
1878               (if emphasis ?e ? )))))
1879
1880 (defun gnus-article-hide-headers-if-wanted ()
1881   "Hide unwanted headers if `gnus-have-all-headers' is nil.
1882 Provided for backwards compatibility."
1883   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
1884       gnus-inhibit-hiding
1885       (gnus-article-hide-headers)))
1886
1887 ;;; Article savers.
1888
1889 (defun gnus-output-to-rmail (file-name)
1890   "Append the current article to an Rmail file named FILE-NAME."
1891   (require 'rmail)
1892   ;; Most of these codes are borrowed from rmailout.el.
1893   (setq file-name (expand-file-name file-name))
1894   (setq rmail-default-rmail-file file-name)
1895   (let ((artbuf (current-buffer))
1896         (tmpbuf (get-buffer-create " *Gnus-output*")))
1897     (save-excursion
1898       (or (get-file-buffer file-name)
1899           (file-exists-p file-name)
1900           (if (gnus-yes-or-no-p
1901                (concat "\"" file-name "\" does not exist, create it? "))
1902               (let ((file-buffer (create-file-buffer file-name)))
1903                 (save-excursion
1904                   (set-buffer file-buffer)
1905                   (rmail-insert-rmail-file-header)
1906                   (let ((require-final-newline nil))
1907                     (gnus-write-buffer file-name)))
1908                 (kill-buffer file-buffer))
1909             (error "Output file does not exist")))
1910       (set-buffer tmpbuf)
1911       (buffer-disable-undo (current-buffer))
1912       (erase-buffer)
1913       (insert-buffer-substring artbuf)
1914       (gnus-convert-article-to-rmail)
1915       ;; Decide whether to append to a file or to an Emacs buffer.
1916       (let ((outbuf (get-file-buffer file-name)))
1917         (if (not outbuf)
1918             (append-to-file (point-min) (point-max) file-name)
1919           ;; File has been visited, in buffer OUTBUF.
1920           (set-buffer outbuf)
1921           (let ((buffer-read-only nil)
1922                 (msg (and (boundp 'rmail-current-message)
1923                           (symbol-value 'rmail-current-message))))
1924             ;; If MSG is non-nil, buffer is in RMAIL mode.
1925             (when msg
1926               (widen)
1927               (narrow-to-region (point-max) (point-max)))
1928             (insert-buffer-substring tmpbuf)
1929             (when msg
1930               (goto-char (point-min))
1931               (widen)
1932               (search-backward "\^_")
1933               (narrow-to-region (point) (point-max))
1934               (goto-char (1+ (point-min)))
1935               (rmail-count-new-messages t)
1936               (rmail-show-message msg))))))
1937     (kill-buffer tmpbuf)))
1938
1939 (defun gnus-output-to-file (file-name)
1940   "Append the current article to a file named FILE-NAME."
1941   (let ((artbuf (current-buffer)))
1942     (nnheader-temp-write nil
1943       (insert-buffer-substring artbuf)
1944       ;; Append newline at end of the buffer as separator, and then
1945       ;; save it to file.
1946       (goto-char (point-max))
1947       (insert "\n")
1948       (append-to-file (point-min) (point-max) file-name))))
1949
1950 (defun gnus-convert-article-to-rmail ()
1951   "Convert article in current buffer to Rmail message format."
1952   (let ((buffer-read-only nil))
1953     ;; Convert article directly into Babyl format.
1954     ;; Suggested by Rob Austein <sra@lcs.mit.edu>
1955     (goto-char (point-min))
1956     (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1957     (while (search-forward "\n\^_" nil t) ;single char
1958       (replace-match "\n^_" t t))       ;2 chars: "^" and "_"
1959     (goto-char (point-max))
1960     (insert "\^_")))
1961
1962 (defun gnus-narrow-to-page (&optional arg)
1963   "Narrow the article buffer to a page.
1964 If given a numerical ARG, move forward ARG pages."
1965   (interactive "P")
1966   (setq arg (if arg (prefix-numeric-value arg) 0))
1967   (save-excursion
1968     (set-buffer gnus-article-buffer)
1969     (goto-char (point-min))
1970     (widen)
1971     ;; Remove any old next/prev buttons.
1972     (when (gnus-visual-p 'page-marker)
1973       (let ((buffer-read-only nil))
1974         (gnus-remove-text-with-property 'gnus-prev)
1975         (gnus-remove-text-with-property 'gnus-next)))
1976     (when
1977         (cond ((< arg 0)
1978                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
1979               ((> arg 0)
1980                (re-search-forward page-delimiter nil 'move arg)))
1981       (goto-char (match-end 0)))
1982     (narrow-to-region
1983      (point)
1984      (if (re-search-forward page-delimiter nil 'move)
1985          (match-beginning 0)
1986        (point)))
1987     (when (and (gnus-visual-p 'page-marker)
1988                (not (= (point-min) 1)))
1989       (save-excursion
1990         (goto-char (point-min))
1991         (gnus-insert-prev-page-button)))
1992     (when (and (gnus-visual-p 'page-marker)
1993                (< (+ (point-max) 2) (buffer-size)))
1994       (save-excursion
1995         (goto-char (point-max))
1996         (gnus-insert-next-page-button)))))
1997
1998 ;; Article mode commands
1999
2000 (defun gnus-article-goto-next-page ()
2001   "Show the next page of the article."
2002   (interactive)
2003   (when (gnus-article-next-page)
2004     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2005
2006 (defun gnus-article-goto-prev-page ()
2007   "Show the next page of the article."
2008   (interactive)
2009   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2010     (gnus-article-prev-page nil)))
2011
2012 (defun gnus-article-next-page (&optional lines)
2013   "Show the next page of the current article.
2014 If end of article, return non-nil.  Otherwise return nil.
2015 Argument LINES specifies lines to be scrolled up."
2016   (interactive "p")
2017   (move-to-window-line -1)
2018   (if (save-excursion
2019         (end-of-line)
2020         (and (pos-visible-in-window-p)  ;Not continuation line.
2021              (eobp)))
2022       ;; Nothing in this page.
2023       (if (or (not gnus-break-pages)
2024               (save-excursion
2025                 (save-restriction
2026                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2027           t                             ;Nothing more.
2028         (gnus-narrow-to-page 1)         ;Go to next page.
2029         nil)
2030     ;; More in this page.
2031     (let ((scroll-in-place nil))
2032       (condition-case ()
2033           (scroll-up lines)
2034         (end-of-buffer
2035          ;; Long lines may cause an end-of-buffer error.
2036          (goto-char (point-max)))))
2037     (move-to-window-line 0)
2038     nil))
2039
2040 (defun gnus-article-prev-page (&optional lines)
2041   "Show previous page of current article.
2042 Argument LINES specifies lines to be scrolled down."
2043   (interactive "p")
2044   (move-to-window-line 0)
2045   (if (and gnus-break-pages
2046            (bobp)
2047            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2048       (progn
2049         (gnus-narrow-to-page -1)        ;Go to previous page.
2050         (goto-char (point-max))
2051         (recenter -1))
2052     (let ((scroll-in-place nil))
2053       (prog1
2054           (ignore-errors
2055             (scroll-down lines))
2056         (move-to-window-line 0)))))
2057
2058 (defun gnus-article-refer-article ()
2059   "Read article specified by message-id around point."
2060   (interactive)
2061   (let ((point (point)))
2062     (search-forward ">" nil t)          ;Move point to end of "<....>".
2063     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2064         (let ((message-id (match-string 1)))
2065           (goto-char point)
2066           (set-buffer gnus-summary-buffer)
2067           (gnus-summary-refer-article message-id))
2068       (goto-char (point))
2069       (error "No references around point"))))
2070
2071 (defun gnus-article-show-summary ()
2072   "Reconfigure windows to show summary buffer."
2073   (interactive)
2074   (gnus-configure-windows 'article)
2075   (gnus-summary-goto-subject gnus-current-article))
2076
2077 (defun gnus-article-describe-briefly ()
2078   "Describe article mode commands briefly."
2079   (interactive)
2080   (gnus-message 6
2081                 (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")))
2082
2083 (defun gnus-article-summary-command ()
2084   "Execute the last keystroke in the summary buffer."
2085   (interactive)
2086   (let ((obuf (current-buffer))
2087         (owin (current-window-configuration))
2088         func)
2089     (switch-to-buffer gnus-summary-buffer 'norecord)
2090     (setq func (lookup-key (current-local-map) (this-command-keys)))
2091     (call-interactively func)
2092     (set-buffer obuf)
2093     (set-window-configuration owin)
2094     (set-window-point (get-buffer-window (current-buffer)) (point))))
2095
2096 (defun gnus-article-summary-command-nosave ()
2097   "Execute the last keystroke in the summary buffer."
2098   (interactive)
2099   (let (func)
2100     (pop-to-buffer gnus-summary-buffer 'norecord)
2101     (setq func (lookup-key (current-local-map) (this-command-keys)))
2102     (call-interactively func)))
2103
2104 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2105   "Read a summary buffer key sequence and execute it from the article buffer."
2106   (interactive "P")
2107   (let ((nosaves
2108          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
2109            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2110            "=" "^" "\M-^" "|"))
2111         (nosave-but-article
2112          '("A\r"))
2113         (nosave-in-article
2114          '("\C-d"))
2115         keys)
2116     (save-excursion
2117       (set-buffer gnus-summary-buffer)
2118       (push (or key last-command-event) unread-command-events)
2119       (setq keys (read-key-sequence nil)))
2120     (message "")
2121
2122     (if (or (member keys nosaves)
2123             (member keys nosave-but-article)
2124             (member keys nosave-in-article))
2125         (let (func)
2126           (save-window-excursion
2127             (pop-to-buffer gnus-summary-buffer 'norecord)
2128             (setq func (lookup-key (current-local-map) keys)))
2129           (if (not func)
2130               (ding)
2131             (unless (member keys nosave-in-article)
2132               (set-buffer gnus-summary-buffer))
2133             (call-interactively func))
2134           (when (member keys nosave-but-article)
2135             (pop-to-buffer gnus-article-buffer 'norecord)))
2136       ;; These commands should restore window configuration.
2137       (let ((obuf (current-buffer))
2138             (owin (current-window-configuration))
2139             (opoint (point))
2140             func in-buffer)
2141         (if not-restore-window
2142             (pop-to-buffer gnus-summary-buffer 'norecord)
2143           (switch-to-buffer gnus-summary-buffer 'norecord))
2144         (setq in-buffer (current-buffer))
2145         (if (setq func (lookup-key (current-local-map) keys))
2146             (call-interactively func)
2147           (ding))
2148         (when (eq in-buffer (current-buffer))
2149           (set-buffer obuf)
2150           (unless not-restore-window
2151             (set-window-configuration owin))
2152           (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2153
2154 (defun gnus-article-hide (&optional arg force)
2155   "Hide all the gruft in the current article.
2156 This means that PGP stuff, signatures, cited text and (some)
2157 headers will be hidden.
2158 If given a prefix, show the hidden text instead."
2159   (interactive (list current-prefix-arg 'force))
2160   (gnus-article-hide-headers arg)
2161   (gnus-article-hide-pgp arg)
2162   (gnus-article-hide-citation-maybe arg force)
2163   (gnus-article-hide-signature arg))
2164
2165 (defun gnus-article-maybe-highlight ()
2166   "Do some article highlighting if `article-visual' is non-nil."
2167   (when (gnus-visual-p 'article-highlight 'highlight)
2168     (gnus-article-highlight-some)))
2169
2170 (defun gnus-request-article-this-buffer (article group)
2171   "Get an article and insert it into this buffer."
2172   (let (do-update-line)
2173     (prog1
2174         (save-excursion
2175           (erase-buffer)
2176           (gnus-kill-all-overlays)
2177           (setq group (or group gnus-newsgroup-name))
2178
2179           ;; Open server if it has closed.
2180           (gnus-check-server (gnus-find-method-for-group group))
2181
2182           ;; Using `gnus-request-article' directly will insert the article into
2183           ;; `nntp-server-buffer' - so we'll save some time by not having to
2184           ;; copy it from the server buffer into the article buffer.
2185
2186           ;; We only request an article by message-id when we do not have the
2187           ;; headers for it, so we'll have to get those.
2188           (when (stringp article)
2189             (let ((gnus-override-method gnus-refer-article-method))
2190               (gnus-read-header article)))
2191
2192           ;; If the article number is negative, that means that this article
2193           ;; doesn't belong in this newsgroup (possibly), so we find its
2194           ;; message-id and request it by id instead of number.
2195           (when (and (numberp article)
2196                      gnus-summary-buffer
2197                      (get-buffer gnus-summary-buffer)
2198                      (buffer-name (get-buffer gnus-summary-buffer)))
2199             (save-excursion
2200               (set-buffer gnus-summary-buffer)
2201               (let ((header (gnus-summary-article-header article)))
2202                 (when (< article 0)
2203                   (cond 
2204                    ((memq article gnus-newsgroup-sparse)
2205                     ;; This is a sparse gap article.
2206                     (setq do-update-line article)
2207                     (setq article (mail-header-id header))
2208                     (let ((gnus-override-method gnus-refer-article-method))
2209                       (gnus-read-header article))
2210                     (setq gnus-newsgroup-sparse
2211                           (delq article gnus-newsgroup-sparse)))
2212                    ((vectorp header)
2213                     ;; It's a real article.
2214                     (setq article (mail-header-id header)))
2215                    (t
2216                     ;; It is an extracted pseudo-article.
2217                     (setq article 'pseudo)
2218                     (gnus-request-pseudo-article header))))
2219                 
2220                 (let ((method (gnus-find-method-for-group 
2221                                gnus-newsgroup-name)))
2222                   (if (not (eq (car method) 'nneething))
2223                       ()
2224                     (let ((dir (concat (file-name-as-directory (nth 1 method))
2225                                        (mail-header-subject header))))
2226                       (when (file-directory-p dir)
2227                         (setq article 'nneething)
2228                         (gnus-group-enter-directory dir))))))))
2229
2230           (cond
2231            ;; Refuse to select canceled articles.
2232            ((and (numberp article)
2233                  gnus-summary-buffer
2234                  (get-buffer gnus-summary-buffer)
2235                  (buffer-name (get-buffer gnus-summary-buffer))
2236                  (eq (cdr (save-excursion
2237                             (set-buffer gnus-summary-buffer)
2238                             (assq article gnus-newsgroup-reads)))
2239                      gnus-canceled-mark))
2240             nil)
2241            ;; We first check `gnus-original-article-buffer'.
2242            ((and (get-buffer gnus-original-article-buffer)
2243                  (numberp article)
2244                  (save-excursion
2245                    (set-buffer gnus-original-article-buffer)
2246                    (and (equal (car gnus-original-article) group)
2247                         (eq (cdr gnus-original-article) article))))
2248             (insert-buffer-substring gnus-original-article-buffer)
2249             'article)
2250            ;; Check the backlog.
2251            ((and gnus-keep-backlog
2252                  (gnus-backlog-request-article group article (current-buffer)))
2253             'article)
2254            ;; Check asynchronous pre-fetch.
2255            ((gnus-async-request-fetched-article group article (current-buffer))
2256             (gnus-async-prefetch-next group article gnus-summary-buffer)
2257             'article)
2258            ;; Check the cache.
2259            ((and gnus-use-cache
2260                  (numberp article)
2261                  (gnus-cache-request-article article group))
2262             'article)
2263            ;; Get the article and put into the article buffer.
2264            ((or (stringp article) (numberp article))
2265             (let ((gnus-override-method
2266                    (and (stringp article) gnus-refer-article-method))
2267                   (buffer-read-only nil))
2268               (erase-buffer)
2269               (gnus-kill-all-overlays)
2270               (when (gnus-request-article article group (current-buffer))
2271                 (when (numberp article)
2272                   (gnus-async-prefetch-next group article gnus-summary-buffer)
2273                   (when gnus-keep-backlog
2274                     (gnus-backlog-enter-article 
2275                      group article (current-buffer))))
2276                 'article)))
2277            ;; It was a pseudo.
2278            (t article)))
2279
2280       ;; Take the article from the original article buffer
2281       ;; and place it in the buffer it's supposed to be in.
2282       (when (and (get-buffer gnus-article-buffer)
2283                  ;;(numberp article)
2284                  (equal (buffer-name (current-buffer))
2285                         (buffer-name (get-buffer gnus-article-buffer))))
2286         (save-excursion
2287           (if (get-buffer gnus-original-article-buffer)
2288               (set-buffer (get-buffer gnus-original-article-buffer))
2289             (set-buffer (get-buffer-create gnus-original-article-buffer))
2290             (buffer-disable-undo (current-buffer))
2291             (setq major-mode 'gnus-original-article-mode)
2292             (setq buffer-read-only t)
2293             (gnus-add-current-to-buffer-list))
2294           (let (buffer-read-only)
2295             (erase-buffer)
2296             (insert-buffer-substring gnus-article-buffer))
2297           (setq gnus-original-article (cons group article))))
2298     
2299       ;; Update sparse articles.
2300       (when (and do-update-line
2301                  (or (numberp article)
2302                      (stringp article)))
2303         (let ((buf (current-buffer)))
2304           (set-buffer gnus-summary-buffer)
2305           (gnus-summary-update-article do-update-line)
2306           (gnus-summary-goto-subject do-update-line nil t)
2307           (set-window-point (get-buffer-window (current-buffer) t)
2308                             (point))
2309           (set-buffer buf))))))
2310
2311 ;;;
2312 ;;; Article editing
2313 ;;;
2314
2315 (defcustom gnus-article-edit-mode-hook nil
2316   "Hook run in article edit mode buffers."
2317   :group 'article
2318   :type 'hook)
2319
2320 (defvar gnus-article-edit-done-function nil)
2321
2322 (defvar gnus-article-edit-mode-map nil)
2323
2324 (unless gnus-article-edit-mode-map 
2325   (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2326
2327   (gnus-define-keys gnus-article-edit-mode-map
2328     "\C-c\C-c" gnus-article-edit-done
2329     "\C-c\C-k" gnus-article-edit-exit)
2330
2331   (gnus-define-keys (gnus-article-edit-wash-map
2332                      "\C-c\C-w" gnus-article-edit-mode-map)
2333     "f" gnus-article-edit-full-stops))
2334
2335 (defun gnus-article-edit-mode ()
2336   "Major mode for editing articles.
2337 This is an extended text-mode.
2338
2339 \\{gnus-article-edit-mode-map}"
2340   (interactive)
2341   (kill-all-local-variables)
2342   (setq major-mode 'gnus-article-edit-mode)
2343   (setq mode-name "Article Edit")
2344   (use-local-map gnus-article-edit-mode-map)
2345   (make-local-variable 'gnus-article-edit-done-function)
2346   (make-local-variable 'gnus-prev-winconf)
2347   (setq buffer-read-only nil)
2348   (buffer-enable-undo)
2349   (widen)
2350   (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2351
2352 (defun gnus-article-edit (&optional force)
2353   "Edit the current article.
2354 This will have permanent effect only in mail groups.
2355 If FORCE is non-nil, allow editing of articles even in read-only
2356 groups."
2357   (interactive "P")
2358   (when (and (not force)
2359              (gnus-group-read-only-p))
2360     (error "The current newsgroup does not support article editing."))
2361   (gnus-article-edit-article
2362    `(lambda ()
2363       (gnus-summary-edit-article-done
2364        ,(or (mail-header-references gnus-current-headers) "")
2365        ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2366
2367 (defun gnus-article-edit-article (exit-func)
2368   "Start editing the contents of the current article buffer."
2369   (let ((winconf (current-window-configuration)))
2370     (set-buffer gnus-article-buffer)
2371     (gnus-article-edit-mode)
2372     (set-text-properties (point-min) (point-max) nil)
2373     (gnus-configure-windows 'edit-article)
2374     (setq gnus-article-edit-done-function exit-func)
2375     (setq gnus-prev-winconf winconf)
2376     (gnus-message 6 "C-c C-c to end edits")))
2377
2378 (defun gnus-article-edit-done ()
2379   "Update the article edits and exit."
2380   (interactive)
2381   (let ((func gnus-article-edit-done-function)
2382         (buf (current-buffer))
2383         (start (window-start)))
2384     (gnus-article-edit-exit)
2385     (save-excursion
2386       (set-buffer buf)
2387       (let ((buffer-read-only nil))
2388         (funcall func)))
2389     (set-buffer buf)
2390     (set-window-start (get-buffer-window buf) start)
2391     (set-window-point (get-buffer-window buf) (point))))
2392
2393 (defun gnus-article-edit-exit ()
2394   "Exit the article editing without updating."
2395   (interactive)
2396   ;; We remove all text props from the article buffer.
2397   (let ((buf (format "%s" (buffer-string)))
2398         (curbuf (current-buffer))
2399         (p (point))
2400         (window-start (window-start)))
2401     (erase-buffer)
2402     (insert buf)
2403     (let ((winconf gnus-prev-winconf))
2404       (gnus-article-mode)
2405       ;; The cache and backlog have to be flushed somewhat.
2406       (when gnus-use-cache
2407         (gnus-cache-update-article      
2408          (car gnus-article-current) (cdr gnus-article-current)))
2409       (when gnus-keep-backlog
2410         (gnus-backlog-remove-article 
2411          (car gnus-article-current) (cdr gnus-article-current)))
2412       ;; Flush original article as well.
2413       (save-excursion
2414         (when (get-buffer gnus-original-article-buffer)
2415           (set-buffer gnus-original-article-buffer)
2416           (setq gnus-original-article nil)))
2417       (set-window-configuration winconf)
2418       ;; Tippy-toe some to make sure that point remains where it was.
2419       (let ((buf (current-buffer)))
2420         (set-buffer curbuf)
2421         (set-window-start (get-buffer-window (current-buffer)) window-start)
2422         (goto-char p)
2423         (set-buffer buf)))))
2424       
2425 (defun gnus-article-edit-full-stops ()
2426   "Interactively repair spacing at end of sentences."
2427   (interactive)
2428   (save-excursion
2429     (goto-char (point-min))
2430     (search-forward-regexp "^$" nil t)
2431     (let ((case-fold-search nil))
2432       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2433
2434 ;;; 
2435 ;;; Article highlights
2436 ;;;
2437
2438 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2439
2440 ;;; Internal Variables:
2441
2442 (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\\)"
2443   "Regular expression that matches URLs."
2444   :group 'article
2445   :type 'regexp)
2446
2447 (defcustom gnus-button-alist 
2448   `(("\\(\\b<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
2449      gnus-button-message-id 3)
2450     ("\\(\\b<?\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>?\\)" 1 t
2451      gnus-button-fetch-group 4)
2452     ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 
2453      t gnus-button-message-id 3)
2454     ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-url-mailto 2)
2455     ;; This is how URLs _should_ be embedded in text...
2456     ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2457     ;; Raw URLs.
2458     (,gnus-button-url-regexp 0 t gnus-button-url 0))
2459   "Alist of regexps matching buttons in article bodies.
2460
2461 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2462 REGEXP: is the string matching text around the button,
2463 BUTTON: is the number of the regexp grouping actually matching the button,
2464 FORM: is a lisp expression which must eval to true for the button to
2465 be added, 
2466 CALLBACK: is the function to call when the user push this button, and each
2467 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2468
2469 CALLBACK can also be a variable, in that case the value of that
2470 variable it the real callback function."
2471   :group 'article
2472   :type '(repeat (list regexp 
2473                        (integer :tag "Button")
2474                        (sexp :tag "Form")
2475                        (function :tag "Callback")
2476                        (repeat :tag "Par"
2477                                :inline t
2478                                (integer :tag "Regexp group")))))
2479
2480 (defcustom gnus-header-button-alist 
2481   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2482      0 t gnus-button-message-id 0)
2483     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2484     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+" 
2485      0 t gnus-button-mailto 0)
2486     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2487     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2488     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2489      gnus-button-message-id 3))
2490   "Alist of headers and regexps to match buttons in article heads.
2491
2492 This alist is very similar to `gnus-button-alist', except that each
2493 alist has an additional HEADER element first in each entry:
2494
2495 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2496
2497 HEADER is a regexp to match a header.  For a fuller explanation, see
2498 `gnus-button-alist'."
2499   :group 'article
2500   :type '(repeat (list (regexp :tag "Header")
2501                        regexp 
2502                        (integer :tag "Button")
2503                        (sexp :tag "Form")
2504                        (function :tag "Callback")
2505                        (repeat :tag "Par"
2506                                :inline t
2507                                (integer :tag "Regexp group")))))
2508
2509 (defvar gnus-button-regexp nil)
2510 (defvar gnus-button-marker-list nil)
2511 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2512
2513 (defvar gnus-button-last nil)
2514 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2515
2516 ;;; Commands:
2517
2518 (defun gnus-article-push-button (event)
2519   "Check text under the mouse pointer for a callback function.
2520 If the text under the mouse pointer has a `gnus-callback' property,
2521 call it with the value of the `gnus-data' text property."
2522   (interactive "e")
2523   (set-buffer (window-buffer (posn-window (event-start event))))
2524   (let* ((pos (posn-point (event-start event)))
2525          (data (get-text-property pos 'gnus-data))
2526          (fun (get-text-property pos 'gnus-callback)))
2527     (when fun
2528       (funcall fun data))))
2529
2530 (defun gnus-article-press-button ()
2531   "Check text at point for a callback function.
2532 If the text at point has a `gnus-callback' property,
2533 call it with the value of the `gnus-data' text property."
2534   (interactive)
2535   (let* ((data (get-text-property (point) 'gnus-data))
2536          (fun (get-text-property (point) 'gnus-callback)))
2537     (when fun
2538       (funcall fun data))))
2539
2540 (defun gnus-article-prev-button (n)
2541   "Move point to N buttons backward.
2542 If N is negative, move forward instead."
2543   (interactive "p")
2544   (gnus-article-next-button (- n)))
2545
2546 (defun gnus-article-next-button (n)
2547   "Move point to N buttons forward.
2548 If N is negative, move backward instead."
2549   (interactive "p")
2550   (let ((function (if (< n 0) 'previous-single-property-change
2551                     'next-single-property-change))
2552         (inhibit-point-motion-hooks t)
2553         (backward (< n 0))
2554         (limit (if (< n 0) (point-min) (point-max))))
2555     (setq n (abs n))
2556     (while (and (not (= limit (point)))
2557                 (> n 0))
2558       ;; Skip past the current button.
2559       (when (get-text-property (point) 'gnus-callback)
2560         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2561       ;; Go to the next (or previous) button.
2562       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2563       ;; Put point at the start of the button.
2564       (when (and backward (not (get-text-property (point) 'gnus-callback)))
2565         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2566       ;; Skip past intangible buttons.
2567       (when (get-text-property (point) 'intangible)
2568         (incf n))
2569       (decf n))
2570     (unless (zerop n)
2571       (gnus-message 5 "No more buttons"))
2572     n))
2573
2574 (defun gnus-article-highlight (&optional force)
2575   "Highlight current article.
2576 This function calls `gnus-article-highlight-headers',
2577 `gnus-article-highlight-citation', 
2578 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2579 do the highlighting.  See the documentation for those functions."
2580   (interactive (list 'force))
2581   (gnus-article-highlight-headers)
2582   (gnus-article-highlight-citation force)
2583   (gnus-article-highlight-signature)
2584   (gnus-article-add-buttons force)
2585   (gnus-article-add-buttons-to-head))
2586
2587 (defun gnus-article-highlight-some (&optional force)
2588   "Highlight current article.
2589 This function calls `gnus-article-highlight-headers',
2590 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2591 do the highlighting.  See the documentation for those functions."
2592   (interactive (list 'force))
2593   (gnus-article-highlight-headers)
2594   (gnus-article-highlight-signature)
2595   (gnus-article-add-buttons))
2596
2597 (defun gnus-article-highlight-headers ()
2598   "Highlight article headers as specified by `gnus-header-face-alist'."
2599   (interactive)
2600   (save-excursion
2601     (set-buffer gnus-article-buffer)
2602     (save-restriction
2603       (let ((alist gnus-header-face-alist)
2604             (buffer-read-only nil)
2605             (case-fold-search t)
2606             (inhibit-point-motion-hooks t)
2607             entry regexp header-face field-face from hpoints fpoints)
2608         (goto-char (point-min))
2609         (when (search-forward "\n\n" nil t)
2610           (narrow-to-region (1- (point)) (point-min))
2611           (while (setq entry (pop alist))
2612             (goto-char (point-min))
2613             (setq regexp (concat "^\\("
2614                                  (if (string-equal "" (nth 0 entry))
2615                                      "[^\t ]"
2616                                    (nth 0 entry))
2617                                  "\\)")
2618                   header-face (nth 1 entry)
2619                   field-face (nth 2 entry))
2620             (while (and (re-search-forward regexp nil t)
2621                         (not (eobp)))
2622               (beginning-of-line)
2623               (setq from (point))
2624               (unless (search-forward ":" nil t)
2625                 (forward-char 1))
2626               (when (and header-face
2627                          (not (memq (point) hpoints)))
2628                 (push (point) hpoints)
2629                 (gnus-put-text-property from (point) 'face header-face))
2630               (when (and field-face
2631                          (not (memq (setq from (point)) fpoints)))
2632                 (push from fpoints)
2633                 (if (re-search-forward "^[^ \t]" nil t)
2634                     (forward-char -2)
2635                   (goto-char (point-max)))
2636                 (gnus-put-text-property from (point) 'face field-face)))))))))
2637
2638 (defun gnus-article-highlight-signature ()
2639   "Highlight the signature in an article.
2640 It does this by highlighting everything after
2641 `gnus-signature-separator' using `gnus-signature-face'." 
2642   (interactive)
2643   (save-excursion
2644     (set-buffer gnus-article-buffer)
2645     (let ((buffer-read-only nil)
2646           (inhibit-point-motion-hooks t))
2647       (save-restriction
2648         (when (and gnus-signature-face
2649                    (gnus-article-narrow-to-signature))
2650           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2651                             'face gnus-signature-face)
2652           (widen)
2653           (gnus-article-search-signature)
2654           (let ((start (match-beginning 0))
2655                 (end (set-marker (make-marker) (1+ (match-end 0)))))
2656             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2657                                      end)))))))
2658
2659 (defun gnus-article-add-buttons (&optional force)
2660   "Find external references in the article and make buttons of them.
2661 \"External references\" are things like Message-IDs and URLs, as
2662 specified by `gnus-button-alist'."
2663   (interactive (list 'force))
2664   (save-excursion
2665     (set-buffer gnus-article-buffer)
2666     ;; Remove all old markers.
2667     (while gnus-button-marker-list
2668       (set-marker (pop gnus-button-marker-list) nil))
2669     (let ((buffer-read-only nil)
2670           (inhibit-point-motion-hooks t)
2671           (case-fold-search t)
2672           (alist gnus-button-alist)
2673           beg entry regexp)
2674       (goto-char (point-min))
2675       ;; We skip the headers.
2676       (unless (search-forward "\n\n" nil t)
2677         (goto-char (point-max)))
2678       (setq beg (point))
2679       (while (setq entry (pop alist))
2680         (setq regexp (car entry))
2681         (goto-char beg)
2682         (while (re-search-forward regexp nil t)
2683           (let* ((start (and entry (match-beginning (nth 1 entry))))
2684                  (end (and entry (match-end (nth 1 entry))))
2685                  (from (match-beginning 0)))
2686             (when (and (or (eq t (nth 1 entry))
2687                            (eval (nth 1 entry)))
2688                        (not (get-text-property (point) 'gnus-callback)))
2689               ;; That optional form returned non-nil, so we add the
2690               ;; button. 
2691               (gnus-article-add-button 
2692                start end 'gnus-button-push 
2693                (car (push (set-marker (make-marker) from)
2694                           gnus-button-marker-list))))))))))
2695
2696 ;; Add buttons to the head of an article.
2697 (defun gnus-article-add-buttons-to-head ()
2698   "Add buttons to the head of the article."
2699   (interactive)
2700   (save-excursion
2701     (set-buffer gnus-article-buffer)
2702     (let ((buffer-read-only nil)
2703           (inhibit-point-motion-hooks t)
2704           (case-fold-search t)
2705           (alist gnus-header-button-alist)
2706           entry beg end)
2707       (nnheader-narrow-to-headers)
2708       (while alist
2709         ;; Each alist entry.
2710         (setq entry (car alist)
2711               alist (cdr alist))
2712         (goto-char (point-min))
2713         (while (re-search-forward (car entry) nil t)
2714           ;; Each header matching the entry.
2715           (setq beg (match-beginning 0))
2716           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2717                              (match-beginning 0))
2718                         (point-max)))
2719           (goto-char beg)
2720           (while (re-search-forward (nth 1 entry) end t)
2721             ;; Each match within a header.
2722             (let* ((entry (cdr entry))
2723                    (start (match-beginning (nth 1 entry)))
2724                    (end (match-end (nth 1 entry)))
2725                    (form (nth 2 entry)))
2726               (goto-char (match-end 0))
2727               (when (eval form)
2728                 (gnus-article-add-button 
2729                  start end (nth 3 entry)
2730                  (buffer-substring (match-beginning (nth 4 entry))
2731                                    (match-end (nth 4 entry)))))))
2732           (goto-char end))))
2733     (widen)))
2734
2735 ;;; External functions:
2736
2737 (defun gnus-article-add-button (from to fun &optional data)
2738   "Create a button between FROM and TO with callback FUN and data DATA."
2739   (when gnus-article-button-face
2740     (gnus-overlay-put (gnus-make-overlay from to)
2741                       'face gnus-article-button-face))
2742   (gnus-add-text-properties 
2743    from to
2744    (nconc (and gnus-article-mouse-face
2745                (list gnus-mouse-face-prop gnus-article-mouse-face))
2746           (list 'gnus-callback fun)
2747           (and data (list 'gnus-data data)))))
2748
2749 ;;; Internal functions:
2750
2751 (defun gnus-signature-toggle (end)
2752   (save-excursion
2753     (set-buffer gnus-article-buffer)
2754     (let ((buffer-read-only nil)
2755           (inhibit-point-motion-hooks t))
2756       (if (get-text-property end 'invisible)
2757           (gnus-article-unhide-text end (point-max))
2758         (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2759
2760 (defun gnus-button-entry ()
2761   ;; Return the first entry in `gnus-button-alist' matching this place.
2762   (let ((alist gnus-button-alist)
2763         (entry nil))
2764     (while alist
2765       (setq entry (pop alist))
2766       (if (looking-at (car entry))
2767           (setq alist nil)
2768         (setq entry nil)))
2769     entry))
2770
2771 (defun gnus-button-push (marker)
2772   ;; Push button starting at MARKER.
2773   (save-excursion
2774     (set-buffer gnus-article-buffer)
2775     (goto-char marker)
2776     (let* ((entry (gnus-button-entry))
2777            (inhibit-point-motion-hooks t)
2778            (fun (nth 3 entry))
2779            (args (mapcar (lambda (group)
2780                            (let ((string (match-string group)))
2781                              (gnus-set-text-properties
2782                               0 (length string) nil string)
2783                              string))
2784                          (nthcdr 4 entry))))
2785       (cond
2786        ((fboundp fun)
2787         (apply fun args))
2788        ((and (boundp fun)
2789              (fboundp (symbol-value fun)))
2790         (apply (symbol-value fun) args))
2791        (t
2792         (gnus-message 1 "You must define `%S' to use this button"
2793                       (cons fun args)))))))
2794
2795 (defun gnus-button-message-id (message-id)
2796   "Fetch MESSAGE-ID."
2797   (save-excursion
2798     (set-buffer gnus-summary-buffer)
2799     (gnus-summary-refer-article message-id)))
2800
2801 (defun gnus-button-fetch-group (address)
2802   "Fetch GROUP specified by ADDRESS."
2803   (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
2804       (error "Can't parse %s" address)
2805     (gnus-group-read-ephemeral-group
2806      (match-string 4 address)
2807      `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
2808             (nntp-port-number ,(if (match-end 3)
2809                                    (match-string 3 address)
2810                                  "nntp"))))))
2811
2812 (defun gnus-split-string (string pattern)
2813   "Return a list of substrings of STRING which are separated by PATTERN."
2814   (let (parts (start 0))
2815     (while (string-match pattern string start)
2816       (setq parts (cons (substring string start (match-beginning 0)) parts)
2817             start (match-end 0)))
2818     (nreverse (cons (substring string start) parts))))
2819  
2820 (defun gnus-url-parse-query-string (query &optional downcase)
2821   (let (retval pairs cur key val)
2822     (setq pairs (gnus-split-string query "&"))
2823     (while pairs
2824       (setq cur (car pairs)
2825             pairs (cdr pairs))
2826       (if (not (string-match "=" cur))
2827           nil                           ; Grace
2828         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2829               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2830         (if downcase
2831             (setq key (downcase key)))
2832         (setq cur (assoc key retval))
2833         (if cur
2834             (setcdr cur (cons val (cdr cur)))
2835           (setq retval (cons (list key val) retval)))))
2836     retval))
2837  
2838 (defun gnus-url-unhex (x)
2839   (if (> x ?9)
2840       (if (>= x ?a)
2841           (+ 10 (- x ?a))
2842         (+ 10 (- x ?A)))
2843     (- x ?0)))
2844  
2845 (defun gnus-url-unhex-string (str &optional allow-newlines)
2846   "Remove %XXX embedded spaces, etc in a url.
2847 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2848 decoding of carriage returns and line feeds in the string, which is normally
2849 forbidden in URL encoding."
2850   (setq str (or str ""))
2851   (let ((tmp "")
2852         (case-fold-search t))
2853     (while (string-match "%[0-9a-f][0-9a-f]" str)
2854       (let* ((start (match-beginning 0))
2855              (ch1 (gnus-url-unhex (elt str (+ start 1))))
2856              (code (+ (* 16 ch1)
2857                       (gnus-url-unhex (elt str (+ start 2))))))
2858         (setq tmp (concat 
2859                    tmp (substring str 0 start)
2860                    (cond
2861                     (allow-newlines
2862                      (char-to-string code))
2863                     ((or (= code ?\n) (= code ?\r))
2864                      " ")
2865                     (t (char-to-string code))))
2866               str (substring str (match-end 0)))))
2867     (setq tmp (concat tmp str))
2868     tmp))
2869  
2870 (defun gnus-url-mailto (url)
2871   ;; Send mail to someone
2872   (when (string-match "mailto:/*\\(.*\\)" 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