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