*** empty log message ***
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996 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 'gnus-load)
29 (require 'gnus-sum)
30 (require 'article)
31 (require 'gnus-spec)
32 (require 'gnus-int)
33 (require 'browse-url)
34
35 (defcustom gnus-article-save-directory gnus-directory
36   "*Name of the directory articles will be saved in (default \"~/News\")."
37   :group 'article
38   :type 'directory)
39
40 (defcustom gnus-save-all-headers t
41   "*If non-nil, don't remove any headers before saving."
42   :group 'article
43   :type 'boolean)
44
45 (defcustom gnus-prompt-before-saving 'always
46   "*This variable says how much prompting is to be done when saving articles.
47 If it is nil, no prompting will be done, and the articles will be
48 saved to the default files.  If this variable is `always', each and
49 every article that is saved will be preceded by a prompt, even when
50 saving large batches of articles.  If this variable is neither nil not
51 `always', there the user will be prompted once for a file name for
52 each invocation of the saving commands."
53   :group 'article
54   :type '(choice (item always)
55                  (item :tag "never" nil)
56                  (sexp :tag "once" :format "%t")))
57
58 (defcustom gnus-saved-headers gnus-visible-headers
59   "Headers to keep if `gnus-save-all-headers' is nil.
60 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
61 If that variable is nil, however, all headers that match this regexp
62 will be kept while the rest will be deleted before saving."
63   :group 'article
64   :type '(repeat string))
65
66 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
67   "A function to save articles in your favourite format.
68 The function must be interactively callable (in other words, it must
69 be an Emacs command).
70
71 Gnus provides the following functions:
72
73 * gnus-summary-save-in-rmail (Rmail format)
74 * gnus-summary-save-in-mail (Unix mail format)
75 * gnus-summary-save-in-folder (MH folder)
76 * gnus-summary-save-in-file (article format).
77 * gnus-summary-save-in-vm (use VM's folder format)."
78   :group 'article
79   :type '(radio (function-item gnus-summary-save-in-rmail)
80                 (function-item gnus-summary-save-in-mail)
81                 (function-item gnus-summary-save-in-folder)
82                 (function-item gnus-summary-save-in-file)
83                 (function-item gnus-summary-save-in-vm)))
84
85 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
86   "A function generating a file name to save articles in Rmail format.
87 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
88   :group 'article
89   :type 'function)
90
91 (defcustom gnus-mail-save-name 'gnus-plain-save-name
92   "A function generating a file name to save articles in Unix mail format.
93 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
94   :group 'article
95   :type 'function)
96
97 (defcustom gnus-folder-save-name 'gnus-folder-save-name
98   "A function generating a file name to save articles in MH folder.
99 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
100   :group 'article
101   :type 'function)
102
103 (defcustom gnus-file-save-name 'gnus-numeric-save-name
104   "A function generating a file name to save articles in article format.
105 The function is called with NEWSGROUP, HEADERS, and optional
106 LAST-FILE."
107   :group 'article
108   :type 'function)
109
110 (defcustom gnus-split-methods
111   '((gnus-article-archive-name))
112   "Variable used to suggest where articles are to be saved.
113 For instance, if you would like to save articles related to Gnus in
114 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
115 you could set this variable to something like:
116
117  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
118    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
119
120 This variable is an alist where the where the key is the match and the
121 value is a list of possible files to save in if the match is non-nil.
122
123 If the match is a string, it is used as a regexp match on the
124 article.  If the match is a symbol, that symbol will be funcalled
125 from the buffer of the article to be saved with the newsgroup as the
126 parameter.  If it is a list, it will be evaled in the same buffer.
127
128 If this form or function returns a string, this string will be used as
129 a possible file name; and if it returns a non-nil list, that list will
130 be used as possible file names."
131   :group 'article
132   :type '(repeat (choice (list function)
133                          (cons regexp (repeat string))
134                          sexp)))
135
136 (defcustom gnus-strict-mime t
137   "*If nil, MIME-decode even if there is no Mime-Version header."
138   :group 'article
139   :type 'boolean)
140
141 (defcustom gnus-show-mime-method 'metamail-buffer
142   "Function to process a MIME message.
143 The function is called from the article buffer."
144   :group 'article
145   :type 'function)
146
147 (defcustom gnus-decode-encoded-word-method (lambda ())
148   "*Function to decode a MIME encoded-words.
149 The function is called from the article buffer."
150   :group 'article
151   :type 'function)
152
153 (defcustom gnus-page-delimiter "^\^L"
154   "*Regexp describing what to use as article page delimiters.
155 The default value is \"^\^L\", which is a form linefeed at the
156 beginning of a line."
157   :type 'regexp
158   :group 'article)
159
160 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
161   "*The format specification for the article mode line.
162 See `gnus-summary-mode-line-format' for a closer description."
163   :type 'string
164   :group 'article)
165
166 (defcustom gnus-article-mode-hook nil
167   "*A hook for Gnus article mode."
168   :type 'hook
169   :group 'article)
170
171 (defcustom gnus-article-menu-hook nil
172   "*Hook run after the creation of the article mode menu."
173   :type 'hook
174   :group 'article)
175
176 (defcustom gnus-article-prepare-hook nil
177   "*A hook called after an article has been prepared in the article buffer.
178 If you want to run a special decoding program like nkf, use this hook."
179   :type 'hook
180   :group 'article)
181
182 (defcustom gnus-article-button-face 'bold
183   "Face used for highlighting buttons in the article buffer.
184
185 An article button is a piece of text that you can activate by pressing
186 `RET' or `mouse-2' above it."
187   :type 'face
188   :group 'article)
189
190 (defcustom gnus-article-mouse-face 'highlight
191   "Face used for mouse highlighting in the article buffer.
192
193 Article buttons will be displayed in this face when the cursor is
194 above them."
195   :type 'face
196   :group 'article)
197
198 (defcustom gnus-signature-face 'italic
199   "Face used for highlighting a signature in the article buffer."
200   :type 'face
201   :group 'article)
202
203 (defface gnus-header-from-face 
204   '((((class color)
205       (background dark))
206      (:foreground "light blue" :bold t :italic t))
207     (((class color)
208       (background light))
209      (:foreground "MidnightBlue" :bold t :italic t))
210     (t 
211      (:bold t :italic t)))
212   "Face used for displaying from headers."
213   :group 'article)
214
215 (defface gnus-header-subject-face 
216   '((((class color)
217       (background dark))
218      (:foreground "pink" :bold t :italic t))
219     (((class color)
220       (background light))
221      (:foreground "firebrick" :bold t :italic t))
222     (t 
223      (:bold t :italic t)))
224   "Face used for displaying subject headers."
225   :group 'article)
226
227 (defface gnus-header-newsgroups-face 
228   '((((class color)
229       (background dark))
230      (:foreground "yellow" :bold t :italic t))
231     (((class color)
232       (background light))
233      (:foreground "indianred" :bold t :italic t))
234     (t 
235      (:bold t :italic t)))
236   "Face used for displaying newsgroups headers."
237   :group 'article)
238
239 (defface gnus-header-name-face 
240   '((((class color)
241       (background dark))
242      (:foreground "cyan" :bold t))
243     (((class color)
244       (background light))
245      (:foreground "DarkGreen" :bold t))
246     (t 
247      (:bold t)))
248   "Face used for displaying header names."
249   :group 'article)
250
251 (defface gnus-header-content-face
252   '((((class color)
253       (background dark))
254      (:foreground "forest green" :italic t))
255     (((class color)
256       (background light))
257      (:foreground "DarkGreen" :italic t))
258     (t 
259      (:italic t)))  "Face used for displaying header content."
260   :group 'article)
261
262 (defcustom gnus-header-face-alist
263   '(("From" nil gnus-header-from-face)
264     ("Subject" nil gnus-header-subject-face)
265     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
266     ("" gnus-header-name-face gnus-header-content-face))
267   "Controls highlighting of article header.
268
269 An alist of the form (HEADER NAME CONTENT). 
270
271 HEADER is a regular expression which should match the name of an
272 header header and NAME and CONTENT are either face names or nil.
273
274 The name of each header field will be displayed using the face
275 specified by the first element in the list where HEADER match the
276 header name and NAME is non-nil.  Similarly, the content will be
277 displayed by the first non-nil matching CONTENT face."
278   :group 'article
279   :type '(repeat (list (regexp :tag "Header")
280                        (choice :tag "Name"
281                                (item :tag "skip" nil)
282                                (face :value default))
283                        (choice :tag "Content"
284                                (item :tag "skip" nil)
285                                (face :value default)))))
286
287 ;;; Internal variables
288
289 (defvar gnus-article-mode-line-format-alist
290     (nconc '((?w (gnus-article-wash-status) ?s))
291            gnus-summary-mode-line-format-alist))
292
293 (defvar gnus-number-of-articles-to-be-saved nil)
294
295 ;;; Provide a mapping from `gnus-*' commands to Article commands.
296
297 (eval-and-compile
298   (mapcar
299    (lambda (func)
300      (let (afunc gfunc)
301        (if (consp func)
302            (setq afunc (car func)
303                  gfunc (cdr func))
304          (setq afunc func
305                gfunc (intern (format "gnus-%s" func))))
306        (fset gfunc 
307              `(lambda (&optional interactive &rest args)
308                 ,(documentation afunc t)
309                 (interactive (list t))
310                 (save-excursion
311                   (set-buffer gnus-article-buffer)
312                   (if interactive
313                       (call-interactively ',afunc)
314                     (apply ',afunc args)))))))
315    '(article-hide-headers
316      article-hide-boring-headers
317      article-treat-overstrike
318      (article-fill . gnus-article-word-wrap)
319      article-remove-cr
320      article-display-x-face
321      article-de-quoted-unreadable
322      article-mime-decode-quoted-printable
323      article-hide-pgp
324      article-hide-pem
325      article-hide-signature
326      article-remove-trailing-blank-lines
327      article-strip-leading-blank-lines
328      article-strip-multiple-blank-lines
329      article-strip-blank-lines
330      article-date-local
331      article-date-original
332      article-date-lapsed
333      article-emphasize
334      (article-show-all . gnus-article-show-all-headers))))
335
336 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
337
338 ;;; Saving functions.
339
340 (defun gnus-article-save (save-buffer file &optional num)
341   "Save the currently selected article."
342   (unless gnus-save-all-headers
343     ;; Remove headers according to `gnus-saved-headers'.
344     (let ((gnus-visible-headers
345            (or gnus-saved-headers gnus-visible-headers))
346           (gnus-article-buffer save-buffer))
347       (gnus-article-hide-headers 1 t)))
348   (save-window-excursion
349     (if (not gnus-default-article-saver)
350         (error "No default saver is defined.")
351       ;; !!! Magic!  The saving functions all save
352       ;; `gnus-original-article-buffer' (or so they think),
353       ;; but we bind that variable to our save-buffer.
354       (set-buffer gnus-article-buffer)
355       (let* ((gnus-original-article-buffer save-buffer)
356              (filename
357               (cond
358                ((not gnus-prompt-before-saving)
359                 'default)
360                ((eq gnus-prompt-before-saving 'always)
361                 nil)
362                (t file)))
363              (gnus-number-of-articles-to-be-saved
364               (when (eq gnus-prompt-before-saving t)
365                 num)))                  ; Magic
366         (set-buffer gnus-summary-buffer)
367         (funcall gnus-default-article-saver filename))))) 
368
369 (defun gnus-read-save-file-name (prompt default-name &optional filename)
370   (cond
371    ((eq filename 'default)
372     default-name)
373    (filename filename)
374    (t
375     (let* ((split-name (gnus-get-split-value gnus-split-methods))
376            (prompt
377             (format prompt (if (and gnus-number-of-articles-to-be-saved
378                                     (> gnus-number-of-articles-to-be-saved 1))
379                                (format "these %d articles"
380                                        gnus-number-of-articles-to-be-saved)
381                              "this article")))
382            (file
383             ;; Let the split methods have their say.
384             (cond
385              ;; No split name was found.
386              ((null split-name)
387               (read-file-name
388                (concat prompt " (default "
389                        (file-name-nondirectory default-name) ") ")
390                (file-name-directory default-name)
391                default-name))
392              ;; A single split name was found
393              ((= 1 (length split-name))
394               (let* ((name (car split-name))
395                      (dir (cond ((file-directory-p name)
396                                  (file-name-as-directory name))
397                                 ((file-exists-p name) name)
398                                 (t gnus-article-save-directory))))
399                 (read-file-name
400                  (concat prompt " (default " name ") ")
401                  dir name)))
402              ;; A list of splits was found.
403              (t
404               (setq split-name (nreverse split-name))
405               (let (result)
406                 (let ((file-name-history (nconc split-name file-name-history)))
407                   (setq result
408                         (read-file-name
409                          (concat prompt " (`M-p' for defaults) ")
410                          gnus-article-save-directory
411                          (car split-name))))
412                 (car (push result file-name-history)))))))
413       ;; Create the directory.
414       (gnus-make-directory (file-name-directory file))
415       ;; If we have read a directory, we append the default file name.
416       (when (file-directory-p file)
417         (setq file (concat (file-name-as-directory file)
418                            (file-name-nondirectory default-name))))
419       ;; Possibly translate some characters.
420       (nnheader-translate-file-chars file)))))
421
422 (defun gnus-article-archive-name (group)
423   "Return the first instance of an \"Archive-name\" in the current buffer."
424   (let ((case-fold-search t))
425     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
426       (nnheader-concat gnus-article-save-directory
427                        (match-string 1)))))
428
429 (defun gnus-summary-save-in-rmail (&optional filename)
430   "Append this article to Rmail file.
431 Optional argument FILENAME specifies file name.
432 Directory to save to is default to `gnus-article-save-directory'."
433   (interactive)
434   (gnus-set-global-variables)
435   (let ((default-name
436           (funcall gnus-rmail-save-name gnus-newsgroup-name
437                    gnus-current-headers gnus-newsgroup-last-rmail)))
438     (setq filename (gnus-read-save-file-name
439                     "Save %s in rmail file:" default-name filename))
440     (gnus-make-directory (file-name-directory filename))
441     (gnus-eval-in-buffer-window gnus-original-article-buffer
442       (save-excursion
443         (save-restriction
444           (widen)
445           (gnus-output-to-rmail filename))))
446     ;; Remember the directory name to save articles
447     (setq gnus-newsgroup-last-rmail filename)))
448
449 (defun gnus-summary-save-in-mail (&optional filename)
450   "Append this article to Unix mail file.
451 Optional argument FILENAME specifies file name.
452 Directory to save to is default to `gnus-article-save-directory'."
453   (interactive)
454   (gnus-set-global-variables)
455   (let ((default-name
456           (funcall gnus-mail-save-name gnus-newsgroup-name
457                    gnus-current-headers gnus-newsgroup-last-mail)))
458     (setq filename (gnus-read-save-file-name
459                     "Save %s in Unix mail file:" default-name filename))
460     (setq filename
461           (expand-file-name filename
462                             (and default-name
463                                  (file-name-directory default-name))))
464     (gnus-make-directory (file-name-directory filename))
465     (gnus-eval-in-buffer-window gnus-original-article-buffer
466       (save-excursion
467         (save-restriction
468           (widen)
469           (if (and (file-readable-p filename) (mail-file-babyl-p filename))
470               (gnus-output-to-rmail filename)
471             (let ((mail-use-rfc822 t))
472               (rmail-output filename 1 t t))))))
473     ;; Remember the directory name to save articles.
474     (setq gnus-newsgroup-last-mail filename)))
475
476 (defun gnus-summary-save-in-file (&optional filename)
477   "Append this article to file.
478 Optional argument FILENAME specifies file name.
479 Directory to save to is default to `gnus-article-save-directory'."
480   (interactive)
481   (gnus-set-global-variables)
482   (let ((default-name
483           (funcall gnus-file-save-name gnus-newsgroup-name
484                    gnus-current-headers gnus-newsgroup-last-file)))
485     (setq filename (gnus-read-save-file-name
486                     "Save %s in file:" default-name filename))
487     (gnus-make-directory (file-name-directory filename))
488     (gnus-eval-in-buffer-window gnus-original-article-buffer
489       (save-excursion
490         (save-restriction
491           (widen)
492           (gnus-output-to-file filename))))
493     ;; Remember the directory name to save articles.
494     (setq gnus-newsgroup-last-file filename)))
495
496 (defun gnus-summary-save-body-in-file (&optional filename)
497   "Append this article body to a file.
498 Optional argument FILENAME specifies file name.
499 The directory to save in defaults to `gnus-article-save-directory'."
500   (interactive)
501   (gnus-set-global-variables)
502   (let ((default-name
503           (funcall gnus-file-save-name gnus-newsgroup-name
504                    gnus-current-headers gnus-newsgroup-last-file)))
505     (setq filename (gnus-read-save-file-name
506                     "Save %s body in file:" default-name filename))
507     (gnus-make-directory (file-name-directory filename))
508     (gnus-eval-in-buffer-window gnus-original-article-buffer
509       (save-excursion
510         (save-restriction
511           (widen)
512           (goto-char (point-min))
513           (when (search-forward "\n\n" nil t)
514             (narrow-to-region (point) (point-max)))
515           (gnus-output-to-file filename))))
516     ;; Remember the directory name to save articles.
517     (setq gnus-newsgroup-last-file filename)))
518
519 (defun gnus-summary-save-in-pipe (&optional command)
520   "Pipe this article to subprocess."
521   (interactive)
522   (gnus-set-global-variables)
523   (setq command
524         (cond ((eq command 'default)
525                gnus-last-shell-command)
526               (command command)
527               (t (read-string "Shell command on article: "
528                               gnus-last-shell-command))))
529   (when (string-equal command "")
530     (setq command gnus-last-shell-command))
531   (gnus-eval-in-buffer-window gnus-article-buffer
532     (save-restriction
533       (widen)
534       (shell-command-on-region (point-min) (point-max) command nil)))
535   (setq gnus-last-shell-command command))
536
537 ;;; Article file names when saving.
538
539 (defun gnus-capitalize-newsgroup (newsgroup)
540   "Capitalize NEWSGROUP name."
541   (when (not (zerop (length newsgroup)))
542     (concat (char-to-string (upcase (aref newsgroup 0)))
543             (substring newsgroup 1))))
544
545 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
546   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
547 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
548 Otherwise, it is like ~/News/news/group/num."
549   (let ((default
550           (expand-file-name
551            (concat (if (gnus-use-long-file-name 'not-save)
552                        (gnus-capitalize-newsgroup newsgroup)
553                      (gnus-newsgroup-directory-form newsgroup))
554                    "/" (int-to-string (mail-header-number headers)))
555            gnus-article-save-directory)))
556     (if (and last-file
557              (string-equal (file-name-directory default)
558                            (file-name-directory last-file))
559              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
560         default
561       (or last-file default))))
562
563 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
564   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
565 If variable `gnus-use-long-file-name' is non-nil, it is
566 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
567   (let ((default
568           (expand-file-name
569            (concat (if (gnus-use-long-file-name 'not-save)
570                        newsgroup
571                      (gnus-newsgroup-directory-form newsgroup))
572                    "/" (int-to-string (mail-header-number headers)))
573            gnus-article-save-directory)))
574     (if (and last-file
575              (string-equal (file-name-directory default)
576                            (file-name-directory last-file))
577              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
578         default
579       (or last-file default))))
580
581 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
582   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
583 If variable `gnus-use-long-file-name' is non-nil, it is
584 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
585   (or last-file
586       (expand-file-name
587        (if (gnus-use-long-file-name 'not-save)
588            (gnus-capitalize-newsgroup newsgroup)
589          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
590        gnus-article-save-directory)))
591
592 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
593   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
594 If variable `gnus-use-long-file-name' is non-nil, it is
595 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
596   (or last-file
597       (expand-file-name
598        (if (gnus-use-long-file-name 'not-save)
599            newsgroup
600          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
601        gnus-article-save-directory)))
602
603 \f
604 ;;;
605 ;;; Gnus article mode
606 ;;;
607
608 (put 'gnus-article-mode 'mode-class 'special)
609
610 (when t
611   (gnus-define-keys gnus-article-mode-map
612     " " gnus-article-goto-next-page
613     "\177" gnus-article-goto-prev-page
614     [delete] gnus-article-goto-prev-page
615     "\C-c^" gnus-article-refer-article
616     "h" gnus-article-show-summary
617     "s" gnus-article-show-summary
618     "\C-c\C-m" gnus-article-mail
619     "?" gnus-article-describe-briefly
620     gnus-mouse-2 gnus-article-push-button
621     "\r" gnus-article-press-button
622     "\t" gnus-article-next-button
623     "\M-\t" gnus-article-prev-button
624     "e" gnus-article-edit
625     "<" beginning-of-buffer
626     ">" end-of-buffer
627     "\C-c\C-i" gnus-info-find-node
628     "\C-c\C-b" gnus-bug
629
630     "\C-d" gnus-article-read-summary-keys
631     "\M-*" gnus-article-read-summary-keys
632     "\M-g" gnus-article-read-summary-keys)
633
634   (substitute-key-definition
635    'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
636
637 (defun gnus-article-make-menu-bar ()
638   (gnus-turn-off-edit-menu 'article)
639   (unless (boundp 'gnus-article-article-menu)
640     (easy-menu-define
641      gnus-article-article-menu gnus-article-mode-map ""
642      '("Article"
643        ["Scroll forwards" gnus-article-goto-next-page t]
644        ["Scroll backwards" gnus-article-goto-prev-page t]
645        ["Show summary" gnus-article-show-summary t]
646        ["Fetch Message-ID at point" gnus-article-refer-article t]
647        ["Mail to address at point" gnus-article-mail t]
648        ))
649
650     (easy-menu-define
651      gnus-article-treatment-menu gnus-article-mode-map ""
652      '("Treatment"
653        ["Hide headers" gnus-article-hide-headers t]
654        ["Hide signature" gnus-article-hide-signature t]
655        ["Hide citation" gnus-article-hide-citation t]
656        ["Treat overstrike" gnus-article-treat-overstrike t]
657        ["Remove carriage return" gnus-article-remove-cr t]
658        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
659        ))
660     (run-hooks 'gnus-article-menu-hook)))
661
662 (defun gnus-article-mode ()
663   "Major mode for displaying an article.
664
665 All normal editing commands are switched off.
666
667 The following commands are available in addition to all summary mode
668 commands:
669 \\<gnus-article-mode-map>
670 \\[gnus-article-next-page]\t Scroll the article one page forwards
671 \\[gnus-article-prev-page]\t Scroll the article one page backwards
672 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
673 \\[gnus-article-show-summary]\t Display the summary buffer
674 \\[gnus-article-mail]\t Send a reply to the address near point
675 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
676 \\[gnus-info-find-node]\t Go to the Gnus info node"
677   (interactive)
678   (when (and menu-bar-mode
679              (gnus-visual-p 'article-menu 'menu))
680     (gnus-article-make-menu-bar))
681   (kill-all-local-variables)
682   (gnus-simplify-mode-line)
683   (setq mode-name "Article")
684   (setq major-mode 'gnus-article-mode)
685   (make-local-variable 'minor-mode-alist)
686   (unless (assq 'gnus-show-mime minor-mode-alist)
687     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
688   (use-local-map gnus-article-mode-map)
689   (gnus-update-format-specifications nil 'article-mode)
690   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
691   (gnus-set-default-directory)
692   (buffer-disable-undo (current-buffer))
693   (setq buffer-read-only t)
694   (run-hooks 'gnus-article-mode-hook))
695
696 (defun gnus-article-setup-buffer ()
697   "Initialize the article buffer."
698   (let* ((name (if gnus-single-article-buffer "*Article*"
699                  (concat "*Article " gnus-newsgroup-name "*")))
700          (original
701           (progn (string-match "\\*Article" name)
702                  (concat " *Original Article"
703                          (substring name (match-end 0))))))
704     (setq gnus-article-buffer name)
705     (setq gnus-original-article-buffer original)
706     ;; This might be a variable local to the summary buffer.
707     (unless gnus-single-article-buffer
708       (save-excursion
709         (set-buffer gnus-summary-buffer)
710         (setq gnus-article-buffer name)
711         (setq gnus-original-article-buffer original)
712         (gnus-set-global-variables)))
713     ;; Init original article buffer.
714     (save-excursion
715       (set-buffer (get-buffer-create gnus-original-article-buffer))
716       (buffer-disable-undo (current-buffer))
717       (setq major-mode 'gnus-original-article-mode)
718       (gnus-add-current-to-buffer-list)
719       (make-local-variable 'gnus-original-article))
720     (if (get-buffer name)
721         (save-excursion
722           (set-buffer name)
723           (buffer-disable-undo (current-buffer))
724           (setq buffer-read-only t)
725           (gnus-add-current-to-buffer-list)
726           (unless (eq major-mode 'gnus-article-mode)
727             (gnus-article-mode))
728           (current-buffer))
729       (save-excursion
730         (set-buffer (get-buffer-create name))
731         (gnus-add-current-to-buffer-list)
732         (gnus-article-mode)
733         (make-local-variable 'gnus-summary-buffer)
734         (current-buffer)))))
735
736 ;; Set article window start at LINE, where LINE is the number of lines
737 ;; from the head of the article.
738 (defun gnus-article-set-window-start (&optional line)
739   (set-window-start
740    (get-buffer-window gnus-article-buffer t)
741    (save-excursion
742      (set-buffer gnus-article-buffer)
743      (goto-char (point-min))
744      (if (not line)
745          (point-min)
746        (gnus-message 6 "Moved to bookmark")
747        (search-forward "\n\n" nil t)
748        (forward-line line)
749        (point)))))
750
751 (defun gnus-article-prepare (article &optional all-headers header)
752   "Prepare ARTICLE in article mode buffer.
753 ARTICLE should either be an article number or a Message-ID.
754 If ARTICLE is an id, HEADER should be the article headers.
755 If ALL-HEADERS is non-nil, no headers are hidden."
756   (save-excursion
757     ;; Make sure we start in a summary buffer.
758     (unless (eq major-mode 'gnus-summary-mode)
759       (set-buffer gnus-summary-buffer))
760     (setq gnus-summary-buffer (current-buffer))
761     ;; Make sure the connection to the server is alive.
762     (unless (gnus-server-opened
763              (gnus-find-method-for-group gnus-newsgroup-name))
764       (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
765       (gnus-request-group gnus-newsgroup-name t))
766     (let* ((article (if header (mail-header-number header) article))
767            (summary-buffer (current-buffer))
768            (internal-hook gnus-article-internal-prepare-hook)
769            (group gnus-newsgroup-name)
770            result)
771       (save-excursion
772         (gnus-article-setup-buffer)
773         (set-buffer gnus-article-buffer)
774         ;; Deactivate active regions.
775         (when (and (boundp 'transient-mark-mode)
776                    transient-mark-mode)
777           (setq mark-active nil))
778         (if (not (setq result (let ((buffer-read-only nil))
779                                 (gnus-request-article-this-buffer
780                                  article group))))
781             ;; There is no such article.
782             (save-excursion
783               (when (and (numberp article)
784                          (not (memq article gnus-newsgroup-sparse)))
785                 (setq gnus-article-current
786                       (cons gnus-newsgroup-name article))
787                 (set-buffer gnus-summary-buffer)
788                 (setq gnus-current-article article)
789                 (gnus-summary-mark-article article gnus-canceled-mark))
790               (unless (memq article gnus-newsgroup-sparse)
791                 (gnus-error
792                  1 "No such article (may have expired or been canceled)")))
793           (if (or (eq result 'pseudo) (eq result 'nneething))
794               (progn
795                 (save-excursion
796                   (set-buffer summary-buffer)
797                   (setq gnus-last-article gnus-current-article
798                         gnus-newsgroup-history (cons gnus-current-article
799                                                      gnus-newsgroup-history)
800                         gnus-current-article 0
801                         gnus-current-headers nil
802                         gnus-article-current nil)
803                   (if (eq result 'nneething)
804                       (gnus-configure-windows 'summary)
805                     (gnus-configure-windows 'article))
806                   (gnus-set-global-variables))
807                 (gnus-set-mode-line 'article))
808             ;; The result from the `request' was an actual article -
809             ;; or at least some text that is now displayed in the
810             ;; article buffer.
811             (when (and (numberp article)
812                        (not (eq article gnus-current-article)))
813               ;; Seems like a new article has been selected.
814               ;; `gnus-current-article' must be an article number.
815               (save-excursion
816                 (set-buffer summary-buffer)
817                 (setq gnus-last-article gnus-current-article
818                       gnus-newsgroup-history (cons gnus-current-article
819                                                    gnus-newsgroup-history)
820                       gnus-current-article article
821                       gnus-current-headers
822                       (gnus-summary-article-header gnus-current-article)
823                       gnus-article-current
824                       (cons gnus-newsgroup-name gnus-current-article))
825                 (unless (vectorp gnus-current-headers)
826                   (setq gnus-current-headers nil))
827                 (gnus-summary-show-thread)
828                 (run-hooks 'gnus-mark-article-hook)
829                 (gnus-set-mode-line 'summary)
830                 (when (gnus-visual-p 'article-highlight 'highlight)
831                   (run-hooks 'gnus-visual-mark-article-hook))
832                 ;; Set the global newsgroup variables here.
833                 ;; Suggested by Jim Sisolak
834                 ;; <sisolak@trans4.neep.wisc.edu>.
835                 (gnus-set-global-variables)
836                 (setq gnus-have-all-headers
837                       (or all-headers gnus-show-all-headers))
838                 (and gnus-use-cache
839                      (vectorp (gnus-summary-article-header article))
840                      (gnus-cache-possibly-enter-article
841                       group article
842                       (gnus-summary-article-header article)
843                       (memq article gnus-newsgroup-marked)
844                       (memq article gnus-newsgroup-dormant)
845                       (memq article gnus-newsgroup-unreads)))))
846             (when (or (numberp article)
847                       (stringp article))
848               ;; Hooks for getting information from the article.
849               ;; This hook must be called before being narrowed.
850               (let (buffer-read-only)
851                 (run-hooks 'internal-hook)
852                 (run-hooks 'gnus-article-prepare-hook)
853                 ;; Decode MIME message.
854                 (when gnus-show-mime
855                   (if (or (not gnus-strict-mime)
856                           (gnus-fetch-field "Mime-Version"))
857                       (funcall gnus-show-mime-method)
858                     (funcall gnus-decode-encoded-word-method)))
859                 ;; Perform the article display hooks.
860                 (run-hooks 'gnus-article-display-hook))
861               ;; Do page break.
862               (goto-char (point-min))
863               (when gnus-break-pages
864                 (gnus-narrow-to-page)))
865             (gnus-set-mode-line 'article)
866             (gnus-configure-windows 'article)
867             (goto-char (point-min))
868             t))))))
869
870 (defun gnus-article-wash-status ()
871   "Return a string which display status of article washing."
872   (save-excursion
873     (set-buffer gnus-article-buffer)
874     (let ((cite (article-hidden-text-p 'cite))
875           (headers (article-hidden-text-p 'headers))
876           (boring (article-hidden-text-p 'boring-headers))
877           (pgp (article-hidden-text-p 'pgp))
878           (pem (article-hidden-text-p 'pem))
879           (signature (article-hidden-text-p 'signature))
880           (overstrike (article-hidden-text-p 'overstrike))
881           (emphasis (article-hidden-text-p 'emphasis))
882           (mime gnus-show-mime))
883       (format "%c%c%c%c%c%c%c"
884               (if cite ?c ? )
885               (if (or headers boring) ?h ? )
886               (if (or pgp pem) ?p ? )
887               (if signature ?s ? )
888               (if overstrike ?o ? )
889               (if mime ?m ? )
890               (if emphasis ?e ? )))))
891
892 (defun gnus-article-hide-headers-if-wanted ()
893   "Hide unwanted headers if `gnus-have-all-headers' is nil.
894 Provided for backwards compatibility."
895   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
896       gnus-inhibit-hiding
897       (gnus-article-hide-headers)))
898
899 ;;; Article savers.
900
901 (defun gnus-output-to-rmail (file-name)
902   "Append the current article to an Rmail file named FILE-NAME."
903   (require 'rmail)
904   ;; Most of these codes are borrowed from rmailout.el.
905   (setq file-name (expand-file-name file-name))
906   (setq rmail-default-rmail-file file-name)
907   (let ((artbuf (current-buffer))
908         (tmpbuf (get-buffer-create " *Gnus-output*")))
909     (save-excursion
910       (or (get-file-buffer file-name)
911           (file-exists-p file-name)
912           (if (gnus-yes-or-no-p
913                (concat "\"" file-name "\" does not exist, create it? "))
914               (let ((file-buffer (create-file-buffer file-name)))
915                 (save-excursion
916                   (set-buffer file-buffer)
917                   (rmail-insert-rmail-file-header)
918                   (let ((require-final-newline nil))
919                     (gnus-write-buffer file-name)))
920                 (kill-buffer file-buffer))
921             (error "Output file does not exist")))
922       (set-buffer tmpbuf)
923       (buffer-disable-undo (current-buffer))
924       (erase-buffer)
925       (insert-buffer-substring artbuf)
926       (gnus-convert-article-to-rmail)
927       ;; Decide whether to append to a file or to an Emacs buffer.
928       (let ((outbuf (get-file-buffer file-name)))
929         (if (not outbuf)
930             (append-to-file (point-min) (point-max) file-name)
931           ;; File has been visited, in buffer OUTBUF.
932           (set-buffer outbuf)
933           (let ((buffer-read-only nil)
934                 (msg (and (boundp 'rmail-current-message)
935                           (symbol-value 'rmail-current-message))))
936             ;; If MSG is non-nil, buffer is in RMAIL mode.
937             (when msg
938               (widen)
939               (narrow-to-region (point-max) (point-max)))
940             (insert-buffer-substring tmpbuf)
941             (when msg
942               (goto-char (point-min))
943               (widen)
944               (search-backward "\^_")
945               (narrow-to-region (point) (point-max))
946               (goto-char (1+ (point-min)))
947               (rmail-count-new-messages t)
948               (rmail-show-message msg))))))
949     (kill-buffer tmpbuf)))
950
951 (defun gnus-output-to-file (file-name)
952   "Append the current article to a file named FILE-NAME."
953   (let ((artbuf (current-buffer)))
954     (nnheader-temp-write nil
955       (insert-buffer-substring artbuf)
956       ;; Append newline at end of the buffer as separator, and then
957       ;; save it to file.
958       (goto-char (point-max))
959       (insert "\n")
960       (append-to-file (point-min) (point-max) file-name))))
961
962 (defun gnus-convert-article-to-rmail ()
963   "Convert article in current buffer to Rmail message format."
964   (let ((buffer-read-only nil))
965     ;; Convert article directly into Babyl format.
966     ;; Suggested by Rob Austein <sra@lcs.mit.edu>
967     (goto-char (point-min))
968     (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
969     (while (search-forward "\n\^_" nil t) ;single char
970       (replace-match "\n^_" t t))       ;2 chars: "^" and "_"
971     (goto-char (point-max))
972     (insert "\^_")))
973
974 (defun gnus-narrow-to-page (&optional arg)
975   "Narrow the article buffer to a page.
976 If given a numerical ARG, move forward ARG pages."
977   (interactive "P")
978   (setq arg (if arg (prefix-numeric-value arg) 0))
979   (save-excursion
980     (set-buffer gnus-article-buffer)
981     (goto-char (point-min))
982     (widen)
983     ;; Remove any old next/prev buttons.
984     (when (gnus-visual-p 'page-marker)
985       (let ((buffer-read-only nil))
986         (gnus-remove-text-with-property 'gnus-prev)
987         (gnus-remove-text-with-property 'gnus-next)))
988     (when
989         (cond ((< arg 0)
990                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
991               ((> arg 0)
992                (re-search-forward page-delimiter nil 'move arg)))
993       (goto-char (match-end 0)))
994     (narrow-to-region
995      (point)
996      (if (re-search-forward page-delimiter nil 'move)
997          (match-beginning 0)
998        (point)))
999     (when (and (gnus-visual-p 'page-marker)
1000                (not (= (point-min) 1)))
1001       (save-excursion
1002         (goto-char (point-min))
1003         (gnus-insert-prev-page-button)))
1004     (when (and (gnus-visual-p 'page-marker)
1005                (< (+ (point-max) 2) (buffer-size)))
1006       (save-excursion
1007         (goto-char (point-max))
1008         (gnus-insert-next-page-button)))))
1009
1010 ;; Article mode commands
1011
1012 (defun gnus-article-goto-next-page ()
1013   "Show the next page of the article."
1014   (interactive)
1015   (when (gnus-article-next-page)
1016     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
1017
1018 (defun gnus-article-goto-prev-page ()
1019   "Show the next page of the article."
1020   (interactive)
1021   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
1022     (gnus-article-prev-page nil)))
1023
1024 (defun gnus-article-next-page (&optional lines)
1025   "Show the next page of the current article.
1026 If end of article, return non-nil.  Otherwise return nil.
1027 Argument LINES specifies lines to be scrolled up."
1028   (interactive "p")
1029   (move-to-window-line -1)
1030   (if (save-excursion
1031         (end-of-line)
1032         (and (pos-visible-in-window-p)  ;Not continuation line.
1033              (eobp)))
1034       ;; Nothing in this page.
1035       (if (or (not gnus-break-pages)
1036               (save-excursion
1037                 (save-restriction
1038                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
1039           t                             ;Nothing more.
1040         (gnus-narrow-to-page 1)         ;Go to next page.
1041         nil)
1042     ;; More in this page.
1043     (condition-case ()
1044         (scroll-up lines)
1045       (end-of-buffer
1046        ;; Long lines may cause an end-of-buffer error.
1047        (goto-char (point-max))))
1048     (move-to-window-line 0)
1049     nil))
1050
1051 (defun gnus-article-prev-page (&optional lines)
1052   "Show previous page of current article.
1053 Argument LINES specifies lines to be scrolled down."
1054   (interactive "p")
1055   (move-to-window-line 0)
1056   (if (and gnus-break-pages
1057            (bobp)
1058            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
1059       (progn
1060         (gnus-narrow-to-page -1)        ;Go to previous page.
1061         (goto-char (point-max))
1062         (recenter -1))
1063     (prog1
1064         (condition-case ()
1065             (scroll-down lines)
1066           (error nil))
1067       (move-to-window-line 0))))
1068
1069 (defun gnus-article-refer-article ()
1070   "Read article specified by message-id around point."
1071   (interactive)
1072   (let ((point (point)))
1073     (search-forward ">" nil t)          ;Move point to end of "<....>".
1074     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
1075         (let ((message-id (match-string 1)))
1076           (goto-char point)
1077           (set-buffer gnus-summary-buffer)
1078           (gnus-summary-refer-article message-id))
1079       (goto-char (point))
1080       (error "No references around point"))))
1081
1082 (defun gnus-article-show-summary ()
1083   "Reconfigure windows to show summary buffer."
1084   (interactive)
1085   (gnus-configure-windows 'article)
1086   (gnus-summary-goto-subject gnus-current-article))
1087
1088 (defun gnus-article-describe-briefly ()
1089   "Describe article mode commands briefly."
1090   (interactive)
1091   (gnus-message 6
1092                 (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")))
1093
1094 (defun gnus-article-summary-command ()
1095   "Execute the last keystroke in the summary buffer."
1096   (interactive)
1097   (let ((obuf (current-buffer))
1098         (owin (current-window-configuration))
1099         func)
1100     (switch-to-buffer gnus-summary-buffer 'norecord)
1101     (setq func (lookup-key (current-local-map) (this-command-keys)))
1102     (call-interactively func)
1103     (set-buffer obuf)
1104     (set-window-configuration owin)
1105     (set-window-point (get-buffer-window (current-buffer)) (point))))
1106
1107 (defun gnus-article-summary-command-nosave ()
1108   "Execute the last keystroke in the summary buffer."
1109   (interactive)
1110   (let (func)
1111     (pop-to-buffer gnus-summary-buffer 'norecord)
1112     (setq func (lookup-key (current-local-map) (this-command-keys)))
1113     (call-interactively func)))
1114
1115 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
1116   "Read a summary buffer key sequence and execute it from the article buffer."
1117   (interactive "P")
1118   (let ((nosaves
1119          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
1120            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
1121            "=" "^" "\M-^" "|"))
1122         (nosave-but-article
1123          '("A\r"))
1124         (nosave-in-article
1125          '("\C-d"))
1126         keys)
1127     (save-excursion
1128       (set-buffer gnus-summary-buffer)
1129       (push (or key last-command-event) unread-command-events)
1130       (setq keys (read-key-sequence nil)))
1131     (message "")
1132
1133     (if (or (member keys nosaves)
1134             (member keys nosave-but-article)
1135             (member keys nosave-in-article))
1136         (let (func)
1137           (save-window-excursion
1138             (pop-to-buffer gnus-summary-buffer 'norecord)
1139             (setq func (lookup-key (current-local-map) keys)))
1140           (if (not func)
1141               (ding)
1142             (unless (member keys nosave-in-article)
1143               (set-buffer gnus-summary-buffer))
1144             (call-interactively func))
1145           (when (member keys nosave-but-article)
1146             (pop-to-buffer gnus-article-buffer 'norecord)))
1147       ;; These commands should restore window configuration.
1148       (let ((obuf (current-buffer))
1149             (owin (current-window-configuration))
1150             (opoint (point))
1151             func in-buffer)
1152         (if not-restore-window
1153             (pop-to-buffer gnus-summary-buffer 'norecord)
1154           (switch-to-buffer gnus-summary-buffer 'norecord))
1155         (setq in-buffer (current-buffer))
1156         (if (setq func (lookup-key (current-local-map) keys))
1157             (call-interactively func)
1158           (ding))
1159         (when (eq in-buffer (current-buffer))
1160           (set-buffer obuf)
1161           (unless not-restore-window
1162             (set-window-configuration owin))
1163           (set-window-point (get-buffer-window (current-buffer)) opoint))))))
1164
1165 (defun gnus-article-hide (&optional arg force)
1166   "Hide all the gruft in the current article.
1167 This means that PGP stuff, signatures, cited text and (some)
1168 headers will be hidden.
1169 If given a prefix, show the hidden text instead."
1170   (interactive (list current-prefix-arg 'force))
1171   (gnus-article-hide-headers arg)
1172   (gnus-article-hide-pgp arg)
1173   (gnus-article-hide-citation-maybe arg force)
1174   (gnus-article-hide-signature arg))
1175
1176 (defun gnus-article-maybe-highlight ()
1177   "Do some article highlighting if `article-visual' is non-nil."
1178   (when (gnus-visual-p 'article-highlight 'highlight)
1179     (gnus-article-highlight-some)))
1180
1181 (defun gnus-request-article-this-buffer (article group)
1182   "Get an article and insert it into this buffer."
1183   (let (do-update-line)
1184     (prog1
1185         (save-excursion
1186           (erase-buffer)
1187           (gnus-kill-all-overlays)
1188           (setq group (or group gnus-newsgroup-name))
1189
1190           ;; Open server if it has closed.
1191           (gnus-check-server (gnus-find-method-for-group group))
1192
1193           ;; Using `gnus-request-article' directly will insert the article into
1194           ;; `nntp-server-buffer' - so we'll save some time by not having to
1195           ;; copy it from the server buffer into the article buffer.
1196
1197           ;; We only request an article by message-id when we do not have the
1198           ;; headers for it, so we'll have to get those.
1199           (when (and (not gnus-doing-request-article)
1200                      (stringp article))
1201             (let ((gnus-override-method gnus-refer-article-method))
1202               (gnus-read-header article)))
1203
1204           ;; If the article number is negative, that means that this article
1205           ;; doesn't belong in this newsgroup (possibly), so we find its
1206           ;; message-id and request it by id instead of number.
1207           (when (and (numberp article)
1208                      gnus-summary-buffer
1209                      (get-buffer gnus-summary-buffer)
1210                      (buffer-name (get-buffer gnus-summary-buffer)))
1211             (save-excursion
1212               (set-buffer gnus-summary-buffer)
1213               (let ((header (gnus-summary-article-header article)))
1214                 (when (< article 0)
1215                   (cond 
1216                    ((memq article gnus-newsgroup-sparse)
1217                     ;; This is a sparse gap article.
1218                     (setq do-update-line article)
1219                     (setq article (mail-header-id header))
1220                     (let ((gnus-override-method gnus-refer-article-method))
1221                       (gnus-read-header article))
1222                     (setq gnus-newsgroup-sparse
1223                           (delq article gnus-newsgroup-sparse)))
1224                    ((vectorp header)
1225                     ;; It's a real article.
1226                     (setq article (mail-header-id header)))
1227                    (t
1228                     ;; It is an extracted pseudo-article.
1229                     (setq article 'pseudo)
1230                     (gnus-request-pseudo-article header))))
1231                 
1232                 (let ((method (gnus-find-method-for-group 
1233                                gnus-newsgroup-name)))
1234                   (if (not (eq (car method) 'nneething))
1235                       ()
1236                     (let ((dir (concat (file-name-as-directory (nth 1 method))
1237                                        (mail-header-subject header))))
1238                       (when (file-directory-p dir)
1239                         (setq article 'nneething)
1240                         (gnus-group-enter-directory dir))))))))
1241
1242           (cond
1243            ;; Refuse to select canceled articles.
1244            ((and (numberp article)
1245                  gnus-summary-buffer
1246                  (get-buffer gnus-summary-buffer)
1247                  (buffer-name (get-buffer gnus-summary-buffer))
1248                  (eq (cdr (save-excursion
1249                             (set-buffer gnus-summary-buffer)
1250                             (assq article gnus-newsgroup-reads)))
1251                      gnus-canceled-mark))
1252             nil)
1253            ;; We first check `gnus-original-article-buffer'.
1254            ((and (get-buffer gnus-original-article-buffer)
1255                  (numberp article)
1256                  (save-excursion
1257                    (set-buffer gnus-original-article-buffer)
1258                    (and (equal (car gnus-original-article) group)
1259                         (eq (cdr gnus-original-article) article))))
1260             (insert-buffer-substring gnus-original-article-buffer)
1261             'article)
1262            ;; Check the backlog.
1263            ((and gnus-keep-backlog
1264                  (gnus-backlog-request-article group article (current-buffer)))
1265             'article)
1266            ;; Check asynchronous pre-fetch.
1267            ((gnus-async-request-fetched-article group article (current-buffer))
1268             (gnus-async-prefetch-next group article gnus-summary-buffer)
1269             'article)
1270            ;; Check the cache.
1271            ((and gnus-use-cache
1272                  (numberp article)
1273                  (gnus-cache-request-article article group))
1274             'article)
1275            ;; Get the article and put into the article buffer.
1276            ((or (stringp article) (numberp article))
1277             (let ((gnus-override-method
1278                    (and (stringp article) gnus-refer-article-method))
1279                   (buffer-read-only nil))
1280               (erase-buffer)
1281               (gnus-kill-all-overlays)
1282               (when (gnus-request-article article group (current-buffer))
1283                 (when (numberp article)
1284                   (gnus-async-prefetch-next group article gnus-summary-buffer)
1285                   (when gnus-keep-backlog
1286                     (gnus-backlog-enter-article 
1287                      group article (current-buffer))))
1288                 'article)))
1289            ;; It was a pseudo.
1290            (t article)))
1291
1292       ;; Take the article from the original article buffer
1293       ;; and place it in the buffer it's supposed to be in.
1294       (when (and (get-buffer gnus-article-buffer)
1295                  ;;(numberp article)
1296                  (equal (buffer-name (current-buffer))
1297                         (buffer-name (get-buffer gnus-article-buffer))))
1298         (save-excursion
1299           (if (get-buffer gnus-original-article-buffer)
1300               (set-buffer (get-buffer gnus-original-article-buffer))
1301             (set-buffer (get-buffer-create gnus-original-article-buffer))
1302             (buffer-disable-undo (current-buffer))
1303             (setq major-mode 'gnus-original-article-mode)
1304             (setq buffer-read-only t)
1305             (gnus-add-current-to-buffer-list))
1306           (let (buffer-read-only)
1307             (erase-buffer)
1308             (insert-buffer-substring gnus-article-buffer))
1309           (setq gnus-original-article (cons group article))))
1310     
1311       ;; Update sparse articles.
1312       (when (and do-update-line
1313                  (or (numberp article)
1314                      (stringp article)))
1315         (let ((buf (current-buffer)))
1316           (set-buffer gnus-summary-buffer)
1317           (gnus-summary-update-article do-update-line)
1318           (gnus-summary-goto-subject do-update-line nil t)
1319           (set-window-point (get-buffer-window (current-buffer) t)
1320                             (point))
1321           (set-buffer buf))))))
1322
1323 (defun gnus-article-date-ut (&optional type highlight)
1324   "Convert DATE date to universal time in the current article.
1325 If TYPE is `local', convert to local time; if it is `lapsed', output
1326 how much time has lapsed since DATE."
1327   (interactive (list 'ut t))
1328   (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1329     (save-excursion
1330       (set-buffer gnus-article-buffer)
1331       (article-date-ut type highlight headers))))
1332
1333 ;;;
1334 ;;; Article editing
1335 ;;;
1336
1337 (defcustom gnus-article-edit-mode-hook nil
1338   "Hook run in article edit mode buffers."
1339   :group 'article
1340   :type 'hook)
1341
1342 (defvar gnus-article-edit-done-function nil)
1343
1344 (defvar gnus-article-edit-mode-map nil)
1345
1346 (unless gnus-article-edit-mode-map 
1347   (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1348
1349   (gnus-define-keys gnus-article-edit-mode-map
1350     "\C-c\C-c" gnus-article-edit-done
1351     "\C-c\C-k" gnus-article-edit-exit)
1352
1353   (gnus-define-keys (gnus-article-edit-wash-map
1354                      "\C-c\C-w" gnus-article-edit-mode-map)
1355     "f" gnus-article-edit-full-stops))
1356
1357 (defun gnus-article-edit-mode ()
1358   "Major mode for editing articles.
1359 This is an extended text-mode.
1360
1361 \\{gnus-article-edit-mode-map}"
1362   (interactive)
1363   (kill-all-local-variables)
1364   (setq major-mode 'gnus-article-edit-mode)
1365   (setq mode-name "Article Edit")
1366   (use-local-map gnus-article-edit-mode-map)
1367   (make-local-variable 'gnus-article-edit-done-function)
1368   (make-local-variable 'gnus-prev-winconf)
1369   (setq buffer-read-only nil)
1370   (buffer-enable-undo)
1371   (widen)
1372   (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1373
1374 (defun gnus-article-edit (&optional force)
1375   "Edit the current article.
1376 This will have permanent effect only in mail groups.
1377 If FORCE is non-nil, allow editing of articles even in read-only
1378 groups."
1379   (interactive "P")
1380   (when (and (not force)
1381              (gnus-group-read-only-p))
1382     (error "The current newsgroup does not support article editing."))
1383   (gnus-article-edit-article
1384    `(lambda ()
1385       (gnus-summary-edit-article-done
1386        ,(or (mail-header-references gnus-current-headers) "")
1387        ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1388
1389 (defun gnus-article-edit-article (exit-func)
1390   "Start editing the contents of the current article buffer."
1391   (let ((winconf (current-window-configuration)))
1392     (set-buffer gnus-article-buffer)
1393     (gnus-article-edit-mode)
1394     (set-text-properties (point-min) (point-max) nil)
1395     (gnus-configure-windows 'edit-article)
1396     (setq gnus-article-edit-done-function exit-func)
1397     (setq gnus-prev-winconf winconf)
1398     (gnus-message 6 "C-c C-c to end edits")))
1399
1400 (defun gnus-article-edit-done ()
1401   "Update the article edits and exit."
1402   (interactive)
1403   (let ((func gnus-article-edit-done-function)
1404         (buf (current-buffer))
1405         (start (window-start)))
1406     (gnus-article-edit-exit)
1407     (save-excursion
1408       (set-buffer buf)
1409       (let ((buffer-read-only nil))
1410         (funcall func)))
1411     (set-buffer buf)
1412     (set-window-start (get-buffer-window buf) start)
1413     (set-window-point (get-buffer-window buf) (point))))
1414
1415 (defun gnus-article-edit-exit ()
1416   "Exit the article editing without updating."
1417   (interactive)
1418   ;; We remove all text props from the article buffer.
1419   (let ((buf (format "%s" (buffer-string)))
1420         (curbuf (current-buffer))
1421         (p (point))
1422         (window-start (window-start)))
1423     (erase-buffer)
1424     (insert buf)
1425     (let ((winconf gnus-prev-winconf))
1426       (gnus-article-mode)
1427       ;; The cache and backlog have to be flushed somewhat.
1428       (when gnus-use-cache
1429         (gnus-cache-update-article      
1430          (car gnus-article-current) (cdr gnus-article-current)))
1431       (when gnus-keep-backlog
1432         (gnus-backlog-remove-article 
1433          (car gnus-article-current) (cdr gnus-article-current)))
1434       ;; Flush original article as well.
1435       (save-excursion
1436         (when (get-buffer gnus-original-article-buffer)
1437           (set-buffer gnus-original-article-buffer)
1438           (setq gnus-original-article nil)))
1439       (set-window-configuration winconf)
1440       ;; Tippy-toe some to make sure that point remains where it was.
1441       (let ((buf (current-buffer)))
1442         (set-buffer curbuf)
1443         (set-window-start (get-buffer-window (current-buffer)) window-start)
1444         (goto-char p)
1445         (set-buffer buf)))))
1446       
1447 (defun gnus-article-edit-full-stops ()
1448   "Interactively repair spacing at end of sentences."
1449   (interactive)
1450   (save-excursion
1451     (goto-char (point-min))
1452     (search-forward-regexp "^$" nil t)
1453     (let ((case-fold-search nil))
1454       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1455
1456 ;;; 
1457 ;;; Article highlights
1458 ;;;
1459
1460 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1461
1462 ;;; Internal Variables:
1463
1464 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-\\wa-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]*[-\\wa-zA-Z0-9_=#$@~`%&*+|\\/]"
1465   "Regular expression that matches URLs."
1466   :group 'article
1467   :type 'regexp)
1468
1469 (defcustom gnus-button-alist 
1470   `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 
1471      t gnus-button-message-id 3)
1472     ("\\(<?\\(url: ?\\)?news://\\([^>\n\t ]*\\)>?\\)" 1 t
1473      gnus-button-fetch-group 3)
1474     ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1475      gnus-button-message-id 3)
1476     ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-button-reply 2)
1477     ;; This is how URLs _should_ be embedded in text...
1478     ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1479     ;; Next regexp stolen from highlight-headers.el.
1480     ;; Modified by Vladimir Alexiev.
1481     (,gnus-button-url-regexp 0 t gnus-button-url 0))
1482   "Alist of regexps matching buttons in article bodies.
1483
1484 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1485 REGEXP: is the string matching text around the button,
1486 BUTTON: is the number of the regexp grouping actually matching the button,
1487 FORM: is a lisp expression which must eval to true for the button to
1488 be added, 
1489 CALLBACK: is the function to call when the user push this button, and each
1490 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1491
1492 CALLBACK can also be a variable, in that case the value of that
1493 variable it the real callback function."
1494   :group 'article
1495   :type '(repeat (list regexp 
1496                        (integer :tag "Button")
1497                        (sexp :tag "Form")
1498                        (function :tag "Callback")
1499                        (repeat :tag "Par"
1500                                :inline t
1501                                (integer :tag "Regexp group")))))
1502
1503 (defcustom gnus-header-button-alist 
1504   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1505      0 t gnus-button-message-id 0)
1506     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1507     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+" 
1508      0 t gnus-button-mailto 0)
1509     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1510     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1511     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1512      gnus-button-message-id 3))
1513   "Alist of headers and regexps to match buttons in article heads.
1514
1515 This alist is very similar to `gnus-button-alist', except that each
1516 alist has an additional HEADER element first in each entry:
1517
1518 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1519
1520 HEADER is a regexp to match a header.  For a fuller explanation, see
1521 `gnus-button-alist'."
1522   :group 'article
1523   :type '(repeat (list (regexp :tag "Header")
1524                        regexp 
1525                        (integer :tag "Button")
1526                        (sexp :tag "Form")
1527                        (function :tag "Callback")
1528                        (repeat :tag "Par"
1529                                :inline t
1530                                (integer :tag "Regexp group")))))
1531
1532 (defvar gnus-button-regexp nil)
1533 (defvar gnus-button-marker-list nil)
1534 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1535
1536 (defvar gnus-button-last nil)
1537 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1538
1539 ;;; Commands:
1540
1541 (defun gnus-article-push-button (event)
1542   "Check text under the mouse pointer for a callback function.
1543 If the text under the mouse pointer has a `gnus-callback' property,
1544 call it with the value of the `gnus-data' text property."
1545   (interactive "e")
1546   (set-buffer (window-buffer (posn-window (event-start event))))
1547   (let* ((pos (posn-point (event-start event)))
1548          (data (get-text-property pos 'gnus-data))
1549          (fun (get-text-property pos 'gnus-callback)))
1550     (when fun
1551       (funcall fun data))))
1552
1553 (defun gnus-article-press-button ()
1554   "Check text at point for a callback function.
1555 If the text at point has a `gnus-callback' property,
1556 call it with the value of the `gnus-data' text property."
1557   (interactive)
1558   (let* ((data (get-text-property (point) 'gnus-data))
1559          (fun (get-text-property (point) 'gnus-callback)))
1560     (when fun
1561       (funcall fun data))))
1562
1563 (defun gnus-article-prev-button (n)
1564   "Move point to N buttons backward.
1565 If N is negative, move forward instead."
1566   (interactive "p")
1567   (gnus-article-next-button (- n)))
1568
1569 (defun gnus-article-next-button (n)
1570   "Move point to N buttons forward.
1571 If N is negative, move backward instead."
1572   (interactive "p")
1573   (let ((function (if (< n 0) 'previous-single-property-change
1574                     'next-single-property-change))
1575         (inhibit-point-motion-hooks t)
1576         (backward (< n 0))
1577         (limit (if (< n 0) (point-min) (point-max))))
1578     (setq n (abs n))
1579     (while (and (not (= limit (point)))
1580                 (> n 0))
1581       ;; Skip past the current button.
1582       (when (get-text-property (point) 'gnus-callback)
1583         (goto-char (funcall function (point) 'gnus-callback nil limit)))
1584       ;; Go to the next (or previous) button.
1585       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1586       ;; Put point at the start of the button.
1587       (when (and backward (not (get-text-property (point) 'gnus-callback)))
1588         (goto-char (funcall function (point) 'gnus-callback nil limit)))
1589       ;; Skip past intangible buttons.
1590       (when (get-text-property (point) 'intangible)
1591         (incf n))
1592       (decf n))
1593     (unless (zerop n)
1594       (gnus-message 5 "No more buttons"))
1595     n))
1596
1597 (defun gnus-article-highlight (&optional force)
1598   "Highlight current article.
1599 This function calls `gnus-article-highlight-headers',
1600 `gnus-article-highlight-citation', 
1601 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1602 do the highlighting.  See the documentation for those functions."
1603   (interactive (list 'force))
1604   (gnus-article-highlight-headers)
1605   (gnus-article-highlight-citation force)
1606   (gnus-article-highlight-signature)
1607   (gnus-article-add-buttons force)
1608   (gnus-article-add-buttons-to-head))
1609
1610 (defun gnus-article-highlight-some (&optional force)
1611   "Highlight current article.
1612 This function calls `gnus-article-highlight-headers',
1613 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1614 do the highlighting.  See the documentation for those functions."
1615   (interactive (list 'force))
1616   (gnus-article-highlight-headers)
1617   (gnus-article-highlight-signature)
1618   (gnus-article-add-buttons))
1619
1620 (defun gnus-article-highlight-headers ()
1621   "Highlight article headers as specified by `gnus-header-face-alist'."
1622   (interactive)
1623   (save-excursion
1624     (set-buffer gnus-article-buffer)
1625     (save-restriction
1626       (let ((alist gnus-header-face-alist)
1627             (buffer-read-only nil)
1628             (case-fold-search t)
1629             (inhibit-point-motion-hooks t)
1630             entry regexp header-face field-face from hpoints fpoints)
1631         (goto-char (point-min))
1632         (when (search-forward "\n\n" nil t)
1633           (narrow-to-region (1- (point)) (point-min))
1634           (while (setq entry (pop alist))
1635             (goto-char (point-min))
1636             (setq regexp (concat "^\\("
1637                                  (if (string-equal "" (nth 0 entry))
1638                                      "[^\t ]"
1639                                    (nth 0 entry))
1640                                  "\\)")
1641                   header-face (nth 1 entry)
1642                   field-face (nth 2 entry))
1643             (while (and (re-search-forward regexp nil t)
1644                         (not (eobp)))
1645               (beginning-of-line)
1646               (setq from (point))
1647               (unless (search-forward ":" nil t)
1648                 (forward-char 1))
1649               (when (and header-face
1650                          (not (memq (point) hpoints)))
1651                 (push (point) hpoints)
1652                 (gnus-put-text-property from (point) 'face header-face))
1653               (when (and field-face
1654                          (not (memq (setq from (point)) fpoints)))
1655                 (push from fpoints)
1656                 (if (re-search-forward "^[^ \t]" nil t)
1657                     (forward-char -2)
1658                   (goto-char (point-max)))
1659                 (gnus-put-text-property from (point) 'face field-face)))))))))
1660
1661 (defun gnus-article-highlight-signature ()
1662   "Highlight the signature in an article.
1663 It does this by highlighting everything after
1664 `gnus-signature-separator' using `gnus-signature-face'." 
1665   (interactive)
1666   (save-excursion
1667     (set-buffer gnus-article-buffer)
1668     (let ((buffer-read-only nil)
1669           (inhibit-point-motion-hooks t))
1670       (save-restriction
1671         (when (and gnus-signature-face
1672                    (article-narrow-to-signature))
1673           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1674                             'face gnus-signature-face)
1675           (widen)
1676           (article-search-signature)
1677           (let ((start (match-beginning 0))
1678                 (end (set-marker (make-marker) (1+ (match-end 0)))))
1679             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1680                                      end)))))))
1681
1682 (defun gnus-article-add-buttons (&optional force)
1683   "Find external references in the article and make buttons of them.
1684 \"External references\" are things like Message-IDs and URLs, as
1685 specified by `gnus-button-alist'."
1686   (interactive (list 'force))
1687   (save-excursion
1688     (set-buffer gnus-article-buffer)
1689     ;; Remove all old markers.
1690     (while gnus-button-marker-list
1691       (set-marker (pop gnus-button-marker-list) nil))
1692     (let ((buffer-read-only nil)
1693           (inhibit-point-motion-hooks t)
1694           (case-fold-search t)
1695           (alist gnus-button-alist)
1696           beg entry regexp)
1697       (goto-char (point-min))
1698       ;; We skip the headers.
1699       (unless (search-forward "\n\n" nil t)
1700         (goto-char (point-max)))
1701       (setq beg (point))
1702       (while (setq entry (pop alist))
1703         (setq regexp (car entry))
1704         (goto-char beg)
1705         (while (re-search-forward regexp nil t)
1706           (let* ((start (and entry (match-beginning (nth 1 entry))))
1707                  (end (and entry (match-end (nth 1 entry))))
1708                  (from (match-beginning 0)))
1709             (when (or (eq t (nth 1 entry))
1710                       (eval (nth 1 entry)))
1711               ;; That optional form returned non-nil, so we add the
1712               ;; button. 
1713               (gnus-article-add-button 
1714                start end 'gnus-button-push 
1715                (car (push (set-marker (make-marker) from)
1716                           gnus-button-marker-list))))))))))
1717
1718 ;; Add buttons to the head of an article.
1719 (defun gnus-article-add-buttons-to-head ()
1720   "Add buttons to the head of the article."
1721   (interactive)
1722   (save-excursion
1723     (set-buffer gnus-article-buffer)
1724     (let ((buffer-read-only nil)
1725           (inhibit-point-motion-hooks t)
1726           (case-fold-search t)
1727           (alist gnus-header-button-alist)
1728           entry beg end)
1729       (nnheader-narrow-to-headers)
1730       (while alist
1731         ;; Each alist entry.
1732         (setq entry (car alist)
1733               alist (cdr alist))
1734         (goto-char (point-min))
1735         (while (re-search-forward (car entry) nil t)
1736           ;; Each header matching the entry.
1737           (setq beg (match-beginning 0))
1738           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1739                              (match-beginning 0))
1740                         (point-max)))
1741           (goto-char beg)
1742           (while (re-search-forward (nth 1 entry) end t)
1743             ;; Each match within a header.
1744             (let* ((entry (cdr entry))
1745                    (start (match-beginning (nth 1 entry)))
1746                    (end (match-end (nth 1 entry)))
1747                    (form (nth 2 entry)))
1748               (goto-char (match-end 0))
1749               (when (eval form)
1750                 (gnus-article-add-button 
1751                  start end (nth 3 entry)
1752                  (buffer-substring (match-beginning (nth 4 entry))
1753                                    (match-end (nth 4 entry)))))))
1754           (goto-char end))))
1755     (widen)))
1756
1757 ;;; External functions:
1758
1759 (defun gnus-article-add-button (from to fun &optional data)
1760   "Create a button between FROM and TO with callback FUN and data DATA."
1761   (when gnus-article-button-face
1762     (gnus-overlay-put (gnus-make-overlay from to)
1763                       'face gnus-article-button-face))
1764   (gnus-add-text-properties 
1765    from to
1766    (nconc (and gnus-article-mouse-face
1767                (list gnus-mouse-face-prop gnus-article-mouse-face))
1768           (list 'gnus-callback fun)
1769           (and data (list 'gnus-data data)))))
1770
1771 ;;; Internal functions:
1772
1773 (defun gnus-signature-toggle (end)
1774   (save-excursion
1775     (set-buffer gnus-article-buffer)
1776     (let ((buffer-read-only nil)
1777           (inhibit-point-motion-hooks t))
1778       (if (get-text-property end 'invisible)
1779           (article-unhide-text end (point-max))
1780         (article-hide-text end (point-max) gnus-hidden-properties)))))
1781
1782 (defun gnus-button-entry ()
1783   ;; Return the first entry in `gnus-button-alist' matching this place.
1784   (let ((alist gnus-button-alist)
1785         (entry nil))
1786     (while alist
1787       (setq entry (pop alist))
1788       (if (looking-at (car entry))
1789           (setq alist nil)
1790         (setq entry nil)))
1791     entry))
1792
1793 (defun gnus-button-push (marker)
1794   ;; Push button starting at MARKER.
1795   (save-excursion
1796     (set-buffer gnus-article-buffer)
1797     (goto-char marker)
1798     (let* ((entry (gnus-button-entry))
1799            (inhibit-point-motion-hooks t)
1800            (fun (nth 3 entry))
1801            (args (mapcar (lambda (group)
1802                            (let ((string (buffer-substring
1803                                           (match-beginning group)
1804                                           (match-end group))))
1805                              (gnus-set-text-properties
1806                               0 (length string) nil string)
1807                              string))
1808                          (nthcdr 4 entry))))
1809       (cond
1810        ((fboundp fun)
1811         (apply fun args))
1812        ((and (boundp fun)
1813              (fboundp (symbol-value fun)))
1814         (apply (symbol-value fun) args))
1815        (t
1816         (gnus-message 1 "You must define `%S' to use this button"
1817                       (cons fun args)))))))
1818
1819 (defun gnus-button-message-id (message-id)
1820   "Fetch MESSAGE-ID."
1821   (save-excursion
1822     (set-buffer gnus-summary-buffer)
1823     (gnus-summary-refer-article message-id)))
1824
1825 (defun gnus-button-fetch-group (address)
1826   "Fetch GROUP specified by ADDRESS."
1827   (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
1828       (error "Can't parse %s" address)
1829     (gnus-group-read-ephemeral-group
1830      (match-string 4 address)
1831      `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
1832             (nntp-port-number ,(if (match-end 3)
1833                                    (match-string 3 address)
1834                                  "nntp"))))))
1835
1836 (defun gnus-button-mailto (address)
1837   ;; Mail to ADDRESS.
1838   (set-buffer (gnus-copy-article-buffer))
1839   (message-reply address))
1840
1841 (defun gnus-button-reply (address)
1842   ;; Reply to ADDRESS.
1843   (message-reply address))
1844
1845 (defun gnus-button-url (address)
1846   "Browse ADDRESS."
1847   (funcall browse-url-browser-function address))
1848
1849 ;;; Next/prev buttons in the article buffer.
1850
1851 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1852 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1853
1854 (defvar gnus-prev-page-map nil)
1855 (unless gnus-prev-page-map
1856   (setq gnus-prev-page-map (make-sparse-keymap))
1857   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1858   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1859
1860 (defun gnus-insert-prev-page-button ()
1861   (let ((buffer-read-only nil))
1862     (gnus-eval-format 
1863      gnus-prev-page-line-format nil
1864      `(gnus-prev t local-map ,gnus-prev-page-map
1865                  gnus-callback gnus-article-button-prev-page))))
1866
1867 (defvar gnus-next-page-map nil)
1868 (unless gnus-next-page-map
1869   (setq gnus-next-page-map (make-keymap))
1870   (suppress-keymap gnus-prev-page-map)
1871   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1872   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1873
1874 (defun gnus-button-next-page ()
1875   "Go to the next page."
1876   (interactive)
1877   (let ((win (selected-window)))
1878     (select-window (get-buffer-window gnus-article-buffer t))
1879     (gnus-article-next-page)
1880     (select-window win)))
1881
1882 (defun gnus-button-prev-page ()
1883   "Go to the prev page."
1884   (interactive)
1885   (let ((win (selected-window)))
1886     (select-window (get-buffer-window gnus-article-buffer t))
1887     (gnus-article-prev-page)
1888     (select-window win)))
1889
1890 (defun gnus-insert-next-page-button ()
1891   (let ((buffer-read-only nil))
1892     (gnus-eval-format gnus-next-page-line-format nil
1893                       `(gnus-next t local-map ,gnus-next-page-map
1894                                   gnus-callback 
1895                                   gnus-article-button-next-page))))
1896
1897 (defun gnus-article-button-next-page (arg)
1898   "Go to the next page."
1899   (interactive "P")
1900   (let ((win (selected-window)))
1901     (select-window (get-buffer-window gnus-article-buffer t))
1902     (gnus-article-next-page)
1903     (select-window win)))
1904
1905 (defun gnus-article-button-prev-page (arg)
1906   "Go to the prev page."
1907   (interactive "P")
1908   (let ((win (selected-window)))
1909     (select-window (get-buffer-window gnus-article-buffer t))
1910     (gnus-article-prev-page)
1911     (select-window win))) 
1912
1913 (provide 'gnus-art)
1914
1915 ;;; gnus-art.el ends here