*** 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 (eval-and-compile
1087   (autoload 'w3-parse-buffer "w3-parse"))
1088
1089 (defun gnus-article-treat-html ()
1090   "Render HTML."
1091   (interactive)
1092   (let ((cbuf (current-buffer)))
1093     (set-buffer gnus-article-buffer)
1094     (let (buf buffer-read-only b e)
1095       (goto-char (point-min))
1096       (narrow-to-region
1097        (if (search-forward "\n\n" nil t)
1098            (setq b (point))
1099          (point-max))
1100        (setq e (point-max)))
1101       (nnheader-temp-write nil
1102         (insert-buffer-substring gnus-article-buffer b e)
1103         (save-window-excursion
1104           (setq buf (car (w3-parse-buffer (current-buffer))))))
1105       (when buf
1106         (delete-region (point-min) (point-max))
1107         (insert-buffer-substring buf)
1108         (kill-buffer buf))
1109       (widen)
1110       (goto-char (point-min))
1111       (set-window-start (get-buffer-window (current-buffer)) (point-min))
1112       (set-buffer cbuf))))
1113
1114 (defun gnus-article-hidden-arg ()
1115   "Return the current prefix arg as a number, or 0 if no prefix."
1116   (list (if current-prefix-arg
1117             (prefix-numeric-value current-prefix-arg)
1118           0)))
1119
1120 (defun gnus-article-check-hidden-text (type arg)
1121   "Return nil if hiding is necessary.
1122 Arg can be nil or a number.  Nil and positive means hide, negative
1123 means show, 0 means toggle."
1124   (save-excursion
1125     (save-restriction
1126       (widen)
1127       (let ((hide (gnus-article-hidden-text-p type)))
1128         (cond
1129          ((or (null arg)
1130               (> arg 0))
1131           nil)
1132          ((< arg 0)
1133           (gnus-article-show-hidden-text type))
1134          (t
1135           (if (eq hide 'hidden)
1136               (gnus-article-show-hidden-text type)
1137             nil)))))))
1138
1139 (defun gnus-article-hidden-text-p (type)
1140   "Say whether the current buffer contains hidden text of type TYPE."
1141   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1142     (when pos
1143       (if (get-text-property pos 'invisible)
1144           'hidden
1145         'shown))))
1146
1147 (defun gnus-article-show-hidden-text (type &optional hide)
1148   "Show all hidden text of type TYPE.
1149 If HIDE, hide the text instead."
1150   (save-excursion
1151     (let ((buffer-read-only nil)
1152           (inhibit-point-motion-hooks t)
1153           (end (point-min))
1154           beg)
1155       (while (setq beg (text-property-any end (point-max) 'article-type type))
1156         (goto-char beg)
1157         (setq end (or
1158                    (text-property-not-all beg (point-max) 'article-type type)
1159                    (point-max)))
1160         (if hide
1161             (gnus-article-hide-text beg end gnus-hidden-properties)
1162           (gnus-article-unhide-text beg end))
1163         (goto-char end))
1164       t)))
1165
1166 (defconst article-time-units
1167   `((year . ,(* 365.25 24 60 60))
1168     (week . ,(* 7 24 60 60))
1169     (day . ,(* 24 60 60))
1170     (hour . ,(* 60 60))
1171     (minute . 60)
1172     (second . 1))
1173   "Mapping from time units to seconds.")
1174
1175 (defun article-date-ut (&optional type highlight header)
1176   "Convert DATE date to universal time in the current article.
1177 If TYPE is `local', convert to local time; if it is `lapsed', output
1178 how much time has lapsed since DATE."
1179   (interactive (list 'ut t))
1180   (let* ((header (or header 
1181                      (mail-header-date gnus-current-headers)
1182                      (message-fetch-field "date")
1183                      ""))
1184          (date (if (vectorp header) (mail-header-date header)
1185                  header))
1186          (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1187          (inhibit-point-motion-hooks t)
1188          bface eface)
1189     (when (and date (not (string= date "")))
1190       (save-excursion
1191         (save-restriction
1192           (nnheader-narrow-to-headers)
1193           (let ((buffer-read-only nil))
1194             ;; Delete any old Date headers.
1195             (if (re-search-forward date-regexp nil t)
1196                 (progn
1197                   (setq bface (get-text-property (gnus-point-at-bol) 'face)
1198                         eface (get-text-property (1- (gnus-point-at-eol))
1199                                                  'face))
1200                   (message-remove-header date-regexp t)
1201                   (beginning-of-line))
1202               (goto-char (point-max)))
1203             (insert (article-make-date-line date type))
1204             ;; Do highlighting.
1205             (forward-line -1)
1206             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1207               (put-text-property (match-beginning 1) (match-end 1)
1208                                  'face bface)
1209               (put-text-property (match-beginning 2) (match-end 2)
1210                                  'face eface))))))))
1211
1212 (defun article-make-date-line (date type)
1213   "Return a DATE line of TYPE."
1214   (cond
1215    ;; Convert to the local timezone.  We have to slap a
1216    ;; `condition-case' round the calls to the timezone
1217    ;; functions since they aren't particularly resistant to
1218    ;; buggy dates.
1219    ((eq type 'local)
1220     (concat "Date: " (condition-case ()
1221                          (timezone-make-date-arpa-standard date)
1222                        (error date))
1223             "\n"))
1224    ;; Convert to Universal Time.
1225    ((eq type 'ut)
1226     (concat "Date: "
1227             (condition-case ()
1228                 (timezone-make-date-arpa-standard date nil "UT")
1229               (error date))
1230             "\n"))
1231    ;; Get the original date from the article.
1232    ((eq type 'original)
1233     (concat "Date: " date "\n"))
1234    ;; Let the user define the format.
1235    ((eq type 'user)
1236     (concat
1237      "Date: "
1238      (format-time-string gnus-article-time-format
1239                          (ignore-errors
1240                            (gnus-encode-date
1241                             (timezone-make-date-arpa-standard
1242                              date nil "UT"))))
1243      "\n"))
1244    ;; Do an X-Sent lapsed format.
1245    ((eq type 'lapsed)
1246     ;; If the date is seriously mangled, the timezone functions are
1247     ;; liable to bug out, so we ignore all errors.
1248     (let* ((now (current-time))
1249            (real-time
1250             (ignore-errors
1251               (gnus-time-minus
1252                (gnus-encode-date
1253                 (timezone-make-date-arpa-standard
1254                  (current-time-string now)
1255                  (current-time-zone now) "UT"))
1256                (gnus-encode-date
1257                 (timezone-make-date-arpa-standard
1258                  date nil "UT")))))
1259            (real-sec (and real-time
1260                           (+ (* (float (car real-time)) 65536)
1261                              (cadr real-time))))
1262            (sec (and real-time (abs real-sec)))
1263            num prev)
1264       (cond
1265        ((null real-time)
1266         "X-Sent: Unknown\n")
1267        ((zerop sec)
1268         "X-Sent: Now\n")
1269        (t
1270         (concat
1271          "X-Sent: "
1272          ;; This is a bit convoluted, but basically we go
1273          ;; through the time units for years, weeks, etc,
1274          ;; and divide things to see whether that results
1275          ;; in positive answers.
1276          (mapconcat
1277           (lambda (unit)
1278             (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1279                 ;; The (remaining) seconds are too few to
1280                 ;; be divided into this time unit.
1281                 ""
1282               ;; It's big enough, so we output it.
1283               (setq sec (- sec (* num (cdr unit))))
1284               (prog1
1285                   (concat (if prev ", " "") (int-to-string
1286                                              (floor num))
1287                           " " (symbol-name (car unit)) 
1288                           (if (> num 1) "s" ""))
1289                 (setq prev t))))
1290           article-time-units "")
1291          ;; If dates are odd, then it might appear like the
1292          ;; article was sent in the future.
1293          (if (> real-sec 0)
1294              " ago\n"
1295            " in the future\n"))))))
1296    (t
1297     (error "Unknown conversion type: %s" type))))
1298
1299 (defun article-date-local (&optional highlight)
1300   "Convert the current article date to the local timezone."
1301   (interactive (list t))
1302   (article-date-ut 'local highlight))
1303
1304 (defun article-date-original (&optional highlight)
1305   "Convert the current article date to what it was originally.
1306 This is only useful if you have used some other date conversion
1307 function and want to see what the date was before converting."
1308   (interactive (list t))
1309   (article-date-ut 'original highlight))
1310
1311 (defun article-date-lapsed (&optional highlight)
1312   "Convert the current article date to time lapsed since it was sent."
1313   (interactive (list t))
1314   (article-date-ut 'lapsed highlight))
1315
1316 (defun article-date-user (&optional highlight)
1317   "Convert the current article date to the user-defined format.
1318 This format is defined by the `gnus-article-time-format' variable."
1319   (interactive (list t))
1320   (article-date-ut 'user highlight))
1321
1322 (defun article-show-all ()
1323   "Show all hidden text in the article buffer."
1324   (interactive)
1325   (save-excursion
1326     (let ((buffer-read-only nil))
1327       (gnus-article-unhide-text (point-min) (point-max)))))
1328
1329 (defun article-emphasize (&optional arg)
1330   "Emphasize text according to `gnus-emphasis-alist'."
1331   (interactive (gnus-article-hidden-arg))
1332   (unless (gnus-article-check-hidden-text 'emphasis arg)
1333     (save-excursion
1334       (let ((alist gnus-emphasis-alist)
1335             (buffer-read-only nil)
1336             (props (append '(article-type emphasis)
1337                            gnus-hidden-properties))
1338             regexp elem beg invisible visible face)
1339         (goto-char (point-min))
1340         (search-forward "\n\n" nil t)
1341         (setq beg (point))
1342         (while (setq elem (pop alist))
1343           (goto-char beg)
1344           (setq regexp (car elem)
1345                 invisible (nth 1 elem)
1346                 visible (nth 2 elem)
1347                 face (nth 3 elem))
1348           (while (re-search-forward regexp nil t)
1349             (when (and (match-beginning visible) (match-beginning invisible))
1350               (gnus-article-hide-text
1351                (match-beginning invisible) (match-end invisible) props)
1352               (gnus-article-unhide-text-type
1353                (match-beginning visible) (match-end visible) 'emphasis)
1354               (gnus-put-text-property-excluding-newlines
1355                (match-beginning visible) (match-end visible) 'face face)
1356               (goto-char (match-end invisible)))))))))
1357
1358 (defvar gnus-summary-article-menu)
1359 (defvar gnus-summary-post-menu)
1360
1361 ;;; Saving functions.
1362
1363 (defun gnus-article-save (save-buffer file &optional num)
1364   "Save the currently selected article."
1365   (unless gnus-save-all-headers
1366     ;; Remove headers according to `gnus-saved-headers'.
1367     (let ((gnus-visible-headers
1368            (or gnus-saved-headers gnus-visible-headers))
1369           (gnus-article-buffer save-buffer))
1370       (gnus-article-hide-headers 1 t)))
1371   (save-window-excursion
1372     (if (not gnus-default-article-saver)
1373         (error "No default saver is defined.")
1374       ;; !!! Magic!  The saving functions all save
1375       ;; `gnus-original-article-buffer' (or so they think), but we
1376       ;; bind that variable to our save-buffer.
1377       (set-buffer gnus-article-buffer)
1378       (let* ((gnus-save-article-buffer save-buffer)
1379              (filename
1380               (cond
1381                ((not gnus-prompt-before-saving) 'default)
1382                ((eq gnus-prompt-before-saving 'always) nil)
1383                (t file)))
1384              (gnus-number-of-articles-to-be-saved
1385               (when (eq gnus-prompt-before-saving t)
1386                 num)))                  ; Magic
1387         (set-buffer gnus-summary-buffer)
1388         (funcall gnus-default-article-saver filename))))) 
1389
1390 (defun gnus-read-save-file-name (prompt default-name &optional filename)
1391   (cond
1392    ((eq filename 'default)
1393     default-name)
1394    (filename filename)
1395    (t
1396     (let* ((split-name (gnus-get-split-value gnus-split-methods))
1397            (prompt
1398             (format prompt (if (and gnus-number-of-articles-to-be-saved
1399                                     (> gnus-number-of-articles-to-be-saved 1))
1400                                (format "these %d articles"
1401                                        gnus-number-of-articles-to-be-saved)
1402                              "this article")))
1403            (file
1404             ;; Let the split methods have their say.
1405             (cond
1406              ;; No split name was found.
1407              ((null split-name)
1408               (read-file-name
1409                (concat prompt " (default "
1410                        (file-name-nondirectory default-name) ") ")
1411                (file-name-directory default-name)
1412                default-name))
1413              ;; A single split name was found
1414              ((= 1 (length split-name))
1415               (let* ((name (car split-name))
1416                      (dir (cond ((file-directory-p name)
1417                                  (file-name-as-directory name))
1418                                 ((file-exists-p name) name)
1419                                 (t gnus-article-save-directory))))
1420                 (read-file-name
1421                  (concat prompt " (default " name ") ")
1422                  dir name)))
1423              ;; A list of splits was found.
1424              (t
1425               (setq split-name (nreverse split-name))
1426               (let (result)
1427                 (let ((file-name-history (nconc split-name file-name-history)))
1428                   (setq result
1429                         (expand-file-name
1430                          (read-file-name
1431                           (concat prompt " (`M-p' for defaults) ")
1432                           gnus-article-save-directory
1433                           (car split-name))
1434                          gnus-article-save-directory)))
1435                 (car (push result file-name-history)))))))
1436       ;; Create the directory.
1437       (gnus-make-directory (file-name-directory file))
1438       ;; If we have read a directory, we append the default file name.
1439       (when (file-directory-p file)
1440         (setq file (concat (file-name-as-directory file)
1441                            (file-name-nondirectory default-name))))
1442       ;; Possibly translate some characters.
1443       (nnheader-translate-file-chars file)))))
1444
1445 (defun gnus-article-archive-name (group)
1446   "Return the first instance of an \"Archive-name\" in the current buffer."
1447   (let ((case-fold-search t))
1448     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1449       (nnheader-concat gnus-article-save-directory
1450                        (match-string 1)))))
1451
1452 (defun gnus-summary-save-in-rmail (&optional filename)
1453   "Append this article to Rmail file.
1454 Optional argument FILENAME specifies file name.
1455 Directory to save to is default to `gnus-article-save-directory'."
1456   (interactive)
1457   (gnus-set-global-variables)
1458   (let ((default-name
1459           (funcall gnus-rmail-save-name gnus-newsgroup-name
1460                    gnus-current-headers gnus-newsgroup-last-rmail)))
1461     (setq filename (gnus-read-save-file-name
1462                     "Save %s in rmail file:" default-name filename))
1463     (gnus-make-directory (file-name-directory filename))
1464     (gnus-eval-in-buffer-window gnus-save-article-buffer
1465       (save-excursion
1466         (save-restriction
1467           (widen)
1468           (gnus-output-to-rmail filename))))
1469     ;; Remember the directory name to save articles
1470     (setq gnus-newsgroup-last-rmail filename)))
1471
1472 (defun gnus-summary-save-in-mail (&optional filename)
1473   "Append this article to Unix mail file.
1474 Optional argument FILENAME specifies file name.
1475 Directory to save to is default to `gnus-article-save-directory'."
1476   (interactive)
1477   (gnus-set-global-variables)
1478   (let ((default-name
1479           (funcall gnus-mail-save-name gnus-newsgroup-name
1480                    gnus-current-headers gnus-newsgroup-last-mail)))
1481     (setq filename (gnus-read-save-file-name
1482                     "Save %s in Unix mail file:" default-name filename))
1483     (setq filename
1484           (expand-file-name filename
1485                             (and default-name
1486                                  (file-name-directory default-name))))
1487     (gnus-make-directory (file-name-directory filename))
1488     (gnus-eval-in-buffer-window gnus-save-article-buffer
1489       (save-excursion
1490         (save-restriction
1491           (widen)
1492           (if (and (file-readable-p filename)
1493                    (mail-file-babyl-p filename))
1494               (gnus-output-to-rmail filename t)
1495             (gnus-output-to-mail filename)))))
1496     ;; Remember the directory name to save articles.
1497     (setq gnus-newsgroup-last-mail filename)))
1498
1499 (defun gnus-summary-save-in-file (&optional filename overwrite)
1500   "Append this article to file.
1501 Optional argument FILENAME specifies file name.
1502 Directory to save to is default 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 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           (when (and overwrite
1516                      (file-exists-p filename))
1517             (delete-file filename))
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-write-to-file (&optional filename)
1523   "Write this article to a file.
1524 Optional argument FILENAME specifies file name.
1525 The directory to save in defaults to `gnus-article-save-directory'."
1526   (interactive)
1527   (gnus-summary-save-in-file nil t))
1528
1529 (defun gnus-summary-save-body-in-file (&optional filename)
1530   "Append this article body to a file.
1531 Optional argument FILENAME specifies file name.
1532 The directory to save in defaults to `gnus-article-save-directory'."
1533   (interactive)
1534   (gnus-set-global-variables)
1535   (let ((default-name
1536           (funcall gnus-file-save-name gnus-newsgroup-name
1537                    gnus-current-headers gnus-newsgroup-last-file)))
1538     (setq filename (gnus-read-save-file-name
1539                     "Save %s body in file:" default-name filename))
1540     (gnus-make-directory (file-name-directory filename))
1541     (gnus-eval-in-buffer-window gnus-save-article-buffer
1542       (save-excursion
1543         (save-restriction
1544           (widen)
1545           (goto-char (point-min))
1546           (when (search-forward "\n\n" nil t)
1547             (narrow-to-region (point) (point-max)))
1548           (gnus-output-to-file filename))))
1549     ;; Remember the directory name to save articles.
1550     (setq gnus-newsgroup-last-file filename)))
1551
1552 (defun gnus-summary-save-in-pipe (&optional command)
1553   "Pipe this article to subprocess."
1554   (interactive)
1555   (gnus-set-global-variables)
1556   (setq command
1557         (cond ((eq command 'default)
1558                gnus-last-shell-command)
1559               (command command)
1560               (t (read-string 
1561                   (format
1562                    "Shell command on %s: "
1563                    (if (and gnus-number-of-articles-to-be-saved
1564                             (> gnus-number-of-articles-to-be-saved 1))
1565                        (format "these %d articles"
1566                                gnus-number-of-articles-to-be-saved)
1567                      "this article"))
1568                   gnus-last-shell-command))))
1569   (when (string-equal command "")
1570     (setq command gnus-last-shell-command))
1571   (gnus-eval-in-buffer-window gnus-article-buffer
1572     (save-restriction
1573       (widen)
1574       (shell-command-on-region (point-min) (point-max) command nil)))
1575   (setq gnus-last-shell-command command))
1576
1577 ;;; Article file names when saving.
1578
1579 (defun gnus-capitalize-newsgroup (newsgroup)
1580   "Capitalize NEWSGROUP name."
1581   (when (not (zerop (length newsgroup)))
1582     (concat (char-to-string (upcase (aref newsgroup 0)))
1583             (substring newsgroup 1))))
1584
1585 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1586   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1587 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1588 Otherwise, it is like ~/News/news/group/num."
1589   (let ((default
1590           (expand-file-name
1591            (concat (if (gnus-use-long-file-name 'not-save)
1592                        (gnus-capitalize-newsgroup newsgroup)
1593                      (gnus-newsgroup-directory-form newsgroup))
1594                    "/" (int-to-string (mail-header-number headers)))
1595            gnus-article-save-directory)))
1596     (if (and last-file
1597              (string-equal (file-name-directory default)
1598                            (file-name-directory last-file))
1599              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1600         default
1601       (or last-file default))))
1602
1603 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1604   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1605 If variable `gnus-use-long-file-name' is non-nil, it is
1606 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
1607   (let ((default
1608           (expand-file-name
1609            (concat (if (gnus-use-long-file-name 'not-save)
1610                        newsgroup
1611                      (gnus-newsgroup-directory-form newsgroup))
1612                    "/" (int-to-string (mail-header-number headers)))
1613            gnus-article-save-directory)))
1614     (if (and last-file
1615              (string-equal (file-name-directory default)
1616                            (file-name-directory last-file))
1617              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1618         default
1619       (or last-file default))))
1620
1621 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1622   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1623 If variable `gnus-use-long-file-name' is non-nil, it is
1624 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
1625   (or last-file
1626       (expand-file-name
1627        (if (gnus-use-long-file-name 'not-save)
1628            (gnus-capitalize-newsgroup newsgroup)
1629          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1630        gnus-article-save-directory)))
1631
1632 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1633   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1634 If variable `gnus-use-long-file-name' is non-nil, it is
1635 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
1636   (or last-file
1637       (expand-file-name
1638        (if (gnus-use-long-file-name 'not-save)
1639            newsgroup
1640          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1641        gnus-article-save-directory)))
1642
1643 (eval-and-compile
1644   (mapcar
1645    (lambda (func)
1646      (let (afunc gfunc)
1647        (if (consp func)
1648            (setq afunc (car func)
1649                  gfunc (cdr func))
1650          (setq afunc func
1651                gfunc (intern (format "gnus-%s" func))))
1652        (fset gfunc 
1653              (if (not (fboundp afunc))
1654                  nil
1655                `(lambda (&optional interactive &rest args)
1656                   ,(documentation afunc t)
1657                   (interactive (list t))
1658                   (save-excursion
1659                     (set-buffer gnus-article-buffer)
1660                     (if interactive
1661                         (call-interactively ',afunc)
1662                       (apply ',afunc args))))))))
1663    '(article-hide-headers
1664      article-hide-boring-headers
1665      article-treat-overstrike
1666      (article-fill . gnus-article-word-wrap)
1667      article-remove-cr
1668      article-display-x-face
1669      article-de-quoted-unreadable
1670      article-mime-decode-quoted-printable
1671      article-hide-pgp
1672      article-hide-pem
1673      article-hide-signature
1674      article-remove-trailing-blank-lines
1675      article-strip-leading-blank-lines
1676      article-strip-multiple-blank-lines
1677      article-strip-blank-lines
1678      article-date-local
1679      article-date-original
1680      article-date-ut
1681      article-date-user
1682      article-date-lapsed
1683      article-emphasize
1684      (article-show-all . gnus-article-show-all-headers))))
1685 \f
1686 ;;;
1687 ;;; Gnus article mode
1688 ;;;
1689
1690 (put 'gnus-article-mode 'mode-class 'special)
1691
1692 (when t
1693   (gnus-define-keys gnus-article-mode-map
1694     " " gnus-article-goto-next-page
1695     "\177" gnus-article-goto-prev-page
1696     [delete] gnus-article-goto-prev-page
1697     "\C-c^" gnus-article-refer-article
1698     "h" gnus-article-show-summary
1699     "s" gnus-article-show-summary
1700     "\C-c\C-m" gnus-article-mail
1701     "?" gnus-article-describe-briefly
1702     gnus-mouse-2 gnus-article-push-button
1703     "\r" gnus-article-press-button
1704     "\t" gnus-article-next-button
1705     "\M-\t" gnus-article-prev-button
1706     "e" gnus-article-edit
1707     "<" beginning-of-buffer
1708     ">" end-of-buffer
1709     "\C-c\C-i" gnus-info-find-node
1710     "\C-c\C-b" gnus-bug
1711
1712     "\C-d" gnus-article-read-summary-keys
1713     "\M-*" gnus-article-read-summary-keys
1714     "\M-#" gnus-article-read-summary-keys
1715     "\M-^" gnus-article-read-summary-keys
1716     "\M-g" gnus-article-read-summary-keys)
1717
1718   (substitute-key-definition
1719    'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1720
1721 (defun gnus-article-make-menu-bar ()
1722   (gnus-turn-off-edit-menu 'article)
1723   (unless (boundp 'gnus-article-article-menu)
1724     (easy-menu-define
1725      gnus-article-article-menu gnus-article-mode-map ""
1726      '("Article"
1727        ["Scroll forwards" gnus-article-goto-next-page t]
1728        ["Scroll backwards" gnus-article-goto-prev-page t]
1729        ["Show summary" gnus-article-show-summary t]
1730        ["Fetch Message-ID at point" gnus-article-refer-article t]
1731        ["Mail to address at point" gnus-article-mail t]))
1732
1733     (easy-menu-define
1734      gnus-article-treatment-menu gnus-article-mode-map ""
1735      '("Treatment"
1736        ["Hide headers" gnus-article-hide-headers t]
1737        ["Hide signature" gnus-article-hide-signature t]
1738        ["Hide citation" gnus-article-hide-citation t]
1739        ["Treat overstrike" gnus-article-treat-overstrike t]
1740        ["Remove carriage return" gnus-article-remove-cr t]
1741        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1742
1743     (when nil
1744       (when (boundp 'gnus-summary-article-menu)
1745         (define-key gnus-article-mode-map [menu-bar commands]
1746           (cons "Commands" gnus-summary-article-menu))))
1747
1748     (when (boundp 'gnus-summary-post-menu)
1749       (define-key gnus-article-mode-map [menu-bar post]
1750         (cons "Post" gnus-summary-post-menu)))
1751
1752     (run-hooks 'gnus-article-menu-hook)))
1753
1754 (defun gnus-article-mode ()
1755   "Major mode for displaying an article.
1756
1757 All normal editing commands are switched off.
1758
1759 The following commands are available in addition to all summary mode
1760 commands:
1761 \\<gnus-article-mode-map>
1762 \\[gnus-article-next-page]\t Scroll the article one page forwards
1763 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1764 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1765 \\[gnus-article-show-summary]\t Display the summary buffer
1766 \\[gnus-article-mail]\t Send a reply to the address near point
1767 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1768 \\[gnus-info-find-node]\t Go to the Gnus info node"
1769   (interactive)
1770   (when (gnus-visual-p 'article-menu 'menu)
1771     (gnus-article-make-menu-bar))
1772   (kill-all-local-variables)
1773   (gnus-simplify-mode-line)
1774   (setq mode-name "Article")
1775   (setq major-mode 'gnus-article-mode)
1776   (make-local-variable 'minor-mode-alist)
1777   (unless (assq 'gnus-show-mime minor-mode-alist)
1778     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1779   (use-local-map gnus-article-mode-map)
1780   (gnus-update-format-specifications nil 'article-mode)
1781   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1782   (set (make-local-variable 'gnus-button-marker-list) nil)
1783   (gnus-set-default-directory)
1784   (buffer-disable-undo (current-buffer))
1785   (setq buffer-read-only t)
1786   (set-syntax-table gnus-article-mode-syntax-table)
1787   (run-hooks 'gnus-article-mode-hook))
1788
1789 (defun gnus-article-setup-buffer ()
1790   "Initialize the article buffer."
1791   (let* ((name (if gnus-single-article-buffer "*Article*"
1792                  (concat "*Article " gnus-newsgroup-name "*")))
1793          (original
1794           (progn (string-match "\\*Article" name)
1795                  (concat " *Original Article"
1796                          (substring name (match-end 0))))))
1797     (setq gnus-article-buffer name)
1798     (setq gnus-original-article-buffer original)
1799     ;; This might be a variable local to the summary buffer.
1800     (unless gnus-single-article-buffer
1801       (save-excursion
1802         (set-buffer gnus-summary-buffer)
1803         (setq gnus-article-buffer name)
1804         (setq gnus-original-article-buffer original)
1805         (gnus-set-global-variables)))
1806     ;; Init original article buffer.
1807     (save-excursion
1808       (set-buffer (get-buffer-create gnus-original-article-buffer))
1809       (buffer-disable-undo (current-buffer))
1810       (setq major-mode 'gnus-original-article-mode)
1811       (gnus-add-current-to-buffer-list)
1812       (make-local-variable 'gnus-original-article))
1813     (if (get-buffer name)
1814         (save-excursion
1815           (set-buffer name)
1816           (buffer-disable-undo (current-buffer))
1817           (setq buffer-read-only t)
1818           (gnus-add-current-to-buffer-list)
1819           (unless (eq major-mode 'gnus-article-mode)
1820             (gnus-article-mode))
1821           (current-buffer))
1822       (save-excursion
1823         (set-buffer (get-buffer-create name))
1824         (gnus-add-current-to-buffer-list)
1825         (gnus-article-mode)
1826         (make-local-variable 'gnus-summary-buffer)
1827         (current-buffer)))))
1828
1829 ;; Set article window start at LINE, where LINE is the number of lines
1830 ;; from the head of the article.
1831 (defun gnus-article-set-window-start (&optional line)
1832   (set-window-start
1833    (get-buffer-window gnus-article-buffer t)
1834    (save-excursion
1835      (set-buffer gnus-article-buffer)
1836      (goto-char (point-min))
1837      (if (not line)
1838          (point-min)
1839        (gnus-message 6 "Moved to bookmark")
1840        (search-forward "\n\n" nil t)
1841        (forward-line line)
1842        (point)))))
1843
1844 (defun gnus-article-prepare (article &optional all-headers header)
1845   "Prepare ARTICLE in article mode buffer.
1846 ARTICLE should either be an article number or a Message-ID.
1847 If ARTICLE is an id, HEADER should be the article headers.
1848 If ALL-HEADERS is non-nil, no headers are hidden."
1849   (save-excursion
1850     ;; Make sure we start in a summary buffer.
1851     (unless (eq major-mode 'gnus-summary-mode)
1852       (set-buffer gnus-summary-buffer))
1853     (setq gnus-summary-buffer (current-buffer))
1854     ;; Make sure the connection to the server is alive.
1855     (unless (gnus-server-opened
1856              (gnus-find-method-for-group gnus-newsgroup-name))
1857       (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1858       (gnus-request-group gnus-newsgroup-name t))
1859     (let* ((gnus-article (if header (mail-header-number header) article))
1860            (summary-buffer (current-buffer))
1861            (internal-hook gnus-article-internal-prepare-hook)
1862            (group gnus-newsgroup-name)
1863            result)
1864       (save-excursion
1865         (gnus-article-setup-buffer)
1866         (set-buffer gnus-article-buffer)
1867         ;; Deactivate active regions.
1868         (when (and (boundp 'transient-mark-mode)
1869                    transient-mark-mode)
1870           (setq mark-active nil))
1871         (if (not (setq result (let ((buffer-read-only nil))
1872                                 (gnus-request-article-this-buffer
1873                                  article group))))
1874             ;; There is no such article.
1875             (save-excursion
1876               (when (and (numberp article)
1877                          (not (memq article gnus-newsgroup-sparse)))
1878                 (setq gnus-article-current
1879                       (cons gnus-newsgroup-name article))
1880                 (set-buffer gnus-summary-buffer)
1881                 (setq gnus-current-article article)
1882                 (gnus-summary-mark-article article gnus-canceled-mark))
1883               (unless (memq article gnus-newsgroup-sparse)
1884                 (gnus-error
1885                  1 "No such article (may have expired or been canceled)")))
1886           (if (or (eq result 'pseudo) (eq result 'nneething))
1887               (progn
1888                 (save-excursion
1889                   (set-buffer summary-buffer)
1890                   (setq gnus-last-article gnus-current-article
1891                         gnus-newsgroup-history (cons gnus-current-article
1892                                                      gnus-newsgroup-history)
1893                         gnus-current-article 0
1894                         gnus-current-headers nil
1895                         gnus-article-current nil)
1896                   (if (eq result 'nneething)
1897                       (gnus-configure-windows 'summary)
1898                     (gnus-configure-windows 'article))
1899                   (gnus-set-global-variables))
1900                 (gnus-set-mode-line 'article))
1901             ;; The result from the `request' was an actual article -
1902             ;; or at least some text that is now displayed in the
1903             ;; article buffer.
1904             (when (and (numberp article)
1905                        (not (eq article gnus-current-article)))
1906               ;; Seems like a new article has been selected.
1907               ;; `gnus-current-article' must be an article number.
1908               (save-excursion
1909                 (set-buffer summary-buffer)
1910                 (setq gnus-last-article gnus-current-article
1911                       gnus-newsgroup-history (cons gnus-current-article
1912                                                    gnus-newsgroup-history)
1913                       gnus-current-article article
1914                       gnus-current-headers
1915                       (gnus-summary-article-header gnus-current-article)
1916                       gnus-article-current
1917                       (cons gnus-newsgroup-name gnus-current-article))
1918                 (unless (vectorp gnus-current-headers)
1919                   (setq gnus-current-headers nil))
1920                 (gnus-summary-show-thread)
1921                 (run-hooks 'gnus-mark-article-hook)
1922                 (gnus-set-mode-line 'summary)
1923                 (when (gnus-visual-p 'article-highlight 'highlight)
1924                   (run-hooks 'gnus-visual-mark-article-hook))
1925                 ;; Set the global newsgroup variables here.
1926                 ;; Suggested by Jim Sisolak
1927                 ;; <sisolak@trans4.neep.wisc.edu>.
1928                 (gnus-set-global-variables)
1929                 (setq gnus-have-all-headers
1930                       (or all-headers gnus-show-all-headers))
1931                 (and gnus-use-cache
1932                      (vectorp (gnus-summary-article-header article))
1933                      (gnus-cache-possibly-enter-article
1934                       group article
1935                       (gnus-summary-article-header article)
1936                       (memq article gnus-newsgroup-marked)
1937                       (memq article gnus-newsgroup-dormant)
1938                       (memq article gnus-newsgroup-unreads)))))
1939             (when (or (numberp article)
1940                       (stringp article))
1941               ;; Hooks for getting information from the article.
1942               ;; This hook must be called before being narrowed.
1943               (let (buffer-read-only)
1944                 (run-hooks 'internal-hook)
1945                 (run-hooks 'gnus-article-prepare-hook)
1946                 ;; Decode MIME message.
1947                 (when gnus-show-mime
1948                   (if (or (not gnus-strict-mime)
1949                           (gnus-fetch-field "Mime-Version"))
1950                       (funcall gnus-show-mime-method)
1951                     (funcall gnus-decode-encoded-word-method)))
1952                 ;; Perform the article display hooks.
1953                 (run-hooks 'gnus-article-display-hook))
1954               ;; Do page break.
1955               (goto-char (point-min))
1956               (when gnus-break-pages
1957                 (gnus-narrow-to-page)))
1958             (gnus-set-mode-line 'article)
1959             (gnus-configure-windows 'article)
1960             (goto-char (point-min))
1961             t))))))
1962
1963 (defun gnus-article-wash-status ()
1964   "Return a string which display status of article washing."
1965   (save-excursion
1966     (set-buffer gnus-article-buffer)
1967     (let ((cite (gnus-article-hidden-text-p 'cite))
1968           (headers (gnus-article-hidden-text-p 'headers))
1969           (boring (gnus-article-hidden-text-p 'boring-headers))
1970           (pgp (gnus-article-hidden-text-p 'pgp))
1971           (pem (gnus-article-hidden-text-p 'pem))
1972           (signature (gnus-article-hidden-text-p 'signature))
1973           (overstrike (gnus-article-hidden-text-p 'overstrike))
1974           (emphasis (gnus-article-hidden-text-p 'emphasis))
1975           (mime gnus-show-mime))
1976       (format "%c%c%c%c%c%c%c"
1977               (if cite ?c ? )
1978               (if (or headers boring) ?h ? )
1979               (if (or pgp pem) ?p ? )
1980               (if signature ?s ? )
1981               (if overstrike ?o ? )
1982               (if mime ?m ? )
1983               (if emphasis ?e ? )))))
1984
1985 (defun gnus-article-hide-headers-if-wanted ()
1986   "Hide unwanted headers if `gnus-have-all-headers' is nil.
1987 Provided for backwards compatibility."
1988   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
1989       gnus-inhibit-hiding
1990       (gnus-article-hide-headers)))
1991
1992 ;;; Article savers.
1993
1994 (defun gnus-output-to-file (file-name)
1995   "Append the current article to a file named FILE-NAME."
1996   (let ((artbuf (current-buffer)))
1997     (nnheader-temp-write nil
1998       (insert-buffer-substring artbuf)
1999       ;; Append newline at end of the buffer as separator, and then
2000       ;; save it to file.
2001       (goto-char (point-max))
2002       (insert "\n")
2003       (append-to-file (point-min) (point-max) file-name))))
2004
2005 (defun gnus-narrow-to-page (&optional arg)
2006   "Narrow the article buffer to a page.
2007 If given a numerical ARG, move forward ARG pages."
2008   (interactive "P")
2009   (setq arg (if arg (prefix-numeric-value arg) 0))
2010   (save-excursion
2011     (set-buffer gnus-article-buffer)
2012     (goto-char (point-min))
2013     (widen)
2014     ;; Remove any old next/prev buttons.
2015     (when (gnus-visual-p 'page-marker)
2016       (let ((buffer-read-only nil))
2017         (gnus-remove-text-with-property 'gnus-prev)
2018         (gnus-remove-text-with-property 'gnus-next)))
2019     (when
2020         (cond ((< arg 0)
2021                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2022               ((> arg 0)
2023                (re-search-forward page-delimiter nil 'move arg)))
2024       (goto-char (match-end 0)))
2025     (narrow-to-region
2026      (point)
2027      (if (re-search-forward page-delimiter nil 'move)
2028          (match-beginning 0)
2029        (point)))
2030     (when (and (gnus-visual-p 'page-marker)
2031                (not (= (point-min) 1)))
2032       (save-excursion
2033         (goto-char (point-min))
2034         (gnus-insert-prev-page-button)))
2035     (when (and (gnus-visual-p 'page-marker)
2036                (< (+ (point-max) 2) (buffer-size)))
2037       (save-excursion
2038         (goto-char (point-max))
2039         (gnus-insert-next-page-button)))))
2040
2041 ;; Article mode commands
2042
2043 (defun gnus-article-goto-next-page ()
2044   "Show the next page of the article."
2045   (interactive)
2046   (when (gnus-article-next-page)
2047     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2048
2049 (defun gnus-article-goto-prev-page ()
2050   "Show the next page of the article."
2051   (interactive)
2052   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2053     (gnus-article-prev-page nil)))
2054
2055 (defun gnus-article-next-page (&optional lines)
2056   "Show the next page of the current article.
2057 If end of article, return non-nil.  Otherwise return nil.
2058 Argument LINES specifies lines to be scrolled up."
2059   (interactive "p")
2060   (move-to-window-line -1)
2061   (if (save-excursion
2062         (end-of-line)
2063         (and (pos-visible-in-window-p)  ;Not continuation line.
2064              (eobp)))
2065       ;; Nothing in this page.
2066       (if (or (not gnus-break-pages)
2067               (save-excursion
2068                 (save-restriction
2069                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2070           t                             ;Nothing more.
2071         (gnus-narrow-to-page 1)         ;Go to next page.
2072         nil)
2073     ;; More in this page.
2074     (let ((scroll-in-place nil))
2075       (condition-case ()
2076           (scroll-up lines)
2077         (end-of-buffer
2078          ;; Long lines may cause an end-of-buffer error.
2079          (goto-char (point-max)))))
2080     (move-to-window-line 0)
2081     nil))
2082
2083 (defun gnus-article-prev-page (&optional lines)
2084   "Show previous page of current article.
2085 Argument LINES specifies lines to be scrolled down."
2086   (interactive "p")
2087   (move-to-window-line 0)
2088   (if (and gnus-break-pages
2089            (bobp)
2090            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2091       (progn
2092         (gnus-narrow-to-page -1)        ;Go to previous page.
2093         (goto-char (point-max))
2094         (recenter -1))
2095     (let ((scroll-in-place nil))
2096       (prog1
2097           (ignore-errors
2098             (scroll-down lines))
2099         (move-to-window-line 0)))))
2100
2101 (defun gnus-article-refer-article ()
2102   "Read article specified by message-id around point."
2103   (interactive)
2104   (let ((point (point)))
2105     (search-forward ">" nil t)          ;Move point to end of "<....>".
2106     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2107         (let ((message-id (match-string 1)))
2108           (goto-char point)
2109           (set-buffer gnus-summary-buffer)
2110           (gnus-summary-refer-article message-id))
2111       (goto-char (point))
2112       (error "No references around point"))))
2113
2114 (defun gnus-article-show-summary ()
2115   "Reconfigure windows to show summary buffer."
2116   (interactive)
2117   (gnus-configure-windows 'article)
2118   (gnus-summary-goto-subject gnus-current-article))
2119
2120 (defun gnus-article-describe-briefly ()
2121   "Describe article mode commands briefly."
2122   (interactive)
2123   (gnus-message 6
2124                 (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")))
2125
2126 (defun gnus-article-summary-command ()
2127   "Execute the last keystroke in the summary buffer."
2128   (interactive)
2129   (let ((obuf (current-buffer))
2130         (owin (current-window-configuration))
2131         func)
2132     (switch-to-buffer gnus-summary-buffer 'norecord)
2133     (setq func (lookup-key (current-local-map) (this-command-keys)))
2134     (call-interactively func)
2135     (set-buffer obuf)
2136     (set-window-configuration owin)
2137     (set-window-point (get-buffer-window (current-buffer)) (point))))
2138
2139 (defun gnus-article-summary-command-nosave ()
2140   "Execute the last keystroke in the summary buffer."
2141   (interactive)
2142   (let (func)
2143     (pop-to-buffer gnus-summary-buffer 'norecord)
2144     (setq func (lookup-key (current-local-map) (this-command-keys)))
2145     (call-interactively func)))
2146
2147 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2148   "Read a summary buffer key sequence and execute it from the article buffer."
2149   (interactive "P")
2150   (let ((nosaves
2151          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
2152            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2153            "=" "^" "\M-^" "|"))
2154         (nosave-but-article
2155          '("A\r"))
2156         (nosave-in-article
2157          '("\C-d"))
2158         keys)
2159     (save-excursion
2160       (set-buffer gnus-summary-buffer)
2161       (let (gnus-pick-mode)
2162         (push (or key last-command-event) unread-command-events)
2163         (setq keys (read-key-sequence nil))))
2164     (message "")
2165
2166     (if (or (member keys nosaves)
2167             (member keys nosave-but-article)
2168             (member keys nosave-in-article))
2169         (let (func)
2170           (save-window-excursion
2171             (pop-to-buffer gnus-summary-buffer 'norecord)
2172             ;; We disable the pick minor mode commands.
2173             (let (gnus-pick-mode)
2174               (setq func (lookup-key (current-local-map) keys))))
2175           (if (not func)
2176               (ding)
2177             (unless (member keys nosave-in-article)
2178               (set-buffer gnus-summary-buffer))
2179             (call-interactively func))
2180           (when (member keys nosave-but-article)
2181             (pop-to-buffer gnus-article-buffer 'norecord)))
2182       ;; These commands should restore window configuration.
2183       (let ((obuf (current-buffer))
2184             (owin (current-window-configuration))
2185             (opoint (point))
2186             func in-buffer)
2187         (if not-restore-window
2188             (pop-to-buffer gnus-summary-buffer 'norecord)
2189           (switch-to-buffer gnus-summary-buffer 'norecord))
2190         (setq in-buffer (current-buffer))
2191         ;; We disable the pick minor mode commands.
2192         (if (setq func (let (gnus-pick-mode)
2193                          (lookup-key (current-local-map) keys)))
2194             (call-interactively func)
2195           (ding))
2196         (when (eq in-buffer (current-buffer))
2197           (set-buffer obuf)
2198           (unless not-restore-window
2199             (set-window-configuration owin))
2200           (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2201
2202 (defun gnus-article-hide (&optional arg force)
2203   "Hide all the gruft in the current article.
2204 This means that PGP stuff, signatures, cited text and (some)
2205 headers will be hidden.
2206 If given a prefix, show the hidden text instead."
2207   (interactive (list current-prefix-arg 'force))
2208   (gnus-article-hide-headers arg)
2209   (gnus-article-hide-pgp arg)
2210   (gnus-article-hide-citation-maybe arg force)
2211   (gnus-article-hide-signature arg))
2212
2213 (defun gnus-article-maybe-highlight ()
2214   "Do some article highlighting if `article-visual' is non-nil."
2215   (when (gnus-visual-p 'article-highlight 'highlight)
2216     (gnus-article-highlight-some)))
2217
2218 (defun gnus-request-article-this-buffer (article group)
2219   "Get an article and insert it into this buffer."
2220   (let (do-update-line)
2221     (prog1
2222         (save-excursion
2223           (erase-buffer)
2224           (gnus-kill-all-overlays)
2225           (setq group (or group gnus-newsgroup-name))
2226
2227           ;; Open server if it has closed.
2228           (gnus-check-server (gnus-find-method-for-group group))
2229
2230           ;; Using `gnus-request-article' directly will insert the article into
2231           ;; `nntp-server-buffer' - so we'll save some time by not having to
2232           ;; copy it from the server buffer into the article buffer.
2233
2234           ;; We only request an article by message-id when we do not have the
2235           ;; headers for it, so we'll have to get those.
2236           (when (stringp article)
2237             (let ((gnus-override-method gnus-refer-article-method))
2238               (gnus-read-header article)))
2239
2240           ;; If the article number is negative, that means that this article
2241           ;; doesn't belong in this newsgroup (possibly), so we find its
2242           ;; message-id and request it by id instead of number.
2243           (when (and (numberp article)
2244                      gnus-summary-buffer
2245                      (get-buffer gnus-summary-buffer)
2246                      (buffer-name (get-buffer gnus-summary-buffer)))
2247             (save-excursion
2248               (set-buffer gnus-summary-buffer)
2249               (let ((header (gnus-summary-article-header article)))
2250                 (when (< article 0)
2251                   (cond 
2252                    ((memq article gnus-newsgroup-sparse)
2253                     ;; This is a sparse gap article.
2254                     (setq do-update-line article)
2255                     (setq article (mail-header-id header))
2256                     (let ((gnus-override-method gnus-refer-article-method))
2257                       (gnus-read-header article))
2258                     (setq gnus-newsgroup-sparse
2259                           (delq article gnus-newsgroup-sparse)))
2260                    ((vectorp header)
2261                     ;; It's a real article.
2262                     (setq article (mail-header-id header)))
2263                    (t
2264                     ;; It is an extracted pseudo-article.
2265                     (setq article 'pseudo)
2266                     (gnus-request-pseudo-article header))))
2267                 
2268                 (let ((method (gnus-find-method-for-group 
2269                                gnus-newsgroup-name)))
2270                   (if (not (eq (car method) 'nneething))
2271                       ()
2272                     (let ((dir (concat (file-name-as-directory (nth 1 method))
2273                                        (mail-header-subject header))))
2274                       (when (file-directory-p dir)
2275                         (setq article 'nneething)
2276                         (gnus-group-enter-directory dir))))))))
2277
2278           (cond
2279            ;; Refuse to select canceled articles.
2280            ((and (numberp article)
2281                  gnus-summary-buffer
2282                  (get-buffer gnus-summary-buffer)
2283                  (buffer-name (get-buffer gnus-summary-buffer))
2284                  (eq (cdr (save-excursion
2285                             (set-buffer gnus-summary-buffer)
2286                             (assq article gnus-newsgroup-reads)))
2287                      gnus-canceled-mark))
2288             nil)
2289            ;; We first check `gnus-original-article-buffer'.
2290            ((and (get-buffer gnus-original-article-buffer)
2291                  (numberp article)
2292                  (save-excursion
2293                    (set-buffer gnus-original-article-buffer)
2294                    (and (equal (car gnus-original-article) group)
2295                         (eq (cdr gnus-original-article) article))))
2296             (insert-buffer-substring gnus-original-article-buffer)
2297             'article)
2298            ;; Check the backlog.
2299            ((and gnus-keep-backlog
2300                  (gnus-backlog-request-article group article (current-buffer)))
2301             'article)
2302            ;; Check asynchronous pre-fetch.
2303            ((gnus-async-request-fetched-article group article (current-buffer))
2304             (gnus-async-prefetch-next group article gnus-summary-buffer)
2305             'article)
2306            ;; Check the cache.
2307            ((and gnus-use-cache
2308                  (numberp article)
2309                  (gnus-cache-request-article article group))
2310             'article)
2311            ;; Get the article and put into the article buffer.
2312            ((or (stringp article) (numberp article))
2313             (let ((gnus-override-method
2314                    (and (stringp article) gnus-refer-article-method))
2315                   (buffer-read-only nil))
2316               (erase-buffer)
2317               (gnus-kill-all-overlays)
2318               (when (gnus-request-article article group (current-buffer))
2319                 (when (numberp article)
2320                   (gnus-async-prefetch-next group article gnus-summary-buffer)
2321                   (when gnus-keep-backlog
2322                     (gnus-backlog-enter-article 
2323                      group article (current-buffer))))
2324                 'article)))
2325            ;; It was a pseudo.
2326            (t article)))
2327
2328       ;; Take the article from the original article buffer
2329       ;; and place it in the buffer it's supposed to be in.
2330       (when (and (get-buffer gnus-article-buffer)
2331                  ;;(numberp article)
2332                  (equal (buffer-name (current-buffer))
2333                         (buffer-name (get-buffer gnus-article-buffer))))
2334         (save-excursion
2335           (if (get-buffer gnus-original-article-buffer)
2336               (set-buffer (get-buffer gnus-original-article-buffer))
2337             (set-buffer (get-buffer-create gnus-original-article-buffer))
2338             (buffer-disable-undo (current-buffer))
2339             (setq major-mode 'gnus-original-article-mode)
2340             (setq buffer-read-only t)
2341             (gnus-add-current-to-buffer-list))
2342           (let (buffer-read-only)
2343             (erase-buffer)
2344             (insert-buffer-substring gnus-article-buffer))
2345           (setq gnus-original-article (cons group article))))
2346     
2347       ;; Update sparse articles.
2348       (when (and do-update-line
2349                  (or (numberp article)
2350                      (stringp article)))
2351         (let ((buf (current-buffer)))
2352           (set-buffer gnus-summary-buffer)
2353           (gnus-summary-update-article do-update-line)
2354           (gnus-summary-goto-subject do-update-line nil t)
2355           (set-window-point (get-buffer-window (current-buffer) t)
2356                             (point))
2357           (set-buffer buf))))))
2358
2359 ;;;
2360 ;;; Article editing
2361 ;;;
2362
2363 (defcustom gnus-article-edit-mode-hook nil
2364   "Hook run in article edit mode buffers."
2365   :group 'gnus-article-various
2366   :type 'hook)
2367
2368 (defvar gnus-article-edit-done-function nil)
2369
2370 (defvar gnus-article-edit-mode-map nil)
2371
2372 (unless gnus-article-edit-mode-map 
2373   (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2374
2375   (gnus-define-keys gnus-article-edit-mode-map
2376     "\C-c\C-c" gnus-article-edit-done
2377     "\C-c\C-k" gnus-article-edit-exit)
2378
2379   (gnus-define-keys (gnus-article-edit-wash-map
2380                      "\C-c\C-w" gnus-article-edit-mode-map)
2381     "f" gnus-article-edit-full-stops))
2382
2383 (defun gnus-article-edit-mode ()
2384   "Major mode for editing articles.
2385 This is an extended text-mode.
2386
2387 \\{gnus-article-edit-mode-map}"
2388   (interactive)
2389   (kill-all-local-variables)
2390   (setq major-mode 'gnus-article-edit-mode)
2391   (setq mode-name "Article Edit")
2392   (use-local-map gnus-article-edit-mode-map)
2393   (make-local-variable 'gnus-article-edit-done-function)
2394   (make-local-variable 'gnus-prev-winconf)
2395   (setq buffer-read-only nil)
2396   (buffer-enable-undo)
2397   (widen)
2398   (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2399
2400 (defun gnus-article-edit (&optional force)
2401   "Edit the current article.
2402 This will have permanent effect only in mail groups.
2403 If FORCE is non-nil, allow editing of articles even in read-only
2404 groups."
2405   (interactive "P")
2406   (when (and (not force)
2407              (gnus-group-read-only-p))
2408     (error "The current newsgroup does not support article editing."))
2409   (gnus-article-edit-article
2410    `(lambda ()
2411       (gnus-summary-edit-article-done
2412        ,(or (mail-header-references gnus-current-headers) "")
2413        ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2414
2415 (defun gnus-article-edit-article (exit-func)
2416   "Start editing the contents of the current article buffer."
2417   (let ((winconf (current-window-configuration)))
2418     (set-buffer gnus-article-buffer)
2419     (gnus-article-edit-mode)
2420     (set-text-properties (point-min) (point-max) nil)
2421     (gnus-configure-windows 'edit-article)
2422     (setq gnus-article-edit-done-function exit-func)
2423     (setq gnus-prev-winconf winconf)
2424     (gnus-message 6 "C-c C-c to end edits")))
2425
2426 (defun gnus-article-edit-done ()
2427   "Update the article edits and exit."
2428   (interactive)
2429   (let ((func gnus-article-edit-done-function)
2430         (buf (current-buffer))
2431         (start (window-start)))
2432     (gnus-article-edit-exit)
2433     (save-excursion
2434       (set-buffer buf)
2435       (let ((buffer-read-only nil))
2436         (funcall func)))
2437     (set-buffer buf)
2438     (set-window-start (get-buffer-window buf) start)
2439     (set-window-point (get-buffer-window buf) (point))))
2440
2441 (defun gnus-article-edit-exit ()
2442   "Exit the article editing without updating."
2443   (interactive)
2444   ;; We remove all text props from the article buffer.
2445   (let ((buf (format "%s" (buffer-string)))
2446         (curbuf (current-buffer))
2447         (p (point))
2448         (window-start (window-start)))
2449     (erase-buffer)
2450     (insert buf)
2451     (let ((winconf gnus-prev-winconf))
2452       (gnus-article-mode)
2453       ;; The cache and backlog have to be flushed somewhat.
2454       (when gnus-use-cache
2455         (gnus-cache-update-article      
2456          (car gnus-article-current) (cdr gnus-article-current)))
2457       (when gnus-keep-backlog
2458         (gnus-backlog-remove-article 
2459          (car gnus-article-current) (cdr gnus-article-current)))
2460       ;; Flush original article as well.
2461       (save-excursion
2462         (when (get-buffer gnus-original-article-buffer)
2463           (set-buffer gnus-original-article-buffer)
2464           (setq gnus-original-article nil)))
2465       (set-window-configuration winconf)
2466       ;; Tippy-toe some to make sure that point remains where it was.
2467       (let ((buf (current-buffer)))
2468         (set-buffer curbuf)
2469         (set-window-start (get-buffer-window (current-buffer)) window-start)
2470         (goto-char p)
2471         (set-buffer buf)))))
2472       
2473 (defun gnus-article-edit-full-stops ()
2474   "Interactively repair spacing at end of sentences."
2475   (interactive)
2476   (save-excursion
2477     (goto-char (point-min))
2478     (search-forward-regexp "^$" nil t)
2479     (let ((case-fold-search nil))
2480       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2481
2482 ;;; 
2483 ;;; Article highlights
2484 ;;;
2485
2486 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2487
2488 ;;; Internal Variables:
2489
2490 (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\\)"
2491   "Regular expression that matches URLs."
2492   :group 'gnus-article-buttons
2493   :type 'regexp)
2494
2495 (defcustom gnus-button-alist 
2496   `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2497      gnus-button-message-id 2)
2498     ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*+\\)" 0 t gnus-button-message-id 1)
2499     ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2500      gnus-button-fetch-group 4)
2501     ("\\bnews:\\(//\\)?\\([^>\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2502     ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 
2503      t gnus-button-message-id 3)
2504     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 1)
2505     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 2)
2506     ;; This is how URLs _should_ be embedded in text...
2507     ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2508     ;; Raw URLs.
2509     (,gnus-button-url-regexp 0 t gnus-button-url 0))
2510   "Alist of regexps matching buttons in article bodies.
2511
2512 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2513 REGEXP: is the string matching text around the button,
2514 BUTTON: is the number of the regexp grouping actually matching the button,
2515 FORM: is a lisp expression which must eval to true for the button to
2516 be added, 
2517 CALLBACK: is the function to call when the user push this button, and each
2518 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2519
2520 CALLBACK can also be a variable, in that case the value of that
2521 variable it the real callback function."
2522   :group 'gnus-article-buttons
2523   :type '(repeat (list regexp 
2524                        (integer :tag "Button")
2525                        (sexp :tag "Form")
2526                        (function :tag "Callback")
2527                        (repeat :tag "Par"
2528                                :inline t
2529                                (integer :tag "Regexp group")))))
2530
2531 (defcustom gnus-header-button-alist 
2532   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2533      0 t gnus-button-message-id 0)
2534     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2535     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+" 
2536      0 t gnus-button-mailto 0)
2537     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2538     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2539     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2540      gnus-button-message-id 3))
2541   "Alist of headers and regexps to match buttons in article heads.
2542
2543 This alist is very similar to `gnus-button-alist', except that each
2544 alist has an additional HEADER element first in each entry:
2545
2546 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2547
2548 HEADER is a regexp to match a header.  For a fuller explanation, see
2549 `gnus-button-alist'."
2550   :group 'gnus-article-buttons
2551   :group 'gnus-article-headers
2552   :type '(repeat (list (regexp :tag "Header")
2553                        regexp 
2554                        (integer :tag "Button")
2555                        (sexp :tag "Form")
2556                        (function :tag "Callback")
2557                        (repeat :tag "Par"
2558                                :inline t
2559                                (integer :tag "Regexp group")))))
2560
2561 (defvar gnus-button-regexp nil)
2562 (defvar gnus-button-marker-list nil)
2563 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2564
2565 (defvar gnus-button-last nil)
2566 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2567
2568 ;;; Commands:
2569
2570 (defun gnus-article-push-button (event)
2571   "Check text under the mouse pointer for a callback function.
2572 If the text under the mouse pointer has a `gnus-callback' property,
2573 call it with the value of the `gnus-data' text property."
2574   (interactive "e")
2575   (set-buffer (window-buffer (posn-window (event-start event))))
2576   (let* ((pos (posn-point (event-start event)))
2577          (data (get-text-property pos 'gnus-data))
2578          (fun (get-text-property pos 'gnus-callback)))
2579     (when fun
2580       (funcall fun data))))
2581
2582 (defun gnus-article-press-button ()
2583   "Check text at point for a callback function.
2584 If the text at point has a `gnus-callback' property,
2585 call it with the value of the `gnus-data' text property."
2586   (interactive)
2587   (let* ((data (get-text-property (point) 'gnus-data))
2588          (fun (get-text-property (point) 'gnus-callback)))
2589     (when fun
2590       (funcall fun data))))
2591
2592 (defun gnus-article-prev-button (n)
2593   "Move point to N buttons backward.
2594 If N is negative, move forward instead."
2595   (interactive "p")
2596   (gnus-article-next-button (- n)))
2597
2598 (defun gnus-article-next-button (n)
2599   "Move point to N buttons forward.
2600 If N is negative, move backward instead."
2601   (interactive "p")
2602   (let ((function (if (< n 0) 'previous-single-property-change
2603                     'next-single-property-change))
2604         (inhibit-point-motion-hooks t)
2605         (backward (< n 0))
2606         (limit (if (< n 0) (point-min) (point-max))))
2607     (setq n (abs n))
2608     (while (and (not (= limit (point)))
2609                 (> n 0))
2610       ;; Skip past the current button.
2611       (when (get-text-property (point) 'gnus-callback)
2612         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2613       ;; Go to the next (or previous) button.
2614       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2615       ;; Put point at the start of the button.
2616       (when (and backward (not (get-text-property (point) 'gnus-callback)))
2617         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2618       ;; Skip past intangible buttons.
2619       (when (get-text-property (point) 'intangible)
2620         (incf n))
2621       (decf n))
2622     (unless (zerop n)
2623       (gnus-message 5 "No more buttons"))
2624     n))
2625
2626 (defun gnus-article-highlight (&optional force)
2627   "Highlight current article.
2628 This function calls `gnus-article-highlight-headers',
2629 `gnus-article-highlight-citation', 
2630 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2631 do the highlighting.  See the documentation for those functions."
2632   (interactive (list 'force))
2633   (gnus-article-highlight-headers)
2634   (gnus-article-highlight-citation force)
2635   (gnus-article-highlight-signature)
2636   (gnus-article-add-buttons force)
2637   (gnus-article-add-buttons-to-head))
2638
2639 (defun gnus-article-highlight-some (&optional force)
2640   "Highlight current article.
2641 This function calls `gnus-article-highlight-headers',
2642 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2643 do the highlighting.  See the documentation for those functions."
2644   (interactive (list 'force))
2645   (gnus-article-highlight-headers)
2646   (gnus-article-highlight-signature)
2647   (gnus-article-add-buttons))
2648
2649 (defun gnus-article-highlight-headers ()
2650   "Highlight article headers as specified by `gnus-header-face-alist'."
2651   (interactive)
2652   (save-excursion
2653     (set-buffer gnus-article-buffer)
2654     (save-restriction
2655       (let ((alist gnus-header-face-alist)
2656             (buffer-read-only nil)
2657             (case-fold-search t)
2658             (inhibit-point-motion-hooks t)
2659             entry regexp header-face field-face from hpoints fpoints)
2660         (goto-char (point-min))
2661         (when (search-forward "\n\n" nil t)
2662           (narrow-to-region (1- (point)) (point-min))
2663           (while (setq entry (pop alist))
2664             (goto-char (point-min))
2665             (setq regexp (concat "^\\("
2666                                  (if (string-equal "" (nth 0 entry))
2667                                      "[^\t ]"
2668                                    (nth 0 entry))
2669                                  "\\)")
2670                   header-face (nth 1 entry)
2671                   field-face (nth 2 entry))
2672             (while (and (re-search-forward regexp nil t)
2673                         (not (eobp)))
2674               (beginning-of-line)
2675               (setq from (point))
2676               (unless (search-forward ":" nil t)
2677                 (forward-char 1))
2678               (when (and header-face
2679                          (not (memq (point) hpoints)))
2680                 (push (point) hpoints)
2681                 (gnus-put-text-property from (point) 'face header-face))
2682               (when (and field-face
2683                          (not (memq (setq from (point)) fpoints)))
2684                 (push from fpoints)
2685                 (if (re-search-forward "^[^ \t]" nil t)
2686                     (forward-char -2)
2687                   (goto-char (point-max)))
2688                 (gnus-put-text-property from (point) 'face field-face)))))))))
2689
2690 (defun gnus-article-highlight-signature ()
2691   "Highlight the signature in an article.
2692 It does this by highlighting everything after
2693 `gnus-signature-separator' using `gnus-signature-face'." 
2694   (interactive)
2695   (save-excursion
2696     (set-buffer gnus-article-buffer)
2697     (let ((buffer-read-only nil)
2698           (inhibit-point-motion-hooks t))
2699       (save-restriction
2700         (when (and gnus-signature-face
2701                    (gnus-article-narrow-to-signature))
2702           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2703                             'face gnus-signature-face)
2704           (widen)
2705           (gnus-article-search-signature)
2706           (let ((start (match-beginning 0))
2707                 (end (set-marker (make-marker) (1+ (match-end 0)))))
2708             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2709                                      end)))))))
2710
2711 (defun gnus-button-in-region-p (b e prop)
2712   "Say whether PROP exists in the region."
2713   (text-property-not-all b e prop nil))
2714
2715 (defun gnus-article-add-buttons (&optional force)
2716   "Find external references in the article and make buttons of them.
2717 \"External references\" are things like Message-IDs and URLs, as
2718 specified by `gnus-button-alist'."
2719   (interactive (list 'force))
2720   (save-excursion
2721     (set-buffer gnus-article-buffer)
2722     ;; Remove all old markers.
2723     (let (marker entry)
2724       (while (setq marker (pop gnus-button-marker-list))
2725         (goto-char marker)
2726         (when (setq entry (gnus-button-entry))
2727           (put-text-property (match-beginning (nth 1 entry))
2728                              (match-end (nth 1 entry))
2729                              'gnus-callback nil))
2730         (set-marker marker nil)))
2731     (let ((buffer-read-only nil)
2732           (inhibit-point-motion-hooks t)
2733           (case-fold-search t)
2734           (alist gnus-button-alist)
2735           beg entry regexp)
2736       (goto-char (point-min))
2737       ;; We skip the headers.
2738       (unless (search-forward "\n\n" nil t)
2739         (goto-char (point-max)))
2740       (setq beg (point))
2741       (while (setq entry (pop alist))
2742         (setq regexp (car entry))
2743         (goto-char beg)
2744         (while (re-search-forward regexp nil t)
2745           (let* ((start (and entry (match-beginning (nth 1 entry))))
2746                  (end (and entry (match-end (nth 1 entry))))
2747                  (from (match-beginning 0)))
2748             (when (and (or (eq t (nth 1 entry))
2749                            (eval (nth 1 entry)))
2750                        (not (gnus-button-in-region-p
2751                              start end 'gnus-callback)))
2752               ;; That optional form returned non-nil, so we add the
2753               ;; button.
2754               (gnus-article-add-button 
2755                start end 'gnus-button-push 
2756                (car (push (set-marker (make-marker) from)
2757                           gnus-button-marker-list))))))))))
2758
2759 ;; Add buttons to the head of an article.
2760 (defun gnus-article-add-buttons-to-head ()
2761   "Add buttons to the head of the article."
2762   (interactive)
2763   (save-excursion
2764     (set-buffer gnus-article-buffer)
2765     (let ((buffer-read-only nil)
2766           (inhibit-point-motion-hooks t)
2767           (case-fold-search t)
2768           (alist gnus-header-button-alist)
2769           entry beg end)
2770       (nnheader-narrow-to-headers)
2771       (while alist
2772         ;; Each alist entry.
2773         (setq entry (car alist)
2774               alist (cdr alist))
2775         (goto-char (point-min))
2776         (while (re-search-forward (car entry) nil t)
2777           ;; Each header matching the entry.
2778           (setq beg (match-beginning 0))
2779           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2780                              (match-beginning 0))
2781                         (point-max)))
2782           (goto-char beg)
2783           (while (re-search-forward (nth 1 entry) end t)
2784             ;; Each match within a header.
2785             (let* ((entry (cdr entry))
2786                    (start (match-beginning (nth 1 entry)))
2787                    (end (match-end (nth 1 entry)))
2788                    (form (nth 2 entry)))
2789               (goto-char (match-end 0))
2790               (when (eval form)
2791                 (gnus-article-add-button 
2792                  start end (nth 3 entry)
2793                  (buffer-substring (match-beginning (nth 4 entry))
2794                                    (match-end (nth 4 entry)))))))
2795           (goto-char end))))
2796     (widen)))
2797
2798 ;;; External functions:
2799
2800 (defun gnus-article-add-button (from to fun &optional data)
2801   "Create a button between FROM and TO with callback FUN and data DATA."
2802   (when gnus-article-button-face
2803     (gnus-overlay-put (gnus-make-overlay from to)
2804                       'face gnus-article-button-face))
2805   (gnus-add-text-properties 
2806    from to
2807    (nconc (and gnus-article-mouse-face
2808                (list gnus-mouse-face-prop gnus-article-mouse-face))
2809           (list 'gnus-callback fun)
2810           (and data (list 'gnus-data data)))))
2811
2812 ;;; Internal functions:
2813
2814 (defun gnus-signature-toggle (end)
2815   (save-excursion
2816     (set-buffer gnus-article-buffer)
2817     (let ((buffer-read-only nil)
2818           (inhibit-point-motion-hooks t))
2819       (if (get-text-property end 'invisible)
2820           (gnus-article-unhide-text end (point-max))
2821         (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2822
2823 (defun gnus-button-entry ()
2824   ;; Return the first entry in `gnus-button-alist' matching this place.
2825   (let ((alist gnus-button-alist)
2826         (entry nil))
2827     (while alist
2828       (setq entry (pop alist))
2829       (if (looking-at (car entry))
2830           (setq alist nil)
2831         (setq entry nil)))
2832     entry))
2833
2834 (defun gnus-button-push (marker)
2835   ;; Push button starting at MARKER.
2836   (save-excursion
2837     (set-buffer gnus-article-buffer)
2838     (goto-char marker)
2839     (let* ((entry (gnus-button-entry))
2840            (inhibit-point-motion-hooks t)
2841            (fun (nth 3 entry))
2842            (args (mapcar (lambda (group)
2843                            (let ((string (match-string group)))
2844                              (gnus-set-text-properties
2845                               0 (length string) nil string)
2846                              string))
2847                          (nthcdr 4 entry))))
2848       (cond
2849        ((fboundp fun)
2850         (apply fun args))
2851        ((and (boundp fun)
2852              (fboundp (symbol-value fun)))
2853         (apply (symbol-value fun) args))
2854        (t
2855         (gnus-message 1 "You must define `%S' to use this button"
2856                       (cons fun args)))))))
2857
2858 (defun gnus-button-message-id (message-id)
2859   "Fetch MESSAGE-ID."
2860   (save-excursion
2861     (set-buffer gnus-summary-buffer)
2862     (gnus-summary-refer-article message-id)))
2863
2864 (defun gnus-button-fetch-group (address)
2865   "Fetch GROUP specified by ADDRESS."
2866   (if (not (string-match "[:/]" address))
2867       ;; This is just a simple group url.
2868       (gnus-group-read-ephemeral-group address gnus-select-method)
2869     (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
2870                            address))
2871         (error "Can't parse %s" address)
2872       (gnus-group-read-ephemeral-group
2873        (match-string 4 address)
2874        `(nntp ,(match-string 1 address)
2875               (nntp-address ,(match-string 1 address))
2876               (nntp-port-number ,(if (match-end 3)
2877                                      (match-string 3 address)
2878                                    "nntp")))))))
2879
2880 (defun gnus-split-string (string pattern)
2881   "Return a list of substrings of STRING which are separated by PATTERN."
2882   (let (parts (start 0))
2883     (while (string-match pattern string start)
2884       (setq parts (cons (substring string start (match-beginning 0)) parts)
2885             start (match-end 0)))
2886     (nreverse (cons (substring string start) parts))))
2887  
2888 (defun gnus-url-parse-query-string (query &optional downcase)
2889   (let (retval pairs cur key val)
2890     (setq pairs (gnus-split-string query "&"))
2891     (while pairs
2892       (setq cur (car pairs)
2893             pairs (cdr pairs))
2894       (if (not (string-match "=" cur))
2895           nil                           ; Grace
2896         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2897               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2898         (if downcase
2899             (setq key (downcase key)))
2900         (setq cur (assoc key retval))
2901         (if cur
2902             (setcdr cur (cons val (cdr cur)))
2903           (setq retval (cons (list key val) retval)))))
2904     retval))
2905  
2906 (defun gnus-url-unhex (x)
2907   (if (> x ?9)
2908       (if (>= x ?a)
2909           (+ 10 (- x ?a))
2910         (+ 10 (- x ?A)))
2911     (- x ?0)))
2912  
2913 (defun gnus-url-unhex-string (str &optional allow-newlines)
2914   "Remove %XXX embedded spaces, etc in a url.
2915 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2916 decoding of carriage returns and line feeds in the string, which is normally
2917 forbidden in URL encoding."
2918   (setq str (or str ""))
2919   (let ((tmp "")
2920         (case-fold-search t))
2921     (while (string-match "%[0-9a-f][0-9a-f]" str)
2922       (let* ((start (match-beginning 0))
2923              (ch1 (gnus-url-unhex (elt str (+ start 1))))
2924              (code (+ (* 16 ch1)
2925                       (gnus-url-unhex (elt str (+ start 2))))))
2926         (setq tmp (concat 
2927                    tmp (substring str 0 start)
2928                    (cond
2929                     (allow-newlines
2930                      (char-to-string code))
2931                     ((or (= code ?\n) (= code ?\r))
2932                      " ")
2933                     (t (char-to-string code))))
2934               str (substring str (match-end 0)))))
2935     (setq tmp (concat tmp str))
2936     tmp))
2937  
2938 (defun gnus-url-mailto (url)
2939   ;; Send mail to someone
2940   (when (string-match "mailto:/*\\(.*\\)" url)
2941     (setq url (substring url (match-beginning 1) nil)))
2942   (let (to args source-url subject func)
2943     (if (string-match (regexp-quote "?") url)
2944         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2945               args (gnus-url-parse-query-string
2946                     (substring url (match-end 0) nil) t))
2947       (setq to (gnus-url-unhex-string url)))
2948     (setq args (cons (list "to" to) args)
2949           subject (cdr-safe (assoc "subject" args)))
2950     (message-mail)
2951     (while args
2952       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
2953       (if (fboundp func)
2954           (funcall func)
2955         (message-position-on-field (caar args)))
2956       (insert (mapconcat 'identity (cdar args) ", "))
2957       (setq args (cdr args)))
2958     (if subject
2959         (message-goto-body)
2960       (message-goto-subject))))
2961
2962 (defun gnus-button-mailto (address)
2963   ;; Mail to ADDRESS.
2964   (set-buffer (gnus-copy-article-buffer))
2965   (message-reply address))
2966
2967 (defun gnus-button-reply (address)
2968   ;; Reply to ADDRESS.
2969   (message-reply address))
2970
2971 (defun gnus-button-url (address)
2972   "Browse ADDRESS."
2973   (funcall browse-url-browser-function address))
2974
2975 (defun gnus-button-embedded-url (address)
2976   "Browse ADDRESS."
2977   (funcall browse-url-browser-function (gnus-strip-whitespace address)))
2978
2979 ;;; Next/prev buttons in the article buffer.
2980
2981 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
2982 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
2983
2984 (defvar gnus-prev-page-map nil)
2985 (unless gnus-prev-page-map
2986   (setq gnus-prev-page-map (make-sparse-keymap))
2987   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
2988   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
2989
2990 (defun gnus-insert-prev-page-button ()
2991   (let ((buffer-read-only nil))
2992     (gnus-eval-format 
2993      gnus-prev-page-line-format nil
2994      `(gnus-prev t local-map ,gnus-prev-page-map
2995                  gnus-callback gnus-article-button-prev-page))))
2996
2997 (defvar gnus-next-page-map nil)
2998 (unless gnus-next-page-map
2999   (setq gnus-next-page-map (make-keymap))
3000   (suppress-keymap gnus-prev-page-map)
3001   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3002   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3003
3004 (defun gnus-button-next-page ()
3005   "Go to the next page."
3006   (interactive)
3007   (let ((win (selected-window)))
3008     (select-window (get-buffer-window gnus-article-buffer t))
3009     (gnus-article-next-page)
3010     (select-window win)))
3011
3012 (defun gnus-button-prev-page ()
3013   "Go to the prev page."
3014   (interactive)
3015   (let ((win (selected-window)))
3016     (select-window (get-buffer-window gnus-article-buffer t))
3017     (gnus-article-prev-page)
3018     (select-window win)))
3019
3020 (defun gnus-insert-next-page-button ()
3021   (let ((buffer-read-only nil))
3022     (gnus-eval-format gnus-next-page-line-format nil
3023                       `(gnus-next t local-map ,gnus-next-page-map
3024                                   gnus-callback 
3025                                   gnus-article-button-next-page))))
3026
3027 (defun gnus-article-button-next-page (arg)
3028   "Go to the next page."
3029   (interactive "P")
3030   (let ((win (selected-window)))
3031     (select-window (get-buffer-window gnus-article-buffer t))
3032     (gnus-article-next-page)
3033     (select-window win)))
3034
3035 (defun gnus-article-button-prev-page (arg)
3036   "Go to the prev page."
3037   (interactive "P")
3038   (let ((win (selected-window)))
3039     (select-window (get-buffer-window gnus-article-buffer t))
3040     (gnus-article-prev-page)
3041     (select-window win))) 
3042
3043 (gnus-ems-redefine)
3044
3045 (provide 'gnus-art)
3046
3047 (run-hooks 'gnus-art-load-hook)
3048
3049 ;;; gnus-art.el ends here