4388158740824e4bcd0d067ae22ab3a0cb771590
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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 (eval-when-compile (require 'cl))
29
30 (require 'custom)
31 (require 'gnus)
32 (require 'gnus-sum)
33 (require 'gnus-spec)
34 (require 'gnus-int)
35 (require 'browse-url)
36 (require 'mm-bodies)
37 (require 'mail-parse)
38 (require 'mm-decode)
39 (require 'mm-view)
40 (require 'wid-edit)
41 (require 'mm-uu)
42
43 (defgroup gnus-article nil
44   "Article display."
45   :link '(custom-manual "(gnus)The Article Buffer")
46   :group 'gnus)
47
48 (defgroup gnus-article-hiding nil
49   "Hiding article parts."
50   :link '(custom-manual "(gnus)Article Hiding")
51   :group 'gnus-article)
52
53 (defgroup gnus-article-highlight nil
54   "Article highlighting."
55   :link '(custom-manual "(gnus)Article Highlighting")
56   :group 'gnus-article
57   :group 'gnus-visual)
58
59 (defgroup gnus-article-signature nil
60   "Article signatures."
61   :link '(custom-manual "(gnus)Article Signature")
62   :group 'gnus-article)
63
64 (defgroup gnus-article-headers nil
65   "Article headers."
66   :link '(custom-manual "(gnus)Hiding Headers")
67   :group 'gnus-article)
68
69 (defgroup gnus-article-washing nil
70   "Special commands on articles."
71   :link '(custom-manual "(gnus)Article Washing")
72   :group 'gnus-article)
73
74 (defgroup gnus-article-emphasis nil
75   "Fontisizing articles."
76   :link '(custom-manual "(gnus)Article Fontisizing")
77   :group 'gnus-article)
78
79 (defgroup gnus-article-saving nil
80   "Saving articles."
81   :link '(custom-manual "(gnus)Saving Articles")
82   :group 'gnus-article)
83
84 (defgroup gnus-article-mime nil
85   "Worshiping the MIME wonder."
86   :link '(custom-manual "(gnus)Using MIME")
87   :group 'gnus-article)
88
89 (defgroup gnus-article-buttons nil
90   "Pushable buttons in the article buffer."
91   :link '(custom-manual "(gnus)Article Buttons")
92   :group 'gnus-article)
93
94 (defgroup gnus-article-various nil
95   "Other article options."
96   :link '(custom-manual "(gnus)Misc Article")
97   :group 'gnus-article)
98
99 (defcustom gnus-ignored-headers
100   '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
101     "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
102     "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
103     "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
104     "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
105     "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
106     "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
107     "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
108     "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
109     "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
110     "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
111     "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
112     "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
113     "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
114     "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
115     "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
116     "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
117     "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
118     "^Status:")
119   "*All headers that start with this regexp will be hidden.
120 This variable can also be a list of regexps of headers to be ignored.
121 If `gnus-visible-headers' is non-nil, this variable will be ignored."
122   :type '(choice :custom-show nil
123                  regexp
124                  (repeat regexp))
125   :group 'gnus-article-hiding)
126
127 (defcustom gnus-visible-headers
128   "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
129   "*All headers that do not match this regexp will be hidden.
130 This variable can also be a list of regexp of headers to remain visible.
131 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
132   :type '(repeat :value-to-internal (lambda (widget value)
133                                       (custom-split-regexp-maybe value))
134                  :match (lambda (widget value)
135                           (or (stringp value)
136                               (widget-editable-list-match widget value)))
137                  regexp)
138   :group 'gnus-article-hiding)
139
140 (defcustom gnus-sorted-header-list
141   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
142     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
143   "*This variable is a list of regular expressions.
144 If it is non-nil, headers that match the regular expressions will
145 be placed first in the article buffer in the sequence specified by
146 this list."
147   :type '(repeat regexp)
148   :group 'gnus-article-hiding)
149
150 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
151   "Headers that are only to be displayed if they have interesting data.
152 Possible values in this list are `empty', `newsgroups', `followup-to',
153 `reply-to', `date', `long-to', and `many-to'."
154   :type '(set (const :tag "Headers with no content." empty)
155               (const :tag "Newsgroups with only one group." newsgroups)
156               (const :tag "Followup-to identical to newsgroups." followup-to)
157               (const :tag "Reply-to identical to from." reply-to)
158               (const :tag "Date less than four days old." date)
159               (const :tag "Very long To header." long-to)
160               (const :tag "Multiple To headers." many-to))
161   :group 'gnus-article-hiding)
162
163 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
164   "Regexp matching signature separator.
165 This can also be a list of regexps.  In that case, it will be checked
166 from head to tail looking for a separator.  Searches will be done from
167 the end of the buffer."
168   :type '(repeat string)
169   :group 'gnus-article-signature)
170
171 (defcustom gnus-signature-limit nil
172    "Provide a limit to what is considered a signature.
173 If it is a number, no signature may not be longer (in characters) than
174 that number.  If it is a floating point number, no signature may be
175 longer (in lines) than that number.  If it is a function, the function
176 will be called without any parameters, and if it returns nil, there is
177 no signature in the buffer.  If it is a string, it will be used as a
178 regexp.  If it matches, the text in question is not a signature."
179   :type '(choice (integer :value 200)
180                  (number :value 4.0)
181                  (function :value fun)
182                  (regexp :value ".*"))
183   :group 'gnus-article-signature)
184
185 (defcustom gnus-hidden-properties '(invisible t intangible t)
186   "Property list to use for hiding text."
187   :type 'sexp
188   :group 'gnus-article-hiding)
189
190 (defcustom gnus-article-x-face-command
191   "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
192   "*String or function to be executed to display an X-Face header.
193 If it is a string, the command will be executed in a sub-shell
194 asynchronously.  The compressed face will be piped to this command."
195   :type 'string                         ;Leave function case to Lisp.
196   :group 'gnus-article-washing)
197
198 (defcustom gnus-article-x-face-too-ugly nil
199   "Regexp matching posters whose face shouldn't be shown automatically."
200   :type '(choice regexp (const nil))
201   :group 'gnus-article-washing)
202
203 (defcustom gnus-emphasis-alist
204   (let ((format
205          "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
206         (types
207          '(("_" "_" underline)
208            ("/" "/" italic)
209            ("\\*" "\\*" bold)
210            ("_/" "/_" underline-italic)
211            ("_\\*" "\\*_" underline-bold)
212            ("\\*/" "/\\*" bold-italic)
213            ("_\\*/" "/\\*_" underline-bold-italic))))
214     `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
215        2 3 gnus-emphasis-underline)
216       ,@(mapcar
217          (lambda (spec)
218            (list
219             (format format (car spec) (cadr spec))
220             2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
221          types)))
222   "*Alist that says how to fontify certain phrases.
223 Each item looks like this:
224
225   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
226
227 The first element is a regular expression to be matched.  The second
228 is a number that says what regular expression grouping used to find
229 the entire emphasized word.  The third is a number that says what
230 regexp grouping should be displayed and highlighted.  The fourth
231 is the face used for highlighting."
232   :type '(repeat (list :value ("" 0 0 default)
233                        regexp
234                        (integer :tag "Match group")
235                        (integer :tag "Emphasize group")
236                        face))
237   :group 'gnus-article-emphasis)
238
239 (defface gnus-emphasis-bold '((t (:bold t)))
240   "Face used for displaying strong emphasized text (*word*)."
241   :group 'gnus-article-emphasis)
242
243 (defface gnus-emphasis-italic '((t (:italic t)))
244   "Face used for displaying italic emphasized text (/word/)."
245   :group 'gnus-article-emphasis)
246
247 (defface gnus-emphasis-underline '((t (:underline t)))
248   "Face used for displaying underlined emphasized text (_word_)."
249   :group 'gnus-article-emphasis)
250
251 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
252   "Face used for displaying underlined bold emphasized text (_*word*_)."
253   :group 'gnus-article-emphasis)
254
255 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
256   "Face used for displaying underlined italic emphasized text (_*word*_)."
257   :group 'gnus-article-emphasis)
258
259 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
260   "Face used for displaying bold italic emphasized text (/*word*/)."
261   :group 'gnus-article-emphasis)
262
263 (defface gnus-emphasis-underline-bold-italic
264   '((t (:bold t :italic t :underline t)))
265   "Face used for displaying underlined bold italic emphasized text.
266 Esample: (_/*word*/_)."
267   :group 'gnus-article-emphasis)
268
269 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
270   "Format for display of Date headers in article bodies.
271 See `format-time-string' for the possible values.
272
273 The variable can also be function, which should return a complete Date
274 header.  The function is called with one argument, the time, which can
275 be fed to `format-time-string'."
276   :type '(choice string symbol)
277   :link '(custom-manual "(gnus)Article Date")
278   :group 'gnus-article-washing)
279
280 (eval-and-compile
281   (autoload 'mail-extract-address-components "mail-extr"))
282
283 (defcustom gnus-save-all-headers t
284   "*If non-nil, don't remove any headers before saving."
285   :group 'gnus-article-saving
286   :type 'boolean)
287
288 (defcustom gnus-prompt-before-saving 'always
289   "*This variable says how much prompting is to be done when saving articles.
290 If it is nil, no prompting will be done, and the articles will be
291 saved to the default files.  If this variable is `always', each and
292 every article that is saved will be preceded by a prompt, even when
293 saving large batches of articles.  If this variable is neither nil not
294 `always', there the user will be prompted once for a file name for
295 each invocation of the saving commands."
296   :group 'gnus-article-saving
297   :type '(choice (item always)
298                  (item :tag "never" nil)
299                  (sexp :tag "once" :format "%t\n" :value t)))
300
301 (defcustom gnus-saved-headers gnus-visible-headers
302   "Headers to keep if `gnus-save-all-headers' is nil.
303 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
304 If that variable is nil, however, all headers that match this regexp
305 will be kept while the rest will be deleted before saving."
306   :group 'gnus-article-saving
307   :type 'regexp)
308
309 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
310   "A function to save articles in your favourite format.
311 The function must be interactively callable (in other words, it must
312 be an Emacs command).
313
314 Gnus provides the following functions:
315
316 * gnus-summary-save-in-rmail (Rmail format)
317 * gnus-summary-save-in-mail (Unix mail format)
318 * gnus-summary-save-in-folder (MH folder)
319 * gnus-summary-save-in-file (article format)
320 * gnus-summary-save-in-vm (use VM's folder format)
321 * gnus-summary-write-to-file (article format -- overwrite)."
322   :group 'gnus-article-saving
323   :type '(radio (function-item gnus-summary-save-in-rmail)
324                 (function-item gnus-summary-save-in-mail)
325                 (function-item gnus-summary-save-in-folder)
326                 (function-item gnus-summary-save-in-file)
327                 (function-item gnus-summary-save-in-vm)
328                 (function-item gnus-summary-write-to-file)))
329
330 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
331   "A function generating a file name to save articles in Rmail format.
332 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
333   :group 'gnus-article-saving
334   :type 'function)
335
336 (defcustom gnus-mail-save-name 'gnus-plain-save-name
337   "A function generating a file name to save articles in Unix mail format.
338 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
339   :group 'gnus-article-saving
340   :type 'function)
341
342 (defcustom gnus-folder-save-name 'gnus-folder-save-name
343   "A function generating a file name to save articles in MH folder.
344 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
345   :group 'gnus-article-saving
346   :type 'function)
347
348 (defcustom gnus-file-save-name 'gnus-numeric-save-name
349   "A function generating a file name to save articles in article format.
350 The function is called with NEWSGROUP, HEADERS, and optional
351 LAST-FILE."
352   :group 'gnus-article-saving
353   :type 'function)
354
355 (defcustom gnus-split-methods
356   '((gnus-article-archive-name)
357     (gnus-article-nndoc-name))
358   "*Variable used to suggest where articles are to be saved.
359 For instance, if you would like to save articles related to Gnus in
360 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
361 you could set this variable to something like:
362
363  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
364    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
365
366 This variable is an alist where the where the key is the match and the
367 value is a list of possible files to save in if the match is non-nil.
368
369 If the match is a string, it is used as a regexp match on the
370 article.  If the match is a symbol, that symbol will be funcalled
371 from the buffer of the article to be saved with the newsgroup as the
372 parameter.  If it is a list, it will be evaled in the same buffer.
373
374 If this form or function returns a string, this string will be used as
375 a possible file name; and if it returns a non-nil list, that list will
376 be used as possible file names."
377   :group 'gnus-article-saving
378   :type '(repeat (choice (list :value (fun) function)
379                          (cons :value ("" "") regexp (repeat string))
380                          (sexp :value nil))))
381
382 (defcustom gnus-page-delimiter "^\^L"
383   "*Regexp describing what to use as article page delimiters.
384 The default value is \"^\^L\", which is a form linefeed at the
385 beginning of a line."
386   :type 'regexp
387   :group 'gnus-article-various)
388
389 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
390   "*The format specification for the article mode line.
391 See `gnus-summary-mode-line-format' for a closer description."
392   :type 'string
393   :group 'gnus-article-various)
394
395 (defcustom gnus-article-mode-hook nil
396   "*A hook for Gnus article mode."
397   :type 'hook
398   :group 'gnus-article-various)
399
400 (defcustom gnus-article-menu-hook nil
401   "*Hook run after the creation of the article mode menu."
402   :type 'hook
403   :group 'gnus-article-various)
404
405 (defcustom gnus-article-prepare-hook nil
406   "*A hook called after an article has been prepared in the article buffer.
407 If you want to run a special decoding program like nkf, use this hook."
408   :type 'hook
409   :group 'gnus-article-various)
410
411 (defcustom gnus-article-hide-pgp-hook nil
412   "*A hook called after successfully hiding a PGP signature."
413   :type 'hook
414   :group 'gnus-article-various)
415
416 (defcustom gnus-article-button-face 'bold
417   "Face used for highlighting buttons in the article buffer.
418
419 An article button is a piece of text that you can activate by pressing
420 `RET' or `mouse-2' above it."
421   :type 'face
422   :group 'gnus-article-buttons)
423
424 (defcustom gnus-article-mouse-face 'highlight
425   "Face used for mouse highlighting in the article buffer.
426
427 Article buttons will be displayed in this face when the cursor is
428 above them."
429   :type 'face
430   :group 'gnus-article-buttons)
431
432 (defcustom gnus-signature-face 'gnus-signature-face
433   "Face used for highlighting a signature in the article buffer.
434 Obsolete; use the face `gnus-signature-face' for customizations instead."
435   :type 'face
436   :group 'gnus-article-highlight
437   :group 'gnus-article-signature)
438
439 (defface gnus-signature-face
440   '((((type x))
441      (:italic t)))
442   "Face used for highlighting a signature in the article buffer."
443   :group 'gnus-article-highlight
444   :group 'gnus-article-signature)
445
446 (defface gnus-header-from-face
447   '((((class color)
448       (background dark))
449      (:foreground "spring green"))
450     (((class color)
451       (background light))
452      (:foreground "red3"))
453     (t
454      (:italic t)))
455   "Face used for displaying from headers."
456   :group 'gnus-article-headers
457   :group 'gnus-article-highlight)
458
459 (defface gnus-header-subject-face
460   '((((class color)
461       (background dark))
462      (:foreground "SeaGreen3"))
463     (((class color)
464       (background light))
465      (:foreground "red4"))
466     (t
467      (:bold t :italic t)))
468   "Face used for displaying subject headers."
469   :group 'gnus-article-headers
470   :group 'gnus-article-highlight)
471
472 (defface gnus-header-newsgroups-face
473   '((((class color)
474       (background dark))
475      (:foreground "yellow" :italic t))
476     (((class color)
477       (background light))
478      (:foreground "MidnightBlue" :italic t))
479     (t
480      (:italic t)))
481   "Face used for displaying newsgroups headers."
482   :group 'gnus-article-headers
483   :group 'gnus-article-highlight)
484
485 (defface gnus-header-name-face
486   '((((class color)
487       (background dark))
488      (:foreground "SeaGreen"))
489     (((class color)
490       (background light))
491      (:foreground "maroon"))
492     (t
493      (:bold t)))
494   "Face used for displaying header names."
495   :group 'gnus-article-headers
496   :group 'gnus-article-highlight)
497
498 (defface gnus-header-content-face
499   '((((class color)
500       (background dark))
501      (:foreground "forest green" :italic t))
502     (((class color)
503       (background light))
504      (:foreground "indianred4" :italic t))
505     (t
506      (:italic t)))  "Face used for displaying header content."
507   :group 'gnus-article-headers
508   :group 'gnus-article-highlight)
509
510 (defcustom gnus-header-face-alist
511   '(("From" nil gnus-header-from-face)
512     ("Subject" nil gnus-header-subject-face)
513     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
514     ("" gnus-header-name-face gnus-header-content-face))
515   "*Controls highlighting of article header.
516
517 An alist of the form (HEADER NAME CONTENT).
518
519 HEADER is a regular expression which should match the name of an
520 header header and NAME and CONTENT are either face names or nil.
521
522 The name of each header field will be displayed using the face
523 specified by the first element in the list where HEADER match the
524 header name and NAME is non-nil.  Similarly, the content will be
525 displayed by the first non-nil matching CONTENT face."
526   :group 'gnus-article-headers
527   :group 'gnus-article-highlight
528   :type '(repeat (list (regexp :tag "Header")
529                        (choice :tag "Name"
530                                (item :tag "skip" nil)
531                                (face :value default))
532                        (choice :tag "Content"
533                                (item :tag "skip" nil)
534                                (face :value default)))))
535
536 (defcustom gnus-article-decode-hook
537   '(article-decode-charset article-decode-encoded-words)
538   "*Hook run to decode charsets in articles."
539   :group 'gnus-article-headers
540   :type 'hook)
541
542 (defcustom gnus-display-mime-function 'gnus-display-mime
543   "Function to display MIME articles."
544   :group 'gnus-article-headers
545   :type 'function)
546
547 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
548   "Function used to decode headers.")
549
550 (defvar gnus-article-dumbquotes-map
551   '(("\202" ",")
552     ("\203" "f")
553     ("\204" ",,")
554     ("\213" "<")
555     ("\214" "OE")
556     ("\205" "...")
557     ("\221" "`")
558     ("\222" "'")
559     ("\223" "``")
560     ("\224" "''")
561     ("\225" "*")
562     ("\226" "-")
563     ("\227" "-")
564     ("\231" "(TM)")
565     ("\233" ">")
566     ("\234" "oe")
567     ("\264" "'"))
568   "Table for MS-to-Latin1 translation.")
569
570 ;;; Internal variables
571
572 (defvar gnus-article-mime-handle-alist nil)
573 (defvar article-lapsed-timer nil)
574 (defvar gnus-article-current-summary nil)
575
576 (defvar gnus-article-mode-syntax-table
577   (let ((table (copy-syntax-table text-mode-syntax-table)))
578     (modify-syntax-entry ?- "w" table)
579     (modify-syntax-entry ?> ")" table)
580     (modify-syntax-entry ?< "(" table)
581     table)
582   "Syntax table used in article mode buffers.
583 Initialized from `text-mode-syntax-table.")
584
585 (defvar gnus-save-article-buffer nil)
586
587 (defvar gnus-article-mode-line-format-alist
588   (nconc '((?w (gnus-article-wash-status) ?s))
589          gnus-summary-mode-line-format-alist))
590
591 (defvar gnus-number-of-articles-to-be-saved nil)
592
593 (defvar gnus-inhibit-hiding nil)
594
595 (defsubst gnus-article-hide-text (b e props)
596   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
597   (add-text-properties b e props)
598   (when (memq 'intangible props)
599     (put-text-property
600      (max (1- b) (point-min))
601      b 'intangible (cddr (memq 'intangible props)))))
602
603 (defsubst gnus-article-unhide-text (b e)
604   "Remove hidden text properties from region between B and E."
605   (remove-text-properties b e gnus-hidden-properties)
606   (when (memq 'intangible gnus-hidden-properties)
607     (put-text-property (max (1- b) (point-min))
608                        b 'intangible nil)))
609
610 (defun gnus-article-hide-text-type (b e type)
611   "Hide text of TYPE between B and E."
612   (gnus-article-hide-text
613    b e (cons 'article-type (cons type gnus-hidden-properties))))
614
615 (defun gnus-article-unhide-text-type (b e type)
616   "Unhide text of TYPE between B and E."
617   (remove-text-properties
618    b e (cons 'article-type (cons type gnus-hidden-properties)))
619   (when (memq 'intangible gnus-hidden-properties)
620     (put-text-property (max (1- b) (point-min))
621                        b 'intangible nil)))
622
623 (defun gnus-article-hide-text-of-type (type)
624   "Hide text of TYPE in the current buffer."
625   (save-excursion
626     (let ((b (point-min))
627           (e (point-max)))
628       (while (setq b (text-property-any b e 'article-type type))
629         (add-text-properties b (incf b) gnus-hidden-properties)))))
630
631 (defun gnus-article-delete-text-of-type (type)
632   "Delete text of TYPE in the current buffer."
633   (save-excursion
634     (let ((b (point-min)))
635       (while (setq b (text-property-any b (point-max) 'article-type type))
636         (delete-region
637          b (or (text-property-not-all b (point-max) 'article-type type)
638                (point-max)))))))
639
640 (defun gnus-article-delete-invisible-text ()
641   "Delete all invisible text in the current buffer."
642   (save-excursion
643     (let ((b (point-min)))
644       (while (setq b (text-property-any b (point-max) 'invisible t))
645         (delete-region
646          b (or (text-property-not-all b (point-max) 'invisible t)
647                (point-max)))))))
648
649 (defun gnus-article-text-type-exists-p (type)
650   "Say whether any text of type TYPE exists in the buffer."
651   (text-property-any (point-min) (point-max) 'article-type type))
652
653 (defsubst gnus-article-header-rank ()
654   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
655   (let ((list gnus-sorted-header-list)
656         (i 0))
657     (while list
658       (when (looking-at (car list))
659         (setq list nil))
660       (setq list (cdr list))
661       (incf i))
662     i))
663
664 (defun article-hide-headers (&optional arg delete)
665   "Toggle whether to hide unwanted headers and possibly sort them as well.
666 If given a negative prefix, always show; if given a positive prefix,
667 always hide."
668   (interactive (gnus-article-hidden-arg))
669   (current-buffer)
670   (if (gnus-article-check-hidden-text 'headers arg)
671       ;; Show boring headers as well.
672       (gnus-article-show-hidden-text 'boring-headers)
673     ;; This function might be inhibited.
674     (unless gnus-inhibit-hiding
675       (save-excursion
676         (save-restriction
677           (let ((buffer-read-only nil)
678                 (case-fold-search t)
679                 (props (nconc (list 'article-type 'headers)
680                               gnus-hidden-properties))
681                 (max (1+ (length gnus-sorted-header-list)))
682                 (ignored (when (not gnus-visible-headers)
683                            (cond ((stringp gnus-ignored-headers)
684                                   gnus-ignored-headers)
685                                  ((listp gnus-ignored-headers)
686                                   (mapconcat 'identity gnus-ignored-headers
687                                              "\\|")))))
688                 (visible
689                  (cond ((stringp gnus-visible-headers)
690                         gnus-visible-headers)
691                        ((and gnus-visible-headers
692                              (listp gnus-visible-headers))
693                         (mapconcat 'identity gnus-visible-headers "\\|"))))
694                 (inhibit-point-motion-hooks t)
695                 beg)
696             ;; First we narrow to just the headers.
697             (widen)
698             (goto-char (point-min))
699             ;; Hide any "From " lines at the beginning of (mail) articles.
700             (while (looking-at "From ")
701               (forward-line 1))
702             (unless (bobp)
703               (if delete
704                   (delete-region (point-min) (point))
705                 (gnus-article-hide-text (point-min) (point) props)))
706             ;; Then treat the rest of the header lines.
707             (narrow-to-region
708              (point)
709              (if (search-forward "\n\n" nil t) ; if there's a body
710                  (progn (forward-line -1) (point))
711                (point-max)))
712             ;; Then we use the two regular expressions
713             ;; `gnus-ignored-headers' and `gnus-visible-headers' to
714             ;; select which header lines is to remain visible in the
715             ;; article buffer.
716             (goto-char (point-min))
717             (while (re-search-forward "^[^ \t]*:" nil t)
718               (beginning-of-line)
719               ;; Mark the rank of the header.
720               (put-text-property
721                (point) (1+ (point)) 'message-rank
722                (if (or (and visible (looking-at visible))
723                        (and ignored
724                             (not (looking-at ignored))))
725                    (gnus-article-header-rank)
726                  (+ 2 max)))
727               (forward-line 1))
728             (message-sort-headers-1)
729             (when (setq beg (text-property-any
730                              (point-min) (point-max) 'message-rank (+ 2 max)))
731               ;; We make the unwanted headers invisible.
732               (if delete
733                   (delete-region beg (point-max))
734                 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
735                 (gnus-article-hide-text-type beg (point-max) 'headers))
736               ;; Work around XEmacs lossage.
737               (put-text-property (point-min) beg 'invisible nil))))))))
738
739 (defun article-hide-boring-headers (&optional arg)
740   "Toggle hiding of headers that aren't very interesting.
741 If given a negative prefix, always show; if given a positive prefix,
742 always hide."
743   (interactive (gnus-article-hidden-arg))
744   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
745              (not gnus-show-all-headers))
746     (save-excursion
747       (save-restriction
748         (let ((buffer-read-only nil)
749               (list gnus-boring-article-headers)
750               (inhibit-point-motion-hooks t)
751               elem)
752           (nnheader-narrow-to-headers)
753           (while list
754             (setq elem (pop list))
755             (goto-char (point-min))
756             (cond
757              ;; Hide empty headers.
758              ((eq elem 'empty)
759               (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
760                 (forward-line -1)
761                 (gnus-article-hide-text-type
762                  (progn (beginning-of-line) (point))
763                  (progn
764                    (end-of-line)
765                    (if (re-search-forward "^[^ \t]" nil t)
766                        (match-beginning 0)
767                      (point-max)))
768                  'boring-headers)))
769              ;; Hide boring Newsgroups header.
770              ((eq elem 'newsgroups)
771               (when (equal (gnus-fetch-field "newsgroups")
772                            (gnus-group-real-name
773                             (if (boundp 'gnus-newsgroup-name)
774                                 gnus-newsgroup-name
775                               "")))
776                 (gnus-article-hide-header "newsgroups")))
777              ((eq elem 'followup-to)
778               (when (equal (message-fetch-field "followup-to")
779                            (message-fetch-field "newsgroups"))
780                 (gnus-article-hide-header "followup-to")))
781              ((eq elem 'reply-to)
782               (let ((from (message-fetch-field "from"))
783                     (reply-to (message-fetch-field "reply-to")))
784                 (when (and
785                        from reply-to
786                        (ignore-errors
787                          (equal
788                           (nth 1 (mail-extract-address-components from))
789                           (nth 1 (mail-extract-address-components reply-to)))))
790                   (gnus-article-hide-header "reply-to"))))
791              ((eq elem 'date)
792               (let ((date (message-fetch-field "date")))
793                 (when (and date
794                            (< (days-between (current-time-string) date)
795                               4))
796                   (gnus-article-hide-header "date"))))
797              ((eq elem 'long-to)
798               (let ((to (message-fetch-field "to")))
799                 (when (> (length to) 1024)
800                   (gnus-article-hide-header "to"))))
801              ((eq elem 'many-to)
802               (let ((to-count 0))
803                 (goto-char (point-min))
804                 (while (re-search-forward "^to:" nil t)
805                   (setq to-count (1+ to-count)))
806                 (when (> to-count 1)
807                   (while (> to-count 0)
808                     (goto-char (point-min))
809                     (save-restriction
810                       (re-search-forward "^to:" nil nil to-count)
811                       (forward-line -1)
812                       (narrow-to-region (point) (point-max))
813                       (gnus-article-hide-header "to"))
814                     (setq to-count (1- to-count)))))))))))))
815
816 (defun gnus-article-hide-header (header)
817   (save-excursion
818     (goto-char (point-min))
819     (when (re-search-forward (concat "^" header ":") nil t)
820       (gnus-article-hide-text-type
821        (progn (beginning-of-line) (point))
822        (progn
823          (end-of-line)
824          (if (re-search-forward "^[^ \t]" nil t)
825              (match-beginning 0)
826            (point-max)))
827        'boring-headers))))
828
829 (defun article-treat-dumbquotes ()
830   "Translate M******** sm*rtq**t*s into proper text."
831   (interactive)
832   (article-translate-strings gnus-article-dumbquotes-map))
833
834 (defun article-translate-characters (from to)
835   "Translate all characters in the body of the article according to FROM and TO.
836 FROM is a string of characters to translate from; to is a string of
837 characters to translate to."
838   (save-excursion
839     (goto-char (point-min))
840     (when (search-forward "\n\n" nil t)
841       (let ((buffer-read-only nil)
842             (x (make-string 225 ?x))
843             (i -1))
844         (while (< (incf i) (length x))
845           (aset x i i))
846         (setq i 0)
847         (while (< i (length from))
848           (aset x (aref from i) (aref to i))
849           (incf i))
850         (translate-region (point) (point-max) x)))))
851
852 (defun article-translate-strings (map)
853   "Translate all string in the body of the article according to MAP.
854 MAP is an alist where the elements are on the form (\"from\" \"to\")."
855   (save-excursion
856     (goto-char (point-min))
857     (when (search-forward "\n\n" nil t)
858       (let ((buffer-read-only nil)
859             elem)
860         (while (setq elem (pop map))
861           (save-excursion
862             (while (search-forward (car elem) nil t)
863               (replace-match (cadr elem)))))))))
864
865 (defun article-treat-overstrike ()
866   "Translate overstrikes into bold text."
867   (interactive)
868   (save-excursion
869     (goto-char (point-min))
870     (when (search-forward "\n\n" nil t)
871       (let ((buffer-read-only nil))
872         (while (search-forward "\b" nil t)
873           (let ((next (following-char))
874                 (previous (char-after (- (point) 2))))
875             ;; We do the boldification/underlining by hiding the
876             ;; overstrikes and putting the proper text property
877             ;; on the letters.
878             (cond
879              ((eq next previous)
880               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
881               (put-text-property (point) (1+ (point)) 'face 'bold))
882              ((eq next ?_)
883               (gnus-article-hide-text-type
884                (1- (point)) (1+ (point)) 'overstrike)
885               (put-text-property
886                (- (point) 2) (1- (point)) 'face 'underline))
887              ((eq previous ?_)
888               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
889               (put-text-property
890                (point) (1+ (point)) 'face 'underline)))))))))
891
892 (defun article-fill ()
893   "Format too long lines."
894   (interactive)
895   (save-excursion
896     (let ((buffer-read-only nil))
897       (widen)
898       (goto-char (point-min))
899       (search-forward "\n\n" nil t)
900       (end-of-line 1)
901       (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
902             (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
903             (adaptive-fill-mode t))
904         (while (not (eobp))
905           (and (>= (current-column) (min fill-column (window-width)))
906                (/= (preceding-char) ?:)
907                (fill-paragraph nil))
908           (end-of-line 2))))))
909
910 (defun article-remove-cr ()
911   "Remove carriage returns from an article."
912   (interactive)
913   (save-excursion
914     (let ((buffer-read-only nil))
915       (goto-char (point-min))
916       (while (search-forward "\r" nil t)
917         (replace-match "" t t)))))
918
919 (defun article-remove-trailing-blank-lines ()
920   "Remove all trailing blank lines from the article."
921   (interactive)
922   (save-excursion
923     (let ((buffer-read-only nil))
924       (goto-char (point-max))
925       (delete-region
926        (point)
927        (progn
928          (while (and (not (bobp))
929                      (looking-at "^[ \t]*$")
930                      (not (gnus-annotation-in-region-p
931                            (point) (gnus-point-at-eol))))
932            (forward-line -1))
933          (forward-line 1)
934          (point))))))
935
936 (defun article-display-x-face (&optional force)
937   "Look for an X-Face header and display it if present."
938   (interactive (list 'force))
939   (save-excursion
940     ;; Delete the old process, if any.
941     (when (process-status "article-x-face")
942       (delete-process "article-x-face"))
943     (let ((inhibit-point-motion-hooks t)
944           (case-fold-search t)
945           from last)
946       (save-restriction
947         (nnheader-narrow-to-headers)
948         (setq from (message-fetch-field "from"))
949         (goto-char (point-min))
950         (while (and gnus-article-x-face-command
951                     (not last)
952                     (or force
953                         ;; Check whether this face is censored.
954                         (not gnus-article-x-face-too-ugly)
955                         (and gnus-article-x-face-too-ugly from
956                              (not (string-match gnus-article-x-face-too-ugly
957                                                 from))))
958                     ;; Has to be present.
959                     (re-search-forward "^X-Face: " nil t))
960           ;; This used to try to do multiple faces (`while' instead of
961           ;; `when' above), but (a) sending multiple EOFs to xv doesn't
962           ;; work (b) it can crash some versions of Emacs (c) are
963           ;; multiple faces really something to encourage?
964           (when (stringp gnus-article-x-face-command)
965             (setq last t))
966           ;; We now have the area of the buffer where the X-Face is stored.
967           (save-excursion
968             (let ((beg (point))
969                   (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
970               ;; We display the face.
971               (if (symbolp gnus-article-x-face-command)
972                   ;; The command is a lisp function, so we call it.
973                   (if (gnus-functionp gnus-article-x-face-command)
974                       (funcall gnus-article-x-face-command beg end)
975                     (error "%s is not a function" gnus-article-x-face-command))
976                 ;; The command is a string, so we interpret the command
977                 ;; as a, well, command, and fork it off.
978                 (let ((process-connection-type nil))
979                   (process-kill-without-query
980                    (start-process
981                     "article-x-face" nil shell-file-name shell-command-switch
982                     gnus-article-x-face-command))
983                   (process-send-region "article-x-face" beg end)
984                   (process-send-eof "article-x-face"))))))))))
985
986 (defun article-decode-mime-words ()
987   "Decode all MIME-encoded words in the article."
988   (interactive)
989   (save-excursion
990     (set-buffer gnus-article-buffer)
991     (let ((inhibit-point-motion-hooks t)
992           buffer-read-only)
993       (mail-decode-encoded-word-region (point-min) (point-max)))))
994
995 (defun article-decode-charset (&optional prompt)
996   "Decode charset-encoded text in the article.
997 If PROMPT (the prefix), prompt for a coding system to use."
998   (interactive "P")
999   (save-excursion
1000     (save-restriction
1001       (message-narrow-to-head)
1002       (let* ((inhibit-point-motion-hooks t)
1003              (case-fold-search t)
1004              (ct (message-fetch-field "Content-Type" t))
1005              (cte (message-fetch-field "Content-Transfer-Encoding" t))
1006              (ctl (and ct (condition-case ()
1007                               (mail-header-parse-content-type ct)
1008                             (error nil))))
1009              (charset (cond
1010                        (prompt
1011                         (mm-read-coding-system "Charset to decode: "))
1012                        (ctl
1013                         (mail-content-type-get ctl 'charset))
1014                        (gnus-newsgroup-name
1015                         (gnus-group-find-parameter
1016                          gnus-newsgroup-name 'charset))))
1017              buffer-read-only)
1018         (goto-char (point-max))
1019         (widen)
1020         (forward-line 1)
1021         (narrow-to-region (point) (point-max))
1022         (when (or (not ct)
1023                   (equal (car ctl) "text/plain"))
1024           (mm-decode-body
1025            charset (and cte (intern (downcase
1026                                      (gnus-strip-whitespace cte))))))))))
1027
1028 (defun article-decode-encoded-words ()
1029   "Remove encoded-word encoding from headers."
1030   (let ((inhibit-point-motion-hooks t)
1031         (buffer-read-only nil))
1032     (save-restriction
1033       (message-narrow-to-head)
1034       (funcall gnus-decode-header-function (point-min) (point-max)))))
1035
1036 (defun article-de-quoted-unreadable (&optional force)
1037   "Translate a quoted-printable-encoded article.
1038 If FORCE, decode the article whether it is marked as quoted-printable
1039 or not."
1040   (interactive (list 'force))
1041   (save-excursion
1042     (let ((buffer-read-only nil)
1043           (type (gnus-fetch-field "content-transfer-encoding")))
1044       (when (or force
1045                 (and type (string-match "quoted-printable" (downcase type))))
1046         (goto-char (point-min))
1047         (search-forward "\n\n" nil 'move)
1048         (quoted-printable-decode-region (point) (point-max))
1049         (when mm-default-coding-system
1050           (mm-decode-body mm-default-coding-system))))))
1051
1052 (defun article-mime-decode-quoted-printable-buffer ()
1053   "Decode Quoted-Printable in the current buffer."
1054   (quoted-printable-decode-region (point-min) (point-max)))
1055
1056 (defun article-hide-pgp (&optional arg)
1057   "Toggle hiding of any PGP headers and signatures in the current article.
1058 If given a negative prefix, always show; if given a positive prefix,
1059 always hide."
1060   (interactive (gnus-article-hidden-arg))
1061   (unless (gnus-article-check-hidden-text 'pgp arg)
1062     (save-excursion
1063       (let ((inhibit-point-motion-hooks t)
1064             buffer-read-only beg end)
1065         (widen)
1066         (goto-char (point-min))
1067         ;; Hide the "header".
1068         (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1069           (delete-region (1+ (match-beginning 0)) (match-end 0))
1070           ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1071           (when (looking-at "Hash:.*$")
1072             (delete-region (point) (1+ (gnus-point-at-eol))))
1073           (setq beg (point))
1074           ;; Hide the actual signature.
1075           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1076                (setq end (1+ (match-beginning 0)))
1077                (delete-region
1078                 end
1079                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1080                     (match-end 0)
1081                   ;; Perhaps we shouldn't hide to the end of the buffer
1082                   ;; if there is no end to the signature?
1083                   (point-max))))
1084           ;; Hide "- " PGP quotation markers.
1085           (when (and beg end)
1086             (narrow-to-region beg end)
1087             (goto-char (point-min))
1088             (while (re-search-forward "^- " nil t)
1089               (delete-region
1090                (match-beginning 0) (match-end 0)))
1091             (widen))
1092           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1093
1094 (defun article-hide-pem (&optional arg)
1095   "Toggle hiding of any PEM headers and signatures in the current article.
1096 If given a negative prefix, always show; if given a positive prefix,
1097 always hide."
1098   (interactive (gnus-article-hidden-arg))
1099   (unless (gnus-article-check-hidden-text 'pem arg)
1100     (save-excursion
1101       (let (buffer-read-only end)
1102         (widen)
1103         (goto-char (point-min))
1104         ;; hide the horrendously ugly "header".
1105         (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1106                              nil
1107                              t)
1108              (setq end (1+ (match-beginning 0)))
1109              (gnus-article-hide-text-type
1110               end
1111               (if (search-forward "\n\n" nil t)
1112                   (match-end 0)
1113                 (point-max))
1114               'pem))
1115         ;; hide the trailer as well
1116         (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1117                              nil
1118                              t)
1119              (gnus-article-hide-text-type
1120               (match-beginning 0) (match-end 0) 'pem))))))
1121
1122 (defun article-hide-signature (&optional arg)
1123   "Hide the signature in the current article.
1124 If given a negative prefix, always show; if given a positive prefix,
1125 always hide."
1126   (interactive (gnus-article-hidden-arg))
1127   (unless (gnus-article-check-hidden-text 'signature arg)
1128     (save-excursion
1129       (save-restriction
1130         (let ((buffer-read-only nil))
1131           (when (gnus-article-narrow-to-signature)
1132             (gnus-article-hide-text-type
1133              (point-min) (point-max) 'signature)))))))
1134
1135 (defun article-strip-leading-blank-lines ()
1136   "Remove all blank lines from the beginning of the article."
1137   (interactive)
1138   (save-excursion
1139     (let ((inhibit-point-motion-hooks t)
1140           buffer-read-only)
1141       (goto-char (point-min))
1142       (when (search-forward "\n\n" nil t)
1143         (while (and (not (eobp))
1144                     (looking-at "[ \t]*$"))
1145           (gnus-delete-line))))))
1146
1147 (defun article-strip-multiple-blank-lines ()
1148   "Replace consecutive blank lines with one empty line."
1149   (interactive)
1150   (save-excursion
1151     (let ((inhibit-point-motion-hooks t)
1152           buffer-read-only)
1153       ;; First make all blank lines empty.
1154       (goto-char (point-min))
1155       (search-forward "\n\n" nil t)
1156       (while (re-search-forward "^[ \t]+$" nil t)
1157         (unless (gnus-annotation-in-region-p
1158                  (match-beginning 0) (match-end 0))
1159           (replace-match "" nil t)))
1160       ;; Then replace multiple empty lines with a single empty line.
1161       (goto-char (point-min))
1162       (search-forward "\n\n" nil t)
1163       (while (re-search-forward "\n\n\n+" nil t)
1164         (unless (gnus-annotation-in-region-p
1165                  (match-beginning 0) (match-end 0))
1166           (replace-match "\n\n" t t))))))
1167
1168 (defun article-strip-leading-space ()
1169   "Remove all white space from the beginning of the lines in the article."
1170   (interactive)
1171   (save-excursion
1172     (let ((inhibit-point-motion-hooks t)
1173           buffer-read-only)
1174       (goto-char (point-min))
1175       (search-forward "\n\n" nil t)
1176       (while (re-search-forward "^[ \t]+" nil t)
1177         (replace-match "" t t)))))
1178
1179 (defun article-strip-blank-lines ()
1180   "Strip leading, trailing and multiple blank lines."
1181   (interactive)
1182   (article-strip-leading-blank-lines)
1183   (article-remove-trailing-blank-lines)
1184   (article-strip-multiple-blank-lines))
1185
1186 (defun article-strip-all-blank-lines ()
1187   "Strip all blank lines."
1188   (interactive)
1189   (save-excursion
1190     (let ((inhibit-point-motion-hooks t)
1191           buffer-read-only)
1192       (goto-char (point-min))
1193       (search-forward "\n\n" nil t)
1194       (while (re-search-forward "^[ \t]*\n" nil t)
1195         (replace-match "" t t)))))
1196
1197 (defvar mime::preview/content-list)
1198 (defvar mime::preview-content-info/point-min)
1199 (defun gnus-article-narrow-to-signature ()
1200   "Narrow to the signature; return t if a signature is found, else nil."
1201   (widen)
1202   (let ((inhibit-point-motion-hooks t))
1203     (when (and (boundp 'mime::preview/content-list)
1204                mime::preview/content-list)
1205       ;; We have a MIMEish article, so we use the MIME data to narrow.
1206       (let ((pcinfo (car (last mime::preview/content-list))))
1207         (ignore-errors
1208           (narrow-to-region
1209            (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1210            (point-max)))))
1211
1212     (when (gnus-article-search-signature)
1213       (forward-line 1)
1214       ;; Check whether we have some limits to what we consider
1215       ;; to be a signature.
1216       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1217                       (list gnus-signature-limit)))
1218             limit limited)
1219         (while (setq limit (pop limits))
1220           (if (or (and (integerp limit)
1221                        (< (- (point-max) (point)) limit))
1222                   (and (floatp limit)
1223                        (< (count-lines (point) (point-max)) limit))
1224                   (and (gnus-functionp limit)
1225                        (funcall limit))
1226                   (and (stringp limit)
1227                        (not (re-search-forward limit nil t))))
1228               ()                        ; This limit did not succeed.
1229             (setq limited t
1230                   limits nil)))
1231         (unless limited
1232           (narrow-to-region (point) (point-max))
1233           t)))))
1234
1235 (defun gnus-article-search-signature ()
1236   "Search the current buffer for the signature separator.
1237 Put point at the beginning of the signature separator."
1238   (let ((cur (point)))
1239     (goto-char (point-max))
1240     (if (if (stringp gnus-signature-separator)
1241             (re-search-backward gnus-signature-separator nil t)
1242           (let ((seps gnus-signature-separator))
1243             (while (and seps
1244                         (not (re-search-backward (car seps) nil t)))
1245               (pop seps))
1246             seps))
1247         t
1248       (goto-char cur)
1249       nil)))
1250
1251 (eval-and-compile
1252   (autoload 'w3-display "w3-parse")
1253   (autoload 'w3-do-setup "w3" "" t)
1254   (autoload 'w3-region "w3-display" "" t))
1255
1256 (defun gnus-article-treat-html ()
1257   "Render HTML."
1258   (interactive)
1259   (let ((cbuf (current-buffer)))
1260     (set-buffer gnus-article-buffer)
1261     (let (buf buffer-read-only b e)
1262       (w3-do-setup)
1263       (goto-char (point-min))
1264       (narrow-to-region
1265        (if (search-forward "\n\n" nil t)
1266            (setq b (point))
1267          (point-max))
1268        (setq e (point-max)))
1269       (with-temp-buffer
1270         (insert-buffer-substring gnus-article-buffer b e)
1271         (require 'url)
1272         (save-window-excursion
1273           (w3-region (point-min) (point-max))
1274           (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1275       (when buf
1276         (delete-region (point-min) (point-max))
1277         (insert buf))
1278       (widen)
1279       (goto-char (point-min))
1280       (set-window-start (get-buffer-window (current-buffer)) (point-min))
1281       (set-buffer cbuf))))
1282
1283 (defun gnus-article-hidden-arg ()
1284   "Return the current prefix arg as a number, or 0 if no prefix."
1285   (list (if current-prefix-arg
1286             (prefix-numeric-value current-prefix-arg)
1287           0)))
1288
1289 (defun gnus-article-check-hidden-text (type arg)
1290   "Return nil if hiding is necessary.
1291 Arg can be nil or a number.  Nil and positive means hide, negative
1292 means show, 0 means toggle."
1293   (save-excursion
1294     (save-restriction
1295       (widen)
1296       (let ((hide (gnus-article-hidden-text-p type)))
1297         (cond
1298          ((or (null arg)
1299               (> arg 0))
1300           nil)
1301          ((< arg 0)
1302           (gnus-article-show-hidden-text type))
1303          (t
1304           (if (eq hide 'hidden)
1305               (gnus-article-show-hidden-text type)
1306             nil)))))))
1307
1308 (defun gnus-article-hidden-text-p (type)
1309   "Say whether the current buffer contains hidden text of type TYPE."
1310   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1311     (while (and pos
1312                 (not (get-text-property pos 'invisible)))
1313       (setq pos
1314             (text-property-any (1+ pos) (point-max) 'article-type type)))
1315     (if pos
1316         'hidden
1317       'shown)))
1318
1319 (defun gnus-article-show-hidden-text (type &optional hide)
1320   "Show all hidden text of type TYPE.
1321 If HIDE, hide the text instead."
1322   (save-excursion
1323     (let ((buffer-read-only nil)
1324           (inhibit-point-motion-hooks t)
1325           (end (point-min))
1326           beg)
1327       (while (setq beg (text-property-any end (point-max) 'article-type type))
1328         (goto-char beg)
1329         (setq end (or
1330                    (text-property-not-all beg (point-max) 'article-type type)
1331                    (point-max)))
1332         (if hide
1333             (gnus-article-hide-text beg end gnus-hidden-properties)
1334           (gnus-article-unhide-text beg end))
1335         (goto-char end))
1336       t)))
1337
1338 (defconst article-time-units
1339   `((year . ,(* 365.25 24 60 60))
1340     (week . ,(* 7 24 60 60))
1341     (day . ,(* 24 60 60))
1342     (hour . ,(* 60 60))
1343     (minute . 60)
1344     (second . 1))
1345   "Mapping from time units to seconds.")
1346
1347 (defun article-date-ut (&optional type highlight header)
1348   "Convert DATE date to universal time in the current article.
1349 If TYPE is `local', convert to local time; if it is `lapsed', output
1350 how much time has lapsed since DATE."
1351   (interactive (list 'ut t))
1352   (let* ((header (or header
1353                      (mail-header-date gnus-current-headers)
1354                      (message-fetch-field "date")
1355                      ""))
1356          (date (if (vectorp header) (mail-header-date header)
1357                  header))
1358          (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1359          (inhibit-point-motion-hooks t)
1360          bface eface newline)
1361     (when (and date (not (string= date "")))
1362       (save-excursion
1363         (save-restriction
1364           (nnheader-narrow-to-headers)
1365           (let ((buffer-read-only nil))
1366             ;; Delete any old Date headers.
1367             (if (re-search-forward date-regexp nil t)
1368                 (progn
1369                   (setq bface (get-text-property (gnus-point-at-bol) 'face)
1370                         eface (get-text-property (1- (gnus-point-at-eol))
1371                                                  'face))
1372                   (delete-region (progn (beginning-of-line) (point))
1373                                  (progn (end-of-line) (point)))
1374                   (beginning-of-line))
1375               (goto-char (point-max))
1376               (setq newline t))
1377             (insert (article-make-date-line date type))
1378             ;; Do highlighting.
1379             (beginning-of-line)
1380             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1381               (put-text-property (match-beginning 1) (1+ (match-end 1))
1382                                  'face bface)
1383               (put-text-property (match-beginning 2) (match-end 2)
1384                                  'face eface))
1385             (when newline
1386               (end-of-line)
1387               (insert "\n"))))))))
1388
1389 (defun article-make-date-line (date type)
1390   "Return a DATE line of TYPE."
1391   (let ((time (condition-case ()
1392                   (date-to-time date)
1393                 (error '(0 0)))))
1394     (cond
1395      ;; Convert to the local timezone.  We have to slap a
1396      ;; `condition-case' round the calls to the timezone
1397      ;; functions since they aren't particularly resistant to
1398      ;; buggy dates.
1399      ((eq type 'local)
1400       (let ((tz (car (current-time-zone))))
1401         (format "Date: %s %s%04d" (current-time-string time)
1402                 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1403      ;; Convert to Universal Time.
1404      ((eq type 'ut)
1405       (concat "Date: "
1406               (current-time-string
1407                (let* ((e (parse-time-string date))
1408                      (tm (apply 'encode-time e))
1409                      (ms (car tm))
1410                      (ls (- (cadr tm) (car (current-time-zone)))))
1411                  (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1412                        ((> ls 65535) (list (1+ ms) (- ls 65536)))
1413                        (t (list ms ls)))))
1414               " UT"))
1415      ;; Get the original date from the article.
1416      ((eq type 'original)
1417       (concat "Date: " (if (string-match "\n+$" date)
1418                            (substring date 0 (match-beginning 0))
1419                          date)))
1420      ;; Let the user define the format.
1421      ((eq type 'user)
1422       (if (gnus-functionp gnus-article-time-format)
1423           (funcall gnus-article-time-format time)
1424         (concat
1425          "Date: "
1426          (format-time-string gnus-article-time-format time))))
1427      ;; ISO 8601.
1428      ((eq type 'iso8601)
1429       (concat
1430        "Date: "
1431        (format-time-string "%Y%M%DT%h%m%s" time)))
1432      ;; Do an X-Sent lapsed format.
1433      ((eq type 'lapsed)
1434       ;; If the date is seriously mangled, the timezone functions are
1435       ;; liable to bug out, so we ignore all errors.
1436       (let* ((now (current-time))
1437              (real-time (subtract-time now time))
1438              (real-sec (and real-time
1439                             (+ (* (float (car real-time)) 65536)
1440                                (cadr real-time))))
1441              (sec (and real-time (abs real-sec)))
1442              num prev)
1443         (cond
1444          ((null real-time)
1445           "X-Sent: Unknown")
1446          ((zerop sec)
1447           "X-Sent: Now")
1448          (t
1449           (concat
1450            "X-Sent: "
1451            ;; This is a bit convoluted, but basically we go
1452            ;; through the time units for years, weeks, etc,
1453            ;; and divide things to see whether that results
1454            ;; in positive answers.
1455            (mapconcat
1456             (lambda (unit)
1457               (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1458                   ;; The (remaining) seconds are too few to
1459                   ;; be divided into this time unit.
1460                   ""
1461                 ;; It's big enough, so we output it.
1462                 (setq sec (- sec (* num (cdr unit))))
1463                 (prog1
1464                     (concat (if prev ", " "") (int-to-string
1465                                                (floor num))
1466                             " " (symbol-name (car unit))
1467                             (if (> num 1) "s" ""))
1468                   (setq prev t))))
1469             article-time-units "")
1470            ;; If dates are odd, then it might appear like the
1471            ;; article was sent in the future.
1472            (if (> real-sec 0)
1473                " ago"
1474              " in the future"))))))
1475      (t
1476       (error "Unknown conversion type: %s" type)))))
1477
1478 (defun article-date-local (&optional highlight)
1479   "Convert the current article date to the local timezone."
1480   (interactive (list t))
1481   (article-date-ut 'local highlight))
1482
1483 (defun article-date-original (&optional highlight)
1484   "Convert the current article date to what it was originally.
1485 This is only useful if you have used some other date conversion
1486 function and want to see what the date was before converting."
1487   (interactive (list t))
1488   (article-date-ut 'original highlight))
1489
1490 (defun article-date-lapsed (&optional highlight)
1491   "Convert the current article date to time lapsed since it was sent."
1492   (interactive (list t))
1493   (article-date-ut 'lapsed highlight))
1494
1495 (defun article-update-date-lapsed ()
1496   "Function to be run from a timer to update the lapsed time line."
1497   (let (deactivate-mark)
1498     (save-excursion
1499       (ignore-errors
1500         (walk-windows
1501          (lambda (w)
1502            (set-buffer (window-buffer w))
1503            (when (eq major-mode 'gnus-article-mode)
1504              (goto-char (point-min))
1505              (when (re-search-forward "^X-Sent:" nil t)
1506                (article-date-lapsed t)))))))))
1507
1508 (defun gnus-start-date-timer (&optional n)
1509   "Start a timer to update the X-Sent header in the article buffers.
1510 The numerical prefix says how frequently (in seconds) the function
1511 is to run."
1512   (interactive "p")
1513   (unless n
1514     (setq n 1))
1515   (gnus-stop-date-timer)
1516   (setq article-lapsed-timer
1517         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1518
1519 (defun gnus-stop-date-timer ()
1520   "Stop the X-Sent timer."
1521   (interactive)
1522   (when article-lapsed-timer
1523     (nnheader-cancel-timer article-lapsed-timer)
1524     (setq article-lapsed-timer nil)))
1525
1526 (defun article-date-user (&optional highlight)
1527   "Convert the current article date to the user-defined format.
1528 This format is defined by the `gnus-article-time-format' variable."
1529   (interactive (list t))
1530   (article-date-ut 'user highlight))
1531
1532 (defun article-date-iso8601 (&optional highlight)
1533   "Convert the current article date to ISO8601."
1534   (interactive (list t))
1535   (article-date-ut 'iso8601 highlight))
1536
1537 (defun article-show-all ()
1538   "Show all hidden text in the article buffer."
1539   (interactive)
1540   (save-excursion
1541     (let ((buffer-read-only nil))
1542       (gnus-article-unhide-text (point-min) (point-max)))))
1543
1544 (defun article-emphasize (&optional arg)
1545   "Emphasize text according to `gnus-emphasis-alist'."
1546   (interactive (gnus-article-hidden-arg))
1547   (unless (gnus-article-check-hidden-text 'emphasis arg)
1548     (save-excursion
1549       (let ((alist gnus-emphasis-alist)
1550             (buffer-read-only nil)
1551             (props (append '(article-type emphasis)
1552                            gnus-hidden-properties))
1553             regexp elem beg invisible visible face)
1554         (goto-char (point-min))
1555         (search-forward "\n\n" nil t)
1556         (setq beg (point))
1557         (while (setq elem (pop alist))
1558           (goto-char beg)
1559           (setq regexp (car elem)
1560                 invisible (nth 1 elem)
1561                 visible (nth 2 elem)
1562                 face (nth 3 elem))
1563           (while (re-search-forward regexp nil t)
1564             (when (and (match-beginning visible) (match-beginning invisible))
1565               (gnus-article-hide-text
1566                (match-beginning invisible) (match-end invisible) props)
1567               (gnus-article-unhide-text-type
1568                (match-beginning visible) (match-end visible) 'emphasis)
1569               (gnus-put-text-property-excluding-newlines
1570                (match-beginning visible) (match-end visible) 'face face)
1571               (goto-char (match-end invisible)))))))))
1572
1573 (defvar gnus-summary-article-menu)
1574 (defvar gnus-summary-post-menu)
1575
1576 ;;; Saving functions.
1577
1578 (defun gnus-article-save (save-buffer file &optional num)
1579   "Save the currently selected article."
1580   (unless gnus-save-all-headers
1581     ;; Remove headers according to `gnus-saved-headers'.
1582     (let ((gnus-visible-headers
1583            (or gnus-saved-headers gnus-visible-headers))
1584           (gnus-article-buffer save-buffer))
1585       (save-excursion
1586         (set-buffer save-buffer)
1587         (article-hide-headers 1 t))))
1588   (save-window-excursion
1589     (if (not gnus-default-article-saver)
1590         (error "No default saver is defined")
1591       ;; !!! Magic!  The saving functions all save
1592       ;; `gnus-save-article-buffer' (or so they think), but we
1593       ;; bind that variable to our save-buffer.
1594       (set-buffer gnus-article-buffer)
1595       (let* ((gnus-save-article-buffer save-buffer)
1596              (filename
1597               (cond
1598                ((not gnus-prompt-before-saving) 'default)
1599                ((eq gnus-prompt-before-saving 'always) nil)
1600                (t file)))
1601              (gnus-number-of-articles-to-be-saved
1602               (when (eq gnus-prompt-before-saving t)
1603                 num)))                  ; Magic
1604         (set-buffer gnus-article-current-summary)
1605         (funcall gnus-default-article-saver filename)))))
1606
1607 (defun gnus-read-save-file-name (prompt &optional filename
1608                                         function group headers variable)
1609   (let ((default-name
1610           (funcall function group headers (symbol-value variable)))
1611         result)
1612     (setq
1613      result
1614      (cond
1615       ((eq filename 'default)
1616        default-name)
1617       ((eq filename t)
1618        default-name)
1619       (filename filename)
1620       (t
1621        (let* ((split-name (gnus-get-split-value gnus-split-methods))
1622               (prompt
1623                (format prompt
1624                        (if (and gnus-number-of-articles-to-be-saved
1625                                 (> gnus-number-of-articles-to-be-saved 1))
1626                            (format "these %d articles"
1627                                    gnus-number-of-articles-to-be-saved)
1628                          "this article")))
1629               (file
1630                ;; Let the split methods have their say.
1631                (cond
1632                 ;; No split name was found.
1633                 ((null split-name)
1634                  (read-file-name
1635                   (concat prompt " (default "
1636                           (file-name-nondirectory default-name) ") ")
1637                   (file-name-directory default-name)
1638                   default-name))
1639                 ;; A single group name is returned.
1640                 ((stringp split-name)
1641                  (setq default-name
1642                        (funcall function split-name headers
1643                                 (symbol-value variable)))
1644                  (read-file-name
1645                   (concat prompt " (default "
1646                           (file-name-nondirectory default-name) ") ")
1647                   (file-name-directory default-name)
1648                   default-name))
1649                 ;; A single split name was found
1650                 ((= 1 (length split-name))
1651                  (let* ((name (expand-file-name
1652                                (car split-name) gnus-article-save-directory))
1653                         (dir (cond ((file-directory-p name)
1654                                     (file-name-as-directory name))
1655                                    ((file-exists-p name) name)
1656                                    (t gnus-article-save-directory))))
1657                    (read-file-name
1658                     (concat prompt " (default " name ") ")
1659                     dir name)))
1660                 ;; A list of splits was found.
1661                 (t
1662                  (setq split-name (nreverse split-name))
1663                  (let (result)
1664                    (let ((file-name-history
1665                           (nconc split-name file-name-history)))
1666                      (setq result
1667                            (expand-file-name
1668                             (read-file-name
1669                              (concat prompt " (`M-p' for defaults) ")
1670                              gnus-article-save-directory
1671                              (car split-name))
1672                             gnus-article-save-directory)))
1673                    (car (push result file-name-history)))))))
1674          ;; Create the directory.
1675          (gnus-make-directory (file-name-directory file))
1676          ;; If we have read a directory, we append the default file name.
1677          (when (file-directory-p file)
1678            (setq file (concat (file-name-as-directory file)
1679                               (file-name-nondirectory default-name))))
1680          ;; Possibly translate some characters.
1681          (nnheader-translate-file-chars file)))))
1682     (gnus-make-directory (file-name-directory result))
1683     (set variable result)))
1684
1685 (defun gnus-article-archive-name (group)
1686   "Return the first instance of an \"Archive-name\" in the current buffer."
1687   (let ((case-fold-search t))
1688     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1689       (nnheader-concat gnus-article-save-directory
1690                        (match-string 1)))))
1691
1692 (defun gnus-article-nndoc-name (group)
1693   "If GROUP is an nndoc group, return the name of the parent group."
1694   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1695     (gnus-group-get-parameter group 'save-article-group)))
1696
1697 (defun gnus-summary-save-in-rmail (&optional filename)
1698   "Append this article to Rmail file.
1699 Optional argument FILENAME specifies file name.
1700 Directory to save to is default to `gnus-article-save-directory'."
1701   (setq filename (gnus-read-save-file-name
1702                   "Save %s in rmail file:" filename
1703                   gnus-rmail-save-name gnus-newsgroup-name
1704                   gnus-current-headers 'gnus-newsgroup-last-rmail))
1705   (gnus-eval-in-buffer-window gnus-save-article-buffer
1706     (save-excursion
1707       (save-restriction
1708         (widen)
1709         (rmail-output-to-rmail-file filename))))
1710   filename)
1711
1712 (defun gnus-summary-save-in-mail (&optional filename)
1713   "Append this article to Unix mail file.
1714 Optional argument FILENAME specifies file name.
1715 Directory to save to is default to `gnus-article-save-directory'."
1716   (setq filename (gnus-read-save-file-name
1717                   "Save %s in Unix mail file:" filename
1718                   gnus-mail-save-name gnus-newsgroup-name
1719                   gnus-current-headers 'gnus-newsgroup-last-mail))
1720   (gnus-eval-in-buffer-window gnus-save-article-buffer
1721     (save-excursion
1722       (save-restriction
1723         (widen)
1724         (if (and (file-readable-p filename)
1725                  (mail-file-babyl-p filename))
1726             (rmail-output-to-rmail-file filename t)
1727           (gnus-output-to-mail filename)))))
1728   filename)
1729
1730 (defun gnus-summary-save-in-file (&optional filename overwrite)
1731   "Append this article to file.
1732 Optional argument FILENAME specifies file name.
1733 Directory to save to is default to `gnus-article-save-directory'."
1734   (setq filename (gnus-read-save-file-name
1735                   "Save %s in file:" filename
1736                   gnus-file-save-name gnus-newsgroup-name
1737                   gnus-current-headers 'gnus-newsgroup-last-file))
1738   (gnus-eval-in-buffer-window gnus-save-article-buffer
1739     (save-excursion
1740       (save-restriction
1741         (widen)
1742         (when (and overwrite
1743                    (file-exists-p filename))
1744           (delete-file filename))
1745         (gnus-output-to-file filename))))
1746   filename)
1747
1748 (defun gnus-summary-write-to-file (&optional filename)
1749   "Write this article to a file.
1750 Optional argument FILENAME specifies file name.
1751 The directory to save in defaults to `gnus-article-save-directory'."
1752   (gnus-summary-save-in-file nil t))
1753
1754 (defun gnus-summary-save-body-in-file (&optional filename)
1755   "Append this article body to a file.
1756 Optional argument FILENAME specifies file name.
1757 The directory to save in defaults to `gnus-article-save-directory'."
1758   (setq filename (gnus-read-save-file-name
1759                   "Save %s body in file:" filename
1760                   gnus-file-save-name gnus-newsgroup-name
1761                   gnus-current-headers 'gnus-newsgroup-last-file))
1762   (gnus-eval-in-buffer-window gnus-save-article-buffer
1763     (save-excursion
1764       (save-restriction
1765         (widen)
1766         (goto-char (point-min))
1767         (when (search-forward "\n\n" nil t)
1768           (narrow-to-region (point) (point-max)))
1769         (gnus-output-to-file filename))))
1770   filename)
1771
1772 (defun gnus-summary-save-in-pipe (&optional command)
1773   "Pipe this article to subprocess."
1774   (setq command
1775         (cond ((and (eq command 'default)
1776                     gnus-last-shell-command)
1777                gnus-last-shell-command)
1778               (command command)
1779               (t (read-string
1780                   (format
1781                    "Shell command on %s: "
1782                    (if (and gnus-number-of-articles-to-be-saved
1783                             (> gnus-number-of-articles-to-be-saved 1))
1784                        (format "these %d articles"
1785                                gnus-number-of-articles-to-be-saved)
1786                      "this article"))
1787                   gnus-last-shell-command))))
1788   (when (string-equal command "")
1789     (setq command gnus-last-shell-command))
1790   (gnus-eval-in-buffer-window gnus-article-buffer
1791     (save-restriction
1792       (widen)
1793       (shell-command-on-region (point-min) (point-max) command nil)))
1794   (setq gnus-last-shell-command command))
1795
1796 ;;; Article file names when saving.
1797
1798 (defun gnus-capitalize-newsgroup (newsgroup)
1799   "Capitalize NEWSGROUP name."
1800   (when (not (zerop (length newsgroup)))
1801     (concat (char-to-string (upcase (aref newsgroup 0)))
1802             (substring newsgroup 1))))
1803
1804 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1805   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1806 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1807 Otherwise, it is like ~/News/news/group/num."
1808   (let ((default
1809           (expand-file-name
1810            (concat (if (gnus-use-long-file-name 'not-save)
1811                        (gnus-capitalize-newsgroup newsgroup)
1812                      (gnus-newsgroup-directory-form newsgroup))
1813                    "/" (int-to-string (mail-header-number headers)))
1814            gnus-article-save-directory)))
1815     (if (and last-file
1816              (string-equal (file-name-directory default)
1817                            (file-name-directory last-file))
1818              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1819         default
1820       (or last-file default))))
1821
1822 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1823   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1824 If variable `gnus-use-long-file-name' is non-nil, it is
1825 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
1826   (let ((default
1827           (expand-file-name
1828            (concat (if (gnus-use-long-file-name 'not-save)
1829                        newsgroup
1830                      (gnus-newsgroup-directory-form newsgroup))
1831                    "/" (int-to-string (mail-header-number headers)))
1832            gnus-article-save-directory)))
1833     (if (and last-file
1834              (string-equal (file-name-directory default)
1835                            (file-name-directory last-file))
1836              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1837         default
1838       (or last-file default))))
1839
1840 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1841   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1842 If variable `gnus-use-long-file-name' is non-nil, it is
1843 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
1844   (or last-file
1845       (expand-file-name
1846        (if (gnus-use-long-file-name 'not-save)
1847            (gnus-capitalize-newsgroup newsgroup)
1848          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1849        gnus-article-save-directory)))
1850
1851 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1852   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1853 If variable `gnus-use-long-file-name' is non-nil, it is
1854 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
1855   (or last-file
1856       (expand-file-name
1857        (if (gnus-use-long-file-name 'not-save)
1858            newsgroup
1859          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1860        gnus-article-save-directory)))
1861
1862 (eval-and-compile
1863   (mapcar
1864    (lambda (func)
1865      (let (afunc gfunc)
1866        (if (consp func)
1867            (setq afunc (car func)
1868                  gfunc (cdr func))
1869          (setq afunc func
1870                gfunc (intern (format "gnus-%s" func))))
1871        (fset gfunc
1872              (if (not (fboundp afunc))
1873                  nil
1874                `(lambda (&optional interactive &rest args)
1875                   ,(documentation afunc t)
1876                   (interactive (list t))
1877                   (save-excursion
1878                     (set-buffer gnus-article-buffer)
1879                     (if interactive
1880                         (call-interactively ',afunc)
1881                       (apply ',afunc args))))))))
1882    '(article-hide-headers
1883      article-hide-boring-headers
1884      article-treat-overstrike
1885      (article-fill . gnus-article-word-wrap)
1886      article-remove-cr
1887      article-display-x-face
1888      article-de-quoted-unreadable
1889      article-mime-decode-quoted-printable
1890      article-hide-pgp
1891      article-hide-pem
1892      article-hide-signature
1893      article-remove-trailing-blank-lines
1894      article-strip-leading-blank-lines
1895      article-strip-multiple-blank-lines
1896      article-strip-leading-space
1897      article-strip-blank-lines
1898      article-strip-all-blank-lines
1899      article-date-local
1900      article-date-iso8601
1901      article-date-original
1902      article-date-ut
1903      article-decode-mime-words
1904      article-decode-charset
1905      article-decode-encoded-words
1906      article-date-user
1907      article-date-lapsed
1908      article-emphasize
1909      article-treat-dumbquotes
1910      (article-show-all . gnus-article-show-all-headers))))
1911 \f
1912 ;;;
1913 ;;; Gnus article mode
1914 ;;;
1915
1916 (put 'gnus-article-mode 'mode-class 'special)
1917
1918 (set-keymap-parent gnus-article-mode-map widget-keymap)
1919
1920 (gnus-define-keys gnus-article-mode-map
1921   " " gnus-article-goto-next-page
1922   "\177" gnus-article-goto-prev-page
1923   [delete] gnus-article-goto-prev-page
1924   "\C-c^" gnus-article-refer-article
1925   "h" gnus-article-show-summary
1926   "s" gnus-article-show-summary
1927   "\C-c\C-m" gnus-article-mail
1928   "?" gnus-article-describe-briefly
1929   "e" gnus-article-edit
1930   "<" beginning-of-buffer
1931   ">" end-of-buffer
1932   "\C-c\C-i" gnus-info-find-node
1933   "\C-c\C-b" gnus-bug
1934
1935   "\C-d" gnus-article-read-summary-keys
1936   "\M-*" gnus-article-read-summary-keys
1937   "\M-#" gnus-article-read-summary-keys
1938   "\M-^" gnus-article-read-summary-keys
1939   "\M-g" gnus-article-read-summary-keys)
1940
1941 (substitute-key-definition
1942  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1943
1944 (defun gnus-article-make-menu-bar ()
1945   (gnus-turn-off-edit-menu 'article)
1946   (unless (boundp 'gnus-article-article-menu)
1947     (easy-menu-define
1948      gnus-article-article-menu gnus-article-mode-map ""
1949      '("Article"
1950        ["Scroll forwards" gnus-article-goto-next-page t]
1951        ["Scroll backwards" gnus-article-goto-prev-page t]
1952        ["Show summary" gnus-article-show-summary t]
1953        ["Fetch Message-ID at point" gnus-article-refer-article t]
1954        ["Mail to address at point" gnus-article-mail t]
1955        ["Send a bug report" gnus-bug t]))
1956
1957     (easy-menu-define
1958      gnus-article-treatment-menu gnus-article-mode-map ""
1959      '("Treatment"
1960        ["Hide headers" gnus-article-hide-headers t]
1961        ["Hide signature" gnus-article-hide-signature t]
1962        ["Hide citation" gnus-article-hide-citation t]
1963        ["Treat overstrike" gnus-article-treat-overstrike t]
1964        ["Remove carriage return" gnus-article-remove-cr t]
1965        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1966
1967     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1968
1969     (when (boundp 'gnus-summary-post-menu)
1970       (define-key gnus-article-mode-map [menu-bar post]
1971         (cons "Post" gnus-summary-post-menu)))
1972
1973     (gnus-run-hooks 'gnus-article-menu-hook)))
1974
1975 (defun gnus-article-mode ()
1976   "Major mode for displaying an article.
1977
1978 All normal editing commands are switched off.
1979
1980 The following commands are available in addition to all summary mode
1981 commands:
1982 \\<gnus-article-mode-map>
1983 \\[gnus-article-next-page]\t Scroll the article one page forwards
1984 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1985 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1986 \\[gnus-article-show-summary]\t Display the summary buffer
1987 \\[gnus-article-mail]\t Send a reply to the address near point
1988 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1989 \\[gnus-info-find-node]\t Go to the Gnus info node"
1990   (interactive)
1991   (when (gnus-visual-p 'article-menu 'menu)
1992     (gnus-article-make-menu-bar))
1993   (gnus-simplify-mode-line)
1994   (setq mode-name "Article")
1995   (setq major-mode 'gnus-article-mode)
1996   (make-local-variable 'minor-mode-alist)
1997   (use-local-map gnus-article-mode-map)
1998   (gnus-update-format-specifications nil 'article-mode)
1999   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2000   (make-local-variable 'gnus-page-broken)
2001   (make-local-variable 'gnus-button-marker-list)
2002   (make-local-variable 'gnus-article-current-summary)
2003   (make-local-variable 'gnus-article-mime-handles)
2004   (make-local-variable 'gnus-article-decoded-p)
2005   (make-local-variable 'gnus-article-mime-handle-alist)
2006   (gnus-set-default-directory)
2007   (buffer-disable-undo)
2008   (setq buffer-read-only t)
2009   (set-syntax-table gnus-article-mode-syntax-table)
2010   (mm-enable-multibyte)
2011   (gnus-run-hooks 'gnus-article-mode-hook))
2012
2013 (defun gnus-article-setup-buffer ()
2014   "Initialize the article buffer."
2015   (let* ((name (if gnus-single-article-buffer "*Article*"
2016                  (concat "*Article " gnus-newsgroup-name "*")))
2017          (original
2018           (progn (string-match "\\*Article" name)
2019                  (concat " *Original Article"
2020                          (substring name (match-end 0))))))
2021     (setq gnus-article-buffer name)
2022     (setq gnus-original-article-buffer original)
2023     (setq gnus-article-mime-handle-alist nil)
2024     ;; This might be a variable local to the summary buffer.
2025     (unless gnus-single-article-buffer
2026       (save-excursion
2027         (set-buffer gnus-summary-buffer)
2028         (setq gnus-article-buffer name)
2029         (setq gnus-original-article-buffer original)
2030         (gnus-set-global-variables)))
2031     ;; Init original article buffer.
2032     (save-excursion
2033       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2034       (mm-enable-multibyte)
2035       (setq major-mode 'gnus-original-article-mode)
2036       (make-local-variable 'gnus-original-article))
2037     (if (get-buffer name)
2038         (save-excursion
2039           (set-buffer name)
2040           (buffer-disable-undo)
2041           (setq buffer-read-only t)
2042           (unless (eq major-mode 'gnus-article-mode)
2043             (gnus-article-mode))
2044           (current-buffer))
2045       (save-excursion
2046         (set-buffer (gnus-get-buffer-create name))
2047         (gnus-article-mode)
2048         (make-local-variable 'gnus-summary-buffer)
2049         (gnus-summary-set-local-parameters gnus-newsgroup-name)
2050         (current-buffer)))))
2051
2052 ;; Set article window start at LINE, where LINE is the number of lines
2053 ;; from the head of the article.
2054 (defun gnus-article-set-window-start (&optional line)
2055   (set-window-start
2056    (get-buffer-window gnus-article-buffer t)
2057    (save-excursion
2058      (set-buffer gnus-article-buffer)
2059      (goto-char (point-min))
2060      (if (not line)
2061          (point-min)
2062        (gnus-message 6 "Moved to bookmark")
2063        (search-forward "\n\n" nil t)
2064        (forward-line line)
2065        (point)))))
2066
2067 (defun gnus-article-prepare (article &optional all-headers header)
2068   "Prepare ARTICLE in article mode buffer.
2069 ARTICLE should either be an article number or a Message-ID.
2070 If ARTICLE is an id, HEADER should be the article headers.
2071 If ALL-HEADERS is non-nil, no headers are hidden."
2072   (save-excursion
2073     ;; Make sure we start in a summary buffer.
2074     (unless (eq major-mode 'gnus-summary-mode)
2075       (set-buffer gnus-summary-buffer))
2076     (setq gnus-summary-buffer (current-buffer))
2077     (let* ((gnus-article (if header (mail-header-number header) article))
2078            (summary-buffer (current-buffer))
2079            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2080            (group gnus-newsgroup-name)
2081            result)
2082       (save-excursion
2083         (gnus-article-setup-buffer)
2084         (set-buffer gnus-article-buffer)
2085         ;; Deactivate active regions.
2086         (when (and (boundp 'transient-mark-mode)
2087                    transient-mark-mode)
2088           (setq mark-active nil))
2089         (if (not (setq result (let ((buffer-read-only nil))
2090                                 (gnus-request-article-this-buffer
2091                                  article group))))
2092             ;; There is no such article.
2093             (save-excursion
2094               (when (and (numberp article)
2095                          (not (memq article gnus-newsgroup-sparse)))
2096                 (setq gnus-article-current
2097                       (cons gnus-newsgroup-name article))
2098                 (set-buffer gnus-summary-buffer)
2099                 (setq gnus-current-article article)
2100                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2101                     (progn
2102                       (gnus-summary-set-agent-mark article)
2103                       (message "Message marked for downloading"))
2104                   (gnus-summary-mark-article article gnus-canceled-mark)
2105                   (unless (memq article gnus-newsgroup-sparse)
2106                     (gnus-error 1
2107                      "No such article (may have expired or been canceled)")))))
2108           (if (or (eq result 'pseudo)
2109                   (eq result 'nneething))
2110               (progn
2111                 (save-excursion
2112                   (set-buffer summary-buffer)
2113                   (push article gnus-newsgroup-history)
2114                   (setq gnus-last-article gnus-current-article
2115                         gnus-current-article 0
2116                         gnus-current-headers nil
2117                         gnus-article-current nil)
2118                   (if (eq result 'nneething)
2119                       (gnus-configure-windows 'summary)
2120                     (gnus-configure-windows 'article))
2121                   (gnus-set-global-variables))
2122                 (gnus-set-mode-line 'article))
2123             ;; The result from the `request' was an actual article -
2124             ;; or at least some text that is now displayed in the
2125             ;; article buffer.
2126             (when (and (numberp article)
2127                        (not (eq article gnus-current-article)))
2128               ;; Seems like a new article has been selected.
2129               ;; `gnus-current-article' must be an article number.
2130               (save-excursion
2131                 (set-buffer summary-buffer)
2132                 (push article gnus-newsgroup-history)
2133                 (setq gnus-last-article gnus-current-article
2134                       gnus-current-article article
2135                       gnus-current-headers
2136                       (gnus-summary-article-header gnus-current-article)
2137                       gnus-article-current
2138                       (cons gnus-newsgroup-name gnus-current-article))
2139                 (unless (vectorp gnus-current-headers)
2140                   (setq gnus-current-headers nil))
2141                 (gnus-summary-goto-subject gnus-current-article)
2142                 (when (gnus-summary-show-thread)
2143                   ;; If the summary buffer really was folded, the
2144                   ;; previous goto may not actually have gone to
2145                   ;; the right article, but the thread root instead.
2146                   ;; So we go again.
2147                   (gnus-summary-goto-subject gnus-current-article))
2148                 (gnus-run-hooks 'gnus-mark-article-hook)
2149                 (gnus-set-mode-line 'summary)
2150                 (when (gnus-visual-p 'article-highlight 'highlight)
2151                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
2152                 ;; Set the global newsgroup variables here.
2153                 ;; Suggested by Jim Sisolak
2154                 ;; <sisolak@trans4.neep.wisc.edu>.
2155                 (gnus-set-global-variables)
2156                 (setq gnus-have-all-headers
2157                       (or all-headers gnus-show-all-headers))))
2158             (when (or (numberp article)
2159                       (stringp article))
2160               (gnus-article-prepare-display)
2161               ;; Do page break.
2162               (goto-char (point-min))
2163               (setq gnus-page-broken
2164                     (when gnus-break-pages
2165                       (gnus-narrow-to-page)
2166                       t)))
2167             (gnus-set-mode-line 'article)
2168             (gnus-configure-windows 'article)
2169             (goto-char (point-min))
2170             (search-forward "\n\n" nil t)
2171             (set-window-point (get-buffer-window (current-buffer)) (point))
2172             t))))))
2173
2174 (defun gnus-article-prepare-display ()
2175   "Make the current buffer look like a nice article."
2176   ;; Hooks for getting information from the article.
2177   ;; This hook must be called before being narrowed.
2178   (let ((gnus-article-buffer (current-buffer))
2179         buffer-read-only)
2180     (unless (eq major-mode 'gnus-article-mode)
2181       (gnus-article-mode))
2182     (setq buffer-read-only nil)
2183     (gnus-run-hooks 'gnus-tmp-internal-hook)
2184     (gnus-run-hooks 'gnus-article-prepare-hook)
2185     (when gnus-display-mime-function
2186       (let ((url-standalone-mode (not gnus-plugged)))
2187         (funcall gnus-display-mime-function)))
2188     ;; Perform the article display hooks.
2189     (gnus-run-hooks 'gnus-article-display-hook)))
2190
2191 ;;;
2192 ;;; Gnus MIME viewing functions
2193 ;;;
2194
2195 (defvar gnus-mime-button-line-format "%{%([%p. %t%d%n]%)%}%e\n"
2196   "The following specs can be used:
2197 %t  The MIME type
2198 %n  The `name' parameter
2199 %d  The description, if any
2200 %l  The length of the encoded part
2201 %p  The part identifier
2202 %e  Dots if the part isn't displayed")
2203
2204 (defvar gnus-mime-button-line-format-alist
2205   '((?t gnus-tmp-type ?s)
2206     (?n gnus-tmp-name ?s)
2207     (?d gnus-tmp-description ?s)
2208     (?p gnus-tmp-id ?s)
2209     (?l gnus-tmp-length ?d)
2210     (?e gnus-tmp-dots ?s)))
2211
2212 (defvar gnus-mime-button-commands
2213   '((gnus-article-press-button  "\r"    "Toggle Display")
2214     ;(gnus-mime-view-part       "\M-\r" "View Interactively...")
2215     (gnus-mime-view-part        "v"     "View Interactively...")
2216     (gnus-mime-save-part        "o"     "Save...")
2217     (gnus-mime-copy-part        "c"     "View In Buffer")
2218     (gnus-mime-inline-part      "i"     "View Inline")
2219     (gnus-mime-pipe-part        "|"     "Pipe To Command...")))
2220
2221 (defvar gnus-mime-button-map nil)
2222 (unless gnus-mime-button-map
2223   (setq gnus-mime-button-map (make-sparse-keymap))
2224   (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2225   (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2226   (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2227   (mapcar (lambda (c)
2228             (define-key gnus-mime-button-map (cadr c) (car c)))
2229           gnus-mime-button-commands))
2230
2231 (defun gnus-mime-button-menu (event)
2232   "Construct a context-sensitive menu of MIME commands."
2233   (interactive "e")
2234   )
2235
2236 (defun gnus-mime-view-all-parts ()
2237   "View all the MIME parts."
2238   (interactive)
2239   (let ((handles gnus-article-mime-handles))
2240     (while handles
2241       (mm-display-part (pop handles)))))
2242
2243 (defun gnus-mime-save-part ()
2244   "Save the MIME part under point."
2245   (interactive)
2246   (let ((data (get-text-property (point) 'gnus-data)))
2247     (mm-save-part data)))
2248
2249 (defun gnus-mime-pipe-part ()
2250   "Pipe the MIME part under point to a process."
2251   (interactive)
2252   (let ((data (get-text-property (point) 'gnus-data)))
2253     (mm-pipe-part data)))
2254
2255 (defun gnus-mime-view-part ()
2256   "Interactively choose a view method for the MIME part under point."
2257   (interactive)
2258   (let ((data (get-text-property (point) 'gnus-data))
2259         (url-standalone-mode (not gnus-plugged)))
2260     (mm-interactively-view-part data)))
2261
2262 (defun gnus-mime-copy-part ()
2263   "Put the the MIME part under point into a new buffer."
2264   (interactive)
2265   (let* ((handle (get-text-property (point) 'gnus-data))
2266          (contents (mm-get-part handle))
2267          (buffer (generate-new-buffer
2268                        (file-name-nondirectory
2269                         (or
2270                          (mail-content-type-get (mm-handle-type handle) 'name)
2271                          (mail-content-type-get (mm-handle-type handle)
2272                                                 'filename)
2273                          "*decoded*")))))
2274     (set-buffer-major-mode buffer)
2275     (switch-to-buffer buffer)
2276     (insert contents)
2277     (goto-char (point-min))))
2278
2279 (defun gnus-mime-inline-part ()
2280   "Insert the MIME part under point into the current buffer."
2281   (interactive)
2282   (let* ((data (get-text-property (point) 'gnus-data))
2283          (contents (mm-get-part data))
2284          (url-standalone-mode (not gnus-plugged))
2285          (b (point))
2286          buffer-read-only)
2287     (if (mm-handle-undisplayer data)
2288         (mm-remove-part data)
2289       (forward-line 2)
2290       (mm-insert-inline data contents)
2291       (goto-char b))))
2292
2293 (defun gnus-article-view-part (n)
2294   "View MIME part N, which is the numerical prefix."
2295   (interactive "p")
2296   (save-current-buffer
2297     (set-buffer gnus-article-buffer)
2298     (when (> n (length gnus-article-mime-handle-alist))
2299       (error "No such part"))
2300     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2301       (gnus-article-goto-part n)
2302       (gnus-set-window-start)
2303       (gnus-mm-display-part handle))))
2304
2305 (defun gnus-mm-display-part (handle)
2306   "Display HANDLE and fix MIME button."
2307   (let ((id (get-text-property (point) 'gnus-part))
2308         (point (point))
2309         buffer-read-only)
2310     (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2311     (gnus-insert-mime-button
2312      handle id (list (not (mm-handle-displayed-p handle))))
2313     (mm-display-part handle)
2314     (goto-char point)))
2315
2316 (defun gnus-article-goto-part (n)
2317   "Go to MIME part N."
2318   (goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
2319
2320 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2321   (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2322         (gnus-tmp-type (car (mm-handle-type handle)))
2323         (gnus-tmp-description (mm-handle-description handle))
2324         (gnus-tmp-dots
2325          (if (if displayed (car displayed)
2326                (mm-handle-displayed-p handle))
2327              "" "..."))
2328         (gnus-tmp-length (save-excursion
2329                            (set-buffer (mm-handle-buffer handle))
2330                            (buffer-size)))
2331         b e)
2332     (setq gnus-tmp-name
2333           (if gnus-tmp-name
2334               (concat " (" gnus-tmp-name ")")
2335             ""))
2336     (setq gnus-tmp-description
2337           (if gnus-tmp-description
2338               (concat " (" gnus-tmp-description ")")
2339             ""))
2340     (setq b (point))
2341     (gnus-eval-format
2342      gnus-mime-button-line-format gnus-mime-button-line-format-alist
2343      `(local-map ,gnus-mime-button-map
2344                  keymap ,gnus-mime-button-map
2345                  gnus-callback gnus-mm-display-part
2346                  gnus-part ,gnus-tmp-id
2347                  gnus-type annotation
2348                  gnus-data ,handle))
2349     (setq e (point))
2350     (widget-convert-button 'link b e :action 'gnus-widget-press-button
2351                            :button-keymap gnus-mime-button-map)))
2352
2353 (defun gnus-widget-press-button (elems el)
2354   (goto-char (widget-get elems :from))
2355   (let ((url-standalone-mode (not gnus-plugged)))
2356     (gnus-article-press-button)))
2357
2358 (defun gnus-display-mime (&optional ihandles)
2359   "Insert MIME buttons in the buffer."
2360   (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2361          handle name type b e display)
2362     (when handles
2363       (unless ihandles
2364         ;; Top-level call; we clean up.
2365         (mm-destroy-parts gnus-article-mime-handles)
2366         (setq gnus-article-mime-handles handles
2367               gnus-article-mime-handle-alist nil)
2368         (goto-char (point-min))
2369         (search-forward "\n\n" nil t)
2370         (delete-region (point) (point-max)))
2371       (if (stringp (car handles))
2372           (if (equal (car handles) "multipart/alternative")
2373               (gnus-mime-display-alternative (cdr handles))
2374             (gnus-mime-display-mixed (cdr handles)))
2375         (gnus-mime-display-single handles)))))
2376
2377 (defun gnus-mime-display-mixed (handles)
2378   (let (handle)
2379     (while (setq handle (pop handles))
2380       (gnus-mime-display-single handle))))
2381
2382 (defun gnus-mime-display-single (handle)
2383   (let (display)
2384     (when (and (mm-automatic-display-p
2385                 (car (mm-handle-type handle)))
2386                (mm-inlinable-part-p (car (mm-handle-type handle)))
2387                (or (not (mm-handle-disposition handle))
2388                    (equal (car (mm-handle-disposition handle))
2389                           "inline")))
2390       (setq display t))
2391     (let ((id (1+ (length gnus-article-mime-handle-alist))))
2392       (push (cons id handle) gnus-article-mime-handle-alist)
2393       (gnus-insert-mime-button handle id (list display)))
2394     (insert "\n\n")
2395     (when display
2396       (forward-line -2)
2397       (mm-display-part handle t)
2398       (goto-char (point-max)))))
2399
2400 (defun gnus-mime-display-alternative (handles &optional preferred)
2401   (let* ((preferred (mm-preferred-alternative handles preferred))
2402          (ihandles handles)
2403          (point (point))
2404          handle buffer-read-only from)
2405     (goto-char (point-min))
2406     (search-forward "\n\n" nil t)
2407     (delete-region (point) (point-max))
2408     (when preferred
2409       ;; Top-level call; we clean up.
2410       (mm-remove-parts gnus-article-mime-handles)
2411       (setq gnus-article-mime-handles handles
2412             gnus-article-mime-handle-alist nil))
2413     (while (setq handle (pop handles))
2414       (gnus-add-text-properties
2415        (setq from (point))
2416        (progn
2417          (insert (format "[%c] %-18s"
2418                          (if (equal handle preferred) ?* ? )
2419                          (if (stringp (car handle))
2420                              (car handle)
2421                            (car (mm-handle-type handle)))))
2422          (point))
2423        `(local-map ,gnus-mime-button-map
2424                    ,gnus-mouse-face-prop ,gnus-article-mouse-face
2425                    face ,gnus-article-button-face
2426                    keymap ,gnus-mime-button-map
2427                    gnus-callback
2428                    (lambda (handles)
2429                      (gnus-mime-display-alternative
2430                       ',ihandles ,(if (stringp (car handle))
2431                                       (car handle)
2432                                     (car (mm-handle-type handle)))))
2433                    gnus-data ,handle))
2434       (widget-convert-button 'link from (point)
2435                              :action 'gnus-widget-press-button
2436                              :button-keymap gnus-widget-button-keymap)
2437       (insert "  "))
2438     (insert "\n\n")
2439     (when preferred
2440       (if (stringp (car preferred))
2441           (gnus-display-mime preferred)
2442         (mm-display-part preferred)))
2443     (goto-char point)))
2444
2445 (defun gnus-article-wash-status ()
2446   "Return a string which display status of article washing."
2447   (save-excursion
2448     (set-buffer gnus-article-buffer)
2449     (let ((cite (gnus-article-hidden-text-p 'cite))
2450           (headers (gnus-article-hidden-text-p 'headers))
2451           (boring (gnus-article-hidden-text-p 'boring-headers))
2452           (pgp (gnus-article-hidden-text-p 'pgp))
2453           (pem (gnus-article-hidden-text-p 'pem))
2454           (signature (gnus-article-hidden-text-p 'signature))
2455           (overstrike (gnus-article-hidden-text-p 'overstrike))
2456           (emphasis (gnus-article-hidden-text-p 'emphasis)))
2457       (format "%c%c%c%c%c%c%c"
2458               (if cite ?c ? )
2459               (if (or headers boring) ?h ? )
2460               (if (or pgp pem) ?p ? )
2461               (if signature ?s ? )
2462               (if overstrike ?o ? )
2463               (if emphasis ?e ? )))))
2464
2465 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2466
2467 (defun gnus-article-maybe-hide-headers ()
2468   "Hide unwanted headers if `gnus-have-all-headers' is nil.
2469 Provided for backwards compatibility."
2470   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2471       gnus-inhibit-hiding
2472       (gnus-article-hide-headers)))
2473
2474 ;;; Article savers.
2475
2476 (defun gnus-output-to-file (file-name)
2477   "Append the current article to a file named FILE-NAME."
2478   (let ((artbuf (current-buffer)))
2479     (with-temp-buffer
2480       (insert-buffer-substring artbuf)
2481       ;; Append newline at end of the buffer as separator, and then
2482       ;; save it to file.
2483       (goto-char (point-max))
2484       (insert "\n")
2485       (append-to-file (point-min) (point-max) file-name)
2486       t)))
2487
2488 (defun gnus-narrow-to-page (&optional arg)
2489   "Narrow the article buffer to a page.
2490 If given a numerical ARG, move forward ARG pages."
2491   (interactive "P")
2492   (setq arg (if arg (prefix-numeric-value arg) 0))
2493   (save-excursion
2494     (set-buffer gnus-article-buffer)
2495     (goto-char (point-min))
2496     (widen)
2497     ;; Remove any old next/prev buttons.
2498     (when (gnus-visual-p 'page-marker)
2499       (let ((buffer-read-only nil))
2500         (gnus-remove-text-with-property 'gnus-prev)
2501         (gnus-remove-text-with-property 'gnus-next)))
2502     (when
2503         (cond ((< arg 0)
2504                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2505               ((> arg 0)
2506                (re-search-forward page-delimiter nil 'move arg)))
2507       (goto-char (match-end 0)))
2508     (narrow-to-region
2509      (point)
2510      (if (re-search-forward page-delimiter nil 'move)
2511          (match-beginning 0)
2512        (point)))
2513     (when (and (gnus-visual-p 'page-marker)
2514                (not (= (point-min) 1)))
2515       (save-excursion
2516         (goto-char (point-min))
2517         (gnus-insert-prev-page-button)))
2518     (when (and (gnus-visual-p 'page-marker)
2519                (< (+ (point-max) 2) (buffer-size)))
2520       (save-excursion
2521         (goto-char (point-max))
2522         (gnus-insert-next-page-button)))))
2523
2524 ;; Article mode commands
2525
2526 (defun gnus-article-goto-next-page ()
2527   "Show the next page of the article."
2528   (interactive)
2529   (when (gnus-article-next-page)
2530     (goto-char (point-min))
2531     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2532
2533 (defun gnus-article-goto-prev-page ()
2534   "Show the next page of the article."
2535   (interactive)
2536   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2537     (gnus-article-prev-page nil)))
2538
2539 (defun gnus-article-next-page (&optional lines)
2540   "Show the next page of the current article.
2541 If end of article, return non-nil.  Otherwise return nil.
2542 Argument LINES specifies lines to be scrolled up."
2543   (interactive "p")
2544   (move-to-window-line -1)
2545   (if (save-excursion
2546         (end-of-line)
2547         (and (pos-visible-in-window-p)  ;Not continuation line.
2548              (eobp)))
2549       ;; Nothing in this page.
2550       (if (or (not gnus-page-broken)
2551               (save-excursion
2552                 (save-restriction
2553                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2554           t                             ;Nothing more.
2555         (gnus-narrow-to-page 1)         ;Go to next page.
2556         nil)
2557     ;; More in this page.
2558     (let ((scroll-in-place nil))
2559       (condition-case ()
2560           (scroll-up lines)
2561         (end-of-buffer
2562          ;; Long lines may cause an end-of-buffer error.
2563          (goto-char (point-max)))))
2564     (move-to-window-line 0)
2565     nil))
2566
2567 (defun gnus-article-prev-page (&optional lines)
2568   "Show previous page of current article.
2569 Argument LINES specifies lines to be scrolled down."
2570   (interactive "p")
2571   (move-to-window-line 0)
2572   (if (and gnus-page-broken
2573            (bobp)
2574            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2575       (progn
2576         (gnus-narrow-to-page -1)        ;Go to previous page.
2577         (goto-char (point-max))
2578         (recenter -1))
2579     (let ((scroll-in-place nil))
2580       (prog1
2581           (condition-case ()
2582               (scroll-down lines)
2583             (beginning-of-buffer
2584              (goto-char (point-min))))
2585         (move-to-window-line 0)))))
2586
2587 (defun gnus-article-refer-article ()
2588   "Read article specified by message-id around point."
2589   (interactive)
2590   (let ((point (point)))
2591     (search-forward ">" nil t)          ;Move point to end of "<....>".
2592     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2593         (let ((message-id (match-string 1)))
2594           (goto-char point)
2595           (set-buffer gnus-summary-buffer)
2596           (gnus-summary-refer-article message-id))
2597       (goto-char (point))
2598       (error "No references around point"))))
2599
2600 (defun gnus-article-show-summary ()
2601   "Reconfigure windows to show summary buffer."
2602   (interactive)
2603   (if (not (gnus-buffer-live-p gnus-summary-buffer))
2604       (error "There is no summary buffer for this article buffer")
2605     (gnus-article-set-globals)
2606     (gnus-configure-windows 'article)
2607     (gnus-summary-goto-subject gnus-current-article)
2608     (gnus-summary-position-point)))
2609
2610 (defun gnus-article-describe-briefly ()
2611   "Describe article mode commands briefly."
2612   (interactive)
2613   (gnus-message 6
2614                 (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")))
2615
2616 (defun gnus-article-summary-command ()
2617   "Execute the last keystroke in the summary buffer."
2618   (interactive)
2619   (let ((obuf (current-buffer))
2620         (owin (current-window-configuration))
2621         func)
2622     (switch-to-buffer gnus-article-current-summary 'norecord)
2623     (setq func (lookup-key (current-local-map) (this-command-keys)))
2624     (call-interactively func)
2625     (set-buffer obuf)
2626     (set-window-configuration owin)
2627     (set-window-point (get-buffer-window (current-buffer)) (point))))
2628
2629 (defun gnus-article-summary-command-nosave ()
2630   "Execute the last keystroke in the summary buffer."
2631   (interactive)
2632   (let (func)
2633     (pop-to-buffer gnus-article-current-summary 'norecord)
2634     (setq func (lookup-key (current-local-map) (this-command-keys)))
2635     (call-interactively func)))
2636
2637 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2638   "Read a summary buffer key sequence and execute it from the article buffer."
2639   (interactive "P")
2640   (let ((nosaves
2641          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
2642            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2643            "=" "^" "\M-^" "|"))
2644         (nosave-but-article
2645          '("A\r"))
2646         (nosave-in-article
2647          '("\C-d"))
2648         (up-to-top
2649          '("n" "Gn" "p" "Gp"))
2650         keys new-sum-point)
2651     (save-excursion
2652       (set-buffer gnus-article-current-summary)
2653       (let (gnus-pick-mode)
2654         (push (or key last-command-event) unread-command-events)
2655         (setq keys (read-key-sequence nil))))
2656     (message "")
2657
2658     (if (or (member keys nosaves)
2659             (member keys nosave-but-article)
2660             (member keys nosave-in-article))
2661         (let (func)
2662           (save-window-excursion
2663             (pop-to-buffer gnus-article-current-summary 'norecord)
2664             ;; We disable the pick minor mode commands.
2665             (let (gnus-pick-mode)
2666               (setq func (lookup-key (current-local-map) keys))))
2667           (if (not func)
2668               (ding)
2669             (unless (member keys nosave-in-article)
2670               (set-buffer gnus-article-current-summary))
2671             (call-interactively func)
2672             (setq new-sum-point (point)))
2673           (when (member keys nosave-but-article)
2674             (pop-to-buffer gnus-article-buffer 'norecord)))
2675       ;; These commands should restore window configuration.
2676       (let ((obuf (current-buffer))
2677             (owin (current-window-configuration))
2678             (opoint (point))
2679             (summary gnus-article-current-summary)
2680             func in-buffer selected)
2681         (if not-restore-window
2682             (pop-to-buffer summary 'norecord)
2683           (switch-to-buffer summary 'norecord))
2684         (setq in-buffer (current-buffer))
2685         ;; We disable the pick minor mode commands.
2686         (if (setq func (let (gnus-pick-mode)
2687                          (lookup-key (current-local-map) keys)))
2688             (progn
2689               (call-interactively func)
2690               (setq new-sum-point (point)))
2691           (ding))
2692         (when (eq in-buffer (current-buffer))
2693           (setq selected (gnus-summary-select-article))
2694           (set-buffer obuf)
2695           (unless not-restore-window
2696             (set-window-configuration owin))
2697           (unless (or (not (eq selected 'old)) (member keys up-to-top))
2698             (set-window-point (get-buffer-window (current-buffer))
2699                               opoint))
2700           (let ((win (get-buffer-window gnus-article-current-summary)))
2701             (when win
2702               (set-window-point win new-sum-point))))))))
2703
2704 (defun gnus-article-hide (&optional arg force)
2705   "Hide all the gruft in the current article.
2706 This means that PGP stuff, signatures, cited text and (some)
2707 headers will be hidden.
2708 If given a prefix, show the hidden text instead."
2709   (interactive (append (gnus-article-hidden-arg) (list 'force)))
2710   (gnus-article-hide-headers arg)
2711   (gnus-article-hide-pgp arg)
2712   (gnus-article-hide-citation-maybe arg force)
2713   (gnus-article-hide-signature arg))
2714
2715 (defun gnus-article-maybe-highlight ()
2716   "Do some article highlighting if article highlighting is requested."
2717   (when (gnus-visual-p 'article-highlight 'highlight)
2718     (gnus-article-highlight-some)))
2719
2720 (defun gnus-check-group-server ()
2721   ;; Make sure the connection to the server is alive.
2722   (unless (gnus-server-opened
2723            (gnus-find-method-for-group gnus-newsgroup-name))
2724     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2725     (gnus-request-group gnus-newsgroup-name t)))
2726
2727 (defun gnus-request-article-this-buffer (article group)
2728   "Get an article and insert it into this buffer."
2729   (let (do-update-line sparse-header)
2730     (prog1
2731         (save-excursion
2732           (erase-buffer)
2733           (gnus-kill-all-overlays)
2734           (setq group (or group gnus-newsgroup-name))
2735
2736           ;; Using `gnus-request-article' directly will insert the article into
2737           ;; `nntp-server-buffer' - so we'll save some time by not having to
2738           ;; copy it from the server buffer into the article buffer.
2739
2740           ;; We only request an article by message-id when we do not have the
2741           ;; headers for it, so we'll have to get those.
2742           (when (stringp article)
2743             (let ((gnus-override-method gnus-refer-article-method))
2744               (gnus-read-header article)))
2745
2746           ;; If the article number is negative, that means that this article
2747           ;; doesn't belong in this newsgroup (possibly), so we find its
2748           ;; message-id and request it by id instead of number.
2749           (when (and (numberp article)
2750                      gnus-summary-buffer
2751                      (get-buffer gnus-summary-buffer)
2752                      (gnus-buffer-exists-p gnus-summary-buffer))
2753             (save-excursion
2754               (set-buffer gnus-summary-buffer)
2755               (let ((header (gnus-summary-article-header article)))
2756                 (when (< article 0)
2757                   (cond
2758                    ((memq article gnus-newsgroup-sparse)
2759                     ;; This is a sparse gap article.
2760                     (setq do-update-line article)
2761                     (setq article (mail-header-id header))
2762                     (let ((gnus-override-method gnus-refer-article-method))
2763                       (setq sparse-header (gnus-read-header article)))
2764                     (setq gnus-newsgroup-sparse
2765                           (delq article gnus-newsgroup-sparse)))
2766                    ((vectorp header)
2767                     ;; It's a real article.
2768                     (setq article (mail-header-id header)))
2769                    (t
2770                     ;; It is an extracted pseudo-article.
2771                     (setq article 'pseudo)
2772                     (gnus-request-pseudo-article header))))
2773
2774                 (let ((method (gnus-find-method-for-group
2775                                gnus-newsgroup-name)))
2776                   (when (and (eq (car method) 'nneething)
2777                              (vectorp header))
2778                     (let ((dir (concat
2779                                 (file-name-as-directory
2780                                  (or (cadr (assq 'nneething-address method))
2781                                      (nth 1 method)))
2782                                 (mail-header-subject header))))
2783                       (when (file-directory-p dir)
2784                         (setq article 'nneething)
2785                         (gnus-group-enter-directory dir))))))))
2786
2787           (cond
2788            ;; Refuse to select canceled articles.
2789            ((and (numberp article)
2790                  gnus-summary-buffer
2791                  (get-buffer gnus-summary-buffer)
2792                  (gnus-buffer-exists-p gnus-summary-buffer)
2793                  (eq (cdr (save-excursion
2794                             (set-buffer gnus-summary-buffer)
2795                             (assq article gnus-newsgroup-reads)))
2796                      gnus-canceled-mark))
2797             nil)
2798            ;; We first check `gnus-original-article-buffer'.
2799            ((and (get-buffer gnus-original-article-buffer)
2800                  (numberp article)
2801                  (save-excursion
2802                    (set-buffer gnus-original-article-buffer)
2803                    (and (equal (car gnus-original-article) group)
2804                         (eq (cdr gnus-original-article) article))))
2805             (insert-buffer-substring gnus-original-article-buffer)
2806             'article)
2807            ;; Check the backlog.
2808            ((and gnus-keep-backlog
2809                  (gnus-backlog-request-article group article (current-buffer)))
2810             'article)
2811            ;; Check asynchronous pre-fetch.
2812            ((gnus-async-request-fetched-article group article (current-buffer))
2813             (gnus-async-prefetch-next group article gnus-summary-buffer)
2814             (when (and (numberp article) gnus-keep-backlog)
2815               (gnus-backlog-enter-article group article (current-buffer)))
2816             'article)
2817            ;; Check the cache.
2818            ((and gnus-use-cache
2819                  (numberp article)
2820                  (gnus-cache-request-article article group))
2821             'article)
2822            ;; Get the article and put into the article buffer.
2823            ((or (stringp article) (numberp article))
2824             (let ((gnus-override-method
2825                    (and (stringp article) gnus-refer-article-method))
2826                   (buffer-read-only nil))
2827               (erase-buffer)
2828               (gnus-kill-all-overlays)
2829               (gnus-check-group-server)
2830               (when (gnus-request-article article group (current-buffer))
2831                 (when (numberp article)
2832                   (gnus-async-prefetch-next group article gnus-summary-buffer)
2833                   (when gnus-keep-backlog
2834                     (gnus-backlog-enter-article
2835                      group article (current-buffer))))
2836                 'article)))
2837            ;; It was a pseudo.
2838            (t article)))
2839
2840       ;; Associate this article with the current summary buffer.
2841       (setq gnus-article-current-summary gnus-summary-buffer)
2842
2843       ;; Take the article from the original article buffer
2844       ;; and place it in the buffer it's supposed to be in.
2845       (when (and (get-buffer gnus-article-buffer)
2846                  (equal (buffer-name (current-buffer))
2847                         (buffer-name (get-buffer gnus-article-buffer))))
2848         (save-excursion
2849           (if (get-buffer gnus-original-article-buffer)
2850               (set-buffer gnus-original-article-buffer)
2851             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2852             (buffer-disable-undo)
2853             (setq major-mode 'gnus-original-article-mode)
2854             (setq buffer-read-only t))
2855           (let (buffer-read-only)
2856             (erase-buffer)
2857             (insert-buffer-substring gnus-article-buffer))
2858           (setq gnus-original-article (cons group article)))
2859
2860         ;; Decode charsets.
2861         (run-hooks 'gnus-article-decode-hook)
2862         ;; Mark article as decoded or not.
2863         (setq gnus-article-decoded-p gnus-article-decode-hook))
2864
2865       ;; Update sparse articles.
2866       (when (and do-update-line
2867                  (or (numberp article)
2868                      (stringp article)))
2869         (let ((buf (current-buffer)))
2870           (set-buffer gnus-summary-buffer)
2871           (gnus-summary-update-article do-update-line sparse-header)
2872           (gnus-summary-goto-subject do-update-line nil t)
2873           (set-window-point (get-buffer-window (current-buffer) t)
2874                             (point))
2875           (set-buffer buf))))))
2876
2877 ;;;
2878 ;;; Article editing
2879 ;;;
2880
2881 (defcustom gnus-article-edit-mode-hook nil
2882   "Hook run in article edit mode buffers."
2883   :group 'gnus-article-various
2884   :type 'hook)
2885
2886 (defvar gnus-article-edit-done-function nil)
2887
2888 (defvar gnus-article-edit-mode-map nil)
2889
2890 ;; Should we be using derived.el for this?
2891 (unless gnus-article-edit-mode-map
2892   (setq gnus-article-edit-mode-map (make-sparse-keymap))
2893   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
2894
2895   (gnus-define-keys gnus-article-edit-mode-map
2896     "\C-c\C-c" gnus-article-edit-done
2897     "\C-c\C-k" gnus-article-edit-exit)
2898
2899   (gnus-define-keys (gnus-article-edit-wash-map
2900                      "\C-c\C-w" gnus-article-edit-mode-map)
2901     "f" gnus-article-edit-full-stops))
2902
2903 (defun gnus-article-edit-mode ()
2904   "Major mode for editing articles.
2905 This is an extended text-mode.
2906
2907 \\{gnus-article-edit-mode-map}"
2908   (interactive)
2909   (setq major-mode 'gnus-article-edit-mode)
2910   (setq mode-name "Article Edit")
2911   (use-local-map gnus-article-edit-mode-map)
2912   (make-local-variable 'gnus-article-edit-done-function)
2913   (make-local-variable 'gnus-prev-winconf)
2914   (setq buffer-read-only nil)
2915   (buffer-enable-undo)
2916   (widen)
2917   (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2918
2919 (defun gnus-article-edit (&optional force)
2920   "Edit the current article.
2921 This will have permanent effect only in mail groups.
2922 If FORCE is non-nil, allow editing of articles even in read-only
2923 groups."
2924   (interactive "P")
2925   (when (and (not force)
2926              (gnus-group-read-only-p))
2927     (error "The current newsgroup does not support article editing"))
2928   (gnus-article-date-original)
2929   (gnus-article-edit-article
2930    `(lambda (no-highlight)
2931       (gnus-summary-edit-article-done
2932        ,(or (mail-header-references gnus-current-headers) "")
2933        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2934
2935 (defun gnus-article-edit-article (exit-func)
2936   "Start editing the contents of the current article buffer."
2937   (let ((winconf (current-window-configuration)))
2938     (set-buffer gnus-article-buffer)
2939     (gnus-article-edit-mode)
2940     (gnus-article-delete-text-of-type 'annotation)
2941     (gnus-set-text-properties (point-min) (point-max) nil)
2942     (gnus-configure-windows 'edit-article)
2943     (setq gnus-article-edit-done-function exit-func)
2944     (setq gnus-prev-winconf winconf)
2945     (gnus-message 6 "C-c C-c to end edits")))
2946
2947 (defun gnus-article-edit-done (&optional arg)
2948   "Update the article edits and exit."
2949   (interactive "P")
2950   (save-excursion
2951     (save-restriction
2952       (widen)
2953       (goto-char (point-min))
2954       (when (search-forward "\n\n" nil 1)
2955         (let ((lines (count-lines (point) (point-max)))
2956               (length (- (point-max) (point)))
2957               (case-fold-search t)
2958               (body (copy-marker (point))))
2959           (goto-char (point-min))
2960           (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2961             (delete-region (match-beginning 1) (match-end 1))
2962             (insert (number-to-string length)))
2963           (goto-char (point-min))
2964           (when (re-search-forward
2965                  "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2966             (delete-region (match-beginning 1) (match-end 1))
2967             (insert (number-to-string length)))
2968           (goto-char (point-min))
2969           (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2970             (delete-region (match-beginning 1) (match-end 1))
2971             (insert (number-to-string lines)))))))
2972   (let ((func gnus-article-edit-done-function)
2973         (buf (current-buffer))
2974         (start (window-start)))
2975     (gnus-article-edit-exit)
2976     (save-excursion
2977       (set-buffer buf)
2978       (let ((buffer-read-only nil))
2979         (funcall func arg))
2980       ;; The cache and backlog have to be flushed somewhat.
2981       (when gnus-keep-backlog
2982         (gnus-backlog-remove-article
2983          (car gnus-article-current) (cdr gnus-article-current)))
2984       ;; Flush original article as well.
2985       (save-excursion
2986         (when (get-buffer gnus-original-article-buffer)
2987           (set-buffer gnus-original-article-buffer)
2988           (setq gnus-original-article nil)))
2989       (when gnus-use-cache
2990         (gnus-cache-update-article
2991          (car gnus-article-current) (cdr gnus-article-current))))
2992     (set-buffer buf)
2993     (set-window-start (get-buffer-window buf) start)
2994     (set-window-point (get-buffer-window buf) (point))))
2995
2996 (defun gnus-article-edit-exit ()
2997   "Exit the article editing without updating."
2998   (interactive)
2999   ;; We remove all text props from the article buffer.
3000   (let ((buf (format "%s" (buffer-string)))
3001         (curbuf (current-buffer))
3002         (p (point))
3003         (window-start (window-start)))
3004     (erase-buffer)
3005     (insert buf)
3006     (let ((winconf gnus-prev-winconf))
3007       (gnus-article-mode)
3008       (set-window-configuration winconf)
3009       ;; Tippy-toe some to make sure that point remains where it was.
3010       (save-current-buffer
3011         (set-buffer curbuf)
3012         (set-window-start (get-buffer-window (current-buffer)) window-start)
3013         (goto-char p)))))
3014
3015 (defun gnus-article-edit-full-stops ()
3016   "Interactively repair spacing at end of sentences."
3017   (interactive)
3018   (save-excursion
3019     (goto-char (point-min))
3020     (search-forward-regexp "^$" nil t)
3021     (let ((case-fold-search nil))
3022       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3023
3024 ;;;
3025 ;;; Article highlights
3026 ;;;
3027
3028 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3029
3030 ;;; Internal Variables:
3031
3032 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)"
3033   "Regular expression that matches URLs."
3034   :group 'gnus-article-buttons
3035   :type 'regexp)
3036
3037 (defcustom gnus-button-alist
3038   `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
3039      gnus-button-message-id 2)
3040     ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
3041     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3042      1 t
3043      gnus-button-fetch-group 4)
3044     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3045     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3046      t gnus-button-message-id 3)
3047     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3048     ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3049     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3050     ;; This is how URLs _should_ be embedded in text...
3051     ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3052     ;; Raw URLs.
3053     (,gnus-button-url-regexp 0 t gnus-button-url 0))
3054   "*Alist of regexps matching buttons in article bodies.
3055
3056 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3057 REGEXP: is the string matching text around the button,
3058 BUTTON: is the number of the regexp grouping actually matching the button,
3059 FORM: is a lisp expression which must eval to true for the button to
3060 be added,
3061 CALLBACK: is the function to call when the user push this button, and each
3062 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3063
3064 CALLBACK can also be a variable, in that case the value of that
3065 variable it the real callback function."
3066   :group 'gnus-article-buttons
3067   :type '(repeat (list regexp
3068                        (integer :tag "Button")
3069                        (sexp :tag "Form")
3070                        (function :tag "Callback")
3071                        (repeat :tag "Par"
3072                                :inline t
3073                                (integer :tag "Regexp group")))))
3074
3075 (defcustom gnus-header-button-alist
3076   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3077      0 t gnus-button-message-id 0)
3078     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3079     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3080      0 t gnus-button-mailto 0)
3081     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3082     ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3083     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3084     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3085      gnus-button-message-id 3))
3086   "*Alist of headers and regexps to match buttons in article heads.
3087
3088 This alist is very similar to `gnus-button-alist', except that each
3089 alist has an additional HEADER element first in each entry:
3090
3091 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3092
3093 HEADER is a regexp to match a header.  For a fuller explanation, see
3094 `gnus-button-alist'."
3095   :group 'gnus-article-buttons
3096   :group 'gnus-article-headers
3097   :type '(repeat (list (regexp :tag "Header")
3098                        regexp
3099                        (integer :tag "Button")
3100                        (sexp :tag "Form")
3101                        (function :tag "Callback")
3102                        (repeat :tag "Par"
3103                                :inline t
3104                                (integer :tag "Regexp group")))))
3105
3106 (defvar gnus-button-regexp nil)
3107 (defvar gnus-button-marker-list nil)
3108 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3109
3110 (defvar gnus-button-last nil)
3111 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3112
3113 ;;; Commands:
3114
3115 (defun gnus-article-push-button (event)
3116   "Check text under the mouse pointer for a callback function.
3117 If the text under the mouse pointer has a `gnus-callback' property,
3118 call it with the value of the `gnus-data' text property."
3119   (interactive "e")
3120   (set-buffer (window-buffer (posn-window (event-start event))))
3121   (let* ((pos (posn-point (event-start event)))
3122          (data (get-text-property pos 'gnus-data))
3123          (fun (get-text-property pos 'gnus-callback)))
3124     (goto-char pos)
3125     (when fun
3126       (funcall fun data))))
3127
3128 (defun gnus-article-press-button ()
3129   "Check text at point for a callback function.
3130 If the text at point has a `gnus-callback' property,
3131 call it with the value of the `gnus-data' text property."
3132   (interactive)
3133   (let* ((data (get-text-property (point) 'gnus-data))
3134          (fun (get-text-property (point) 'gnus-callback)))
3135     (when fun
3136       (funcall fun data))))
3137
3138 (defun gnus-article-highlight (&optional force)
3139   "Highlight current article.
3140 This function calls `gnus-article-highlight-headers',
3141 `gnus-article-highlight-citation',
3142 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3143 do the highlighting.  See the documentation for those functions."
3144   (interactive (list 'force))
3145   (gnus-article-highlight-headers)
3146   (gnus-article-highlight-citation force)
3147   (gnus-article-highlight-signature)
3148   (gnus-article-add-buttons force)
3149   (gnus-article-add-buttons-to-head))
3150
3151 (defun gnus-article-highlight-some (&optional force)
3152   "Highlight current article.
3153 This function calls `gnus-article-highlight-headers',
3154 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3155 do the highlighting.  See the documentation for those functions."
3156   (interactive (list 'force))
3157   (gnus-article-highlight-headers)
3158   (gnus-article-highlight-signature)
3159   (gnus-article-add-buttons))
3160
3161 (defun gnus-article-highlight-headers ()
3162   "Highlight article headers as specified by `gnus-header-face-alist'."
3163   (interactive)
3164   (save-excursion
3165     (set-buffer gnus-article-buffer)
3166     (save-restriction
3167       (let ((alist gnus-header-face-alist)
3168             (buffer-read-only nil)
3169             (case-fold-search t)
3170             (inhibit-point-motion-hooks t)
3171             entry regexp header-face field-face from hpoints fpoints)
3172         (message-narrow-to-head)
3173         (while (setq entry (pop alist))
3174           (goto-char (point-min))
3175           (setq regexp (concat "^\\("
3176                                (if (string-equal "" (nth 0 entry))
3177                                    "[^\t ]"
3178                                  (nth 0 entry))
3179                                "\\)")
3180                 header-face (nth 1 entry)
3181                 field-face (nth 2 entry))
3182           (while (and (re-search-forward regexp nil t)
3183                       (not (eobp)))
3184             (beginning-of-line)
3185             (setq from (point))
3186             (unless (search-forward ":" nil t)
3187               (forward-char 1))
3188             (when (and header-face
3189                        (not (memq (point) hpoints)))
3190               (push (point) hpoints)
3191               (gnus-put-text-property from (point) 'face header-face))
3192             (when (and field-face
3193                        (not (memq (setq from (point)) fpoints)))
3194               (push from fpoints)
3195               (if (re-search-forward "^[^ \t]" nil t)
3196                   (forward-char -2)
3197                 (goto-char (point-max)))
3198               (gnus-put-text-property from (point) 'face field-face))))))))
3199
3200 (defun gnus-article-highlight-signature ()
3201   "Highlight the signature in an article.
3202 It does this by highlighting everything after
3203 `gnus-signature-separator' using `gnus-signature-face'."
3204   (interactive)
3205   (save-excursion
3206     (set-buffer gnus-article-buffer)
3207     (let ((buffer-read-only nil)
3208           (inhibit-point-motion-hooks t))
3209       (save-restriction
3210         (when (and gnus-signature-face
3211                    (gnus-article-narrow-to-signature))
3212           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3213                             'face gnus-signature-face)
3214           (widen)
3215           (gnus-article-search-signature)
3216           (let ((start (match-beginning 0))
3217                 (end (set-marker (make-marker) (1+ (match-end 0)))))
3218             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3219                                      end)))))))
3220
3221 (defun gnus-button-in-region-p (b e prop)
3222   "Say whether PROP exists in the region."
3223   (text-property-not-all b e prop nil))
3224
3225 (defun gnus-article-add-buttons (&optional force)
3226   "Find external references in the article and make buttons of them.
3227 \"External references\" are things like Message-IDs and URLs, as
3228 specified by `gnus-button-alist'."
3229   (interactive (list 'force))
3230   (save-excursion
3231     (set-buffer gnus-article-buffer)
3232     (let ((buffer-read-only nil)
3233           (inhibit-point-motion-hooks t)
3234           (case-fold-search t)
3235           (alist gnus-button-alist)
3236           beg entry regexp)
3237       ;; Remove all old markers.
3238       (let (marker entry)
3239         (while (setq marker (pop gnus-button-marker-list))
3240           (goto-char marker)
3241           (when (setq entry (gnus-button-entry))
3242             (put-text-property (match-beginning (nth 1 entry))
3243                                (match-end (nth 1 entry))
3244                                'gnus-callback nil))
3245           (set-marker marker nil)))
3246       ;; We skip the headers.
3247       (goto-char (point-min))
3248       (unless (search-forward "\n\n" nil t)
3249         (goto-char (point-max)))
3250       (setq beg (point))
3251       (while (setq entry (pop alist))
3252         (setq regexp (car entry))
3253         (goto-char beg)
3254         (while (re-search-forward regexp nil t)
3255           (let* ((start (and entry (match-beginning (nth 1 entry))))
3256                  (end (and entry (match-end (nth 1 entry))))
3257                  (from (match-beginning 0)))
3258             (when (and (or (eq t (nth 2 entry))
3259                            (eval (nth 2 entry)))
3260                        (not (gnus-button-in-region-p
3261                              start end 'gnus-callback)))
3262               ;; That optional form returned non-nil, so we add the
3263               ;; button.
3264               (gnus-article-add-button
3265                start end 'gnus-button-push
3266                (car (push (set-marker (make-marker) from)
3267                           gnus-button-marker-list))))))))))
3268
3269 ;; Add buttons to the head of an article.
3270 (defun gnus-article-add-buttons-to-head ()
3271   "Add buttons to the head of the article."
3272   (interactive)
3273   (save-excursion
3274     (set-buffer gnus-article-buffer)
3275     (let ((buffer-read-only nil)
3276           (inhibit-point-motion-hooks t)
3277           (case-fold-search t)
3278           (alist gnus-header-button-alist)
3279           entry beg end)
3280       (nnheader-narrow-to-headers)
3281       (while alist
3282         ;; Each alist entry.
3283         (setq entry (car alist)
3284               alist (cdr alist))
3285         (goto-char (point-min))
3286         (while (re-search-forward (car entry) nil t)
3287           ;; Each header matching the entry.
3288           (setq beg (match-beginning 0))
3289           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3290                              (match-beginning 0))
3291                         (point-max)))
3292           (goto-char beg)
3293           (while (re-search-forward (nth 1 entry) end t)
3294             ;; Each match within a header.
3295             (let* ((entry (cdr entry))
3296                    (start (match-beginning (nth 1 entry)))
3297                    (end (match-end (nth 1 entry)))
3298                    (form (nth 2 entry)))
3299               (goto-char (match-end 0))
3300               (when (eval form)
3301                 (gnus-article-add-button
3302                  start end (nth 3 entry)
3303                  (buffer-substring (match-beginning (nth 4 entry))
3304                                    (match-end (nth 4 entry)))))))
3305           (goto-char end))))
3306     (widen)))
3307
3308 ;;; External functions:
3309
3310 (defun gnus-article-add-button (from to fun &optional data)
3311   "Create a button between FROM and TO with callback FUN and data DATA."
3312   (when gnus-article-button-face
3313     (gnus-overlay-put (gnus-make-overlay from to)
3314                       'face gnus-article-button-face))
3315   (gnus-add-text-properties
3316    from to
3317    (nconc (and gnus-article-mouse-face
3318                (list gnus-mouse-face-prop gnus-article-mouse-face))
3319           (list 'gnus-callback fun)
3320           (and data (list 'gnus-data data))))
3321   (widget-convert-button 'link from to :action 'gnus-widget-press-button
3322                          :button-keymap gnus-widget-button-keymap))
3323
3324 ;;; Internal functions:
3325
3326 (defun gnus-article-set-globals ()
3327   (save-excursion
3328     (set-buffer gnus-summary-buffer)
3329     (gnus-set-global-variables)))
3330
3331 (defun gnus-signature-toggle (end)
3332   (save-excursion
3333     (set-buffer gnus-article-buffer)
3334     (let ((buffer-read-only nil)
3335           (inhibit-point-motion-hooks t))
3336       (if (get-text-property end 'invisible)
3337           (gnus-article-unhide-text end (point-max))
3338         (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3339
3340 (defun gnus-button-entry ()
3341   ;; Return the first entry in `gnus-button-alist' matching this place.
3342   (let ((alist gnus-button-alist)
3343         (entry nil))
3344     (while alist
3345       (setq entry (pop alist))
3346       (if (looking-at (car entry))
3347           (setq alist nil)
3348         (setq entry nil)))
3349     entry))
3350
3351 (defun gnus-button-push (marker)
3352   ;; Push button starting at MARKER.
3353   (save-excursion
3354     (set-buffer gnus-article-buffer)
3355     (goto-char marker)
3356     (let* ((entry (gnus-button-entry))
3357            (inhibit-point-motion-hooks t)
3358            (fun (nth 3 entry))
3359            (args (mapcar (lambda (group)
3360                            (let ((string (match-string group)))
3361                              (gnus-set-text-properties
3362                               0 (length string) nil string)
3363                              string))
3364                          (nthcdr 4 entry))))
3365       (cond
3366        ((fboundp fun)
3367         (apply fun args))
3368        ((and (boundp fun)
3369              (fboundp (symbol-value fun)))
3370         (apply (symbol-value fun) args))
3371        (t
3372         (gnus-message 1 "You must define `%S' to use this button"
3373                       (cons fun args)))))))
3374
3375 (defun gnus-button-message-id (message-id)
3376   "Fetch MESSAGE-ID."
3377   (save-excursion
3378     (set-buffer gnus-summary-buffer)
3379     (gnus-summary-refer-article message-id)))
3380
3381 (defun gnus-button-fetch-group (address)
3382   "Fetch GROUP specified by ADDRESS."
3383   (if (not (string-match "[:/]" address))
3384       ;; This is just a simple group url.
3385       (gnus-group-read-ephemeral-group address gnus-select-method)
3386     (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3387                            address))
3388         (error "Can't parse %s" address)
3389       (gnus-group-read-ephemeral-group
3390        (match-string 4 address)
3391        `(nntp ,(match-string 1 address)
3392               (nntp-address ,(match-string 1 address))
3393               (nntp-port-number ,(if (match-end 3)
3394                                      (match-string 3 address)
3395                                    "nntp")))))))
3396
3397 (defun gnus-url-parse-query-string (query &optional downcase)
3398   (let (retval pairs cur key val)
3399     (setq pairs (split-string query "&"))
3400     (while pairs
3401       (setq cur (car pairs)
3402             pairs (cdr pairs))
3403       (if (not (string-match "=" cur))
3404           nil                           ; Grace
3405         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3406               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3407         (if downcase
3408             (setq key (downcase key)))
3409         (setq cur (assoc key retval))
3410         (if cur
3411             (setcdr cur (cons val (cdr cur)))
3412           (setq retval (cons (list key val) retval)))))
3413     retval))
3414
3415 (defun gnus-url-unhex (x)
3416   (if (> x ?9)
3417       (if (>= x ?a)
3418           (+ 10 (- x ?a))
3419         (+ 10 (- x ?A)))
3420     (- x ?0)))
3421
3422 (defun gnus-url-unhex-string (str &optional allow-newlines)
3423   "Remove %XXX embedded spaces, etc in a url.
3424 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3425 decoding of carriage returns and line feeds in the string, which is normally
3426 forbidden in URL encoding."
3427   (setq str (or str ""))
3428   (let ((tmp "")
3429         (case-fold-search t))
3430     (while (string-match "%[0-9a-f][0-9a-f]" str)
3431       (let* ((start (match-beginning 0))
3432              (ch1 (gnus-url-unhex (elt str (+ start 1))))
3433              (code (+ (* 16 ch1)
3434                       (gnus-url-unhex (elt str (+ start 2))))))
3435         (setq tmp (concat
3436                    tmp (substring str 0 start)
3437                    (cond
3438                     (allow-newlines
3439                      (char-to-string code))
3440                     ((or (= code ?\n) (= code ?\r))
3441                      " ")
3442                     (t (char-to-string code))))
3443               str (substring str (match-end 0)))))
3444     (setq tmp (concat tmp str))
3445     tmp))
3446
3447 (defun gnus-url-mailto (url)
3448   ;; Send mail to someone
3449   (when (string-match "mailto:/*\\(.*\\)" url)
3450     (setq url (substring url (match-beginning 1) nil)))
3451   (let (to args subject func)
3452     (if (string-match (regexp-quote "?") url)
3453         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3454               args (gnus-url-parse-query-string
3455                     (substring url (match-end 0) nil) t))
3456       (setq to (gnus-url-unhex-string url)))
3457     (setq args (cons (list "to" to) args)
3458           subject (cdr-safe (assoc "subject" args)))
3459     (message-mail)
3460     (while args
3461       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3462       (if (fboundp func)
3463           (funcall func)
3464         (message-position-on-field (caar args)))
3465       (insert (mapconcat 'identity (cdar args) ", "))
3466       (setq args (cdr args)))
3467     (if subject
3468         (message-goto-body)
3469       (message-goto-subject))))
3470
3471 (defun gnus-button-mailto (address)
3472   ;; Mail to ADDRESS.
3473   (set-buffer (gnus-copy-article-buffer))
3474   (message-reply address))
3475
3476 (defun gnus-button-reply (address)
3477   ;; Reply to ADDRESS.
3478   (message-reply address))
3479
3480 (defun gnus-button-url (address)
3481   "Browse ADDRESS."
3482   ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3483   (if (listp browse-url-browser-function)
3484       (browse-url address)
3485     (funcall browse-url-browser-function address)))
3486
3487 (defun gnus-button-embedded-url (address)
3488   "Browse ADDRESS."
3489   ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3490   (if (listp browse-url-browser-function)
3491       (browse-url (gnus-strip-whitespace address))
3492     (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3493
3494 ;;; Next/prev buttons in the article buffer.
3495
3496 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3497 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3498
3499 (defvar gnus-prev-page-map nil)
3500 (unless gnus-prev-page-map
3501   (setq gnus-prev-page-map (make-sparse-keymap))
3502   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3503   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3504
3505 (defun gnus-insert-prev-page-button ()
3506   (let ((buffer-read-only nil))
3507     (gnus-eval-format
3508      gnus-prev-page-line-format nil
3509      `(gnus-prev t local-map ,gnus-prev-page-map
3510                  gnus-callback gnus-article-button-prev-page
3511                  gnus-type annotation))))
3512
3513 (defvar gnus-next-page-map nil)
3514 (unless gnus-next-page-map
3515   (setq gnus-next-page-map (make-keymap))
3516   (suppress-keymap gnus-prev-page-map)
3517   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3518   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3519
3520 (defun gnus-button-next-page ()
3521   "Go to the next page."
3522   (interactive)
3523   (let ((win (selected-window)))
3524     (select-window (get-buffer-window gnus-article-buffer t))
3525     (gnus-article-next-page)
3526     (select-window win)))
3527
3528 (defun gnus-button-prev-page ()
3529   "Go to the prev page."
3530   (interactive)
3531   (let ((win (selected-window)))
3532     (select-window (get-buffer-window gnus-article-buffer t))
3533     (gnus-article-prev-page)
3534     (select-window win)))
3535
3536 (defun gnus-insert-next-page-button ()
3537   (let ((buffer-read-only nil))
3538     (gnus-eval-format gnus-next-page-line-format nil
3539                       `(gnus-next
3540                         t local-map ,gnus-next-page-map
3541                         gnus-callback gnus-article-button-next-page
3542                         gnus-type annotation))))
3543
3544 (defun gnus-article-button-next-page (arg)
3545   "Go to the next page."
3546   (interactive "P")
3547   (let ((win (selected-window)))
3548     (select-window (get-buffer-window gnus-article-buffer t))
3549     (gnus-article-next-page)
3550     (select-window win)))
3551
3552 (defun gnus-article-button-prev-page (arg)
3553   "Go to the prev page."
3554   (interactive "P")
3555   (let ((win (selected-window)))
3556     (select-window (get-buffer-window gnus-article-buffer t))
3557     (gnus-article-prev-page)
3558     (select-window win)))
3559
3560 (gnus-ems-redefine)
3561
3562 (provide 'gnus-art)
3563
3564 (run-hooks 'gnus-art-load-hook)
3565
3566 ;;; gnus-art.el ends here