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