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