*** 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 (stringp article)
1200             (let ((gnus-override-method gnus-refer-article-method))
1201               (gnus-read-header article)))
1202
1203           ;; If the article number is negative, that means that this article
1204           ;; doesn't belong in this newsgroup (possibly), so we find its
1205           ;; message-id and request it by id instead of number.
1206           (when (and (numberp article)
1207                      gnus-summary-buffer
1208                      (get-buffer gnus-summary-buffer)
1209                      (buffer-name (get-buffer gnus-summary-buffer)))
1210             (save-excursion
1211               (set-buffer gnus-summary-buffer)
1212               (let ((header (gnus-summary-article-header article)))
1213                 (when (< article 0)
1214                   (cond 
1215                    ((memq article gnus-newsgroup-sparse)
1216                     ;; This is a sparse gap article.
1217                     (setq do-update-line article)
1218                     (setq article (mail-header-id header))
1219                     (let ((gnus-override-method gnus-refer-article-method))
1220                       (gnus-read-header article))
1221                     (setq gnus-newsgroup-sparse
1222                           (delq article gnus-newsgroup-sparse)))
1223                    ((vectorp header)
1224                     ;; It's a real article.
1225                     (setq article (mail-header-id header)))
1226                    (t
1227                     ;; It is an extracted pseudo-article.
1228                     (setq article 'pseudo)
1229                     (gnus-request-pseudo-article header))))
1230                 
1231                 (let ((method (gnus-find-method-for-group 
1232                                gnus-newsgroup-name)))
1233                   (if (not (eq (car method) 'nneething))
1234                       ()
1235                     (let ((dir (concat (file-name-as-directory (nth 1 method))
1236                                        (mail-header-subject header))))
1237                       (when (file-directory-p dir)
1238                         (setq article 'nneething)
1239                         (gnus-group-enter-directory dir))))))))
1240
1241           (cond
1242            ;; Refuse to select canceled articles.
1243            ((and (numberp article)
1244                  gnus-summary-buffer
1245                  (get-buffer gnus-summary-buffer)
1246                  (buffer-name (get-buffer gnus-summary-buffer))
1247                  (eq (cdr (save-excursion
1248                             (set-buffer gnus-summary-buffer)
1249                             (assq article gnus-newsgroup-reads)))
1250                      gnus-canceled-mark))
1251             nil)
1252            ;; We first check `gnus-original-article-buffer'.
1253            ((and (get-buffer gnus-original-article-buffer)
1254                  (numberp article)
1255                  (save-excursion
1256                    (set-buffer gnus-original-article-buffer)
1257                    (and (equal (car gnus-original-article) group)
1258                         (eq (cdr gnus-original-article) article))))
1259             (insert-buffer-substring gnus-original-article-buffer)
1260             'article)
1261            ;; Check the backlog.
1262            ((and gnus-keep-backlog
1263                  (gnus-backlog-request-article group article (current-buffer)))
1264             'article)
1265            ;; Check asynchronous pre-fetch.
1266            ((gnus-async-request-fetched-article group article (current-buffer))
1267             (gnus-async-prefetch-next group article gnus-summary-buffer)
1268             'article)
1269            ;; Check the cache.
1270            ((and gnus-use-cache
1271                  (numberp article)
1272                  (gnus-cache-request-article article group))
1273             'article)
1274            ;; Get the article and put into the article buffer.
1275            ((or (stringp article) (numberp article))
1276             (let ((gnus-override-method
1277                    (and (stringp article) gnus-refer-article-method))
1278                   (buffer-read-only nil))
1279               (erase-buffer)
1280               (gnus-kill-all-overlays)
1281               (when (gnus-request-article article group (current-buffer))
1282                 (when (numberp article)
1283                   (gnus-async-prefetch-next group article gnus-summary-buffer)
1284                   (when gnus-keep-backlog
1285                     (gnus-backlog-enter-article 
1286                      group article (current-buffer))))
1287                 'article)))
1288            ;; It was a pseudo.
1289            (t article)))
1290
1291       ;; Take the article from the original article buffer
1292       ;; and place it in the buffer it's supposed to be in.
1293       (when (and (get-buffer gnus-article-buffer)
1294                  ;;(numberp article)
1295                  (equal (buffer-name (current-buffer))
1296                         (buffer-name (get-buffer gnus-article-buffer))))
1297         (save-excursion
1298           (if (get-buffer gnus-original-article-buffer)
1299               (set-buffer (get-buffer gnus-original-article-buffer))
1300             (set-buffer (get-buffer-create gnus-original-article-buffer))
1301             (buffer-disable-undo (current-buffer))
1302             (setq major-mode 'gnus-original-article-mode)
1303             (setq buffer-read-only t)
1304             (gnus-add-current-to-buffer-list))
1305           (let (buffer-read-only)
1306             (erase-buffer)
1307             (insert-buffer-substring gnus-article-buffer))
1308           (setq gnus-original-article (cons group article))))
1309     
1310       ;; Update sparse articles.
1311       (when (and do-update-line
1312                  (or (numberp article)
1313                      (stringp article)))
1314         (let ((buf (current-buffer)))
1315           (set-buffer gnus-summary-buffer)
1316           (gnus-summary-update-article do-update-line)
1317           (gnus-summary-goto-subject do-update-line nil t)
1318           (set-window-point (get-buffer-window (current-buffer) t)
1319                             (point))
1320           (set-buffer buf))))))
1321
1322 (defun gnus-article-date-ut (&optional type highlight)
1323   "Convert DATE date to universal time in the current article.
1324 If TYPE is `local', convert to local time; if it is `lapsed', output
1325 how much time has lapsed since DATE."
1326   (interactive (list 'ut t))
1327   (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1328     (save-excursion
1329       (set-buffer gnus-article-buffer)
1330       (article-date-ut type highlight headers))))
1331
1332 ;;;
1333 ;;; Article editing
1334 ;;;
1335
1336 (defcustom gnus-article-edit-mode-hook nil
1337   "Hook run in article edit mode buffers."
1338   :group 'article
1339   :type 'hook)
1340
1341 (defvar gnus-article-edit-done-function nil)
1342
1343 (defvar gnus-article-edit-mode-map nil)
1344
1345 (unless gnus-article-edit-mode-map 
1346   (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1347
1348   (gnus-define-keys gnus-article-edit-mode-map
1349     "\C-c\C-c" gnus-article-edit-done
1350     "\C-c\C-k" gnus-article-edit-exit)
1351
1352   (gnus-define-keys (gnus-article-edit-wash-map
1353                      "\C-c\C-w" gnus-article-edit-mode-map)
1354     "f" gnus-article-edit-full-stops))
1355
1356 (defun gnus-article-edit-mode ()
1357   "Major mode for editing articles.
1358 This is an extended text-mode.
1359
1360 \\{gnus-article-edit-mode-map}"
1361   (interactive)
1362   (kill-all-local-variables)
1363   (setq major-mode 'gnus-article-edit-mode)
1364   (setq mode-name "Article Edit")
1365   (use-local-map gnus-article-edit-mode-map)
1366   (make-local-variable 'gnus-article-edit-done-function)
1367   (make-local-variable 'gnus-prev-winconf)
1368   (setq buffer-read-only nil)
1369   (buffer-enable-undo)
1370   (widen)
1371   (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1372
1373 (defun gnus-article-edit (&optional force)
1374   "Edit the current article.
1375 This will have permanent effect only in mail groups.
1376 If FORCE is non-nil, allow editing of articles even in read-only
1377 groups."
1378   (interactive "P")
1379   (when (and (not force)
1380              (gnus-group-read-only-p))
1381     (error "The current newsgroup does not support article editing."))
1382   (gnus-article-edit-article
1383    `(lambda ()
1384       (gnus-summary-edit-article-done
1385        ,(or (mail-header-references gnus-current-headers) "")
1386        ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1387
1388 (defun gnus-article-edit-article (exit-func)
1389   "Start editing the contents of the current article buffer."
1390   (let ((winconf (current-window-configuration)))
1391     (set-buffer gnus-article-buffer)
1392     (gnus-article-edit-mode)
1393     (set-text-properties (point-min) (point-max) nil)
1394     (gnus-configure-windows 'edit-article)
1395     (setq gnus-article-edit-done-function exit-func)
1396     (setq gnus-prev-winconf winconf)
1397     (gnus-message 6 "C-c C-c to end edits")))
1398
1399 (defun gnus-article-edit-done ()
1400   "Update the article edits and exit."
1401   (interactive)
1402   (let ((func gnus-article-edit-done-function)
1403         (buf (current-buffer))
1404         (start (window-start)))
1405     (gnus-article-edit-exit)
1406     (save-excursion
1407       (set-buffer buf)
1408       (let ((buffer-read-only nil))
1409         (funcall func)))
1410     (set-buffer buf)
1411     (set-window-start (get-buffer-window buf) start)
1412     (set-window-point (get-buffer-window buf) (point))))
1413
1414 (defun gnus-article-edit-exit ()
1415   "Exit the article editing without updating."
1416   (interactive)
1417   ;; We remove all text props from the article buffer.
1418   (let ((buf (format "%s" (buffer-string)))
1419         (curbuf (current-buffer))
1420         (p (point))
1421         (window-start (window-start)))
1422     (erase-buffer)
1423     (insert buf)
1424     (let ((winconf gnus-prev-winconf))
1425       (gnus-article-mode)
1426       ;; The cache and backlog have to be flushed somewhat.
1427       (when gnus-use-cache
1428         (gnus-cache-update-article      
1429          (car gnus-article-current) (cdr gnus-article-current)))
1430       (when gnus-keep-backlog
1431         (gnus-backlog-remove-article 
1432          (car gnus-article-current) (cdr gnus-article-current)))
1433       ;; Flush original article as well.
1434       (save-excursion
1435         (when (get-buffer gnus-original-article-buffer)
1436           (set-buffer gnus-original-article-buffer)
1437           (setq gnus-original-article nil)))
1438       (set-window-configuration winconf)
1439       ;; Tippy-toe some to make sure that point remains where it was.
1440       (let ((buf (current-buffer)))
1441         (set-buffer curbuf)
1442         (set-window-start (get-buffer-window (current-buffer)) window-start)
1443         (goto-char p)
1444         (set-buffer buf)))))
1445       
1446 (defun gnus-article-edit-full-stops ()
1447   "Interactively repair spacing at end of sentences."
1448   (interactive)
1449   (save-excursion
1450     (goto-char (point-min))
1451     (search-forward-regexp "^$" nil t)
1452     (let ((case-fold-search nil))
1453       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1454
1455 ;;; 
1456 ;;; Article highlights
1457 ;;;
1458
1459 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1460
1461 ;;; Internal Variables:
1462
1463 (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_=#$@~`%&*+|\\/]"
1464   "Regular expression that matches URLs."
1465   :group 'article
1466   :type 'regexp)
1467
1468 (defcustom gnus-button-alist 
1469   `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 
1470      t gnus-button-message-id 3)
1471     ("\\(<?\\(url: ?\\)?news://\\([^>\n\t ]*\\)>?\\)" 1 t
1472      gnus-button-fetch-group 3)
1473     ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1474      gnus-button-message-id 3)
1475     ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-button-reply 2)
1476     ;; This is how URLs _should_ be embedded in text...
1477     ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1478     ;; Next regexp stolen from highlight-headers.el.
1479     ;; Modified by Vladimir Alexiev.
1480     (,gnus-button-url-regexp 0 t gnus-button-url 0))
1481   "Alist of regexps matching buttons in article bodies.
1482
1483 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1484 REGEXP: is the string matching text around the button,
1485 BUTTON: is the number of the regexp grouping actually matching the button,
1486 FORM: is a lisp expression which must eval to true for the button to
1487 be added, 
1488 CALLBACK: is the function to call when the user push this button, and each
1489 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1490
1491 CALLBACK can also be a variable, in that case the value of that
1492 variable it the real callback function."
1493   :group 'article
1494   :type '(repeat (list regexp 
1495                        (integer :tag "Button")
1496                        (sexp :tag "Form")
1497                        (function :tag "Callback")
1498                        (repeat :tag "Par"
1499                                :inline t
1500                                (integer :tag "Regexp group")))))
1501
1502 (defcustom gnus-header-button-alist 
1503   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1504      0 t gnus-button-message-id 0)
1505     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1506     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+" 
1507      0 t gnus-button-mailto 0)
1508     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1509     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1510     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1511      gnus-button-message-id 3))
1512   "Alist of headers and regexps to match buttons in article heads.
1513
1514 This alist is very similar to `gnus-button-alist', except that each
1515 alist has an additional HEADER element first in each entry:
1516
1517 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1518
1519 HEADER is a regexp to match a header.  For a fuller explanation, see
1520 `gnus-button-alist'."
1521   :group 'article
1522   :type '(repeat (list (regexp :tag "Header")
1523                        regexp 
1524                        (integer :tag "Button")
1525                        (sexp :tag "Form")
1526                        (function :tag "Callback")
1527                        (repeat :tag "Par"
1528                                :inline t
1529                                (integer :tag "Regexp group")))))
1530
1531 (defvar gnus-button-regexp nil)
1532 (defvar gnus-button-marker-list nil)
1533 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1534
1535 (defvar gnus-button-last nil)
1536 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1537
1538 ;;; Commands:
1539
1540 (defun gnus-article-push-button (event)
1541   "Check text under the mouse pointer for a callback function.
1542 If the text under the mouse pointer has a `gnus-callback' property,
1543 call it with the value of the `gnus-data' text property."
1544   (interactive "e")
1545   (set-buffer (window-buffer (posn-window (event-start event))))
1546   (let* ((pos (posn-point (event-start event)))
1547          (data (get-text-property pos 'gnus-data))
1548          (fun (get-text-property pos 'gnus-callback)))
1549     (when fun
1550       (funcall fun data))))
1551
1552 (defun gnus-article-press-button ()
1553   "Check text at point for a callback function.
1554 If the text at point has a `gnus-callback' property,
1555 call it with the value of the `gnus-data' text property."
1556   (interactive)
1557   (let* ((data (get-text-property (point) 'gnus-data))
1558          (fun (get-text-property (point) 'gnus-callback)))
1559     (when fun
1560       (funcall fun data))))
1561
1562 (defun gnus-article-prev-button (n)
1563   "Move point to N buttons backward.
1564 If N is negative, move forward instead."
1565   (interactive "p")
1566   (gnus-article-next-button (- n)))
1567
1568 (defun gnus-article-next-button (n)
1569   "Move point to N buttons forward.
1570 If N is negative, move backward instead."
1571   (interactive "p")
1572   (let ((function (if (< n 0) 'previous-single-property-change
1573                     'next-single-property-change))
1574         (inhibit-point-motion-hooks t)
1575         (backward (< n 0))
1576         (limit (if (< n 0) (point-min) (point-max))))
1577     (setq n (abs n))
1578     (while (and (not (= limit (point)))
1579                 (> n 0))
1580       ;; Skip past the current button.
1581       (when (get-text-property (point) 'gnus-callback)
1582         (goto-char (funcall function (point) 'gnus-callback nil limit)))
1583       ;; Go to the next (or previous) button.
1584       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1585       ;; Put point at the start of the button.
1586       (when (and backward (not (get-text-property (point) 'gnus-callback)))
1587         (goto-char (funcall function (point) 'gnus-callback nil limit)))
1588       ;; Skip past intangible buttons.
1589       (when (get-text-property (point) 'intangible)
1590         (incf n))
1591       (decf n))
1592     (unless (zerop n)
1593       (gnus-message 5 "No more buttons"))
1594     n))
1595
1596 (defun gnus-article-highlight (&optional force)
1597   "Highlight current article.
1598 This function calls `gnus-article-highlight-headers',
1599 `gnus-article-highlight-citation', 
1600 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1601 do the highlighting.  See the documentation for those functions."
1602   (interactive (list 'force))
1603   (gnus-article-highlight-headers)
1604   (gnus-article-highlight-citation force)
1605   (gnus-article-highlight-signature)
1606   (gnus-article-add-buttons force)
1607   (gnus-article-add-buttons-to-head))
1608
1609 (defun gnus-article-highlight-some (&optional force)
1610   "Highlight current article.
1611 This function calls `gnus-article-highlight-headers',
1612 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1613 do the highlighting.  See the documentation for those functions."
1614   (interactive (list 'force))
1615   (gnus-article-highlight-headers)
1616   (gnus-article-highlight-signature)
1617   (gnus-article-add-buttons))
1618
1619 (defun gnus-article-highlight-headers ()
1620   "Highlight article headers as specified by `gnus-header-face-alist'."
1621   (interactive)
1622   (save-excursion
1623     (set-buffer gnus-article-buffer)
1624     (save-restriction
1625       (let ((alist gnus-header-face-alist)
1626             (buffer-read-only nil)
1627             (case-fold-search t)
1628             (inhibit-point-motion-hooks t)
1629             entry regexp header-face field-face from hpoints fpoints)
1630         (goto-char (point-min))
1631         (when (search-forward "\n\n" nil t)
1632           (narrow-to-region (1- (point)) (point-min))
1633           (while (setq entry (pop alist))
1634             (goto-char (point-min))
1635             (setq regexp (concat "^\\("
1636                                  (if (string-equal "" (nth 0 entry))
1637                                      "[^\t ]"
1638                                    (nth 0 entry))
1639                                  "\\)")
1640                   header-face (nth 1 entry)
1641                   field-face (nth 2 entry))
1642             (while (and (re-search-forward regexp nil t)
1643                         (not (eobp)))
1644               (beginning-of-line)
1645               (setq from (point))
1646               (unless (search-forward ":" nil t)
1647                 (forward-char 1))
1648               (when (and header-face
1649                          (not (memq (point) hpoints)))
1650                 (push (point) hpoints)
1651                 (gnus-put-text-property from (point) 'face header-face))
1652               (when (and field-face
1653                          (not (memq (setq from (point)) fpoints)))
1654                 (push from fpoints)
1655                 (if (re-search-forward "^[^ \t]" nil t)
1656                     (forward-char -2)
1657                   (goto-char (point-max)))
1658                 (gnus-put-text-property from (point) 'face field-face)))))))))
1659
1660 (defun gnus-article-highlight-signature ()
1661   "Highlight the signature in an article.
1662 It does this by highlighting everything after
1663 `gnus-signature-separator' using `gnus-signature-face'." 
1664   (interactive)
1665   (save-excursion
1666     (set-buffer gnus-article-buffer)
1667     (let ((buffer-read-only nil)
1668           (inhibit-point-motion-hooks t))
1669       (save-restriction
1670         (when (and gnus-signature-face
1671                    (article-narrow-to-signature))
1672           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1673                             'face gnus-signature-face)
1674           (widen)
1675           (article-search-signature)
1676           (let ((start (match-beginning 0))
1677                 (end (set-marker (make-marker) (1+ (match-end 0)))))
1678             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1679                                      end)))))))
1680
1681 (defun gnus-article-add-buttons (&optional force)
1682   "Find external references in the article and make buttons of them.
1683 \"External references\" are things like Message-IDs and URLs, as
1684 specified by `gnus-button-alist'."
1685   (interactive (list 'force))
1686   (save-excursion
1687     (set-buffer gnus-article-buffer)
1688     ;; Remove all old markers.
1689     (while gnus-button-marker-list
1690       (set-marker (pop gnus-button-marker-list) nil))
1691     (let ((buffer-read-only nil)
1692           (inhibit-point-motion-hooks t)
1693           (case-fold-search t)
1694           (alist gnus-button-alist)
1695           beg entry regexp)
1696       (goto-char (point-min))
1697       ;; We skip the headers.
1698       (unless (search-forward "\n\n" nil t)
1699         (goto-char (point-max)))
1700       (setq beg (point))
1701       (while (setq entry (pop alist))
1702         (setq regexp (car entry))
1703         (goto-char beg)
1704         (while (re-search-forward regexp nil t)
1705           (let* ((start (and entry (match-beginning (nth 1 entry))))
1706                  (end (and entry (match-end (nth 1 entry))))
1707                  (from (match-beginning 0)))
1708             (when (or (eq t (nth 1 entry))
1709                       (eval (nth 1 entry)))
1710               ;; That optional form returned non-nil, so we add the
1711               ;; button. 
1712               (gnus-article-add-button 
1713                start end 'gnus-button-push 
1714                (car (push (set-marker (make-marker) from)
1715                           gnus-button-marker-list))))))))))
1716
1717 ;; Add buttons to the head of an article.
1718 (defun gnus-article-add-buttons-to-head ()
1719   "Add buttons to the head of the article."
1720   (interactive)
1721   (save-excursion
1722     (set-buffer gnus-article-buffer)
1723     (let ((buffer-read-only nil)
1724           (inhibit-point-motion-hooks t)
1725           (case-fold-search t)
1726           (alist gnus-header-button-alist)
1727           entry beg end)
1728       (nnheader-narrow-to-headers)
1729       (while alist
1730         ;; Each alist entry.
1731         (setq entry (car alist)
1732               alist (cdr alist))
1733         (goto-char (point-min))
1734         (while (re-search-forward (car entry) nil t)
1735           ;; Each header matching the entry.
1736           (setq beg (match-beginning 0))
1737           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1738                              (match-beginning 0))
1739                         (point-max)))
1740           (goto-char beg)
1741           (while (re-search-forward (nth 1 entry) end t)
1742             ;; Each match within a header.
1743             (let* ((entry (cdr entry))
1744                    (start (match-beginning (nth 1 entry)))
1745                    (end (match-end (nth 1 entry)))
1746                    (form (nth 2 entry)))
1747               (goto-char (match-end 0))
1748               (when (eval form)
1749                 (gnus-article-add-button 
1750                  start end (nth 3 entry)
1751                  (buffer-substring (match-beginning (nth 4 entry))
1752                                    (match-end (nth 4 entry)))))))
1753           (goto-char end))))
1754     (widen)))
1755
1756 ;;; External functions:
1757
1758 (defun gnus-article-add-button (from to fun &optional data)
1759   "Create a button between FROM and TO with callback FUN and data DATA."
1760   (when gnus-article-button-face
1761     (gnus-overlay-put (gnus-make-overlay from to)
1762                       'face gnus-article-button-face))
1763   (gnus-add-text-properties 
1764    from to
1765    (nconc (and gnus-article-mouse-face
1766                (list gnus-mouse-face-prop gnus-article-mouse-face))
1767           (list 'gnus-callback fun)
1768           (and data (list 'gnus-data data)))))
1769
1770 ;;; Internal functions:
1771
1772 (defun gnus-signature-toggle (end)
1773   (save-excursion
1774     (set-buffer gnus-article-buffer)
1775     (let ((buffer-read-only nil)
1776           (inhibit-point-motion-hooks t))
1777       (if (get-text-property end 'invisible)
1778           (article-unhide-text end (point-max))
1779         (article-hide-text end (point-max) gnus-hidden-properties)))))
1780
1781 (defun gnus-button-entry ()
1782   ;; Return the first entry in `gnus-button-alist' matching this place.
1783   (let ((alist gnus-button-alist)
1784         (entry nil))
1785     (while alist
1786       (setq entry (pop alist))
1787       (if (looking-at (car entry))
1788           (setq alist nil)
1789         (setq entry nil)))
1790     entry))
1791
1792 (defun gnus-button-push (marker)
1793   ;; Push button starting at MARKER.
1794   (save-excursion
1795     (set-buffer gnus-article-buffer)
1796     (goto-char marker)
1797     (let* ((entry (gnus-button-entry))
1798            (inhibit-point-motion-hooks t)
1799            (fun (nth 3 entry))
1800            (args (mapcar (lambda (group)
1801                            (let ((string (buffer-substring
1802                                           (match-beginning group)
1803                                           (match-end group))))
1804                              (gnus-set-text-properties
1805                               0 (length string) nil string)
1806                              string))
1807                          (nthcdr 4 entry))))
1808       (cond
1809        ((fboundp fun)
1810         (apply fun args))
1811        ((and (boundp fun)
1812              (fboundp (symbol-value fun)))
1813         (apply (symbol-value fun) args))
1814        (t
1815         (gnus-message 1 "You must define `%S' to use this button"
1816                       (cons fun args)))))))
1817
1818 (defun gnus-button-message-id (message-id)
1819   "Fetch MESSAGE-ID."
1820   (save-excursion
1821     (set-buffer gnus-summary-buffer)
1822     (gnus-summary-refer-article message-id)))
1823
1824 (defun gnus-button-fetch-group (address)
1825   "Fetch GROUP specified by ADDRESS."
1826   (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
1827       (error "Can't parse %s" address)
1828     (gnus-group-read-ephemeral-group
1829      (match-string 4 address)
1830      `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
1831             (nntp-port-number ,(if (match-end 3)
1832                                    (match-string 3 address)
1833                                  "nntp"))))))
1834
1835 (defun gnus-button-mailto (address)
1836   ;; Mail to ADDRESS.
1837   (set-buffer (gnus-copy-article-buffer))
1838   (message-reply address))
1839
1840 (defun gnus-button-reply (address)
1841   ;; Reply to ADDRESS.
1842   (message-reply address))
1843
1844 (defun gnus-button-url (address)
1845   "Browse ADDRESS."
1846   (funcall browse-url-browser-function address))
1847
1848 ;;; Next/prev buttons in the article buffer.
1849
1850 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1851 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1852
1853 (defvar gnus-prev-page-map nil)
1854 (unless gnus-prev-page-map
1855   (setq gnus-prev-page-map (make-sparse-keymap))
1856   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1857   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1858
1859 (defun gnus-insert-prev-page-button ()
1860   (let ((buffer-read-only nil))
1861     (gnus-eval-format 
1862      gnus-prev-page-line-format nil
1863      `(gnus-prev t local-map ,gnus-prev-page-map
1864                  gnus-callback gnus-article-button-prev-page))))
1865
1866 (defvar gnus-next-page-map nil)
1867 (unless gnus-next-page-map
1868   (setq gnus-next-page-map (make-keymap))
1869   (suppress-keymap gnus-prev-page-map)
1870   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1871   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1872
1873 (defun gnus-button-next-page ()
1874   "Go to the next page."
1875   (interactive)
1876   (let ((win (selected-window)))
1877     (select-window (get-buffer-window gnus-article-buffer t))
1878     (gnus-article-next-page)
1879     (select-window win)))
1880
1881 (defun gnus-button-prev-page ()
1882   "Go to the prev page."
1883   (interactive)
1884   (let ((win (selected-window)))
1885     (select-window (get-buffer-window gnus-article-buffer t))
1886     (gnus-article-prev-page)
1887     (select-window win)))
1888
1889 (defun gnus-insert-next-page-button ()
1890   (let ((buffer-read-only nil))
1891     (gnus-eval-format gnus-next-page-line-format nil
1892                       `(gnus-next t local-map ,gnus-next-page-map
1893                                   gnus-callback 
1894                                   gnus-article-button-next-page))))
1895
1896 (defun gnus-article-button-next-page (arg)
1897   "Go to the next page."
1898   (interactive "P")
1899   (let ((win (selected-window)))
1900     (select-window (get-buffer-window gnus-article-buffer t))
1901     (gnus-article-next-page)
1902     (select-window win)))
1903
1904 (defun gnus-article-button-prev-page (arg)
1905   "Go to the prev page."
1906   (interactive "P")
1907   (let ((win (selected-window)))
1908     (select-window (get-buffer-window gnus-article-buffer t))
1909     (gnus-article-prev-page)
1910     (select-window win))) 
1911
1912 (provide 'gnus-art)
1913
1914 ;;; gnus-art.el ends here