1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
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)
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.
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.
35 (defgroup gnus-article nil
37 :link '(custom-manual "(gnus)The Article Buffer")
40 (defgroup gnus-article-hiding nil
41 "Hiding article parts."
42 :link '(custom-manual "(gnus)Article Hiding")
45 (defgroup gnus-article-highlight nil
46 "Article highlighting."
47 :link '(custom-manual "(gnus)Article Highlighting")
51 (defgroup gnus-article-signature nil
53 :link '(custom-manual "(gnus)Article Signature")
56 (defgroup gnus-article-headers nil
58 :link '(custom-manual "(gnus)Hiding Headers")
61 (defgroup gnus-article-washing nil
62 "Special commands on articles."
63 :link '(custom-manual "(gnus)Article Washing")
66 (defgroup gnus-article-emphasis nil
67 "Fontisizing articles."
68 :link '(custom-manual "(gnus)Article Fontisizing")
71 (defgroup gnus-article-saving nil
73 :link '(custom-manual "(gnus)Saving Articles")
76 (defgroup gnus-article-mime nil
77 "Worshiping the MIME wonder."
78 :link '(custom-manual "(gnus)Using MIME")
81 (defgroup gnus-article-buttons nil
82 "Pushable buttons in the article buffer."
83 :link '(custom-manual "(gnus)Article Buttons")
86 (defgroup gnus-article-various nil
87 "Other article options."
88 :link '(custom-manual "(gnus)Misc Article")
91 (defcustom gnus-ignored-headers
92 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
93 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
94 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
95 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
96 "All headers that match this regexp will be hidden.
97 This variable can also be a list of regexps of headers to be ignored.
98 If `gnus-visible-headers' is non-nil, this variable will be ignored."
99 :type '(choice :custom-show nil
102 :group 'gnus-article-hiding)
104 (defcustom gnus-visible-headers
105 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From"
106 "All headers that do not match this regexp will be hidden.
107 This variable can also be a list of regexp of headers to remain visible.
108 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
109 :type '(repeat :value-to-internal (lambda (widget value)
110 (custom-split-regexp-maybe value))
111 :match (lambda (widget value)
113 (widget-editable-list-match widget value)))
115 :group 'gnus-article-hiding)
117 (defcustom gnus-sorted-header-list
118 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:"
119 "^Cc:" "^Date:" "^Organization:")
120 "This variable is a list of regular expressions.
121 If it is non-nil, headers that match the regular expressions will
122 be placed first in the article buffer in the sequence specified by
124 :type '(repeat regexp)
125 :group 'gnus-article-hiding)
127 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
128 "Headers that are only to be displayed if they have interesting data.
129 Possible values in this list are `empty', `newsgroups', `followup-to',
130 `reply-to', and `date'."
131 :type '(set (const :tag "Headers with no content." empty)
132 (const :tag "Newsgroups with only one group." newsgroups)
133 (const :tag "Followup-to identical to newsgroups." followup-to)
134 (const :tag "Reply-to identical to from." reply-to)
135 (const :tag "Date less than four days old." date))
136 :group 'gnus-article-hiding)
138 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
139 "Regexp matching signature separator.
140 This can also be a list of regexps. In that case, it will be checked
141 from head to tail looking for a separator. Searches will be done from
142 the end of the buffer."
143 :type '(repeat string)
144 :group 'gnus-article-signature)
146 (defcustom gnus-signature-limit nil
147 "Provide a limit to what is considered a signature.
148 If it is a number, no signature may not be longer (in characters) than
149 that number. If it is a floating point number, no signature may be
150 longer (in lines) than that number. If it is a function, the function
151 will be called without any parameters, and if it returns nil, there is
152 no signature in the buffer. If it is a string, it will be used as a
153 regexp. If it matches, the text in question is not a signature."
154 :type '(choice integer number function regexp)
155 :group 'gnus-article-signature)
157 (defcustom gnus-hidden-properties '(invisible t intangible t)
158 "Property list to use for hiding text."
160 :group 'gnus-article-hiding)
162 (defcustom gnus-article-x-face-command
163 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
164 "String or function to be executed to display an X-Face header.
165 If it is a string, the command will be executed in a sub-shell
166 asynchronously. The compressed face will be piped to this command."
167 :type 'string ;Leave function case to Lisp.
168 :group 'gnus-article-washing)
170 (defcustom gnus-article-x-face-too-ugly nil
171 "Regexp matching posters whose face shouldn't be shown automatically."
173 :group 'gnus-article-washing)
175 (defcustom gnus-emphasis-alist
177 "\\(\\s-\\|^\\|[-\"\(]\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"\)]\\)")
179 '(("_" "_" underline)
182 ("_/" "/_" underline-italic)
183 ("_\\*" "\\*_" underline-bold)
184 ("\\*/" "/\\*" bold-italic)
185 ("_\\*/" "/\\*_" underline-bold-italic))))
186 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
187 2 3 gnus-emphasis-underline)
191 (format format (car spec) (cadr spec))
192 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
194 "Alist that says how to fontify certain phrases.
195 Each item looks like this:
197 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
199 The first element is a regular expression to be matched. The second
200 is a number that says what regular expression grouping used to find
201 the entire emphasized word. The third is a number that says what
202 regexp grouping should be displayed and highlighted. The fourth
203 is the face used for highlighting."
204 :type '(repeat (list :value ("" 0 0 default)
206 (integer :tag "Match group")
207 (integer :tag "Emphasize group")
209 :group 'gnus-article-emphasis)
211 (defface gnus-emphasis-bold '((t (:bold t)))
212 "Face used for displaying strong emphasized text (*word*)."
213 :group 'gnus-article-emphasis)
215 (defface gnus-emphasis-italic '((t (:italic t)))
216 "Face used for displaying italic emphasized text (/word/)."
217 :group 'gnus-article-emphasis)
219 (defface gnus-emphasis-underline '((t (:underline t)))
220 "Face used for displaying underlined emphasized text (_word_)."
221 :group 'gnus-article-emphasis)
223 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
224 "Face used for displaying underlined bold emphasized text (_*word*_)."
225 :group 'gnus-article-emphasis)
227 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
228 "Face used for displaying underlined italic emphasized text (_*word*_)."
229 :group 'gnus-article-emphasis)
231 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
232 "Face used for displaying bold italic emphasized text (/*word*/)."
233 :group 'gnus-article-emphasis)
235 (defface gnus-emphasis-underline-bold-italic
236 '((t (:bold t :italic t :underline t)))
237 "Face used for displaying underlined bold italic emphasized text.
238 Esample: (_/*word*/_)."
239 :group 'gnus-article-emphasis)
241 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
242 "Format for display of Date headers in article bodies.
243 See `format-time-zone' for the possible values."
245 :link '(custom-manual "(gnus)Article Date")
246 :group 'gnus-article-washing)
249 (autoload 'hexl-hex-string-to-integer "hexl")
250 (autoload 'timezone-make-date-arpa-standard "timezone")
251 (autoload 'mail-extract-address-components "mail-extr"))
253 (defcustom gnus-save-all-headers t
254 "*If non-nil, don't remove any headers before saving."
255 :group 'gnus-article-saving
258 (defcustom gnus-prompt-before-saving 'always
259 "*This variable says how much prompting is to be done when saving articles.
260 If it is nil, no prompting will be done, and the articles will be
261 saved to the default files. If this variable is `always', each and
262 every article that is saved will be preceded by a prompt, even when
263 saving large batches of articles. If this variable is neither nil not
264 `always', there the user will be prompted once for a file name for
265 each invocation of the saving commands."
266 :group 'gnus-article-saving
267 :type '(choice (item always)
268 (item :tag "never" nil)
269 (sexp :tag "once" :format "%t")))
271 (defcustom gnus-saved-headers gnus-visible-headers
272 "Headers to keep if `gnus-save-all-headers' is nil.
273 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
274 If that variable is nil, however, all headers that match this regexp
275 will be kept while the rest will be deleted before saving."
276 :group 'gnus-article-saving
277 :type '(repeat string))
279 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
280 "A function to save articles in your favourite format.
281 The function must be interactively callable (in other words, it must
282 be an Emacs command).
284 Gnus provides the following functions:
286 * gnus-summary-save-in-rmail (Rmail format)
287 * gnus-summary-save-in-mail (Unix mail format)
288 * gnus-summary-save-in-folder (MH folder)
289 * gnus-summary-save-in-file (article format)
290 * gnus-summary-save-in-vm (use VM's folder format)
291 * gnus-summary-write-to-file (article format -- overwrite)."
292 :group 'gnus-article-saving
293 :type '(radio (function-item gnus-summary-save-in-rmail)
294 (function-item gnus-summary-save-in-mail)
295 (function-item gnus-summary-save-in-folder)
296 (function-item gnus-summary-save-in-file)
297 (function-item gnus-summary-save-in-vm)
298 (function-item gnus-summary-write-to-file)))
300 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
301 "A function generating a file name to save articles in Rmail format.
302 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
303 :group 'gnus-article-saving
306 (defcustom gnus-mail-save-name 'gnus-plain-save-name
307 "A function generating a file name to save articles in Unix mail format.
308 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
309 :group 'gnus-article-saving
312 (defcustom gnus-folder-save-name 'gnus-folder-save-name
313 "A function generating a file name to save articles in MH folder.
314 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
315 :group 'gnus-article-saving
318 (defcustom gnus-file-save-name 'gnus-numeric-save-name
319 "A function generating a file name to save articles in article format.
320 The function is called with NEWSGROUP, HEADERS, and optional
322 :group 'gnus-article-saving
325 (defcustom gnus-split-methods
326 '((gnus-article-archive-name))
327 "Variable used to suggest where articles are to be saved.
328 For instance, if you would like to save articles related to Gnus in
329 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
330 you could set this variable to something like:
332 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
333 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
335 This variable is an alist where the where the key is the match and the
336 value is a list of possible files to save in if the match is non-nil.
338 If the match is a string, it is used as a regexp match on the
339 article. If the match is a symbol, that symbol will be funcalled
340 from the buffer of the article to be saved with the newsgroup as the
341 parameter. If it is a list, it will be evaled in the same buffer.
343 If this form or function returns a string, this string will be used as
344 a possible file name; and if it returns a non-nil list, that list will
345 be used as possible file names."
346 :group 'gnus-article-saving
347 :type '(repeat (choice (list function)
348 (cons regexp (repeat string))
351 (defcustom gnus-strict-mime t
352 "*If nil, MIME-decode even if there is no Mime-Version header."
353 :group 'gnus-article-mime
356 (defcustom gnus-show-mime-method 'metamail-buffer
357 "Function to process a MIME message.
358 The function is called from the article buffer."
359 :group 'gnus-article-mime
362 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
363 "*Function to decode MIME encoded words.
364 The function is called from the article buffer."
365 :group 'gnus-article-mime
368 (defcustom gnus-page-delimiter "^\^L"
369 "*Regexp describing what to use as article page delimiters.
370 The default value is \"^\^L\", which is a form linefeed at the
371 beginning of a line."
373 :group 'gnus-article-various)
375 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
376 "*The format specification for the article mode line.
377 See `gnus-summary-mode-line-format' for a closer description."
379 :group 'gnus-article-various)
381 (defcustom gnus-article-mode-hook nil
382 "*A hook for Gnus article mode."
384 :group 'gnus-article-various)
386 (defcustom gnus-article-menu-hook nil
387 "*Hook run after the creation of the article mode menu."
389 :group 'gnus-article-various)
391 (defcustom gnus-article-prepare-hook nil
392 "*A hook called after an article has been prepared in the article buffer.
393 If you want to run a special decoding program like nkf, use this hook."
395 :group 'gnus-article-various)
397 (defcustom gnus-article-button-face 'bold
398 "Face used for highlighting buttons in the article buffer.
400 An article button is a piece of text that you can activate by pressing
401 `RET' or `mouse-2' above it."
403 :group 'gnus-article-buttons)
405 (defcustom gnus-article-mouse-face 'highlight
406 "Face used for mouse highlighting in the article buffer.
408 Article buttons will be displayed in this face when the cursor is
411 :group 'gnus-article-buttons)
413 (defcustom gnus-signature-face 'italic
414 "Face used for highlighting a signature in the article buffer."
416 :group 'gnus-article-highlight
417 :group 'gnus-article-signature)
419 (defface gnus-header-from-face
422 (:foreground "spring green" :bold t :italic t))
425 (:foreground "indianred" :bold t :italic t))
427 (:bold t :italic t)))
428 "Face used for displaying from headers."
429 :group 'gnus-article-headers
430 :group 'gnus-article-highlight)
432 (defface gnus-header-subject-face
435 (:foreground "SeaGreen3" :bold t :italic t))
438 (:foreground "firebrick" :bold t :italic t))
440 (:bold t :italic t)))
441 "Face used for displaying subject headers."
442 :group 'gnus-article-headers
443 :group 'gnus-article-highlight)
445 (defface gnus-header-newsgroups-face
448 (:foreground "yellow" :bold t :italic t))
451 (:foreground "MidnightBlue" :bold t :italic t))
453 (:bold t :italic t)))
454 "Face used for displaying newsgroups headers."
455 :group 'gnus-article-headers
456 :group 'gnus-article-highlight)
458 (defface gnus-header-name-face
461 (:foreground "SeaGreen"))
464 (:foreground "maroon"))
467 "Face used for displaying header names."
468 :group 'gnus-article-headers
469 :group 'gnus-article-highlight)
471 (defface gnus-header-content-face
474 (:foreground "forest green" :italic t))
477 (:foreground "indianred4" :italic t))
479 (:italic t))) "Face used for displaying header content."
480 :group 'gnus-article-headers
481 :group 'gnus-article-highlight)
483 (defcustom gnus-header-face-alist
484 '(("From" nil gnus-header-from-face)
485 ("Subject" nil gnus-header-subject-face)
486 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
487 ("" gnus-header-name-face gnus-header-content-face))
488 "Controls highlighting of article header.
490 An alist of the form (HEADER NAME CONTENT).
492 HEADER is a regular expression which should match the name of an
493 header header and NAME and CONTENT are either face names or nil.
495 The name of each header field will be displayed using the face
496 specified by the first element in the list where HEADER match the
497 header name and NAME is non-nil. Similarly, the content will be
498 displayed by the first non-nil matching CONTENT face."
499 :group 'gnus-article-headers
500 :group 'gnus-article-highlight
501 :type '(repeat (list (regexp :tag "Header")
503 (item :tag "skip" nil)
504 (face :value default))
505 (choice :tag "Content"
506 (item :tag "skip" nil)
507 (face :value default)))))
509 ;;; Internal variables
511 (defvar gnus-article-mode-syntax-table
512 (let ((table (copy-syntax-table text-mode-syntax-table)))
513 ;;(modify-syntax-entry ?_ "w" table)
515 "Syntax table used in article mode buffers.
516 Initialized from `text-mode-syntax-table.")
518 (defvar gnus-save-article-buffer nil)
520 (defvar gnus-article-mode-line-format-alist
521 (nconc '((?w (gnus-article-wash-status) ?s))
522 gnus-summary-mode-line-format-alist))
524 (defvar gnus-number-of-articles-to-be-saved nil)
526 (defvar gnus-inhibit-hiding nil)
527 (defvar gnus-newsgroup-name)
529 (defsubst gnus-article-hide-text (b e props)
530 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
531 (add-text-properties b e props)
532 (when (memq 'intangible props)
534 (max (1- b) (point-min))
535 b 'intangible (cddr (memq 'intangible props)))))
537 (defsubst gnus-article-unhide-text (b e)
538 "Remove hidden text properties from region between B and E."
539 (remove-text-properties b e gnus-hidden-properties)
540 (when (memq 'intangible gnus-hidden-properties)
541 (put-text-property (max (1- b) (point-min))
544 (defun gnus-article-hide-text-type (b e type)
545 "Hide text of TYPE between B and E."
546 (gnus-article-hide-text
547 b e (cons 'article-type (cons type gnus-hidden-properties))))
549 (defun gnus-article-unhide-text-type (b e type)
550 "Hide text of TYPE between B and E."
551 (remove-text-properties
552 b e (cons 'article-type (cons type gnus-hidden-properties)))
553 (when (memq 'intangible gnus-hidden-properties)
554 (put-text-property (max (1- b) (point-min))
557 (defun gnus-article-hide-text-of-type (type)
558 "Hide text of TYPE in the current buffer."
560 (let ((b (point-min))
562 (while (setq b (text-property-any b e 'article-type type))
563 (add-text-properties b (incf b) gnus-hidden-properties)))))
565 (defun gnus-article-delete-text-of-type (type)
566 "Delete text of TYPE in the current buffer."
568 (let ((b (point-min)))
569 (while (setq b (text-property-any b (point-max) 'article-type type))
570 (delete-region b (incf b))))))
572 (defun gnus-article-delete-invisible-text ()
573 "Delete all invisible text in the current buffer."
575 (let ((b (point-min)))
576 (while (setq b (text-property-any b (point-max) 'invisible t))
577 (delete-region b (incf b))))))
579 (defun gnus-article-text-type-exists-p (type)
580 "Say whether any text of type TYPE exists in the buffer."
581 (text-property-any (point-min) (point-max) 'article-type type))
583 (defsubst gnus-article-header-rank ()
584 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
585 (let ((list gnus-sorted-header-list)
588 (when (looking-at (car list))
590 (setq list (cdr list))
594 (defun article-hide-headers (&optional arg delete)
595 "Toggle whether to hide unwanted headers and possibly sort them as well.
596 If given a negative prefix, always show; if given a positive prefix,
598 (interactive (gnus-article-hidden-arg))
599 (if (gnus-article-check-hidden-text 'headers arg)
600 ;; Show boring headers as well.
601 (gnus-article-show-hidden-text 'boring-headers)
602 ;; This function might be inhibited.
603 (unless gnus-inhibit-hiding
606 (let ((buffer-read-only nil)
607 (props (nconc (list 'article-type 'headers)
608 gnus-hidden-properties))
609 (max (1+ (length gnus-sorted-header-list)))
610 (ignored (when (not gnus-visible-headers)
611 (cond ((stringp gnus-ignored-headers)
612 gnus-ignored-headers)
613 ((listp gnus-ignored-headers)
614 (mapconcat 'identity gnus-ignored-headers
617 (cond ((stringp gnus-visible-headers)
618 gnus-visible-headers)
619 ((and gnus-visible-headers
620 (listp gnus-visible-headers))
621 (mapconcat 'identity gnus-visible-headers "\\|"))))
622 (inhibit-point-motion-hooks t)
624 ;; First we narrow to just the headers.
626 (goto-char (point-min))
627 ;; Hide any "From " lines at the beginning of (mail) articles.
628 (while (looking-at "From ")
632 (delete-region (point-min) (point))
633 (gnus-article-hide-text (point-min) (point) props)))
634 ;; Then treat the rest of the header lines.
637 (if (search-forward "\n\n" nil t) ; if there's a body
638 (progn (forward-line -1) (point))
640 ;; Then we use the two regular expressions
641 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
642 ;; select which header lines is to remain visible in the
644 (goto-char (point-min))
645 (while (re-search-forward "^[^ \t]*:" nil t)
647 ;; Mark the rank of the header.
649 (point) (1+ (point)) 'message-rank
650 (if (or (and visible (looking-at visible))
652 (not (looking-at ignored))))
653 (gnus-article-header-rank)
656 (message-sort-headers-1)
657 (when (setq beg (text-property-any
658 (point-min) (point-max) 'message-rank (+ 2 max)))
659 ;; We make the unwanted headers invisible.
661 (delete-region beg (point-max))
662 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
663 (gnus-article-hide-text-type beg (point-max) 'headers))
664 ;; Work around XEmacs lossage.
665 (put-text-property (point-min) beg 'invisible nil))))))))
667 (defun article-hide-boring-headers (&optional arg)
668 "Toggle hiding of headers that aren't very interesting.
669 If given a negative prefix, always show; if given a positive prefix,
671 (interactive (gnus-article-hidden-arg))
672 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
673 (not gnus-show-all-headers))
676 (let ((buffer-read-only nil)
677 (list gnus-boring-article-headers)
678 (inhibit-point-motion-hooks t)
680 (nnheader-narrow-to-headers)
682 (setq elem (pop list))
683 (goto-char (point-min))
685 ;; Hide empty headers.
687 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
689 (gnus-article-hide-text-type
690 (progn (beginning-of-line) (point))
693 (if (re-search-forward "^[^ \t]" nil t)
697 ;; Hide boring Newsgroups header.
698 ((eq elem 'newsgroups)
699 (when (equal (gnus-fetch-field "newsgroups")
700 (gnus-group-real-name
701 (if (boundp 'gnus-newsgroup-name)
704 (gnus-article-hide-header "newsgroups")))
705 ((eq elem 'followup-to)
706 (when (equal (message-fetch-field "followup-to")
707 (message-fetch-field "newsgroups"))
708 (gnus-article-hide-header "followup-to")))
710 (let ((from (message-fetch-field "from"))
711 (reply-to (message-fetch-field "reply-to")))
716 (nth 1 (mail-extract-address-components from))
717 (nth 1 (mail-extract-address-components reply-to)))))
718 (gnus-article-hide-header "reply-to"))))
720 (let ((date (message-fetch-field "date")))
722 (< (gnus-days-between (current-time-string) date)
724 (gnus-article-hide-header "date")))))))))))
726 (defun gnus-article-hide-header (header)
728 (goto-char (point-min))
729 (when (re-search-forward (concat "^" header ":") nil t)
730 (gnus-article-hide-text-type
731 (progn (beginning-of-line) (point))
734 (if (re-search-forward "^[^ \t]" nil t)
739 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
740 (defun article-treat-overstrike ()
741 "Translate overstrikes into bold text."
744 (let ((buffer-read-only nil))
745 (while (search-forward "\b" nil t)
746 (let ((next (following-char))
747 (previous (char-after (- (point) 2))))
748 ;; We do the boldification/underlining by hiding the
749 ;; overstrikes and putting the proper text property
753 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
754 (put-text-property (point) (1+ (point)) 'face 'bold))
756 (gnus-article-hide-text-type (1- (point)) (1+ (point)) 'overstrike)
758 (- (point) 2) (1- (point)) 'face 'underline))
760 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
762 (point) (1+ (point)) 'face 'underline))))))))
764 (defun article-fill ()
765 "Format too long lines."
768 (let ((buffer-read-only nil))
770 (goto-char (point-min))
771 (search-forward "\n\n" nil t)
773 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
774 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
775 (adaptive-fill-mode t))
777 (and (>= (current-column) (min fill-column (window-width)))
778 (/= (preceding-char) ?:)
779 (fill-paragraph nil))
782 (defun article-remove-cr ()
783 "Remove carriage returns from an article."
786 (let ((buffer-read-only nil))
787 (goto-char (point-min))
788 (while (search-forward "\r" nil t)
789 (replace-match "" t t)))))
791 (defun article-remove-trailing-blank-lines ()
792 "Remove all trailing blank lines from the article."
795 (let ((buffer-read-only nil))
796 (goto-char (point-max))
800 (while (and (not (bobp))
801 (looking-at "^[ \t]*$"))
806 (defun article-display-x-face (&optional force)
807 "Look for an X-Face header and display it if present."
808 (interactive (list 'force))
810 ;; Delete the old process, if any.
811 (when (process-status "article-x-face")
812 (delete-process "article-x-face"))
813 (let ((inhibit-point-motion-hooks t)
814 (case-fold-search nil)
817 (nnheader-narrow-to-headers)
818 (setq from (message-fetch-field "from"))
819 (goto-char (point-min))
820 (when (and gnus-article-x-face-command
822 ;; Check whether this face is censored.
823 (not gnus-article-x-face-too-ugly)
824 (and gnus-article-x-face-too-ugly from
825 (not (string-match gnus-article-x-face-too-ugly
827 ;; Has to be present.
828 (re-search-forward "^X-Face: " nil t))
829 ;; We now have the area of the buffer where the X-Face is stored.
831 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
832 ;; We display the face.
833 (if (symbolp gnus-article-x-face-command)
834 ;; The command is a lisp function, so we call it.
835 (if (gnus-functionp gnus-article-x-face-command)
836 (funcall gnus-article-x-face-command beg end)
837 (error "%s is not a function" gnus-article-x-face-command))
838 ;; The command is a string, so we interpret the command
839 ;; as a, well, command, and fork it off.
840 (let ((process-connection-type nil))
841 (process-kill-without-query
843 "article-x-face" nil shell-file-name shell-command-switch
844 gnus-article-x-face-command))
845 (process-send-region "article-x-face" beg end)
846 (process-send-eof "article-x-face")))))))))
848 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
849 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
850 (defun article-decode-rfc1522 ()
851 "Hack to remove QP encoding from headers."
852 (let ((case-fold-search t)
853 (inhibit-point-motion-hooks t)
854 (buffer-read-only nil)
858 (goto-char (point-min))
859 (or (search-forward "\n\n" nil t) (point-max)))
860 (goto-char (point-min))
861 (while (re-search-forward
862 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
863 (setq string (match-string 1))
865 (narrow-to-region (match-beginning 0) (match-end 0))
866 (delete-region (point-min) (point-max))
868 (article-mime-decode-quoted-printable
869 (goto-char (point-min)) (point-max))
870 (subst-char-in-region (point-min) (point-max) ?_ ? )
871 (goto-char (point-max)))
872 (goto-char (point-min))))))
874 (defun article-de-quoted-unreadable (&optional force)
875 "Do a naive translation of a quoted-printable-encoded article.
876 This is in no way, shape or form meant as a replacement for real MIME
877 processing, but is simply a stop-gap measure until MIME support is
879 If FORCE, decode the article whether it is marked as quoted-printable
881 (interactive (list 'force))
883 (let ((case-fold-search t)
884 (buffer-read-only nil)
885 (type (gnus-fetch-field "content-transfer-encoding")))
886 (gnus-article-decode-rfc1522)
888 (and type (string-match "quoted-printable" (downcase type))))
889 (goto-char (point-min))
890 (search-forward "\n\n" nil 'move)
891 (article-mime-decode-quoted-printable (point) (point-max))))))
893 (defun article-mime-decode-quoted-printable-buffer ()
894 "Decode Quoted-Printable in the current buffer."
895 (article-mime-decode-quoted-printable (point-min) (point-max)))
897 (defun article-mime-decode-quoted-printable (from to)
898 "Decode Quoted-Printable in the region between FROM and TO."
901 (while (search-forward "=" to t)
902 (cond ((eq (following-char) ?\n)
905 ((looking-at "[0-9A-F][0-9A-F]")
906 (subst-char-in-region
907 (1- (point)) (point) ?=
908 (hexl-hex-string-to-integer
909 (buffer-substring (point) (+ 2 (point)))))
913 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
915 (defun article-hide-pgp (&optional arg)
916 "Toggle hiding of any PGP headers and signatures in the current article.
917 If given a negative prefix, always show; if given a positive prefix,
919 (interactive (gnus-article-hidden-arg))
920 (unless (gnus-article-check-hidden-text 'pgp arg)
922 (let ((inhibit-point-motion-hooks t)
923 buffer-read-only beg end)
925 (goto-char (point-min))
926 ;; Hide the "header".
927 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
928 (gnus-article-hide-text-type (1+ (match-beginning 0))
931 ;; Hide the actual signature.
932 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
933 (setq end (1+ (match-beginning 0)))
934 (gnus-article-hide-text-type
936 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
938 ;; Perhaps we shouldn't hide to the end of the buffer
939 ;; if there is no end to the signature?
942 ;; Hide "- " PGP quotation markers.
944 (narrow-to-region beg end)
945 (goto-char (point-min))
946 (while (re-search-forward "^- " nil t)
947 (gnus-article-hide-text-type
948 (match-beginning 0) (match-end 0) 'pgp))
951 (defun article-hide-pem (&optional arg)
952 "Toggle hiding of any PEM headers and signatures in the current article.
953 If given a negative prefix, always show; if given a positive prefix,
955 (interactive (gnus-article-hidden-arg))
956 (unless (gnus-article-check-hidden-text 'pem arg)
958 (let (buffer-read-only end)
960 (goto-char (point-min))
961 ;; hide the horrendously ugly "header".
962 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
965 (setq end (1+ (match-beginning 0)))
966 (gnus-article-hide-text-type
968 (if (search-forward "\n\n" nil t)
972 ;; hide the trailer as well
973 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
976 (gnus-article-hide-text-type
977 (match-beginning 0) (match-end 0) 'pem))))))
979 (defun article-hide-signature (&optional arg)
980 "Hide the signature in the current article.
981 If given a negative prefix, always show; if given a positive prefix,
983 (interactive (gnus-article-hidden-arg))
984 (unless (gnus-article-check-hidden-text 'signature arg)
987 (let ((buffer-read-only nil))
988 (when (gnus-article-narrow-to-signature)
989 (gnus-article-hide-text-type
990 (point-min) (point-max) 'signature)))))))
992 (defun article-strip-leading-blank-lines ()
993 "Remove all blank lines from the beginning of the article."
996 (let ((inhibit-point-motion-hooks t)
998 (goto-char (point-min))
999 (when (search-forward "\n\n" nil t)
1000 (while (and (not (eobp))
1001 (looking-at "[ \t]*$"))
1002 (gnus-delete-line))))))
1004 (defun article-strip-multiple-blank-lines ()
1005 "Replace consecutive blank lines with one empty line."
1008 (let ((inhibit-point-motion-hooks t)
1010 ;; First make all blank lines empty.
1011 (goto-char (point-min))
1012 (search-forward "\n\n" nil t)
1013 (while (re-search-forward "^[ \t]+$" nil t)
1014 (replace-match "" nil t))
1015 ;; Then replace multiple empty lines with a single empty line.
1016 (goto-char (point-min))
1017 (search-forward "\n\n" nil t)
1018 (while (re-search-forward "\n\n\n+" nil t)
1019 (replace-match "\n\n" t t)))))
1021 (defun article-strip-blank-lines ()
1022 "Strip leading, trailing and multiple blank lines."
1024 (article-strip-leading-blank-lines)
1025 (article-remove-trailing-blank-lines)
1026 (article-strip-multiple-blank-lines))
1028 (defvar mime::preview/content-list)
1029 (defvar mime::preview-content-info/point-min)
1030 (defun gnus-article-narrow-to-signature ()
1031 "Narrow to the signature; return t if a signature is found, else nil."
1033 (when (and (boundp 'mime::preview/content-list)
1034 mime::preview/content-list)
1035 ;; We have a MIMEish article, so we use the MIME data to narrow.
1036 (let ((pcinfo (car (last mime::preview/content-list))))
1039 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1042 (when (gnus-article-search-signature)
1044 ;; Check whether we have some limits to what we consider
1045 ;; to be a signature.
1046 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1047 (list gnus-signature-limit)))
1049 (while (setq limit (pop limits))
1050 (if (or (and (integerp limit)
1051 (< (- (point-max) (point)) limit))
1053 (< (count-lines (point) (point-max)) limit))
1054 (and (gnus-functionp limit)
1056 (and (stringp limit)
1057 (not (re-search-forward limit nil t))))
1058 () ; This limit did not succeed.
1062 (narrow-to-region (point) (point-max))
1065 (defun gnus-article-search-signature ()
1066 "Search the current buffer for the signature separator.
1067 Put point at the beginning of the signature separator."
1068 (let ((cur (point)))
1069 (goto-char (point-max))
1070 (if (if (stringp gnus-signature-separator)
1071 (re-search-backward gnus-signature-separator nil t)
1072 (let ((seps gnus-signature-separator))
1074 (not (re-search-backward (car seps) nil t)))
1082 (autoload 'w3-parse-buffer "w3-parse"))
1084 (defun gnus-article-treat-html ()
1087 (let ((cbuf (current-buffer)))
1088 (set-buffer gnus-article-buffer)
1089 (let (buf buffer-read-only b e)
1090 (goto-char (point-min))
1092 (if (search-forward "\n\n" nil t)
1095 (setq e (point-max)))
1096 (nnheader-temp-write nil
1097 (insert-buffer-substring gnus-article-buffer b e)
1098 (save-window-excursion
1099 (setq buf (car (w3-parse-buffer (current-buffer))))))
1101 (delete-region (point-min) (point-max))
1102 (insert-buffer-substring buf)
1105 (goto-char (point-min))
1106 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1107 (set-buffer cbuf))))
1109 (defun gnus-article-hidden-arg ()
1110 "Return the current prefix arg as a number, or 0 if no prefix."
1111 (list (if current-prefix-arg
1112 (prefix-numeric-value current-prefix-arg)
1115 (defun gnus-article-check-hidden-text (type arg)
1116 "Return nil if hiding is necessary.
1117 Arg can be nil or a number. Nil and positive means hide, negative
1118 means show, 0 means toggle."
1122 (let ((hide (gnus-article-hidden-text-p type)))
1128 (gnus-article-show-hidden-text type))
1130 (if (eq hide 'hidden)
1131 (gnus-article-show-hidden-text type)
1134 (defun gnus-article-hidden-text-p (type)
1135 "Say whether the current buffer contains hidden text of type TYPE."
1136 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1138 (if (get-text-property pos 'invisible)
1142 (defun gnus-article-show-hidden-text (type &optional hide)
1143 "Show all hidden text of type TYPE.
1144 If HIDE, hide the text instead."
1146 (let ((buffer-read-only nil)
1147 (inhibit-point-motion-hooks t)
1150 (while (setq beg (text-property-any end (point-max) 'article-type type))
1153 (text-property-not-all beg (point-max) 'article-type type)
1156 (gnus-article-hide-text beg end gnus-hidden-properties)
1157 (gnus-article-unhide-text beg end))
1161 (defconst article-time-units
1162 `((year . ,(* 365.25 24 60 60))
1163 (week . ,(* 7 24 60 60))
1164 (day . ,(* 24 60 60))
1168 "Mapping from time units to seconds.")
1170 (defun article-date-ut (&optional type highlight header)
1171 "Convert DATE date to universal time in the current article.
1172 If TYPE is `local', convert to local time; if it is `lapsed', output
1173 how much time has lapsed since DATE."
1174 (interactive (list 'ut t))
1175 (let* ((header (or header
1176 (mail-header-date gnus-current-headers)
1177 (message-fetch-field "date")
1179 (date (if (vectorp header) (mail-header-date header)
1181 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1182 (inhibit-point-motion-hooks t)
1184 (when (and date (not (string= date "")))
1187 (nnheader-narrow-to-headers)
1188 (let ((buffer-read-only nil))
1189 ;; Delete any old Date headers.
1190 (if (re-search-forward date-regexp nil t)
1192 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1193 eface (get-text-property (1- (gnus-point-at-eol))
1195 (message-remove-header date-regexp t)
1196 (beginning-of-line))
1197 (goto-char (point-max)))
1198 (insert (article-make-date-line date type))
1201 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1202 (put-text-property (match-beginning 1) (match-end 1)
1204 (put-text-property (match-beginning 2) (match-end 2)
1207 (defun article-make-date-line (date type)
1208 "Return a DATE line of TYPE."
1210 ;; Convert to the local timezone. We have to slap a
1211 ;; `condition-case' round the calls to the timezone
1212 ;; functions since they aren't particularly resistant to
1215 (concat "Date: " (condition-case ()
1216 (timezone-make-date-arpa-standard date)
1219 ;; Convert to Universal Time.
1223 (timezone-make-date-arpa-standard date nil "UT")
1226 ;; Get the original date from the article.
1227 ((eq type 'original)
1228 (concat "Date: " date "\n"))
1229 ;; Let the user define the format.
1233 (format-time-string gnus-article-time-format
1236 (timezone-make-date-arpa-standard
1239 ;; Do an X-Sent lapsed format.
1241 ;; If the date is seriously mangled, the timezone functions are
1242 ;; liable to bug out, so we ignore all errors.
1243 (let* ((now (current-time))
1248 (timezone-make-date-arpa-standard
1249 (current-time-string now)
1250 (current-time-zone now) "UT"))
1252 (timezone-make-date-arpa-standard
1254 (real-sec (and real-time
1255 (+ (* (float (car real-time)) 65536)
1257 (sec (and real-time (abs real-sec)))
1261 "X-Sent: Unknown\n")
1267 ;; This is a bit convoluted, but basically we go
1268 ;; through the time units for years, weeks, etc,
1269 ;; and divide things to see whether that results
1270 ;; in positive answers.
1273 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1274 ;; The (remaining) seconds are too few to
1275 ;; be divided into this time unit.
1277 ;; It's big enough, so we output it.
1278 (setq sec (- sec (* num (cdr unit))))
1280 (concat (if prev ", " "") (int-to-string
1282 " " (symbol-name (car unit))
1283 (if (> num 1) "s" ""))
1285 article-time-units "")
1286 ;; If dates are odd, then it might appear like the
1287 ;; article was sent in the future.
1290 " in the future\n"))))))
1292 (error "Unknown conversion type: %s" type))))
1294 (defun article-date-local (&optional highlight)
1295 "Convert the current article date to the local timezone."
1296 (interactive (list t))
1297 (article-date-ut 'local highlight))
1299 (defun article-date-original (&optional highlight)
1300 "Convert the current article date to what it was originally.
1301 This is only useful if you have used some other date conversion
1302 function and want to see what the date was before converting."
1303 (interactive (list t))
1304 (article-date-ut 'original highlight))
1306 (defun article-date-lapsed (&optional highlight)
1307 "Convert the current article date to time lapsed since it was sent."
1308 (interactive (list t))
1309 (article-date-ut 'lapsed highlight))
1311 (defun article-date-user (&optional highlight)
1312 "Convert the current article date to the user-defined format.
1313 This format is defined by the `gnus-article-time-format' variable."
1314 (interactive (list t))
1315 (article-date-ut 'user highlight))
1317 (defun article-show-all ()
1318 "Show all hidden text in the article buffer."
1321 (let ((buffer-read-only nil))
1322 (gnus-article-unhide-text (point-min) (point-max)))))
1324 (defun article-emphasize (&optional arg)
1325 "Emphasize text according to `gnus-emphasis-alist'."
1326 (interactive (gnus-article-hidden-arg))
1327 (unless (gnus-article-check-hidden-text 'emphasis arg)
1329 (let ((alist gnus-emphasis-alist)
1330 (buffer-read-only nil)
1331 (props (append '(article-type emphasis)
1332 gnus-hidden-properties))
1333 regexp elem beg invisible visible face)
1334 (goto-char (point-min))
1335 (search-forward "\n\n" nil t)
1337 (while (setq elem (pop alist))
1339 (setq regexp (car elem)
1340 invisible (nth 1 elem)
1341 visible (nth 2 elem)
1343 (while (re-search-forward regexp nil t)
1344 (when (and (match-beginning visible) (match-beginning invisible))
1345 (gnus-article-hide-text
1346 (match-beginning invisible) (match-end invisible) props)
1347 (gnus-article-unhide-text-type
1348 (match-beginning visible) (match-end visible) 'emphasis)
1349 (gnus-put-text-property-excluding-newlines
1350 (match-beginning visible) (match-end visible) 'face face)
1351 (goto-char (match-end invisible)))))))))
1353 (defvar gnus-summary-article-menu)
1354 (defvar gnus-summary-post-menu)
1356 ;;; Saving functions.
1358 (defun gnus-article-save (save-buffer file &optional num)
1359 "Save the currently selected article."
1360 (unless gnus-save-all-headers
1361 ;; Remove headers according to `gnus-saved-headers'.
1362 (let ((gnus-visible-headers
1363 (or gnus-saved-headers gnus-visible-headers))
1364 (gnus-article-buffer save-buffer))
1365 (gnus-article-hide-headers 1 t)))
1366 (save-window-excursion
1367 (if (not gnus-default-article-saver)
1368 (error "No default saver is defined.")
1369 ;; !!! Magic! The saving functions all save
1370 ;; `gnus-original-article-buffer' (or so they think), but we
1371 ;; bind that variable to our save-buffer.
1372 (set-buffer gnus-article-buffer)
1373 (let* ((gnus-save-article-buffer save-buffer)
1376 ((not gnus-prompt-before-saving) 'default)
1377 ((eq gnus-prompt-before-saving 'always) nil)
1379 (gnus-number-of-articles-to-be-saved
1380 (when (eq gnus-prompt-before-saving t)
1382 (set-buffer gnus-summary-buffer)
1383 (funcall gnus-default-article-saver filename)))))
1385 (defun gnus-read-save-file-name (prompt default-name &optional filename)
1387 ((eq filename 'default)
1391 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1393 (format prompt (if (and gnus-number-of-articles-to-be-saved
1394 (> gnus-number-of-articles-to-be-saved 1))
1395 (format "these %d articles"
1396 gnus-number-of-articles-to-be-saved)
1399 ;; Let the split methods have their say.
1401 ;; No split name was found.
1404 (concat prompt " (default "
1405 (file-name-nondirectory default-name) ") ")
1406 (file-name-directory default-name)
1408 ;; A single split name was found
1409 ((= 1 (length split-name))
1410 (let* ((name (car split-name))
1411 (dir (cond ((file-directory-p name)
1412 (file-name-as-directory name))
1413 ((file-exists-p name) name)
1414 (t gnus-article-save-directory))))
1416 (concat prompt " (default " name ") ")
1418 ;; A list of splits was found.
1420 (setq split-name (nreverse split-name))
1422 (let ((file-name-history (nconc split-name file-name-history)))
1426 (concat prompt " (`M-p' for defaults) ")
1427 gnus-article-save-directory
1429 gnus-article-save-directory)))
1430 (car (push result file-name-history)))))))
1431 ;; Create the directory.
1432 (gnus-make-directory (file-name-directory file))
1433 ;; If we have read a directory, we append the default file name.
1434 (when (file-directory-p file)
1435 (setq file (concat (file-name-as-directory file)
1436 (file-name-nondirectory default-name))))
1437 ;; Possibly translate some characters.
1438 (nnheader-translate-file-chars file)))))
1440 (defun gnus-article-archive-name (group)
1441 "Return the first instance of an \"Archive-name\" in the current buffer."
1442 (let ((case-fold-search t))
1443 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1444 (nnheader-concat gnus-article-save-directory
1445 (match-string 1)))))
1447 (defun gnus-summary-save-in-rmail (&optional filename)
1448 "Append this article to Rmail file.
1449 Optional argument FILENAME specifies file name.
1450 Directory to save to is default to `gnus-article-save-directory'."
1452 (gnus-set-global-variables)
1454 (funcall gnus-rmail-save-name gnus-newsgroup-name
1455 gnus-current-headers gnus-newsgroup-last-rmail)))
1456 (setq filename (gnus-read-save-file-name
1457 "Save %s in rmail file:" default-name filename))
1458 (gnus-make-directory (file-name-directory filename))
1459 (gnus-eval-in-buffer-window gnus-save-article-buffer
1463 (gnus-output-to-rmail filename))))
1464 ;; Remember the directory name to save articles
1465 (setq gnus-newsgroup-last-rmail filename)))
1467 (defun gnus-summary-save-in-mail (&optional filename)
1468 "Append this article to Unix mail file.
1469 Optional argument FILENAME specifies file name.
1470 Directory to save to is default to `gnus-article-save-directory'."
1472 (gnus-set-global-variables)
1474 (funcall gnus-mail-save-name gnus-newsgroup-name
1475 gnus-current-headers gnus-newsgroup-last-mail)))
1476 (setq filename (gnus-read-save-file-name
1477 "Save %s in Unix mail file:" default-name filename))
1479 (expand-file-name filename
1481 (file-name-directory default-name))))
1482 (gnus-make-directory (file-name-directory filename))
1483 (gnus-eval-in-buffer-window gnus-save-article-buffer
1487 (if (and (file-readable-p filename)
1488 (mail-file-babyl-p filename))
1489 (gnus-output-to-rmail filename t)
1490 (gnus-output-to-mail filename)))))
1491 ;; Remember the directory name to save articles.
1492 (setq gnus-newsgroup-last-mail filename)))
1494 (defun gnus-summary-save-in-file (&optional filename overwrite)
1495 "Append this article to file.
1496 Optional argument FILENAME specifies file name.
1497 Directory to save to is default to `gnus-article-save-directory'."
1499 (gnus-set-global-variables)
1501 (funcall gnus-file-save-name gnus-newsgroup-name
1502 gnus-current-headers gnus-newsgroup-last-file)))
1503 (setq filename (gnus-read-save-file-name
1504 "Save %s in file:" default-name filename))
1505 (gnus-make-directory (file-name-directory filename))
1506 (gnus-eval-in-buffer-window gnus-save-article-buffer
1510 (when (and overwrite
1511 (file-exists-p filename))
1512 (delete-file filename))
1513 (gnus-output-to-file filename))))
1514 ;; Remember the directory name to save articles.
1515 (setq gnus-newsgroup-last-file filename)))
1517 (defun gnus-summary-write-to-file (&optional filename)
1518 "Write this article to a file.
1519 Optional argument FILENAME specifies file name.
1520 The directory to save in defaults to `gnus-article-save-directory'."
1522 (gnus-summary-save-in-file nil t))
1524 (defun gnus-summary-save-body-in-file (&optional filename)
1525 "Append this article body to a file.
1526 Optional argument FILENAME specifies file name.
1527 The directory to save in defaults to `gnus-article-save-directory'."
1529 (gnus-set-global-variables)
1531 (funcall gnus-file-save-name gnus-newsgroup-name
1532 gnus-current-headers gnus-newsgroup-last-file)))
1533 (setq filename (gnus-read-save-file-name
1534 "Save %s body in file:" default-name filename))
1535 (gnus-make-directory (file-name-directory filename))
1536 (gnus-eval-in-buffer-window gnus-save-article-buffer
1540 (goto-char (point-min))
1541 (when (search-forward "\n\n" nil t)
1542 (narrow-to-region (point) (point-max)))
1543 (gnus-output-to-file filename))))
1544 ;; Remember the directory name to save articles.
1545 (setq gnus-newsgroup-last-file filename)))
1547 (defun gnus-summary-save-in-pipe (&optional command)
1548 "Pipe this article to subprocess."
1550 (gnus-set-global-variables)
1552 (cond ((eq command 'default)
1553 gnus-last-shell-command)
1557 "Shell command on %s: "
1558 (if (and gnus-number-of-articles-to-be-saved
1559 (> gnus-number-of-articles-to-be-saved 1))
1560 (format "these %d articles"
1561 gnus-number-of-articles-to-be-saved)
1563 gnus-last-shell-command))))
1564 (when (string-equal command "")
1565 (setq command gnus-last-shell-command))
1566 (gnus-eval-in-buffer-window gnus-article-buffer
1569 (shell-command-on-region (point-min) (point-max) command nil)))
1570 (setq gnus-last-shell-command command))
1572 ;;; Article file names when saving.
1574 (defun gnus-capitalize-newsgroup (newsgroup)
1575 "Capitalize NEWSGROUP name."
1576 (when (not (zerop (length newsgroup)))
1577 (concat (char-to-string (upcase (aref newsgroup 0)))
1578 (substring newsgroup 1))))
1580 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1581 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1582 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1583 Otherwise, it is like ~/News/news/group/num."
1586 (concat (if (gnus-use-long-file-name 'not-save)
1587 (gnus-capitalize-newsgroup newsgroup)
1588 (gnus-newsgroup-directory-form newsgroup))
1589 "/" (int-to-string (mail-header-number headers)))
1590 gnus-article-save-directory)))
1592 (string-equal (file-name-directory default)
1593 (file-name-directory last-file))
1594 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1596 (or last-file default))))
1598 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1599 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1600 If variable `gnus-use-long-file-name' is non-nil, it is
1601 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1604 (concat (if (gnus-use-long-file-name 'not-save)
1606 (gnus-newsgroup-directory-form newsgroup))
1607 "/" (int-to-string (mail-header-number headers)))
1608 gnus-article-save-directory)))
1610 (string-equal (file-name-directory default)
1611 (file-name-directory last-file))
1612 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1614 (or last-file default))))
1616 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1617 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1618 If variable `gnus-use-long-file-name' is non-nil, it is
1619 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1622 (if (gnus-use-long-file-name 'not-save)
1623 (gnus-capitalize-newsgroup newsgroup)
1624 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1625 gnus-article-save-directory)))
1627 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1628 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1629 If variable `gnus-use-long-file-name' is non-nil, it is
1630 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1633 (if (gnus-use-long-file-name 'not-save)
1635 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1636 gnus-article-save-directory)))
1643 (setq afunc (car func)
1646 gfunc (intern (format "gnus-%s" func))))
1648 (if (not (fboundp afunc))
1650 `(lambda (&optional interactive &rest args)
1651 ,(documentation afunc t)
1652 (interactive (list t))
1654 (set-buffer gnus-article-buffer)
1656 (call-interactively ',afunc)
1657 (apply ',afunc args))))))))
1658 '(article-hide-headers
1659 article-hide-boring-headers
1660 article-treat-overstrike
1661 (article-fill . gnus-article-word-wrap)
1663 article-display-x-face
1664 article-de-quoted-unreadable
1665 article-mime-decode-quoted-printable
1668 article-hide-signature
1669 article-remove-trailing-blank-lines
1670 article-strip-leading-blank-lines
1671 article-strip-multiple-blank-lines
1672 article-strip-blank-lines
1674 article-date-original
1679 (article-show-all . gnus-article-show-all-headers))))
1682 ;;; Gnus article mode
1685 (put 'gnus-article-mode 'mode-class 'special)
1688 (gnus-define-keys gnus-article-mode-map
1689 " " gnus-article-goto-next-page
1690 "\177" gnus-article-goto-prev-page
1691 [delete] gnus-article-goto-prev-page
1692 "\C-c^" gnus-article-refer-article
1693 "h" gnus-article-show-summary
1694 "s" gnus-article-show-summary
1695 "\C-c\C-m" gnus-article-mail
1696 "?" gnus-article-describe-briefly
1697 gnus-mouse-2 gnus-article-push-button
1698 "\r" gnus-article-press-button
1699 "\t" gnus-article-next-button
1700 "\M-\t" gnus-article-prev-button
1701 "e" gnus-article-edit
1702 "<" beginning-of-buffer
1704 "\C-c\C-i" gnus-info-find-node
1707 "\C-d" gnus-article-read-summary-keys
1708 "\M-*" gnus-article-read-summary-keys
1709 "\M-#" gnus-article-read-summary-keys
1710 "\M-^" gnus-article-read-summary-keys
1711 "\M-g" gnus-article-read-summary-keys)
1713 (substitute-key-definition
1714 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1716 (defun gnus-article-make-menu-bar ()
1717 (gnus-turn-off-edit-menu 'article)
1718 (unless (boundp 'gnus-article-article-menu)
1720 gnus-article-article-menu gnus-article-mode-map ""
1722 ["Scroll forwards" gnus-article-goto-next-page t]
1723 ["Scroll backwards" gnus-article-goto-prev-page t]
1724 ["Show summary" gnus-article-show-summary t]
1725 ["Fetch Message-ID at point" gnus-article-refer-article t]
1726 ["Mail to address at point" gnus-article-mail t]))
1729 gnus-article-treatment-menu gnus-article-mode-map ""
1731 ["Hide headers" gnus-article-hide-headers t]
1732 ["Hide signature" gnus-article-hide-signature t]
1733 ["Hide citation" gnus-article-hide-citation t]
1734 ["Treat overstrike" gnus-article-treat-overstrike t]
1735 ["Remove carriage return" gnus-article-remove-cr t]
1736 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1739 (when (boundp 'gnus-summary-article-menu)
1740 (define-key gnus-article-mode-map [menu-bar commands]
1741 (cons "Commands" gnus-summary-article-menu))))
1743 (when (boundp 'gnus-summary-post-menu)
1744 (define-key gnus-article-mode-map [menu-bar post]
1745 (cons "Post" gnus-summary-post-menu)))
1747 (run-hooks 'gnus-article-menu-hook)))
1749 (defun gnus-article-mode ()
1750 "Major mode for displaying an article.
1752 All normal editing commands are switched off.
1754 The following commands are available in addition to all summary mode
1756 \\<gnus-article-mode-map>
1757 \\[gnus-article-next-page]\t Scroll the article one page forwards
1758 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1759 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1760 \\[gnus-article-show-summary]\t Display the summary buffer
1761 \\[gnus-article-mail]\t Send a reply to the address near point
1762 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1763 \\[gnus-info-find-node]\t Go to the Gnus info node"
1765 (when (gnus-visual-p 'article-menu 'menu)
1766 (gnus-article-make-menu-bar))
1767 (kill-all-local-variables)
1768 (gnus-simplify-mode-line)
1769 (setq mode-name "Article")
1770 (setq major-mode 'gnus-article-mode)
1771 (make-local-variable 'minor-mode-alist)
1772 (unless (assq 'gnus-show-mime minor-mode-alist)
1773 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1774 (use-local-map gnus-article-mode-map)
1775 (gnus-update-format-specifications nil 'article-mode)
1776 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1777 (set (make-local-variable 'gnus-button-marker-list) nil)
1778 (gnus-set-default-directory)
1779 (buffer-disable-undo (current-buffer))
1780 (setq buffer-read-only t)
1781 (set-syntax-table gnus-article-mode-syntax-table)
1782 (run-hooks 'gnus-article-mode-hook))
1784 (defun gnus-article-setup-buffer ()
1785 "Initialize the article buffer."
1786 (let* ((name (if gnus-single-article-buffer "*Article*"
1787 (concat "*Article " gnus-newsgroup-name "*")))
1789 (progn (string-match "\\*Article" name)
1790 (concat " *Original Article"
1791 (substring name (match-end 0))))))
1792 (setq gnus-article-buffer name)
1793 (setq gnus-original-article-buffer original)
1794 ;; This might be a variable local to the summary buffer.
1795 (unless gnus-single-article-buffer
1797 (set-buffer gnus-summary-buffer)
1798 (setq gnus-article-buffer name)
1799 (setq gnus-original-article-buffer original)
1800 (gnus-set-global-variables)))
1801 ;; Init original article buffer.
1803 (set-buffer (get-buffer-create gnus-original-article-buffer))
1804 (buffer-disable-undo (current-buffer))
1805 (setq major-mode 'gnus-original-article-mode)
1806 (gnus-add-current-to-buffer-list)
1807 (make-local-variable 'gnus-original-article))
1808 (if (get-buffer name)
1811 (buffer-disable-undo (current-buffer))
1812 (setq buffer-read-only t)
1813 (gnus-add-current-to-buffer-list)
1814 (unless (eq major-mode 'gnus-article-mode)
1815 (gnus-article-mode))
1818 (set-buffer (get-buffer-create name))
1819 (gnus-add-current-to-buffer-list)
1821 (make-local-variable 'gnus-summary-buffer)
1822 (current-buffer)))))
1824 ;; Set article window start at LINE, where LINE is the number of lines
1825 ;; from the head of the article.
1826 (defun gnus-article-set-window-start (&optional line)
1828 (get-buffer-window gnus-article-buffer t)
1830 (set-buffer gnus-article-buffer)
1831 (goto-char (point-min))
1834 (gnus-message 6 "Moved to bookmark")
1835 (search-forward "\n\n" nil t)
1839 (defun gnus-article-prepare (article &optional all-headers header)
1840 "Prepare ARTICLE in article mode buffer.
1841 ARTICLE should either be an article number or a Message-ID.
1842 If ARTICLE is an id, HEADER should be the article headers.
1843 If ALL-HEADERS is non-nil, no headers are hidden."
1845 ;; Make sure we start in a summary buffer.
1846 (unless (eq major-mode 'gnus-summary-mode)
1847 (set-buffer gnus-summary-buffer))
1848 (setq gnus-summary-buffer (current-buffer))
1849 ;; Make sure the connection to the server is alive.
1850 (unless (gnus-server-opened
1851 (gnus-find-method-for-group gnus-newsgroup-name))
1852 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1853 (gnus-request-group gnus-newsgroup-name t))
1854 (let* ((gnus-article (if header (mail-header-number header) article))
1855 (summary-buffer (current-buffer))
1856 (internal-hook gnus-article-internal-prepare-hook)
1857 (group gnus-newsgroup-name)
1860 (gnus-article-setup-buffer)
1861 (set-buffer gnus-article-buffer)
1862 ;; Deactivate active regions.
1863 (when (and (boundp 'transient-mark-mode)
1864 transient-mark-mode)
1865 (setq mark-active nil))
1866 (if (not (setq result (let ((buffer-read-only nil))
1867 (gnus-request-article-this-buffer
1869 ;; There is no such article.
1871 (when (and (numberp article)
1872 (not (memq article gnus-newsgroup-sparse)))
1873 (setq gnus-article-current
1874 (cons gnus-newsgroup-name article))
1875 (set-buffer gnus-summary-buffer)
1876 (setq gnus-current-article article)
1877 (gnus-summary-mark-article article gnus-canceled-mark))
1878 (unless (memq article gnus-newsgroup-sparse)
1880 1 "No such article (may have expired or been canceled)")))
1881 (if (or (eq result 'pseudo) (eq result 'nneething))
1884 (set-buffer summary-buffer)
1885 (setq gnus-last-article gnus-current-article
1886 gnus-newsgroup-history (cons gnus-current-article
1887 gnus-newsgroup-history)
1888 gnus-current-article 0
1889 gnus-current-headers nil
1890 gnus-article-current nil)
1891 (if (eq result 'nneething)
1892 (gnus-configure-windows 'summary)
1893 (gnus-configure-windows 'article))
1894 (gnus-set-global-variables))
1895 (gnus-set-mode-line 'article))
1896 ;; The result from the `request' was an actual article -
1897 ;; or at least some text that is now displayed in the
1899 (when (and (numberp article)
1900 (not (eq article gnus-current-article)))
1901 ;; Seems like a new article has been selected.
1902 ;; `gnus-current-article' must be an article number.
1904 (set-buffer summary-buffer)
1905 (setq gnus-last-article gnus-current-article
1906 gnus-newsgroup-history (cons gnus-current-article
1907 gnus-newsgroup-history)
1908 gnus-current-article article
1909 gnus-current-headers
1910 (gnus-summary-article-header gnus-current-article)
1911 gnus-article-current
1912 (cons gnus-newsgroup-name gnus-current-article))
1913 (unless (vectorp gnus-current-headers)
1914 (setq gnus-current-headers nil))
1915 (gnus-summary-show-thread)
1916 (run-hooks 'gnus-mark-article-hook)
1917 (gnus-set-mode-line 'summary)
1918 (when (gnus-visual-p 'article-highlight 'highlight)
1919 (run-hooks 'gnus-visual-mark-article-hook))
1920 ;; Set the global newsgroup variables here.
1921 ;; Suggested by Jim Sisolak
1922 ;; <sisolak@trans4.neep.wisc.edu>.
1923 (gnus-set-global-variables)
1924 (setq gnus-have-all-headers
1925 (or all-headers gnus-show-all-headers))
1927 (vectorp (gnus-summary-article-header article))
1928 (gnus-cache-possibly-enter-article
1930 (gnus-summary-article-header article)
1931 (memq article gnus-newsgroup-marked)
1932 (memq article gnus-newsgroup-dormant)
1933 (memq article gnus-newsgroup-unreads)))))
1934 (when (or (numberp article)
1936 ;; Hooks for getting information from the article.
1937 ;; This hook must be called before being narrowed.
1938 (let (buffer-read-only)
1939 (run-hooks 'internal-hook)
1940 (run-hooks 'gnus-article-prepare-hook)
1941 ;; Decode MIME message.
1942 (when gnus-show-mime
1943 (if (or (not gnus-strict-mime)
1944 (gnus-fetch-field "Mime-Version"))
1945 (funcall gnus-show-mime-method)
1946 (funcall gnus-decode-encoded-word-method)))
1947 ;; Perform the article display hooks.
1948 (run-hooks 'gnus-article-display-hook))
1950 (goto-char (point-min))
1951 (when gnus-break-pages
1952 (gnus-narrow-to-page)))
1953 (gnus-set-mode-line 'article)
1954 (gnus-configure-windows 'article)
1955 (goto-char (point-min))
1958 (defun gnus-article-wash-status ()
1959 "Return a string which display status of article washing."
1961 (set-buffer gnus-article-buffer)
1962 (let ((cite (gnus-article-hidden-text-p 'cite))
1963 (headers (gnus-article-hidden-text-p 'headers))
1964 (boring (gnus-article-hidden-text-p 'boring-headers))
1965 (pgp (gnus-article-hidden-text-p 'pgp))
1966 (pem (gnus-article-hidden-text-p 'pem))
1967 (signature (gnus-article-hidden-text-p 'signature))
1968 (overstrike (gnus-article-hidden-text-p 'overstrike))
1969 (emphasis (gnus-article-hidden-text-p 'emphasis))
1970 (mime gnus-show-mime))
1971 (format "%c%c%c%c%c%c%c"
1973 (if (or headers boring) ?h ? )
1974 (if (or pgp pem) ?p ? )
1975 (if signature ?s ? )
1976 (if overstrike ?o ? )
1978 (if emphasis ?e ? )))))
1980 (defun gnus-article-hide-headers-if-wanted ()
1981 "Hide unwanted headers if `gnus-have-all-headers' is nil.
1982 Provided for backwards compatibility."
1983 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
1985 (gnus-article-hide-headers)))
1989 (defun gnus-output-to-file (file-name)
1990 "Append the current article to a file named FILE-NAME."
1991 (let ((artbuf (current-buffer)))
1992 (nnheader-temp-write nil
1993 (insert-buffer-substring artbuf)
1994 ;; Append newline at end of the buffer as separator, and then
1996 (goto-char (point-max))
1998 (append-to-file (point-min) (point-max) file-name))))
2000 (defun gnus-narrow-to-page (&optional arg)
2001 "Narrow the article buffer to a page.
2002 If given a numerical ARG, move forward ARG pages."
2004 (setq arg (if arg (prefix-numeric-value arg) 0))
2006 (set-buffer gnus-article-buffer)
2007 (goto-char (point-min))
2009 ;; Remove any old next/prev buttons.
2010 (when (gnus-visual-p 'page-marker)
2011 (let ((buffer-read-only nil))
2012 (gnus-remove-text-with-property 'gnus-prev)
2013 (gnus-remove-text-with-property 'gnus-next)))
2016 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2018 (re-search-forward page-delimiter nil 'move arg)))
2019 (goto-char (match-end 0)))
2022 (if (re-search-forward page-delimiter nil 'move)
2025 (when (and (gnus-visual-p 'page-marker)
2026 (not (= (point-min) 1)))
2028 (goto-char (point-min))
2029 (gnus-insert-prev-page-button)))
2030 (when (and (gnus-visual-p 'page-marker)
2031 (< (+ (point-max) 2) (buffer-size)))
2033 (goto-char (point-max))
2034 (gnus-insert-next-page-button)))))
2036 ;; Article mode commands
2038 (defun gnus-article-goto-next-page ()
2039 "Show the next page of the article."
2041 (when (gnus-article-next-page)
2042 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2044 (defun gnus-article-goto-prev-page ()
2045 "Show the next page of the article."
2047 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2048 (gnus-article-prev-page nil)))
2050 (defun gnus-article-next-page (&optional lines)
2051 "Show the next page of the current article.
2052 If end of article, return non-nil. Otherwise return nil.
2053 Argument LINES specifies lines to be scrolled up."
2055 (move-to-window-line -1)
2058 (and (pos-visible-in-window-p) ;Not continuation line.
2060 ;; Nothing in this page.
2061 (if (or (not gnus-break-pages)
2064 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2066 (gnus-narrow-to-page 1) ;Go to next page.
2068 ;; More in this page.
2069 (let ((scroll-in-place nil))
2073 ;; Long lines may cause an end-of-buffer error.
2074 (goto-char (point-max)))))
2075 (move-to-window-line 0)
2078 (defun gnus-article-prev-page (&optional lines)
2079 "Show previous page of current article.
2080 Argument LINES specifies lines to be scrolled down."
2082 (move-to-window-line 0)
2083 (if (and gnus-break-pages
2085 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2087 (gnus-narrow-to-page -1) ;Go to previous page.
2088 (goto-char (point-max))
2090 (let ((scroll-in-place nil))
2093 (scroll-down lines))
2094 (move-to-window-line 0)))))
2096 (defun gnus-article-refer-article ()
2097 "Read article specified by message-id around point."
2099 (let ((point (point)))
2100 (search-forward ">" nil t) ;Move point to end of "<....>".
2101 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2102 (let ((message-id (match-string 1)))
2104 (set-buffer gnus-summary-buffer)
2105 (gnus-summary-refer-article message-id))
2107 (error "No references around point"))))
2109 (defun gnus-article-show-summary ()
2110 "Reconfigure windows to show summary buffer."
2112 (gnus-configure-windows 'article)
2113 (gnus-summary-goto-subject gnus-current-article))
2115 (defun gnus-article-describe-briefly ()
2116 "Describe article mode commands briefly."
2119 (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")))
2121 (defun gnus-article-summary-command ()
2122 "Execute the last keystroke in the summary buffer."
2124 (let ((obuf (current-buffer))
2125 (owin (current-window-configuration))
2127 (switch-to-buffer gnus-summary-buffer 'norecord)
2128 (setq func (lookup-key (current-local-map) (this-command-keys)))
2129 (call-interactively func)
2131 (set-window-configuration owin)
2132 (set-window-point (get-buffer-window (current-buffer)) (point))))
2134 (defun gnus-article-summary-command-nosave ()
2135 "Execute the last keystroke in the summary buffer."
2138 (pop-to-buffer gnus-summary-buffer 'norecord)
2139 (setq func (lookup-key (current-local-map) (this-command-keys)))
2140 (call-interactively func)))
2142 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2143 "Read a summary buffer key sequence and execute it from the article buffer."
2146 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2147 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2148 "=" "^" "\M-^" "|"))
2155 (set-buffer gnus-summary-buffer)
2156 (let (gnus-pick-mode)
2157 (push (or key last-command-event) unread-command-events)
2158 (setq keys (read-key-sequence nil))))
2161 (if (or (member keys nosaves)
2162 (member keys nosave-but-article)
2163 (member keys nosave-in-article))
2165 (save-window-excursion
2166 (pop-to-buffer gnus-summary-buffer 'norecord)
2167 ;; We disable the pick minor mode commands.
2168 (let (gnus-pick-mode)
2169 (setq func (lookup-key (current-local-map) keys))))
2172 (unless (member keys nosave-in-article)
2173 (set-buffer gnus-summary-buffer))
2174 (call-interactively func))
2175 (when (member keys nosave-but-article)
2176 (pop-to-buffer gnus-article-buffer 'norecord)))
2177 ;; These commands should restore window configuration.
2178 (let ((obuf (current-buffer))
2179 (owin (current-window-configuration))
2182 (if not-restore-window
2183 (pop-to-buffer gnus-summary-buffer 'norecord)
2184 (switch-to-buffer gnus-summary-buffer 'norecord))
2185 (setq in-buffer (current-buffer))
2186 ;; We disable the pick minor mode commands.
2187 (if (setq func (let (gnus-pick-mode)
2188 (lookup-key (current-local-map) keys)))
2189 (call-interactively func)
2191 (when (eq in-buffer (current-buffer))
2193 (unless not-restore-window
2194 (set-window-configuration owin))
2195 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2197 (defun gnus-article-hide (&optional arg force)
2198 "Hide all the gruft in the current article.
2199 This means that PGP stuff, signatures, cited text and (some)
2200 headers will be hidden.
2201 If given a prefix, show the hidden text instead."
2202 (interactive (list current-prefix-arg 'force))
2203 (gnus-article-hide-headers arg)
2204 (gnus-article-hide-pgp arg)
2205 (gnus-article-hide-citation-maybe arg force)
2206 (gnus-article-hide-signature arg))
2208 (defun gnus-article-maybe-highlight ()
2209 "Do some article highlighting if `article-visual' is non-nil."
2210 (when (gnus-visual-p 'article-highlight 'highlight)
2211 (gnus-article-highlight-some)))
2213 (defun gnus-request-article-this-buffer (article group)
2214 "Get an article and insert it into this buffer."
2215 (let (do-update-line)
2219 (gnus-kill-all-overlays)
2220 (setq group (or group gnus-newsgroup-name))
2222 ;; Open server if it has closed.
2223 (gnus-check-server (gnus-find-method-for-group group))
2225 ;; Using `gnus-request-article' directly will insert the article into
2226 ;; `nntp-server-buffer' - so we'll save some time by not having to
2227 ;; copy it from the server buffer into the article buffer.
2229 ;; We only request an article by message-id when we do not have the
2230 ;; headers for it, so we'll have to get those.
2231 (when (stringp article)
2232 (let ((gnus-override-method gnus-refer-article-method))
2233 (gnus-read-header article)))
2235 ;; If the article number is negative, that means that this article
2236 ;; doesn't belong in this newsgroup (possibly), so we find its
2237 ;; message-id and request it by id instead of number.
2238 (when (and (numberp article)
2240 (get-buffer gnus-summary-buffer)
2241 (buffer-name (get-buffer gnus-summary-buffer)))
2243 (set-buffer gnus-summary-buffer)
2244 (let ((header (gnus-summary-article-header article)))
2247 ((memq article gnus-newsgroup-sparse)
2248 ;; This is a sparse gap article.
2249 (setq do-update-line article)
2250 (setq article (mail-header-id header))
2251 (let ((gnus-override-method gnus-refer-article-method))
2252 (gnus-read-header article))
2253 (setq gnus-newsgroup-sparse
2254 (delq article gnus-newsgroup-sparse)))
2256 ;; It's a real article.
2257 (setq article (mail-header-id header)))
2259 ;; It is an extracted pseudo-article.
2260 (setq article 'pseudo)
2261 (gnus-request-pseudo-article header))))
2263 (let ((method (gnus-find-method-for-group
2264 gnus-newsgroup-name)))
2265 (if (not (eq (car method) 'nneething))
2267 (let ((dir (concat (file-name-as-directory (nth 1 method))
2268 (mail-header-subject header))))
2269 (when (file-directory-p dir)
2270 (setq article 'nneething)
2271 (gnus-group-enter-directory dir))))))))
2274 ;; Refuse to select canceled articles.
2275 ((and (numberp article)
2277 (get-buffer gnus-summary-buffer)
2278 (buffer-name (get-buffer gnus-summary-buffer))
2279 (eq (cdr (save-excursion
2280 (set-buffer gnus-summary-buffer)
2281 (assq article gnus-newsgroup-reads)))
2282 gnus-canceled-mark))
2284 ;; We first check `gnus-original-article-buffer'.
2285 ((and (get-buffer gnus-original-article-buffer)
2288 (set-buffer gnus-original-article-buffer)
2289 (and (equal (car gnus-original-article) group)
2290 (eq (cdr gnus-original-article) article))))
2291 (insert-buffer-substring gnus-original-article-buffer)
2293 ;; Check the backlog.
2294 ((and gnus-keep-backlog
2295 (gnus-backlog-request-article group article (current-buffer)))
2297 ;; Check asynchronous pre-fetch.
2298 ((gnus-async-request-fetched-article group article (current-buffer))
2299 (gnus-async-prefetch-next group article gnus-summary-buffer)
2302 ((and gnus-use-cache
2304 (gnus-cache-request-article article group))
2306 ;; Get the article and put into the article buffer.
2307 ((or (stringp article) (numberp article))
2308 (let ((gnus-override-method
2309 (and (stringp article) gnus-refer-article-method))
2310 (buffer-read-only nil))
2312 (gnus-kill-all-overlays)
2313 (when (gnus-request-article article group (current-buffer))
2314 (when (numberp article)
2315 (gnus-async-prefetch-next group article gnus-summary-buffer)
2316 (when gnus-keep-backlog
2317 (gnus-backlog-enter-article
2318 group article (current-buffer))))
2323 ;; Take the article from the original article buffer
2324 ;; and place it in the buffer it's supposed to be in.
2325 (when (and (get-buffer gnus-article-buffer)
2327 (equal (buffer-name (current-buffer))
2328 (buffer-name (get-buffer gnus-article-buffer))))
2330 (if (get-buffer gnus-original-article-buffer)
2331 (set-buffer (get-buffer gnus-original-article-buffer))
2332 (set-buffer (get-buffer-create gnus-original-article-buffer))
2333 (buffer-disable-undo (current-buffer))
2334 (setq major-mode 'gnus-original-article-mode)
2335 (setq buffer-read-only t)
2336 (gnus-add-current-to-buffer-list))
2337 (let (buffer-read-only)
2339 (insert-buffer-substring gnus-article-buffer))
2340 (setq gnus-original-article (cons group article))))
2342 ;; Update sparse articles.
2343 (when (and do-update-line
2344 (or (numberp article)
2346 (let ((buf (current-buffer)))
2347 (set-buffer gnus-summary-buffer)
2348 (gnus-summary-update-article do-update-line)
2349 (gnus-summary-goto-subject do-update-line nil t)
2350 (set-window-point (get-buffer-window (current-buffer) t)
2352 (set-buffer buf))))))
2358 (defcustom gnus-article-edit-mode-hook nil
2359 "Hook run in article edit mode buffers."
2360 :group 'gnus-article-various
2363 (defvar gnus-article-edit-done-function nil)
2365 (defvar gnus-article-edit-mode-map nil)
2367 (unless gnus-article-edit-mode-map
2368 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2370 (gnus-define-keys gnus-article-edit-mode-map
2371 "\C-c\C-c" gnus-article-edit-done
2372 "\C-c\C-k" gnus-article-edit-exit)
2374 (gnus-define-keys (gnus-article-edit-wash-map
2375 "\C-c\C-w" gnus-article-edit-mode-map)
2376 "f" gnus-article-edit-full-stops))
2378 (defun gnus-article-edit-mode ()
2379 "Major mode for editing articles.
2380 This is an extended text-mode.
2382 \\{gnus-article-edit-mode-map}"
2384 (kill-all-local-variables)
2385 (setq major-mode 'gnus-article-edit-mode)
2386 (setq mode-name "Article Edit")
2387 (use-local-map gnus-article-edit-mode-map)
2388 (make-local-variable 'gnus-article-edit-done-function)
2389 (make-local-variable 'gnus-prev-winconf)
2390 (setq buffer-read-only nil)
2391 (buffer-enable-undo)
2393 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2395 (defun gnus-article-edit (&optional force)
2396 "Edit the current article.
2397 This will have permanent effect only in mail groups.
2398 If FORCE is non-nil, allow editing of articles even in read-only
2401 (when (and (not force)
2402 (gnus-group-read-only-p))
2403 (error "The current newsgroup does not support article editing."))
2404 (gnus-article-edit-article
2406 (gnus-summary-edit-article-done
2407 ,(or (mail-header-references gnus-current-headers) "")
2408 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2410 (defun gnus-article-edit-article (exit-func)
2411 "Start editing the contents of the current article buffer."
2412 (let ((winconf (current-window-configuration)))
2413 (set-buffer gnus-article-buffer)
2414 (gnus-article-edit-mode)
2415 (set-text-properties (point-min) (point-max) nil)
2416 (gnus-configure-windows 'edit-article)
2417 (setq gnus-article-edit-done-function exit-func)
2418 (setq gnus-prev-winconf winconf)
2419 (gnus-message 6 "C-c C-c to end edits")))
2421 (defun gnus-article-edit-done ()
2422 "Update the article edits and exit."
2424 (let ((func gnus-article-edit-done-function)
2425 (buf (current-buffer))
2426 (start (window-start)))
2427 (gnus-article-edit-exit)
2430 (let ((buffer-read-only nil))
2433 (set-window-start (get-buffer-window buf) start)
2434 (set-window-point (get-buffer-window buf) (point))))
2436 (defun gnus-article-edit-exit ()
2437 "Exit the article editing without updating."
2439 ;; We remove all text props from the article buffer.
2440 (let ((buf (format "%s" (buffer-string)))
2441 (curbuf (current-buffer))
2443 (window-start (window-start)))
2446 (let ((winconf gnus-prev-winconf))
2448 ;; The cache and backlog have to be flushed somewhat.
2449 (when gnus-use-cache
2450 (gnus-cache-update-article
2451 (car gnus-article-current) (cdr gnus-article-current)))
2452 (when gnus-keep-backlog
2453 (gnus-backlog-remove-article
2454 (car gnus-article-current) (cdr gnus-article-current)))
2455 ;; Flush original article as well.
2457 (when (get-buffer gnus-original-article-buffer)
2458 (set-buffer gnus-original-article-buffer)
2459 (setq gnus-original-article nil)))
2460 (set-window-configuration winconf)
2461 ;; Tippy-toe some to make sure that point remains where it was.
2462 (let ((buf (current-buffer)))
2464 (set-window-start (get-buffer-window (current-buffer)) window-start)
2466 (set-buffer buf)))))
2468 (defun gnus-article-edit-full-stops ()
2469 "Interactively repair spacing at end of sentences."
2472 (goto-char (point-min))
2473 (search-forward-regexp "^$" nil t)
2474 (let ((case-fold-search nil))
2475 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2478 ;;; Article highlights
2481 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2483 ;;; Internal Variables:
2485 (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\\)"
2486 "Regular expression that matches URLs."
2487 :group 'gnus-article-buttons
2490 (defcustom gnus-button-alist
2491 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2492 gnus-button-message-id 2)
2493 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*+\\)" 0 t gnus-button-message-id 1)
2494 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2495 gnus-button-fetch-group 4)
2496 ("\\bnews:\\(//\\)?\\([^>\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2497 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2498 t gnus-button-message-id 3)
2499 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 1)
2500 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 2)
2501 ;; This is how URLs _should_ be embedded in text...
2502 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2504 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2505 "Alist of regexps matching buttons in article bodies.
2507 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2508 REGEXP: is the string matching text around the button,
2509 BUTTON: is the number of the regexp grouping actually matching the button,
2510 FORM: is a lisp expression which must eval to true for the button to
2512 CALLBACK: is the function to call when the user push this button, and each
2513 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2515 CALLBACK can also be a variable, in that case the value of that
2516 variable it the real callback function."
2517 :group 'gnus-article-buttons
2518 :type '(repeat (list regexp
2519 (integer :tag "Button")
2521 (function :tag "Callback")
2524 (integer :tag "Regexp group")))))
2526 (defcustom gnus-header-button-alist
2527 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2528 0 t gnus-button-message-id 0)
2529 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2530 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2531 0 t gnus-button-mailto 0)
2532 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2533 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2534 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2535 gnus-button-message-id 3))
2536 "Alist of headers and regexps to match buttons in article heads.
2538 This alist is very similar to `gnus-button-alist', except that each
2539 alist has an additional HEADER element first in each entry:
2541 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2543 HEADER is a regexp to match a header. For a fuller explanation, see
2544 `gnus-button-alist'."
2545 :group 'gnus-article-buttons
2546 :group 'gnus-article-headers
2547 :type '(repeat (list (regexp :tag "Header")
2549 (integer :tag "Button")
2551 (function :tag "Callback")
2554 (integer :tag "Regexp group")))))
2556 (defvar gnus-button-regexp nil)
2557 (defvar gnus-button-marker-list nil)
2558 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2560 (defvar gnus-button-last nil)
2561 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2565 (defun gnus-article-push-button (event)
2566 "Check text under the mouse pointer for a callback function.
2567 If the text under the mouse pointer has a `gnus-callback' property,
2568 call it with the value of the `gnus-data' text property."
2570 (set-buffer (window-buffer (posn-window (event-start event))))
2571 (let* ((pos (posn-point (event-start event)))
2572 (data (get-text-property pos 'gnus-data))
2573 (fun (get-text-property pos 'gnus-callback)))
2575 (funcall fun data))))
2577 (defun gnus-article-press-button ()
2578 "Check text at point for a callback function.
2579 If the text at point has a `gnus-callback' property,
2580 call it with the value of the `gnus-data' text property."
2582 (let* ((data (get-text-property (point) 'gnus-data))
2583 (fun (get-text-property (point) 'gnus-callback)))
2585 (funcall fun data))))
2587 (defun gnus-article-prev-button (n)
2588 "Move point to N buttons backward.
2589 If N is negative, move forward instead."
2591 (gnus-article-next-button (- n)))
2593 (defun gnus-article-next-button (n)
2594 "Move point to N buttons forward.
2595 If N is negative, move backward instead."
2597 (let ((function (if (< n 0) 'previous-single-property-change
2598 'next-single-property-change))
2599 (inhibit-point-motion-hooks t)
2601 (limit (if (< n 0) (point-min) (point-max))))
2603 (while (and (not (= limit (point)))
2605 ;; Skip past the current button.
2606 (when (get-text-property (point) 'gnus-callback)
2607 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2608 ;; Go to the next (or previous) button.
2609 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2610 ;; Put point at the start of the button.
2611 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2612 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2613 ;; Skip past intangible buttons.
2614 (when (get-text-property (point) 'intangible)
2618 (gnus-message 5 "No more buttons"))
2621 (defun gnus-article-highlight (&optional force)
2622 "Highlight current article.
2623 This function calls `gnus-article-highlight-headers',
2624 `gnus-article-highlight-citation',
2625 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2626 do the highlighting. See the documentation for those functions."
2627 (interactive (list 'force))
2628 (gnus-article-highlight-headers)
2629 (gnus-article-highlight-citation force)
2630 (gnus-article-highlight-signature)
2631 (gnus-article-add-buttons force)
2632 (gnus-article-add-buttons-to-head))
2634 (defun gnus-article-highlight-some (&optional force)
2635 "Highlight current article.
2636 This function calls `gnus-article-highlight-headers',
2637 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2638 do the highlighting. See the documentation for those functions."
2639 (interactive (list 'force))
2640 (gnus-article-highlight-headers)
2641 (gnus-article-highlight-signature)
2642 (gnus-article-add-buttons))
2644 (defun gnus-article-highlight-headers ()
2645 "Highlight article headers as specified by `gnus-header-face-alist'."
2648 (set-buffer gnus-article-buffer)
2650 (let ((alist gnus-header-face-alist)
2651 (buffer-read-only nil)
2652 (case-fold-search t)
2653 (inhibit-point-motion-hooks t)
2654 entry regexp header-face field-face from hpoints fpoints)
2655 (message-narrow-to-head)
2656 (while (setq entry (pop alist))
2657 (goto-char (point-min))
2658 (setq regexp (concat "^\\("
2659 (if (string-equal "" (nth 0 entry))
2663 header-face (nth 1 entry)
2664 field-face (nth 2 entry))
2665 (while (and (re-search-forward regexp nil t)
2669 (unless (search-forward ":" nil t)
2671 (when (and header-face
2672 (not (memq (point) hpoints)))
2673 (push (point) hpoints)
2674 (gnus-put-text-property from (point) 'face header-face))
2675 (when (and field-face
2676 (not (memq (setq from (point)) fpoints)))
2678 (if (re-search-forward "^[^ \t]" nil t)
2680 (goto-char (point-max)))
2681 (gnus-put-text-property from (point) 'face field-face))))))))
2683 (defun gnus-article-highlight-signature ()
2684 "Highlight the signature in an article.
2685 It does this by highlighting everything after
2686 `gnus-signature-separator' using `gnus-signature-face'."
2689 (set-buffer gnus-article-buffer)
2690 (let ((buffer-read-only nil)
2691 (inhibit-point-motion-hooks t))
2693 (when (and gnus-signature-face
2694 (gnus-article-narrow-to-signature))
2695 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2696 'face gnus-signature-face)
2698 (gnus-article-search-signature)
2699 (let ((start (match-beginning 0))
2700 (end (set-marker (make-marker) (1+ (match-end 0)))))
2701 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2704 (defun gnus-button-in-region-p (b e prop)
2705 "Say whether PROP exists in the region."
2706 (text-property-not-all b e prop nil))
2708 (defun gnus-article-add-buttons (&optional force)
2709 "Find external references in the article and make buttons of them.
2710 \"External references\" are things like Message-IDs and URLs, as
2711 specified by `gnus-button-alist'."
2712 (interactive (list 'force))
2714 (set-buffer gnus-article-buffer)
2715 (let ((buffer-read-only nil)
2716 (inhibit-point-motion-hooks t)
2717 (case-fold-search t)
2718 (alist gnus-button-alist)
2720 ;; Remove all old markers.
2722 (while (setq marker (pop gnus-button-marker-list))
2724 (when (setq entry (gnus-button-entry))
2725 (put-text-property (match-beginning (nth 1 entry))
2726 (match-end (nth 1 entry))
2727 'gnus-callback nil))
2728 (set-marker marker nil)))
2729 ;; We skip the headers.
2730 (goto-char (point-min))
2731 (unless (search-forward "\n\n" nil t)
2732 (goto-char (point-max)))
2734 (while (setq entry (pop alist))
2735 (setq regexp (car entry))
2737 (while (re-search-forward regexp nil t)
2738 (let* ((start (and entry (match-beginning (nth 1 entry))))
2739 (end (and entry (match-end (nth 1 entry))))
2740 (from (match-beginning 0)))
2741 (when (and (or (eq t (nth 1 entry))
2742 (eval (nth 1 entry)))
2743 (not (gnus-button-in-region-p
2744 start end 'gnus-callback)))
2745 ;; That optional form returned non-nil, so we add the
2747 (gnus-article-add-button
2748 start end 'gnus-button-push
2749 (car (push (set-marker (make-marker) from)
2750 gnus-button-marker-list))))))))))
2752 ;; Add buttons to the head of an article.
2753 (defun gnus-article-add-buttons-to-head ()
2754 "Add buttons to the head of the article."
2757 (set-buffer gnus-article-buffer)
2758 (let ((buffer-read-only nil)
2759 (inhibit-point-motion-hooks t)
2760 (case-fold-search t)
2761 (alist gnus-header-button-alist)
2763 (nnheader-narrow-to-headers)
2765 ;; Each alist entry.
2766 (setq entry (car alist)
2768 (goto-char (point-min))
2769 (while (re-search-forward (car entry) nil t)
2770 ;; Each header matching the entry.
2771 (setq beg (match-beginning 0))
2772 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2773 (match-beginning 0))
2776 (while (re-search-forward (nth 1 entry) end t)
2777 ;; Each match within a header.
2778 (let* ((entry (cdr entry))
2779 (start (match-beginning (nth 1 entry)))
2780 (end (match-end (nth 1 entry)))
2781 (form (nth 2 entry)))
2782 (goto-char (match-end 0))
2784 (gnus-article-add-button
2785 start end (nth 3 entry)
2786 (buffer-substring (match-beginning (nth 4 entry))
2787 (match-end (nth 4 entry)))))))
2791 ;;; External functions:
2793 (defun gnus-article-add-button (from to fun &optional data)
2794 "Create a button between FROM and TO with callback FUN and data DATA."
2795 (when gnus-article-button-face
2796 (gnus-overlay-put (gnus-make-overlay from to)
2797 'face gnus-article-button-face))
2798 (gnus-add-text-properties
2800 (nconc (and gnus-article-mouse-face
2801 (list gnus-mouse-face-prop gnus-article-mouse-face))
2802 (list 'gnus-callback fun)
2803 (and data (list 'gnus-data data)))))
2805 ;;; Internal functions:
2807 (defun gnus-signature-toggle (end)
2809 (set-buffer gnus-article-buffer)
2810 (let ((buffer-read-only nil)
2811 (inhibit-point-motion-hooks t))
2812 (if (get-text-property end 'invisible)
2813 (gnus-article-unhide-text end (point-max))
2814 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2816 (defun gnus-button-entry ()
2817 ;; Return the first entry in `gnus-button-alist' matching this place.
2818 (let ((alist gnus-button-alist)
2821 (setq entry (pop alist))
2822 (if (looking-at (car entry))
2827 (defun gnus-button-push (marker)
2828 ;; Push button starting at MARKER.
2830 (set-buffer gnus-article-buffer)
2832 (let* ((entry (gnus-button-entry))
2833 (inhibit-point-motion-hooks t)
2835 (args (mapcar (lambda (group)
2836 (let ((string (match-string group)))
2837 (gnus-set-text-properties
2838 0 (length string) nil string)
2845 (fboundp (symbol-value fun)))
2846 (apply (symbol-value fun) args))
2848 (gnus-message 1 "You must define `%S' to use this button"
2849 (cons fun args)))))))
2851 (defun gnus-button-message-id (message-id)
2854 (set-buffer gnus-summary-buffer)
2855 (gnus-summary-refer-article message-id)))
2857 (defun gnus-button-fetch-group (address)
2858 "Fetch GROUP specified by ADDRESS."
2859 (if (not (string-match "[:/]" address))
2860 ;; This is just a simple group url.
2861 (gnus-group-read-ephemeral-group address gnus-select-method)
2862 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
2864 (error "Can't parse %s" address)
2865 (gnus-group-read-ephemeral-group
2866 (match-string 4 address)
2867 `(nntp ,(match-string 1 address)
2868 (nntp-address ,(match-string 1 address))
2869 (nntp-port-number ,(if (match-end 3)
2870 (match-string 3 address)
2873 (defun gnus-split-string (string pattern)
2874 "Return a list of substrings of STRING which are separated by PATTERN."
2875 (let (parts (start 0))
2876 (while (string-match pattern string start)
2877 (setq parts (cons (substring string start (match-beginning 0)) parts)
2878 start (match-end 0)))
2879 (nreverse (cons (substring string start) parts))))
2881 (defun gnus-url-parse-query-string (query &optional downcase)
2882 (let (retval pairs cur key val)
2883 (setq pairs (gnus-split-string query "&"))
2885 (setq cur (car pairs)
2887 (if (not (string-match "=" cur))
2889 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2890 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2892 (setq key (downcase key)))
2893 (setq cur (assoc key retval))
2895 (setcdr cur (cons val (cdr cur)))
2896 (setq retval (cons (list key val) retval)))))
2899 (defun gnus-url-unhex (x)
2906 (defun gnus-url-unhex-string (str &optional allow-newlines)
2907 "Remove %XXX embedded spaces, etc in a url.
2908 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2909 decoding of carriage returns and line feeds in the string, which is normally
2910 forbidden in URL encoding."
2911 (setq str (or str ""))
2913 (case-fold-search t))
2914 (while (string-match "%[0-9a-f][0-9a-f]" str)
2915 (let* ((start (match-beginning 0))
2916 (ch1 (gnus-url-unhex (elt str (+ start 1))))
2918 (gnus-url-unhex (elt str (+ start 2))))))
2920 tmp (substring str 0 start)
2923 (char-to-string code))
2924 ((or (= code ?\n) (= code ?\r))
2926 (t (char-to-string code))))
2927 str (substring str (match-end 0)))))
2928 (setq tmp (concat tmp str))
2931 (defun gnus-url-mailto (url)
2932 ;; Send mail to someone
2933 (when (string-match "mailto:/*\\(.*\\)" url)
2934 (setq url (substring url (match-beginning 1) nil)))
2935 (let (to args source-url subject func)
2936 (if (string-match (regexp-quote "?") url)
2937 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2938 args (gnus-url-parse-query-string
2939 (substring url (match-end 0) nil) t))
2940 (setq to (gnus-url-unhex-string url)))
2941 (setq args (cons (list "to" to) args)
2942 subject (cdr-safe (assoc "subject" args)))
2945 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
2948 (message-position-on-field (caar args)))
2949 (insert (mapconcat 'identity (cdar args) ", "))
2950 (setq args (cdr args)))
2953 (message-goto-subject))))
2955 (defun gnus-button-mailto (address)
2957 (set-buffer (gnus-copy-article-buffer))
2958 (message-reply address))
2960 (defun gnus-button-reply (address)
2961 ;; Reply to ADDRESS.
2962 (message-reply address))
2964 (defun gnus-button-url (address)
2966 (funcall browse-url-browser-function address))
2968 (defun gnus-button-embedded-url (address)
2970 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
2972 ;;; Next/prev buttons in the article buffer.
2974 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
2975 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
2977 (defvar gnus-prev-page-map nil)
2978 (unless gnus-prev-page-map
2979 (setq gnus-prev-page-map (make-sparse-keymap))
2980 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
2981 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
2983 (defun gnus-insert-prev-page-button ()
2984 (let ((buffer-read-only nil))
2986 gnus-prev-page-line-format nil
2987 `(gnus-prev t local-map ,gnus-prev-page-map
2988 gnus-callback gnus-article-button-prev-page))))
2990 (defvar gnus-next-page-map nil)
2991 (unless gnus-next-page-map
2992 (setq gnus-next-page-map (make-keymap))
2993 (suppress-keymap gnus-prev-page-map)
2994 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
2995 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
2997 (defun gnus-button-next-page ()
2998 "Go to the next page."
3000 (let ((win (selected-window)))
3001 (select-window (get-buffer-window gnus-article-buffer t))
3002 (gnus-article-next-page)
3003 (select-window win)))
3005 (defun gnus-button-prev-page ()
3006 "Go to the prev page."
3008 (let ((win (selected-window)))
3009 (select-window (get-buffer-window gnus-article-buffer t))
3010 (gnus-article-prev-page)
3011 (select-window win)))
3013 (defun gnus-insert-next-page-button ()
3014 (let ((buffer-read-only nil))
3015 (gnus-eval-format gnus-next-page-line-format nil
3016 `(gnus-next t local-map ,gnus-next-page-map
3018 gnus-article-button-next-page))))
3020 (defun gnus-article-button-next-page (arg)
3021 "Go to the next page."
3023 (let ((win (selected-window)))
3024 (select-window (get-buffer-window gnus-article-buffer t))
3025 (gnus-article-next-page)
3026 (select-window win)))
3028 (defun gnus-article-button-prev-page (arg)
3029 "Go to the prev page."
3031 (let ((win (selected-window)))
3032 (select-window (get-buffer-window gnus-article-buffer t))
3033 (gnus-article-prev-page)
3034 (select-window win)))
3040 (run-hooks 'gnus-art-load-hook)
3042 ;;; gnus-art.el ends here