1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996 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 (defcustom gnus-article-save-directory gnus-directory
36 "*Name of the directory articles will be saved in (default \"~/News\")."
40 (defcustom gnus-save-all-headers t
41 "*If non-nil, don't remove any headers before saving."
45 (defcustom gnus-prompt-before-saving 'always
46 "*This variable says how much prompting is to be done when saving articles.
47 If it is nil, no prompting will be done, and the articles will be
48 saved to the default files. If this variable is `always', each and
49 every article that is saved will be preceded by a prompt, even when
50 saving large batches of articles. If this variable is neither nil not
51 `always', there the user will be prompted once for a file name for
52 each invocation of the saving commands."
54 :type '(choice (item always)
55 (item :tag "never" nil)
56 (sexp :tag "once" :format "%t")))
58 (defcustom gnus-saved-headers gnus-visible-headers
59 "Headers to keep if `gnus-save-all-headers' is nil.
60 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
61 If that variable is nil, however, all headers that match this regexp
62 will be kept while the rest will be deleted before saving."
64 :type '(repeat string))
66 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
67 "A function to save articles in your favourite format.
68 The function must be interactively callable (in other words, it must
71 Gnus provides the following functions:
73 * gnus-summary-save-in-rmail (Rmail format)
74 * gnus-summary-save-in-mail (Unix mail format)
75 * gnus-summary-save-in-folder (MH folder)
76 * gnus-summary-save-in-file (article format).
77 * gnus-summary-save-in-vm (use VM's folder format)."
79 :type '(radio (function-item gnus-summary-save-in-rmail)
80 (function-item gnus-summary-save-in-mail)
81 (function-item gnus-summary-save-in-folder)
82 (function-item gnus-summary-save-in-file)
83 (function-item gnus-summary-save-in-vm)))
85 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
86 "A function generating a file name to save articles in Rmail format.
87 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
91 (defcustom gnus-mail-save-name 'gnus-plain-save-name
92 "A function generating a file name to save articles in Unix mail format.
93 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
97 (defcustom gnus-folder-save-name 'gnus-folder-save-name
98 "A function generating a file name to save articles in MH folder.
99 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
103 (defcustom gnus-file-save-name 'gnus-numeric-save-name
104 "A function generating a file name to save articles in article format.
105 The function is called with NEWSGROUP, HEADERS, and optional
110 (defcustom gnus-split-methods
111 '((gnus-article-archive-name))
112 "Variable used to suggest where articles are to be saved.
113 For instance, if you would like to save articles related to Gnus in
114 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
115 you could set this variable to something like:
117 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
118 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
120 This variable is an alist where the where the key is the match and the
121 value is a list of possible files to save in if the match is non-nil.
123 If the match is a string, it is used as a regexp match on the
124 article. If the match is a symbol, that symbol will be funcalled
125 from the buffer of the article to be saved with the newsgroup as the
126 parameter. If it is a list, it will be evaled in the same buffer.
128 If this form or function returns a string, this string will be used as
129 a possible file name; and if it returns a non-nil list, that list will
130 be used as possible file names."
132 :type '(repeat (choice (list function)
133 (cons regexp (repeat string))
136 (defcustom gnus-strict-mime t
137 "*If nil, MIME-decode even if there is no Mime-Version header."
141 (defcustom gnus-show-mime-method 'metamail-buffer
142 "Function to process a MIME message.
143 The function is called from the article buffer."
147 (defcustom gnus-decode-encoded-word-method (lambda ())
148 "*Function to decode a MIME encoded-words.
149 The function is called from the article buffer."
153 (defcustom gnus-page-delimiter "^\^L"
154 "*Regexp describing what to use as article page delimiters.
155 The default value is \"^\^L\", which is a form linefeed at the
156 beginning of a line."
160 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
161 "*The format specification for the article mode line.
162 See `gnus-summary-mode-line-format' for a closer description."
166 (defcustom gnus-article-mode-hook nil
167 "*A hook for Gnus article mode."
171 (defcustom gnus-article-menu-hook nil
172 "*Hook run after the creation of the article mode menu."
176 (defcustom gnus-article-prepare-hook nil
177 "*A hook called after an article has been prepared in the article buffer.
178 If you want to run a special decoding program like nkf, use this hook."
182 (defcustom gnus-article-button-face 'bold
183 "Face used for highlighting buttons in the article buffer.
185 An article button is a piece of text that you can activate by pressing
186 `RET' or `mouse-2' above it."
190 (defcustom gnus-article-mouse-face 'highlight
191 "Face used for mouse highlighting in the article buffer.
193 Article buttons will be displayed in this face when the cursor is
198 (defcustom gnus-signature-face 'italic
199 "Face used for highlighting a signature in the article buffer."
203 (defface gnus-header-from-face
206 (:foreground "light blue" :bold t :italic t))
209 (:foreground "MidnightBlue" :bold t :italic t))
211 (:bold t :italic t)))
212 "Face used for displaying from headers."
215 (defface gnus-header-subject-face
218 (:foreground "pink" :bold t :italic t))
221 (:foreground "firebrick" :bold t :italic t))
223 (:bold t :italic t)))
224 "Face used for displaying subject headers."
227 (defface gnus-header-newsgroups-face
230 (:foreground "yellow" :bold t :italic t))
233 (:foreground "indianred" :bold t :italic t))
235 (:bold t :italic t)))
236 "Face used for displaying newsgroups headers."
239 (defface gnus-header-name-face
242 (:foreground "cyan" :bold t))
245 (:foreground "DarkGreen" :bold t))
248 "Face used for displaying header names."
251 (defface gnus-header-content-face
254 (:foreground "forest green" :italic t))
257 (:foreground "DarkGreen" :italic t))
259 (:italic t))) "Face used for displaying header content."
262 (defcustom gnus-header-face-alist
263 '(("From" nil gnus-header-from-face)
264 ("Subject" nil gnus-header-subject-face)
265 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
266 ("" gnus-header-name-face gnus-header-content-face))
267 "Controls highlighting of article header.
269 An alist of the form (HEADER NAME CONTENT).
271 HEADER is a regular expression which should match the name of an
272 header header and NAME and CONTENT are either face names or nil.
274 The name of each header field will be displayed using the face
275 specified by the first element in the list where HEADER match the
276 header name and NAME is non-nil. Similarly, the content will be
277 displayed by the first non-nil matching CONTENT face."
279 :type '(repeat (list (regexp :tag "Header")
281 (item :tag "skip" nil)
282 (face :value default))
283 (choice :tag "Content"
284 (item :tag "skip" nil)
285 (face :value default)))))
287 ;;; Internal variables
289 (defvar gnus-article-mode-line-format-alist
290 (nconc '((?w (gnus-article-wash-status) ?s))
291 gnus-summary-mode-line-format-alist))
293 (defvar gnus-number-of-articles-to-be-saved nil)
295 ;;; Provide a mapping from `gnus-*' commands to Article commands.
302 (setq afunc (car func)
305 gfunc (intern (format "gnus-%s" func))))
307 `(lambda (&optional interactive &rest args)
308 ,(documentation afunc t)
309 (interactive (list t))
311 (set-buffer gnus-article-buffer)
313 (call-interactively ',afunc)
314 (apply ',afunc args)))))))
315 '(article-hide-headers
316 article-hide-boring-headers
317 article-treat-overstrike
318 (article-fill . gnus-article-word-wrap)
320 article-display-x-face
321 article-de-quoted-unreadable
322 article-mime-decode-quoted-printable
325 article-hide-signature
326 article-remove-trailing-blank-lines
327 article-strip-leading-blank-lines
328 article-strip-multiple-blank-lines
329 article-strip-blank-lines
331 article-date-original
334 (article-show-all . gnus-article-show-all-headers))))
336 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
338 ;;; Saving functions.
340 (defun gnus-article-save (save-buffer file &optional num)
341 "Save the currently selected article."
342 (unless gnus-save-all-headers
343 ;; Remove headers according to `gnus-saved-headers'.
344 (let ((gnus-visible-headers
345 (or gnus-saved-headers gnus-visible-headers))
346 (gnus-article-buffer save-buffer))
347 (gnus-article-hide-headers 1 t)))
348 (save-window-excursion
349 (if (not gnus-default-article-saver)
350 (error "No default saver is defined.")
351 ;; !!! Magic! The saving functions all save
352 ;; `gnus-original-article-buffer' (or so they think),
353 ;; but we bind that variable to our save-buffer.
354 (set-buffer gnus-article-buffer)
355 (let* ((gnus-original-article-buffer save-buffer)
358 ((not gnus-prompt-before-saving)
360 ((eq gnus-prompt-before-saving 'always)
363 (gnus-number-of-articles-to-be-saved
364 (when (eq gnus-prompt-before-saving t)
366 (set-buffer gnus-summary-buffer)
367 (funcall gnus-default-article-saver filename)))))
369 (defun gnus-read-save-file-name (prompt default-name &optional filename)
371 ((eq filename 'default)
375 (let* ((split-name (gnus-get-split-value gnus-split-methods))
377 (format prompt (if (and gnus-number-of-articles-to-be-saved
378 (> gnus-number-of-articles-to-be-saved 1))
379 (format "these %d articles"
380 gnus-number-of-articles-to-be-saved)
383 ;; Let the split methods have their say.
385 ;; No split name was found.
388 (concat prompt " (default "
389 (file-name-nondirectory default-name) ") ")
390 (file-name-directory default-name)
392 ;; A single split name was found
393 ((= 1 (length split-name))
394 (let* ((name (car split-name))
395 (dir (cond ((file-directory-p name)
396 (file-name-as-directory name))
397 ((file-exists-p name) name)
398 (t gnus-article-save-directory))))
400 (concat prompt " (default " name ") ")
402 ;; A list of splits was found.
404 (setq split-name (nreverse split-name))
406 (let ((file-name-history (nconc split-name file-name-history)))
409 (concat prompt " (`M-p' for defaults) ")
410 gnus-article-save-directory
412 (car (push result file-name-history)))))))
413 ;; Create the directory.
414 (gnus-make-directory (file-name-directory file))
415 ;; If we have read a directory, we append the default file name.
416 (when (file-directory-p file)
417 (setq file (concat (file-name-as-directory file)
418 (file-name-nondirectory default-name))))
419 ;; Possibly translate some characters.
420 (nnheader-translate-file-chars file)))))
422 (defun gnus-article-archive-name (group)
423 "Return the first instance of an \"Archive-name\" in the current buffer."
424 (let ((case-fold-search t))
425 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
426 (nnheader-concat gnus-article-save-directory
429 (defun gnus-summary-save-in-rmail (&optional filename)
430 "Append this article to Rmail file.
431 Optional argument FILENAME specifies file name.
432 Directory to save to is default to `gnus-article-save-directory'."
434 (gnus-set-global-variables)
436 (funcall gnus-rmail-save-name gnus-newsgroup-name
437 gnus-current-headers gnus-newsgroup-last-rmail)))
438 (setq filename (gnus-read-save-file-name
439 "Save %s in rmail file:" default-name filename))
440 (gnus-make-directory (file-name-directory filename))
441 (gnus-eval-in-buffer-window gnus-original-article-buffer
445 (gnus-output-to-rmail filename))))
446 ;; Remember the directory name to save articles
447 (setq gnus-newsgroup-last-rmail filename)))
449 (defun gnus-summary-save-in-mail (&optional filename)
450 "Append this article to Unix mail file.
451 Optional argument FILENAME specifies file name.
452 Directory to save to is default to `gnus-article-save-directory'."
454 (gnus-set-global-variables)
456 (funcall gnus-mail-save-name gnus-newsgroup-name
457 gnus-current-headers gnus-newsgroup-last-mail)))
458 (setq filename (gnus-read-save-file-name
459 "Save %s in Unix mail file:" default-name filename))
461 (expand-file-name filename
463 (file-name-directory default-name))))
464 (gnus-make-directory (file-name-directory filename))
465 (gnus-eval-in-buffer-window gnus-original-article-buffer
469 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
470 (gnus-output-to-rmail filename)
471 (let ((mail-use-rfc822 t))
472 (rmail-output filename 1 t t))))))
473 ;; Remember the directory name to save articles.
474 (setq gnus-newsgroup-last-mail filename)))
476 (defun gnus-summary-save-in-file (&optional filename)
477 "Append this article to file.
478 Optional argument FILENAME specifies file name.
479 Directory to save to is default to `gnus-article-save-directory'."
481 (gnus-set-global-variables)
483 (funcall gnus-file-save-name gnus-newsgroup-name
484 gnus-current-headers gnus-newsgroup-last-file)))
485 (setq filename (gnus-read-save-file-name
486 "Save %s in file:" default-name filename))
487 (gnus-make-directory (file-name-directory filename))
488 (gnus-eval-in-buffer-window gnus-original-article-buffer
492 (gnus-output-to-file filename))))
493 ;; Remember the directory name to save articles.
494 (setq gnus-newsgroup-last-file filename)))
496 (defun gnus-summary-save-body-in-file (&optional filename)
497 "Append this article body to a file.
498 Optional argument FILENAME specifies file name.
499 The directory to save in defaults to `gnus-article-save-directory'."
501 (gnus-set-global-variables)
503 (funcall gnus-file-save-name gnus-newsgroup-name
504 gnus-current-headers gnus-newsgroup-last-file)))
505 (setq filename (gnus-read-save-file-name
506 "Save %s body in file:" default-name filename))
507 (gnus-make-directory (file-name-directory filename))
508 (gnus-eval-in-buffer-window gnus-original-article-buffer
512 (goto-char (point-min))
513 (when (search-forward "\n\n" nil t)
514 (narrow-to-region (point) (point-max)))
515 (gnus-output-to-file filename))))
516 ;; Remember the directory name to save articles.
517 (setq gnus-newsgroup-last-file filename)))
519 (defun gnus-summary-save-in-pipe (&optional command)
520 "Pipe this article to subprocess."
522 (gnus-set-global-variables)
524 (cond ((eq command 'default)
525 gnus-last-shell-command)
527 (t (read-string "Shell command on article: "
528 gnus-last-shell-command))))
529 (when (string-equal command "")
530 (setq command gnus-last-shell-command))
531 (gnus-eval-in-buffer-window gnus-article-buffer
534 (shell-command-on-region (point-min) (point-max) command nil)))
535 (setq gnus-last-shell-command command))
537 ;;; Article file names when saving.
539 (defun gnus-capitalize-newsgroup (newsgroup)
540 "Capitalize NEWSGROUP name."
541 (when (not (zerop (length newsgroup)))
542 (concat (char-to-string (upcase (aref newsgroup 0)))
543 (substring newsgroup 1))))
545 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
546 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
547 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
548 Otherwise, it is like ~/News/news/group/num."
551 (concat (if (gnus-use-long-file-name 'not-save)
552 (gnus-capitalize-newsgroup newsgroup)
553 (gnus-newsgroup-directory-form newsgroup))
554 "/" (int-to-string (mail-header-number headers)))
555 gnus-article-save-directory)))
557 (string-equal (file-name-directory default)
558 (file-name-directory last-file))
559 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
561 (or last-file default))))
563 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
564 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
565 If variable `gnus-use-long-file-name' is non-nil, it is
566 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
569 (concat (if (gnus-use-long-file-name 'not-save)
571 (gnus-newsgroup-directory-form newsgroup))
572 "/" (int-to-string (mail-header-number headers)))
573 gnus-article-save-directory)))
575 (string-equal (file-name-directory default)
576 (file-name-directory last-file))
577 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
579 (or last-file default))))
581 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
582 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
583 If variable `gnus-use-long-file-name' is non-nil, it is
584 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
587 (if (gnus-use-long-file-name 'not-save)
588 (gnus-capitalize-newsgroup newsgroup)
589 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
590 gnus-article-save-directory)))
592 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
593 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
594 If variable `gnus-use-long-file-name' is non-nil, it is
595 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
598 (if (gnus-use-long-file-name 'not-save)
600 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
601 gnus-article-save-directory)))
605 ;;; Gnus article mode
608 (put 'gnus-article-mode 'mode-class 'special)
611 (gnus-define-keys gnus-article-mode-map
612 " " gnus-article-goto-next-page
613 "\177" gnus-article-goto-prev-page
614 [delete] gnus-article-goto-prev-page
615 "\C-c^" gnus-article-refer-article
616 "h" gnus-article-show-summary
617 "s" gnus-article-show-summary
618 "\C-c\C-m" gnus-article-mail
619 "?" gnus-article-describe-briefly
620 gnus-mouse-2 gnus-article-push-button
621 "\r" gnus-article-press-button
622 "\t" gnus-article-next-button
623 "\M-\t" gnus-article-prev-button
624 "e" gnus-article-edit
625 "<" beginning-of-buffer
627 "\C-c\C-i" gnus-info-find-node
630 "\C-d" gnus-article-read-summary-keys
631 "\M-*" gnus-article-read-summary-keys
632 "\M-g" gnus-article-read-summary-keys)
634 (substitute-key-definition
635 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
637 (defun gnus-article-make-menu-bar ()
638 (gnus-turn-off-edit-menu 'article)
639 (unless (boundp 'gnus-article-article-menu)
641 gnus-article-article-menu gnus-article-mode-map ""
643 ["Scroll forwards" gnus-article-goto-next-page t]
644 ["Scroll backwards" gnus-article-goto-prev-page t]
645 ["Show summary" gnus-article-show-summary t]
646 ["Fetch Message-ID at point" gnus-article-refer-article t]
647 ["Mail to address at point" gnus-article-mail t]
651 gnus-article-treatment-menu gnus-article-mode-map ""
653 ["Hide headers" gnus-article-hide-headers t]
654 ["Hide signature" gnus-article-hide-signature t]
655 ["Hide citation" gnus-article-hide-citation t]
656 ["Treat overstrike" gnus-article-treat-overstrike t]
657 ["Remove carriage return" gnus-article-remove-cr t]
658 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
660 (run-hooks 'gnus-article-menu-hook)))
662 (defun gnus-article-mode ()
663 "Major mode for displaying an article.
665 All normal editing commands are switched off.
667 The following commands are available in addition to all summary mode
669 \\<gnus-article-mode-map>
670 \\[gnus-article-next-page]\t Scroll the article one page forwards
671 \\[gnus-article-prev-page]\t Scroll the article one page backwards
672 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
673 \\[gnus-article-show-summary]\t Display the summary buffer
674 \\[gnus-article-mail]\t Send a reply to the address near point
675 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
676 \\[gnus-info-find-node]\t Go to the Gnus info node"
678 (when (and menu-bar-mode
679 (gnus-visual-p 'article-menu 'menu))
680 (gnus-article-make-menu-bar))
681 (kill-all-local-variables)
682 (gnus-simplify-mode-line)
683 (setq mode-name "Article")
684 (setq major-mode 'gnus-article-mode)
685 (make-local-variable 'minor-mode-alist)
686 (unless (assq 'gnus-show-mime minor-mode-alist)
687 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
688 (use-local-map gnus-article-mode-map)
689 (gnus-update-format-specifications nil 'article-mode)
690 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
691 (gnus-set-default-directory)
692 (buffer-disable-undo (current-buffer))
693 (setq buffer-read-only t)
694 (run-hooks 'gnus-article-mode-hook))
696 (defun gnus-article-setup-buffer ()
697 "Initialize the article buffer."
698 (let* ((name (if gnus-single-article-buffer "*Article*"
699 (concat "*Article " gnus-newsgroup-name "*")))
701 (progn (string-match "\\*Article" name)
702 (concat " *Original Article"
703 (substring name (match-end 0))))))
704 (setq gnus-article-buffer name)
705 (setq gnus-original-article-buffer original)
706 ;; This might be a variable local to the summary buffer.
707 (unless gnus-single-article-buffer
709 (set-buffer gnus-summary-buffer)
710 (setq gnus-article-buffer name)
711 (setq gnus-original-article-buffer original)
712 (gnus-set-global-variables)))
713 ;; Init original article buffer.
715 (set-buffer (get-buffer-create gnus-original-article-buffer))
716 (buffer-disable-undo (current-buffer))
717 (setq major-mode 'gnus-original-article-mode)
718 (gnus-add-current-to-buffer-list)
719 (make-local-variable 'gnus-original-article))
720 (if (get-buffer name)
723 (buffer-disable-undo (current-buffer))
724 (setq buffer-read-only t)
725 (gnus-add-current-to-buffer-list)
726 (unless (eq major-mode 'gnus-article-mode)
730 (set-buffer (get-buffer-create name))
731 (gnus-add-current-to-buffer-list)
733 (make-local-variable 'gnus-summary-buffer)
736 ;; Set article window start at LINE, where LINE is the number of lines
737 ;; from the head of the article.
738 (defun gnus-article-set-window-start (&optional line)
740 (get-buffer-window gnus-article-buffer t)
742 (set-buffer gnus-article-buffer)
743 (goto-char (point-min))
746 (gnus-message 6 "Moved to bookmark")
747 (search-forward "\n\n" nil t)
751 (defun gnus-article-prepare (article &optional all-headers header)
752 "Prepare ARTICLE in article mode buffer.
753 ARTICLE should either be an article number or a Message-ID.
754 If ARTICLE is an id, HEADER should be the article headers.
755 If ALL-HEADERS is non-nil, no headers are hidden."
757 ;; Make sure we start in a summary buffer.
758 (unless (eq major-mode 'gnus-summary-mode)
759 (set-buffer gnus-summary-buffer))
760 (setq gnus-summary-buffer (current-buffer))
761 ;; Make sure the connection to the server is alive.
762 (unless (gnus-server-opened
763 (gnus-find-method-for-group gnus-newsgroup-name))
764 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
765 (gnus-request-group gnus-newsgroup-name t))
766 (let* ((article (if header (mail-header-number header) article))
767 (summary-buffer (current-buffer))
768 (internal-hook gnus-article-internal-prepare-hook)
769 (group gnus-newsgroup-name)
772 (gnus-article-setup-buffer)
773 (set-buffer gnus-article-buffer)
774 ;; Deactivate active regions.
775 (when (and (boundp 'transient-mark-mode)
777 (setq mark-active nil))
778 (if (not (setq result (let ((buffer-read-only nil))
779 (gnus-request-article-this-buffer
781 ;; There is no such article.
783 (when (and (numberp article)
784 (not (memq article gnus-newsgroup-sparse)))
785 (setq gnus-article-current
786 (cons gnus-newsgroup-name article))
787 (set-buffer gnus-summary-buffer)
788 (setq gnus-current-article article)
789 (gnus-summary-mark-article article gnus-canceled-mark))
790 (unless (memq article gnus-newsgroup-sparse)
792 1 "No such article (may have expired or been canceled)")))
793 (if (or (eq result 'pseudo) (eq result 'nneething))
796 (set-buffer summary-buffer)
797 (setq gnus-last-article gnus-current-article
798 gnus-newsgroup-history (cons gnus-current-article
799 gnus-newsgroup-history)
800 gnus-current-article 0
801 gnus-current-headers nil
802 gnus-article-current nil)
803 (if (eq result 'nneething)
804 (gnus-configure-windows 'summary)
805 (gnus-configure-windows 'article))
806 (gnus-set-global-variables))
807 (gnus-set-mode-line 'article))
808 ;; The result from the `request' was an actual article -
809 ;; or at least some text that is now displayed in the
811 (when (and (numberp article)
812 (not (eq article gnus-current-article)))
813 ;; Seems like a new article has been selected.
814 ;; `gnus-current-article' must be an article number.
816 (set-buffer summary-buffer)
817 (setq gnus-last-article gnus-current-article
818 gnus-newsgroup-history (cons gnus-current-article
819 gnus-newsgroup-history)
820 gnus-current-article article
822 (gnus-summary-article-header gnus-current-article)
824 (cons gnus-newsgroup-name gnus-current-article))
825 (unless (vectorp gnus-current-headers)
826 (setq gnus-current-headers nil))
827 (gnus-summary-show-thread)
828 (run-hooks 'gnus-mark-article-hook)
829 (gnus-set-mode-line 'summary)
830 (when (gnus-visual-p 'article-highlight 'highlight)
831 (run-hooks 'gnus-visual-mark-article-hook))
832 ;; Set the global newsgroup variables here.
833 ;; Suggested by Jim Sisolak
834 ;; <sisolak@trans4.neep.wisc.edu>.
835 (gnus-set-global-variables)
836 (setq gnus-have-all-headers
837 (or all-headers gnus-show-all-headers))
839 (vectorp (gnus-summary-article-header article))
840 (gnus-cache-possibly-enter-article
842 (gnus-summary-article-header article)
843 (memq article gnus-newsgroup-marked)
844 (memq article gnus-newsgroup-dormant)
845 (memq article gnus-newsgroup-unreads)))))
846 (when (or (numberp article)
848 ;; Hooks for getting information from the article.
849 ;; This hook must be called before being narrowed.
850 (let (buffer-read-only)
851 (run-hooks 'internal-hook)
852 (run-hooks 'gnus-article-prepare-hook)
853 ;; Decode MIME message.
855 (if (or (not gnus-strict-mime)
856 (gnus-fetch-field "Mime-Version"))
857 (funcall gnus-show-mime-method)
858 (funcall gnus-decode-encoded-word-method)))
859 ;; Perform the article display hooks.
860 (run-hooks 'gnus-article-display-hook))
862 (goto-char (point-min))
863 (when gnus-break-pages
864 (gnus-narrow-to-page)))
865 (gnus-set-mode-line 'article)
866 (gnus-configure-windows 'article)
867 (goto-char (point-min))
870 (defun gnus-article-wash-status ()
871 "Return a string which display status of article washing."
873 (set-buffer gnus-article-buffer)
874 (let ((cite (article-hidden-text-p 'cite))
875 (headers (article-hidden-text-p 'headers))
876 (boring (article-hidden-text-p 'boring-headers))
877 (pgp (article-hidden-text-p 'pgp))
878 (pem (article-hidden-text-p 'pem))
879 (signature (article-hidden-text-p 'signature))
880 (overstrike (article-hidden-text-p 'overstrike))
881 (emphasis (article-hidden-text-p 'emphasis))
882 (mime gnus-show-mime))
883 (format "%c%c%c%c%c%c%c"
885 (if (or headers boring) ?h ? )
886 (if (or pgp pem) ?p ? )
888 (if overstrike ?o ? )
890 (if emphasis ?e ? )))))
892 (defun gnus-article-hide-headers-if-wanted ()
893 "Hide unwanted headers if `gnus-have-all-headers' is nil.
894 Provided for backwards compatibility."
895 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
897 (gnus-article-hide-headers)))
901 (defun gnus-output-to-rmail (file-name)
902 "Append the current article to an Rmail file named FILE-NAME."
904 ;; Most of these codes are borrowed from rmailout.el.
905 (setq file-name (expand-file-name file-name))
906 (setq rmail-default-rmail-file file-name)
907 (let ((artbuf (current-buffer))
908 (tmpbuf (get-buffer-create " *Gnus-output*")))
910 (or (get-file-buffer file-name)
911 (file-exists-p file-name)
912 (if (gnus-yes-or-no-p
913 (concat "\"" file-name "\" does not exist, create it? "))
914 (let ((file-buffer (create-file-buffer file-name)))
916 (set-buffer file-buffer)
917 (rmail-insert-rmail-file-header)
918 (let ((require-final-newline nil))
919 (gnus-write-buffer file-name)))
920 (kill-buffer file-buffer))
921 (error "Output file does not exist")))
923 (buffer-disable-undo (current-buffer))
925 (insert-buffer-substring artbuf)
926 (gnus-convert-article-to-rmail)
927 ;; Decide whether to append to a file or to an Emacs buffer.
928 (let ((outbuf (get-file-buffer file-name)))
930 (append-to-file (point-min) (point-max) file-name)
931 ;; File has been visited, in buffer OUTBUF.
933 (let ((buffer-read-only nil)
934 (msg (and (boundp 'rmail-current-message)
935 (symbol-value 'rmail-current-message))))
936 ;; If MSG is non-nil, buffer is in RMAIL mode.
939 (narrow-to-region (point-max) (point-max)))
940 (insert-buffer-substring tmpbuf)
942 (goto-char (point-min))
944 (search-backward "\^_")
945 (narrow-to-region (point) (point-max))
946 (goto-char (1+ (point-min)))
947 (rmail-count-new-messages t)
948 (rmail-show-message msg))))))
949 (kill-buffer tmpbuf)))
951 (defun gnus-output-to-file (file-name)
952 "Append the current article to a file named FILE-NAME."
953 (let ((artbuf (current-buffer)))
954 (nnheader-temp-write nil
955 (insert-buffer-substring artbuf)
956 ;; Append newline at end of the buffer as separator, and then
958 (goto-char (point-max))
960 (append-to-file (point-min) (point-max) file-name))))
962 (defun gnus-convert-article-to-rmail ()
963 "Convert article in current buffer to Rmail message format."
964 (let ((buffer-read-only nil))
965 ;; Convert article directly into Babyl format.
966 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
967 (goto-char (point-min))
968 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
969 (while (search-forward "\n\^_" nil t) ;single char
970 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
971 (goto-char (point-max))
974 (defun gnus-narrow-to-page (&optional arg)
975 "Narrow the article buffer to a page.
976 If given a numerical ARG, move forward ARG pages."
978 (setq arg (if arg (prefix-numeric-value arg) 0))
980 (set-buffer gnus-article-buffer)
981 (goto-char (point-min))
983 ;; Remove any old next/prev buttons.
984 (when (gnus-visual-p 'page-marker)
985 (let ((buffer-read-only nil))
986 (gnus-remove-text-with-property 'gnus-prev)
987 (gnus-remove-text-with-property 'gnus-next)))
990 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
992 (re-search-forward page-delimiter nil 'move arg)))
993 (goto-char (match-end 0)))
996 (if (re-search-forward page-delimiter nil 'move)
999 (when (and (gnus-visual-p 'page-marker)
1000 (not (= (point-min) 1)))
1002 (goto-char (point-min))
1003 (gnus-insert-prev-page-button)))
1004 (when (and (gnus-visual-p 'page-marker)
1005 (< (+ (point-max) 2) (buffer-size)))
1007 (goto-char (point-max))
1008 (gnus-insert-next-page-button)))))
1010 ;; Article mode commands
1012 (defun gnus-article-goto-next-page ()
1013 "Show the next page of the article."
1015 (when (gnus-article-next-page)
1016 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
1018 (defun gnus-article-goto-prev-page ()
1019 "Show the next page of the article."
1021 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
1022 (gnus-article-prev-page nil)))
1024 (defun gnus-article-next-page (&optional lines)
1025 "Show the next page of the current article.
1026 If end of article, return non-nil. Otherwise return nil.
1027 Argument LINES specifies lines to be scrolled up."
1029 (move-to-window-line -1)
1032 (and (pos-visible-in-window-p) ;Not continuation line.
1034 ;; Nothing in this page.
1035 (if (or (not gnus-break-pages)
1038 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
1040 (gnus-narrow-to-page 1) ;Go to next page.
1042 ;; More in this page.
1046 ;; Long lines may cause an end-of-buffer error.
1047 (goto-char (point-max))))
1048 (move-to-window-line 0)
1051 (defun gnus-article-prev-page (&optional lines)
1052 "Show previous page of current article.
1053 Argument LINES specifies lines to be scrolled down."
1055 (move-to-window-line 0)
1056 (if (and gnus-break-pages
1058 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
1060 (gnus-narrow-to-page -1) ;Go to previous page.
1061 (goto-char (point-max))
1067 (move-to-window-line 0))))
1069 (defun gnus-article-refer-article ()
1070 "Read article specified by message-id around point."
1072 (let ((point (point)))
1073 (search-forward ">" nil t) ;Move point to end of "<....>".
1074 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
1075 (let ((message-id (match-string 1)))
1077 (set-buffer gnus-summary-buffer)
1078 (gnus-summary-refer-article message-id))
1080 (error "No references around point"))))
1082 (defun gnus-article-show-summary ()
1083 "Reconfigure windows to show summary buffer."
1085 (gnus-configure-windows 'article)
1086 (gnus-summary-goto-subject gnus-current-article))
1088 (defun gnus-article-describe-briefly ()
1089 "Describe article mode commands briefly."
1092 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
1094 (defun gnus-article-summary-command ()
1095 "Execute the last keystroke in the summary buffer."
1097 (let ((obuf (current-buffer))
1098 (owin (current-window-configuration))
1100 (switch-to-buffer gnus-summary-buffer 'norecord)
1101 (setq func (lookup-key (current-local-map) (this-command-keys)))
1102 (call-interactively func)
1104 (set-window-configuration owin)
1105 (set-window-point (get-buffer-window (current-buffer)) (point))))
1107 (defun gnus-article-summary-command-nosave ()
1108 "Execute the last keystroke in the summary buffer."
1111 (pop-to-buffer gnus-summary-buffer 'norecord)
1112 (setq func (lookup-key (current-local-map) (this-command-keys)))
1113 (call-interactively func)))
1115 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
1116 "Read a summary buffer key sequence and execute it from the article buffer."
1119 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
1120 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
1121 "=" "^" "\M-^" "|"))
1128 (set-buffer gnus-summary-buffer)
1129 (push (or key last-command-event) unread-command-events)
1130 (setq keys (read-key-sequence nil)))
1133 (if (or (member keys nosaves)
1134 (member keys nosave-but-article)
1135 (member keys nosave-in-article))
1137 (save-window-excursion
1138 (pop-to-buffer gnus-summary-buffer 'norecord)
1139 (setq func (lookup-key (current-local-map) keys)))
1142 (unless (member keys nosave-in-article)
1143 (set-buffer gnus-summary-buffer))
1144 (call-interactively func))
1145 (when (member keys nosave-but-article)
1146 (pop-to-buffer gnus-article-buffer 'norecord)))
1147 ;; These commands should restore window configuration.
1148 (let ((obuf (current-buffer))
1149 (owin (current-window-configuration))
1152 (if not-restore-window
1153 (pop-to-buffer gnus-summary-buffer 'norecord)
1154 (switch-to-buffer gnus-summary-buffer 'norecord))
1155 (setq in-buffer (current-buffer))
1156 (if (setq func (lookup-key (current-local-map) keys))
1157 (call-interactively func)
1159 (when (eq in-buffer (current-buffer))
1161 (unless not-restore-window
1162 (set-window-configuration owin))
1163 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
1165 (defun gnus-article-hide (&optional arg force)
1166 "Hide all the gruft in the current article.
1167 This means that PGP stuff, signatures, cited text and (some)
1168 headers will be hidden.
1169 If given a prefix, show the hidden text instead."
1170 (interactive (list current-prefix-arg 'force))
1171 (gnus-article-hide-headers arg)
1172 (gnus-article-hide-pgp arg)
1173 (gnus-article-hide-citation-maybe arg force)
1174 (gnus-article-hide-signature arg))
1176 (defun gnus-article-maybe-highlight ()
1177 "Do some article highlighting if `article-visual' is non-nil."
1178 (when (gnus-visual-p 'article-highlight 'highlight)
1179 (gnus-article-highlight-some)))
1181 (defun gnus-request-article-this-buffer (article group)
1182 "Get an article and insert it into this buffer."
1183 (let (do-update-line)
1187 (gnus-kill-all-overlays)
1188 (setq group (or group gnus-newsgroup-name))
1190 ;; Open server if it has closed.
1191 (gnus-check-server (gnus-find-method-for-group group))
1193 ;; Using `gnus-request-article' directly will insert the article into
1194 ;; `nntp-server-buffer' - so we'll save some time by not having to
1195 ;; copy it from the server buffer into the article buffer.
1197 ;; We only request an article by message-id when we do not have the
1198 ;; headers for it, so we'll have to get those.
1199 (when (and (not gnus-doing-request-article)
1201 (let ((gnus-override-method gnus-refer-article-method))
1202 (gnus-read-header article)))
1204 ;; If the article number is negative, that means that this article
1205 ;; doesn't belong in this newsgroup (possibly), so we find its
1206 ;; message-id and request it by id instead of number.
1207 (when (and (numberp article)
1209 (get-buffer gnus-summary-buffer)
1210 (buffer-name (get-buffer gnus-summary-buffer)))
1212 (set-buffer gnus-summary-buffer)
1213 (let ((header (gnus-summary-article-header article)))
1216 ((memq article gnus-newsgroup-sparse)
1217 ;; This is a sparse gap article.
1218 (setq do-update-line article)
1219 (setq article (mail-header-id header))
1220 (let ((gnus-override-method gnus-refer-article-method))
1221 (gnus-read-header article))
1222 (setq gnus-newsgroup-sparse
1223 (delq article gnus-newsgroup-sparse)))
1225 ;; It's a real article.
1226 (setq article (mail-header-id header)))
1228 ;; It is an extracted pseudo-article.
1229 (setq article 'pseudo)
1230 (gnus-request-pseudo-article header))))
1232 (let ((method (gnus-find-method-for-group
1233 gnus-newsgroup-name)))
1234 (if (not (eq (car method) 'nneething))
1236 (let ((dir (concat (file-name-as-directory (nth 1 method))
1237 (mail-header-subject header))))
1238 (when (file-directory-p dir)
1239 (setq article 'nneething)
1240 (gnus-group-enter-directory dir))))))))
1243 ;; Refuse to select canceled articles.
1244 ((and (numberp article)
1246 (get-buffer gnus-summary-buffer)
1247 (buffer-name (get-buffer gnus-summary-buffer))
1248 (eq (cdr (save-excursion
1249 (set-buffer gnus-summary-buffer)
1250 (assq article gnus-newsgroup-reads)))
1251 gnus-canceled-mark))
1253 ;; We first check `gnus-original-article-buffer'.
1254 ((and (get-buffer gnus-original-article-buffer)
1257 (set-buffer gnus-original-article-buffer)
1258 (and (equal (car gnus-original-article) group)
1259 (eq (cdr gnus-original-article) article))))
1260 (insert-buffer-substring gnus-original-article-buffer)
1262 ;; Check the backlog.
1263 ((and gnus-keep-backlog
1264 (gnus-backlog-request-article group article (current-buffer)))
1266 ;; Check asynchronous pre-fetch.
1267 ((gnus-async-request-fetched-article group article (current-buffer))
1268 (gnus-async-prefetch-next group article gnus-summary-buffer)
1271 ((and gnus-use-cache
1273 (gnus-cache-request-article article group))
1275 ;; Get the article and put into the article buffer.
1276 ((or (stringp article) (numberp article))
1277 (let ((gnus-override-method
1278 (and (stringp article) gnus-refer-article-method))
1279 (buffer-read-only nil))
1281 (gnus-kill-all-overlays)
1282 (when (gnus-request-article article group (current-buffer))
1283 (when (numberp article)
1284 (gnus-async-prefetch-next group article gnus-summary-buffer)
1285 (when gnus-keep-backlog
1286 (gnus-backlog-enter-article
1287 group article (current-buffer))))
1292 ;; Take the article from the original article buffer
1293 ;; and place it in the buffer it's supposed to be in.
1294 (when (and (get-buffer gnus-article-buffer)
1296 (equal (buffer-name (current-buffer))
1297 (buffer-name (get-buffer gnus-article-buffer))))
1299 (if (get-buffer gnus-original-article-buffer)
1300 (set-buffer (get-buffer gnus-original-article-buffer))
1301 (set-buffer (get-buffer-create gnus-original-article-buffer))
1302 (buffer-disable-undo (current-buffer))
1303 (setq major-mode 'gnus-original-article-mode)
1304 (setq buffer-read-only t)
1305 (gnus-add-current-to-buffer-list))
1306 (let (buffer-read-only)
1308 (insert-buffer-substring gnus-article-buffer))
1309 (setq gnus-original-article (cons group article))))
1311 ;; Update sparse articles.
1312 (when (and do-update-line
1313 (or (numberp article)
1315 (let ((buf (current-buffer)))
1316 (set-buffer gnus-summary-buffer)
1317 (gnus-summary-update-article do-update-line)
1318 (gnus-summary-goto-subject do-update-line nil t)
1319 (set-window-point (get-buffer-window (current-buffer) t)
1321 (set-buffer buf))))))
1323 (defun gnus-article-date-ut (&optional type highlight)
1324 "Convert DATE date to universal time in the current article.
1325 If TYPE is `local', convert to local time; if it is `lapsed', output
1326 how much time has lapsed since DATE."
1327 (interactive (list 'ut t))
1328 (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1330 (set-buffer gnus-article-buffer)
1331 (article-date-ut type highlight headers))))
1337 (defcustom gnus-article-edit-mode-hook nil
1338 "Hook run in article edit mode buffers."
1342 (defvar gnus-article-edit-done-function nil)
1344 (defvar gnus-article-edit-mode-map nil)
1346 (unless gnus-article-edit-mode-map
1347 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1349 (gnus-define-keys gnus-article-edit-mode-map
1350 "\C-c\C-c" gnus-article-edit-done
1351 "\C-c\C-k" gnus-article-edit-exit)
1353 (gnus-define-keys (gnus-article-edit-wash-map
1354 "\C-c\C-w" gnus-article-edit-mode-map)
1355 "f" gnus-article-edit-full-stops))
1357 (defun gnus-article-edit-mode ()
1358 "Major mode for editing articles.
1359 This is an extended text-mode.
1361 \\{gnus-article-edit-mode-map}"
1363 (kill-all-local-variables)
1364 (setq major-mode 'gnus-article-edit-mode)
1365 (setq mode-name "Article Edit")
1366 (use-local-map gnus-article-edit-mode-map)
1367 (make-local-variable 'gnus-article-edit-done-function)
1368 (make-local-variable 'gnus-prev-winconf)
1369 (setq buffer-read-only nil)
1370 (buffer-enable-undo)
1372 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1374 (defun gnus-article-edit (&optional force)
1375 "Edit the current article.
1376 This will have permanent effect only in mail groups.
1377 If FORCE is non-nil, allow editing of articles even in read-only
1380 (when (and (not force)
1381 (gnus-group-read-only-p))
1382 (error "The current newsgroup does not support article editing."))
1383 (gnus-article-edit-article
1385 (gnus-summary-edit-article-done
1386 ,(or (mail-header-references gnus-current-headers) "")
1387 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1389 (defun gnus-article-edit-article (exit-func)
1390 "Start editing the contents of the current article buffer."
1391 (let ((winconf (current-window-configuration)))
1392 (set-buffer gnus-article-buffer)
1393 (gnus-article-edit-mode)
1394 (set-text-properties (point-min) (point-max) nil)
1395 (gnus-configure-windows 'edit-article)
1396 (setq gnus-article-edit-done-function exit-func)
1397 (setq gnus-prev-winconf winconf)
1398 (gnus-message 6 "C-c C-c to end edits")))
1400 (defun gnus-article-edit-done ()
1401 "Update the article edits and exit."
1403 (let ((func gnus-article-edit-done-function)
1404 (buf (current-buffer))
1405 (start (window-start)))
1406 (gnus-article-edit-exit)
1409 (let ((buffer-read-only nil))
1412 (set-window-start (get-buffer-window buf) start)
1413 (set-window-point (get-buffer-window buf) (point))))
1415 (defun gnus-article-edit-exit ()
1416 "Exit the article editing without updating."
1418 ;; We remove all text props from the article buffer.
1419 (let ((buf (format "%s" (buffer-string)))
1420 (curbuf (current-buffer))
1422 (window-start (window-start)))
1425 (let ((winconf gnus-prev-winconf))
1427 ;; The cache and backlog have to be flushed somewhat.
1428 (when gnus-use-cache
1429 (gnus-cache-update-article
1430 (car gnus-article-current) (cdr gnus-article-current)))
1431 (when gnus-keep-backlog
1432 (gnus-backlog-remove-article
1433 (car gnus-article-current) (cdr gnus-article-current)))
1434 ;; Flush original article as well.
1436 (when (get-buffer gnus-original-article-buffer)
1437 (set-buffer gnus-original-article-buffer)
1438 (setq gnus-original-article nil)))
1439 (set-window-configuration winconf)
1440 ;; Tippy-toe some to make sure that point remains where it was.
1441 (let ((buf (current-buffer)))
1443 (set-window-start (get-buffer-window (current-buffer)) window-start)
1445 (set-buffer buf)))))
1447 (defun gnus-article-edit-full-stops ()
1448 "Interactively repair spacing at end of sentences."
1451 (goto-char (point-min))
1452 (search-forward-regexp "^$" nil t)
1453 (let ((case-fold-search nil))
1454 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1457 ;;; Article highlights
1460 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1462 ;;; Internal Variables:
1464 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-\\wa-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]*[-\\wa-zA-Z0-9_=#$@~`%&*+|\\/]"
1465 "Regular expression that matches URLs."
1469 (defcustom gnus-button-alist
1470 `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
1471 t gnus-button-message-id 3)
1472 ("\\(<?\\(url: ?\\)?news://\\([^>\n\t ]*\\)>?\\)" 1 t
1473 gnus-button-fetch-group 3)
1474 ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1475 gnus-button-message-id 3)
1476 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-button-reply 2)
1477 ;; This is how URLs _should_ be embedded in text...
1478 ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1479 ;; Next regexp stolen from highlight-headers.el.
1480 ;; Modified by Vladimir Alexiev.
1481 (,gnus-button-url-regexp 0 t gnus-button-url 0))
1482 "Alist of regexps matching buttons in article bodies.
1484 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1485 REGEXP: is the string matching text around the button,
1486 BUTTON: is the number of the regexp grouping actually matching the button,
1487 FORM: is a lisp expression which must eval to true for the button to
1489 CALLBACK: is the function to call when the user push this button, and each
1490 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1492 CALLBACK can also be a variable, in that case the value of that
1493 variable it the real callback function."
1495 :type '(repeat (list regexp
1496 (integer :tag "Button")
1498 (function :tag "Callback")
1501 (integer :tag "Regexp group")))))
1503 (defcustom gnus-header-button-alist
1504 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1505 0 t gnus-button-message-id 0)
1506 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1507 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
1508 0 t gnus-button-mailto 0)
1509 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1510 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1511 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1512 gnus-button-message-id 3))
1513 "Alist of headers and regexps to match buttons in article heads.
1515 This alist is very similar to `gnus-button-alist', except that each
1516 alist has an additional HEADER element first in each entry:
1518 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1520 HEADER is a regexp to match a header. For a fuller explanation, see
1521 `gnus-button-alist'."
1523 :type '(repeat (list (regexp :tag "Header")
1525 (integer :tag "Button")
1527 (function :tag "Callback")
1530 (integer :tag "Regexp group")))))
1532 (defvar gnus-button-regexp nil)
1533 (defvar gnus-button-marker-list nil)
1534 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1536 (defvar gnus-button-last nil)
1537 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1541 (defun gnus-article-push-button (event)
1542 "Check text under the mouse pointer for a callback function.
1543 If the text under the mouse pointer has a `gnus-callback' property,
1544 call it with the value of the `gnus-data' text property."
1546 (set-buffer (window-buffer (posn-window (event-start event))))
1547 (let* ((pos (posn-point (event-start event)))
1548 (data (get-text-property pos 'gnus-data))
1549 (fun (get-text-property pos 'gnus-callback)))
1551 (funcall fun data))))
1553 (defun gnus-article-press-button ()
1554 "Check text at point for a callback function.
1555 If the text at point has a `gnus-callback' property,
1556 call it with the value of the `gnus-data' text property."
1558 (let* ((data (get-text-property (point) 'gnus-data))
1559 (fun (get-text-property (point) 'gnus-callback)))
1561 (funcall fun data))))
1563 (defun gnus-article-prev-button (n)
1564 "Move point to N buttons backward.
1565 If N is negative, move forward instead."
1567 (gnus-article-next-button (- n)))
1569 (defun gnus-article-next-button (n)
1570 "Move point to N buttons forward.
1571 If N is negative, move backward instead."
1573 (let ((function (if (< n 0) 'previous-single-property-change
1574 'next-single-property-change))
1575 (inhibit-point-motion-hooks t)
1577 (limit (if (< n 0) (point-min) (point-max))))
1579 (while (and (not (= limit (point)))
1581 ;; Skip past the current button.
1582 (when (get-text-property (point) 'gnus-callback)
1583 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1584 ;; Go to the next (or previous) button.
1585 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1586 ;; Put point at the start of the button.
1587 (when (and backward (not (get-text-property (point) 'gnus-callback)))
1588 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1589 ;; Skip past intangible buttons.
1590 (when (get-text-property (point) 'intangible)
1594 (gnus-message 5 "No more buttons"))
1597 (defun gnus-article-highlight (&optional force)
1598 "Highlight current article.
1599 This function calls `gnus-article-highlight-headers',
1600 `gnus-article-highlight-citation',
1601 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1602 do the highlighting. See the documentation for those functions."
1603 (interactive (list 'force))
1604 (gnus-article-highlight-headers)
1605 (gnus-article-highlight-citation force)
1606 (gnus-article-highlight-signature)
1607 (gnus-article-add-buttons force)
1608 (gnus-article-add-buttons-to-head))
1610 (defun gnus-article-highlight-some (&optional force)
1611 "Highlight current article.
1612 This function calls `gnus-article-highlight-headers',
1613 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1614 do the highlighting. See the documentation for those functions."
1615 (interactive (list 'force))
1616 (gnus-article-highlight-headers)
1617 (gnus-article-highlight-signature)
1618 (gnus-article-add-buttons))
1620 (defun gnus-article-highlight-headers ()
1621 "Highlight article headers as specified by `gnus-header-face-alist'."
1624 (set-buffer gnus-article-buffer)
1626 (let ((alist gnus-header-face-alist)
1627 (buffer-read-only nil)
1628 (case-fold-search t)
1629 (inhibit-point-motion-hooks t)
1630 entry regexp header-face field-face from hpoints fpoints)
1631 (goto-char (point-min))
1632 (when (search-forward "\n\n" nil t)
1633 (narrow-to-region (1- (point)) (point-min))
1634 (while (setq entry (pop alist))
1635 (goto-char (point-min))
1636 (setq regexp (concat "^\\("
1637 (if (string-equal "" (nth 0 entry))
1641 header-face (nth 1 entry)
1642 field-face (nth 2 entry))
1643 (while (and (re-search-forward regexp nil t)
1647 (unless (search-forward ":" nil t)
1649 (when (and header-face
1650 (not (memq (point) hpoints)))
1651 (push (point) hpoints)
1652 (gnus-put-text-property from (point) 'face header-face))
1653 (when (and field-face
1654 (not (memq (setq from (point)) fpoints)))
1656 (if (re-search-forward "^[^ \t]" nil t)
1658 (goto-char (point-max)))
1659 (gnus-put-text-property from (point) 'face field-face)))))))))
1661 (defun gnus-article-highlight-signature ()
1662 "Highlight the signature in an article.
1663 It does this by highlighting everything after
1664 `gnus-signature-separator' using `gnus-signature-face'."
1667 (set-buffer gnus-article-buffer)
1668 (let ((buffer-read-only nil)
1669 (inhibit-point-motion-hooks t))
1671 (when (and gnus-signature-face
1672 (article-narrow-to-signature))
1673 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1674 'face gnus-signature-face)
1676 (article-search-signature)
1677 (let ((start (match-beginning 0))
1678 (end (set-marker (make-marker) (1+ (match-end 0)))))
1679 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1682 (defun gnus-article-add-buttons (&optional force)
1683 "Find external references in the article and make buttons of them.
1684 \"External references\" are things like Message-IDs and URLs, as
1685 specified by `gnus-button-alist'."
1686 (interactive (list 'force))
1688 (set-buffer gnus-article-buffer)
1689 ;; Remove all old markers.
1690 (while gnus-button-marker-list
1691 (set-marker (pop gnus-button-marker-list) nil))
1692 (let ((buffer-read-only nil)
1693 (inhibit-point-motion-hooks t)
1694 (case-fold-search t)
1695 (alist gnus-button-alist)
1697 (goto-char (point-min))
1698 ;; We skip the headers.
1699 (unless (search-forward "\n\n" nil t)
1700 (goto-char (point-max)))
1702 (while (setq entry (pop alist))
1703 (setq regexp (car entry))
1705 (while (re-search-forward regexp nil t)
1706 (let* ((start (and entry (match-beginning (nth 1 entry))))
1707 (end (and entry (match-end (nth 1 entry))))
1708 (from (match-beginning 0)))
1709 (when (or (eq t (nth 1 entry))
1710 (eval (nth 1 entry)))
1711 ;; That optional form returned non-nil, so we add the
1713 (gnus-article-add-button
1714 start end 'gnus-button-push
1715 (car (push (set-marker (make-marker) from)
1716 gnus-button-marker-list))))))))))
1718 ;; Add buttons to the head of an article.
1719 (defun gnus-article-add-buttons-to-head ()
1720 "Add buttons to the head of the article."
1723 (set-buffer gnus-article-buffer)
1724 (let ((buffer-read-only nil)
1725 (inhibit-point-motion-hooks t)
1726 (case-fold-search t)
1727 (alist gnus-header-button-alist)
1729 (nnheader-narrow-to-headers)
1731 ;; Each alist entry.
1732 (setq entry (car alist)
1734 (goto-char (point-min))
1735 (while (re-search-forward (car entry) nil t)
1736 ;; Each header matching the entry.
1737 (setq beg (match-beginning 0))
1738 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1739 (match-beginning 0))
1742 (while (re-search-forward (nth 1 entry) end t)
1743 ;; Each match within a header.
1744 (let* ((entry (cdr entry))
1745 (start (match-beginning (nth 1 entry)))
1746 (end (match-end (nth 1 entry)))
1747 (form (nth 2 entry)))
1748 (goto-char (match-end 0))
1750 (gnus-article-add-button
1751 start end (nth 3 entry)
1752 (buffer-substring (match-beginning (nth 4 entry))
1753 (match-end (nth 4 entry)))))))
1757 ;;; External functions:
1759 (defun gnus-article-add-button (from to fun &optional data)
1760 "Create a button between FROM and TO with callback FUN and data DATA."
1761 (when gnus-article-button-face
1762 (gnus-overlay-put (gnus-make-overlay from to)
1763 'face gnus-article-button-face))
1764 (gnus-add-text-properties
1766 (nconc (and gnus-article-mouse-face
1767 (list gnus-mouse-face-prop gnus-article-mouse-face))
1768 (list 'gnus-callback fun)
1769 (and data (list 'gnus-data data)))))
1771 ;;; Internal functions:
1773 (defun gnus-signature-toggle (end)
1775 (set-buffer gnus-article-buffer)
1776 (let ((buffer-read-only nil)
1777 (inhibit-point-motion-hooks t))
1778 (if (get-text-property end 'invisible)
1779 (article-unhide-text end (point-max))
1780 (article-hide-text end (point-max) gnus-hidden-properties)))))
1782 (defun gnus-button-entry ()
1783 ;; Return the first entry in `gnus-button-alist' matching this place.
1784 (let ((alist gnus-button-alist)
1787 (setq entry (pop alist))
1788 (if (looking-at (car entry))
1793 (defun gnus-button-push (marker)
1794 ;; Push button starting at MARKER.
1796 (set-buffer gnus-article-buffer)
1798 (let* ((entry (gnus-button-entry))
1799 (inhibit-point-motion-hooks t)
1801 (args (mapcar (lambda (group)
1802 (let ((string (buffer-substring
1803 (match-beginning group)
1804 (match-end group))))
1805 (gnus-set-text-properties
1806 0 (length string) nil string)
1813 (fboundp (symbol-value fun)))
1814 (apply (symbol-value fun) args))
1816 (gnus-message 1 "You must define `%S' to use this button"
1817 (cons fun args)))))))
1819 (defun gnus-button-message-id (message-id)
1822 (set-buffer gnus-summary-buffer)
1823 (gnus-summary-refer-article message-id)))
1825 (defun gnus-button-fetch-group (address)
1826 "Fetch GROUP specified by ADDRESS."
1827 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
1828 (error "Can't parse %s" address)
1829 (gnus-group-read-ephemeral-group
1830 (match-string 4 address)
1831 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
1832 (nntp-port-number ,(if (match-end 3)
1833 (match-string 3 address)
1836 (defun gnus-button-mailto (address)
1838 (set-buffer (gnus-copy-article-buffer))
1839 (message-reply address))
1841 (defun gnus-button-reply (address)
1842 ;; Reply to ADDRESS.
1843 (message-reply address))
1845 (defun gnus-button-url (address)
1847 (funcall browse-url-browser-function address))
1849 ;;; Next/prev buttons in the article buffer.
1851 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1852 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1854 (defvar gnus-prev-page-map nil)
1855 (unless gnus-prev-page-map
1856 (setq gnus-prev-page-map (make-sparse-keymap))
1857 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1858 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1860 (defun gnus-insert-prev-page-button ()
1861 (let ((buffer-read-only nil))
1863 gnus-prev-page-line-format nil
1864 `(gnus-prev t local-map ,gnus-prev-page-map
1865 gnus-callback gnus-article-button-prev-page))))
1867 (defvar gnus-next-page-map nil)
1868 (unless gnus-next-page-map
1869 (setq gnus-next-page-map (make-keymap))
1870 (suppress-keymap gnus-prev-page-map)
1871 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1872 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1874 (defun gnus-button-next-page ()
1875 "Go to the next page."
1877 (let ((win (selected-window)))
1878 (select-window (get-buffer-window gnus-article-buffer t))
1879 (gnus-article-next-page)
1880 (select-window win)))
1882 (defun gnus-button-prev-page ()
1883 "Go to the prev page."
1885 (let ((win (selected-window)))
1886 (select-window (get-buffer-window gnus-article-buffer t))
1887 (gnus-article-prev-page)
1888 (select-window win)))
1890 (defun gnus-insert-next-page-button ()
1891 (let ((buffer-read-only nil))
1892 (gnus-eval-format gnus-next-page-line-format nil
1893 `(gnus-next t local-map ,gnus-next-page-map
1895 gnus-article-button-next-page))))
1897 (defun gnus-article-button-next-page (arg)
1898 "Go to the next page."
1900 (let ((win (selected-window)))
1901 (select-window (get-buffer-window gnus-article-buffer t))
1902 (gnus-article-next-page)
1903 (select-window win)))
1905 (defun gnus-article-button-prev-page (arg)
1906 "Go to the prev page."
1908 (let ((win (selected-window)))
1909 (select-window (get-buffer-window gnus-article-buffer t))
1910 (gnus-article-prev-page)
1911 (select-window win)))
1915 ;;; gnus-art.el ends here