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