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) num))) ; Magic
365 (set-buffer gnus-summary-buffer)
366 (funcall gnus-default-article-saver filename)))))
368 (defun gnus-read-save-file-name (prompt default-name &optional filename)
370 ((eq filename 'default)
374 (let* ((split-name (gnus-get-split-value gnus-split-methods))
376 (format prompt (if (and gnus-number-of-articles-to-be-saved
377 (> gnus-number-of-articles-to-be-saved 1))
378 (format "these %d articles"
379 gnus-number-of-articles-to-be-saved)
382 ;; Let the split methods have their say.
384 ;; No split name was found.
387 (concat prompt " (default "
388 (file-name-nondirectory default-name) ") ")
389 (file-name-directory default-name)
391 ;; A single split name was found
392 ((= 1 (length split-name))
393 (let* ((name (car split-name))
394 (dir (cond ((file-directory-p name)
395 (file-name-as-directory name))
396 ((file-exists-p name) name)
397 (t gnus-article-save-directory))))
399 (concat prompt " (default " name ") ")
401 ;; A list of splits was found.
403 (setq split-name (nreverse split-name))
405 (let ((file-name-history (nconc split-name file-name-history)))
408 (concat prompt " (`M-p' for defaults) ")
409 gnus-article-save-directory
411 (car (push result file-name-history)))))))
412 ;; Create the directory.
413 (gnus-make-directory (file-name-directory file))
414 ;; If we have read a directory, we append the default file name.
415 (when (file-directory-p file)
416 (setq file (concat (file-name-as-directory file)
417 (file-name-nondirectory default-name))))
418 ;; Possibly translate some characters.
419 (nnheader-translate-file-chars file)))))
421 (defun gnus-article-archive-name (group)
422 "Return the first instance of an \"Archive-name\" in the current buffer."
423 (let ((case-fold-search t))
424 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
425 (nnheader-concat gnus-article-save-directory
428 (defun gnus-summary-save-in-rmail (&optional filename)
429 "Append this article to Rmail file.
430 Optional argument FILENAME specifies file name.
431 Directory to save to is default to `gnus-article-save-directory'."
433 (gnus-set-global-variables)
435 (funcall gnus-rmail-save-name gnus-newsgroup-name
436 gnus-current-headers gnus-newsgroup-last-rmail)))
437 (setq filename (gnus-read-save-file-name
438 "Save %s in rmail file:" default-name filename))
439 (gnus-make-directory (file-name-directory filename))
440 (gnus-eval-in-buffer-window gnus-original-article-buffer
444 (gnus-output-to-rmail filename))))
445 ;; Remember the directory name to save articles
446 (setq gnus-newsgroup-last-rmail filename)))
448 (defun gnus-summary-save-in-mail (&optional filename)
449 "Append this article to Unix mail file.
450 Optional argument FILENAME specifies file name.
451 Directory to save to is default to `gnus-article-save-directory'."
453 (gnus-set-global-variables)
455 (funcall gnus-mail-save-name gnus-newsgroup-name
456 gnus-current-headers gnus-newsgroup-last-mail)))
457 (setq filename (gnus-read-save-file-name
458 "Save %s in Unix mail file:" default-name filename))
460 (expand-file-name filename
462 (file-name-directory default-name))))
463 (gnus-make-directory (file-name-directory filename))
464 (gnus-eval-in-buffer-window gnus-original-article-buffer
468 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
469 (gnus-output-to-rmail filename)
470 (let ((mail-use-rfc822 t))
471 (rmail-output filename 1 t t))))))
472 ;; Remember the directory name to save articles.
473 (setq gnus-newsgroup-last-mail filename)))
475 (defun gnus-summary-save-in-file (&optional filename)
476 "Append this article to file.
477 Optional argument FILENAME specifies file name.
478 Directory to save to is default to `gnus-article-save-directory'."
480 (gnus-set-global-variables)
482 (funcall gnus-file-save-name gnus-newsgroup-name
483 gnus-current-headers gnus-newsgroup-last-file)))
484 (setq filename (gnus-read-save-file-name
485 "Save %s in file:" default-name filename))
486 (gnus-make-directory (file-name-directory filename))
487 (gnus-eval-in-buffer-window gnus-original-article-buffer
491 (gnus-output-to-file filename))))
492 ;; Remember the directory name to save articles.
493 (setq gnus-newsgroup-last-file filename)))
495 (defun gnus-summary-save-body-in-file (&optional filename)
496 "Append this article body to a file.
497 Optional argument FILENAME specifies file name.
498 The directory to save in defaults to `gnus-article-save-directory'."
500 (gnus-set-global-variables)
502 (funcall gnus-file-save-name gnus-newsgroup-name
503 gnus-current-headers gnus-newsgroup-last-file)))
504 (setq filename (gnus-read-save-file-name
505 "Save %s body in file:" default-name filename))
506 (gnus-make-directory (file-name-directory filename))
507 (gnus-eval-in-buffer-window gnus-original-article-buffer
511 (goto-char (point-min))
512 (and (search-forward "\n\n" nil t)
513 (narrow-to-region (point) (point-max)))
514 (gnus-output-to-file filename))))
515 ;; Remember the directory name to save articles.
516 (setq gnus-newsgroup-last-file filename)))
518 (defun gnus-summary-save-in-pipe (&optional command)
519 "Pipe this article to subprocess."
521 (gnus-set-global-variables)
523 (cond ((eq command 'default)
524 gnus-last-shell-command)
526 (t (read-string "Shell command on article: "
527 gnus-last-shell-command))))
528 (if (string-equal command "")
529 (setq command gnus-last-shell-command))
530 (gnus-eval-in-buffer-window gnus-article-buffer
533 (shell-command-on-region (point-min) (point-max) command nil)))
534 (setq gnus-last-shell-command command))
536 ;;; Article file names when saving.
538 (defun gnus-capitalize-newsgroup (newsgroup)
539 "Capitalize NEWSGROUP name."
540 (and (not (zerop (length newsgroup)))
541 (concat (char-to-string (upcase (aref newsgroup 0)))
542 (substring newsgroup 1))))
544 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
545 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
546 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
547 Otherwise, it is like ~/News/news/group/num."
550 (concat (if (gnus-use-long-file-name 'not-save)
551 (gnus-capitalize-newsgroup newsgroup)
552 (gnus-newsgroup-directory-form newsgroup))
553 "/" (int-to-string (mail-header-number headers)))
554 gnus-article-save-directory)))
556 (string-equal (file-name-directory default)
557 (file-name-directory last-file))
558 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
560 (or last-file default))))
562 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
563 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
564 If variable `gnus-use-long-file-name' is non-nil, it is
565 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
568 (concat (if (gnus-use-long-file-name 'not-save)
570 (gnus-newsgroup-directory-form newsgroup))
571 "/" (int-to-string (mail-header-number headers)))
572 gnus-article-save-directory)))
574 (string-equal (file-name-directory default)
575 (file-name-directory last-file))
576 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
578 (or last-file default))))
580 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
581 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
582 If variable `gnus-use-long-file-name' is non-nil, it is
583 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
586 (if (gnus-use-long-file-name 'not-save)
587 (gnus-capitalize-newsgroup newsgroup)
588 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
589 gnus-article-save-directory)))
591 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
592 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
593 If variable `gnus-use-long-file-name' is non-nil, it is
594 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
597 (if (gnus-use-long-file-name 'not-save)
599 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
600 gnus-article-save-directory)))
604 ;;; Gnus article mode
607 (put 'gnus-article-mode 'mode-class 'special)
610 (gnus-define-keys gnus-article-mode-map
611 " " gnus-article-goto-next-page
612 "\177" gnus-article-goto-prev-page
613 [delete] gnus-article-goto-prev-page
614 "\C-c^" gnus-article-refer-article
615 "h" gnus-article-show-summary
616 "s" gnus-article-show-summary
617 "\C-c\C-m" gnus-article-mail
618 "?" gnus-article-describe-briefly
619 gnus-mouse-2 gnus-article-push-button
620 "\r" gnus-article-press-button
621 "\t" gnus-article-next-button
622 "\M-\t" gnus-article-prev-button
623 "e" gnus-article-edit
624 "<" beginning-of-buffer
626 "\C-c\C-i" gnus-info-find-node
629 "\C-d" gnus-article-read-summary-keys
630 "\M-g" gnus-article-read-summary-keys)
632 (substitute-key-definition
633 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
635 (defun gnus-article-make-menu-bar ()
636 (gnus-turn-off-edit-menu 'article)
637 (unless (boundp 'gnus-article-article-menu)
639 gnus-article-article-menu gnus-article-mode-map ""
641 ["Scroll forwards" gnus-article-goto-next-page t]
642 ["Scroll backwards" gnus-article-goto-prev-page t]
643 ["Show summary" gnus-article-show-summary t]
644 ["Fetch Message-ID at point" gnus-article-refer-article t]
645 ["Mail to address at point" gnus-article-mail t]
649 gnus-article-treatment-menu gnus-article-mode-map ""
651 ["Hide headers" gnus-article-hide-headers t]
652 ["Hide signature" gnus-article-hide-signature t]
653 ["Hide citation" gnus-article-hide-citation t]
654 ["Treat overstrike" gnus-article-treat-overstrike t]
655 ["Remove carriage return" gnus-article-remove-cr t]
656 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
658 (run-hooks 'gnus-article-menu-hook)))
660 (defun gnus-article-mode ()
661 "Major mode for displaying an article.
663 All normal editing commands are switched off.
665 The following commands are available in addition to all summary mode
667 \\<gnus-article-mode-map>
668 \\[gnus-article-next-page]\t Scroll the article one page forwards
669 \\[gnus-article-prev-page]\t Scroll the article one page backwards
670 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
671 \\[gnus-article-show-summary]\t Display the summary buffer
672 \\[gnus-article-mail]\t Send a reply to the address near point
673 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
674 \\[gnus-info-find-node]\t Go to the Gnus info node"
676 (when (and menu-bar-mode
677 (gnus-visual-p 'article-menu 'menu))
678 (gnus-article-make-menu-bar))
679 (kill-all-local-variables)
680 (gnus-simplify-mode-line)
681 (setq mode-name "Article")
682 (setq major-mode 'gnus-article-mode)
683 (make-local-variable 'minor-mode-alist)
684 (unless (assq 'gnus-show-mime minor-mode-alist)
685 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
686 (use-local-map gnus-article-mode-map)
687 (gnus-update-format-specifications nil 'article-mode)
688 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
689 (gnus-set-default-directory)
690 (buffer-disable-undo (current-buffer))
691 (setq buffer-read-only t)
692 (run-hooks 'gnus-article-mode-hook))
694 (defun gnus-article-setup-buffer ()
695 "Initialize the article buffer."
696 (let* ((name (if gnus-single-article-buffer "*Article*"
697 (concat "*Article " gnus-newsgroup-name "*")))
699 (progn (string-match "\\*Article" name)
700 (concat " *Original Article"
701 (substring name (match-end 0))))))
702 (setq gnus-article-buffer name)
703 (setq gnus-original-article-buffer original)
704 ;; This might be a variable local to the summary buffer.
705 (unless gnus-single-article-buffer
707 (set-buffer gnus-summary-buffer)
708 (setq gnus-article-buffer name)
709 (setq gnus-original-article-buffer original)
710 (gnus-set-global-variables)))
711 ;; Init original article buffer.
713 (set-buffer (get-buffer-create gnus-original-article-buffer))
714 (buffer-disable-undo (current-buffer))
715 (setq major-mode 'gnus-original-article-mode)
716 (gnus-add-current-to-buffer-list)
717 (make-local-variable 'gnus-original-article))
718 (if (get-buffer name)
721 (buffer-disable-undo (current-buffer))
722 (setq buffer-read-only t)
723 (gnus-add-current-to-buffer-list)
724 (unless (eq major-mode 'gnus-article-mode)
728 (set-buffer (get-buffer-create name))
729 (gnus-add-current-to-buffer-list)
731 (make-local-variable 'gnus-summary-buffer)
734 ;; Set article window start at LINE, where LINE is the number of lines
735 ;; from the head of the article.
736 (defun gnus-article-set-window-start (&optional line)
738 (get-buffer-window gnus-article-buffer t)
740 (set-buffer gnus-article-buffer)
741 (goto-char (point-min))
744 (gnus-message 6 "Moved to bookmark")
745 (search-forward "\n\n" nil t)
749 (defun gnus-article-prepare (article &optional all-headers header)
750 "Prepare ARTICLE in article mode buffer.
751 ARTICLE should either be an article number or a Message-ID.
752 If ARTICLE is an id, HEADER should be the article headers.
753 If ALL-HEADERS is non-nil, no headers are hidden."
755 ;; Make sure we start in a summary buffer.
756 (unless (eq major-mode 'gnus-summary-mode)
757 (set-buffer gnus-summary-buffer))
758 (setq gnus-summary-buffer (current-buffer))
759 ;; Make sure the connection to the server is alive.
760 (unless (gnus-server-opened
761 (gnus-find-method-for-group gnus-newsgroup-name))
762 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
763 (gnus-request-group gnus-newsgroup-name t))
764 (let* ((article (if header (mail-header-number header) article))
765 (summary-buffer (current-buffer))
766 (internal-hook gnus-article-internal-prepare-hook)
767 (group gnus-newsgroup-name)
770 (gnus-article-setup-buffer)
771 (set-buffer gnus-article-buffer)
772 ;; Deactivate active regions.
773 (when (and (boundp 'transient-mark-mode)
775 (setq mark-active nil))
776 (if (not (setq result (let ((buffer-read-only nil))
777 (gnus-request-article-this-buffer
779 ;; There is no such article.
781 (when (and (numberp article)
782 (not (memq article gnus-newsgroup-sparse)))
783 (setq gnus-article-current
784 (cons gnus-newsgroup-name article))
785 (set-buffer gnus-summary-buffer)
786 (setq gnus-current-article article)
787 (gnus-summary-mark-article article gnus-canceled-mark))
788 (unless (memq article gnus-newsgroup-sparse)
790 1 "No such article (may have expired or been canceled)")))
791 (if (or (eq result 'pseudo) (eq result 'nneething))
794 (set-buffer summary-buffer)
795 (setq gnus-last-article gnus-current-article
796 gnus-newsgroup-history (cons gnus-current-article
797 gnus-newsgroup-history)
798 gnus-current-article 0
799 gnus-current-headers nil
800 gnus-article-current nil)
801 (if (eq result 'nneething)
802 (gnus-configure-windows 'summary)
803 (gnus-configure-windows 'article))
804 (gnus-set-global-variables))
805 (gnus-set-mode-line 'article))
806 ;; The result from the `request' was an actual article -
807 ;; or at least some text that is now displayed in the
809 (if (and (numberp article)
810 (not (eq article gnus-current-article)))
811 ;; Seems like a new article has been selected.
812 ;; `gnus-current-article' must be an article number.
814 (set-buffer summary-buffer)
815 (setq gnus-last-article gnus-current-article
816 gnus-newsgroup-history (cons gnus-current-article
817 gnus-newsgroup-history)
818 gnus-current-article article
820 (gnus-summary-article-header gnus-current-article)
822 (cons gnus-newsgroup-name gnus-current-article))
823 (unless (vectorp gnus-current-headers)
824 (setq gnus-current-headers nil))
825 (gnus-summary-show-thread)
826 (run-hooks 'gnus-mark-article-hook)
827 (gnus-set-mode-line 'summary)
828 (and (gnus-visual-p 'article-highlight 'highlight)
829 (run-hooks 'gnus-visual-mark-article-hook))
830 ;; Set the global newsgroup variables here.
831 ;; Suggested by Jim Sisolak
832 ;; <sisolak@trans4.neep.wisc.edu>.
833 (gnus-set-global-variables)
834 (setq gnus-have-all-headers
835 (or all-headers gnus-show-all-headers))
837 (vectorp (gnus-summary-article-header article))
838 (gnus-cache-possibly-enter-article
840 (gnus-summary-article-header article)
841 (memq article gnus-newsgroup-marked)
842 (memq article gnus-newsgroup-dormant)
843 (memq article gnus-newsgroup-unreads)))))
844 (when (or (numberp article)
846 ;; Hooks for getting information from the article.
847 ;; This hook must be called before being narrowed.
848 (let (buffer-read-only)
849 (run-hooks 'internal-hook)
850 (run-hooks 'gnus-article-prepare-hook)
851 ;; Decode MIME message.
853 (if (or (not gnus-strict-mime)
854 (gnus-fetch-field "Mime-Version"))
855 (funcall gnus-show-mime-method)
856 (funcall gnus-decode-encoded-word-method)))
857 ;; Perform the article display hooks.
858 (run-hooks 'gnus-article-display-hook))
860 (goto-char (point-min))
861 (and gnus-break-pages (gnus-narrow-to-page)))
862 (gnus-set-mode-line 'article)
863 (gnus-configure-windows 'article)
864 (goto-char (point-min))
867 (defun gnus-article-wash-status ()
868 "Return a string which display status of article washing."
870 (set-buffer gnus-article-buffer)
871 (let ((cite (article-hidden-text-p 'cite))
872 (headers (article-hidden-text-p 'headers))
873 (boring (article-hidden-text-p 'boring-headers))
874 (pgp (article-hidden-text-p 'pgp))
875 (pem (article-hidden-text-p 'pem))
876 (signature (article-hidden-text-p 'signature))
877 (overstrike (article-hidden-text-p 'overstrike))
878 (emphasis (article-hidden-text-p 'emphasis))
879 (mime gnus-show-mime))
880 (format "%c%c%c%c%c%c%c"
882 (if (or headers boring) ?h ? )
883 (if (or pgp pem) ?p ? )
885 (if overstrike ?o ? )
887 (if emphasis ?e ? )))))
889 (defun gnus-article-hide-headers-if-wanted ()
890 "Hide unwanted headers if `gnus-have-all-headers' is nil.
891 Provided for backwards compatibility."
892 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
894 (gnus-article-hide-headers)))
898 (defun gnus-output-to-rmail (file-name)
899 "Append the current article to an Rmail file named FILE-NAME."
901 ;; Most of these codes are borrowed from rmailout.el.
902 (setq file-name (expand-file-name file-name))
903 (setq rmail-default-rmail-file file-name)
904 (let ((artbuf (current-buffer))
905 (tmpbuf (get-buffer-create " *Gnus-output*")))
907 (or (get-file-buffer file-name)
908 (file-exists-p file-name)
909 (if (gnus-yes-or-no-p
910 (concat "\"" file-name "\" does not exist, create it? "))
911 (let ((file-buffer (create-file-buffer file-name)))
913 (set-buffer file-buffer)
914 (rmail-insert-rmail-file-header)
915 (let ((require-final-newline nil))
916 (write-region (point-min) (point-max) file-name t 1)))
917 (kill-buffer file-buffer))
918 (error "Output file does not exist")))
920 (buffer-disable-undo (current-buffer))
922 (insert-buffer-substring artbuf)
923 (gnus-convert-article-to-rmail)
924 ;; Decide whether to append to a file or to an Emacs buffer.
925 (let ((outbuf (get-file-buffer file-name)))
927 (append-to-file (point-min) (point-max) file-name)
928 ;; File has been visited, in buffer OUTBUF.
930 (let ((buffer-read-only nil)
931 (msg (and (boundp 'rmail-current-message)
932 (symbol-value 'rmail-current-message))))
933 ;; If MSG is non-nil, buffer is in RMAIL mode.
936 (narrow-to-region (point-max) (point-max))))
937 (insert-buffer-substring tmpbuf)
940 (goto-char (point-min))
942 (search-backward "\^_")
943 (narrow-to-region (point) (point-max))
944 (goto-char (1+ (point-min)))
945 (rmail-count-new-messages t)
946 (rmail-show-message msg)))))))
947 (kill-buffer tmpbuf)))
949 (defun gnus-output-to-file (file-name)
950 "Append the current article to a file named FILE-NAME."
951 (let ((artbuf (current-buffer)))
952 (nnheader-temp-write nil
953 (insert-buffer-substring artbuf)
954 ;; Append newline at end of the buffer as separator, and then
956 (goto-char (point-max))
958 (append-to-file (point-min) (point-max) file-name))))
960 (defun gnus-convert-article-to-rmail ()
961 "Convert article in current buffer to Rmail message format."
962 (let ((buffer-read-only nil))
963 ;; Convert article directly into Babyl format.
964 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
965 (goto-char (point-min))
966 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
967 (while (search-forward "\n\^_" nil t) ;single char
968 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
969 (goto-char (point-max))
972 (defun gnus-narrow-to-page (&optional arg)
973 "Narrow the article buffer to a page.
974 If given a numerical ARG, move forward ARG pages."
976 (setq arg (if arg (prefix-numeric-value arg) 0))
978 (set-buffer gnus-article-buffer)
979 (goto-char (point-min))
981 ;; Remove any old next/prev buttons.
982 (when (gnus-visual-p 'page-marker)
983 (let ((buffer-read-only nil))
984 (gnus-remove-text-with-property 'gnus-prev)
985 (gnus-remove-text-with-property 'gnus-next)))
988 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
990 (re-search-forward page-delimiter nil 'move arg)))
991 (goto-char (match-end 0)))
994 (if (re-search-forward page-delimiter nil 'move)
997 (when (and (gnus-visual-p 'page-marker)
998 (not (= (point-min) 1)))
1000 (goto-char (point-min))
1001 (gnus-insert-prev-page-button)))
1002 (when (and (gnus-visual-p 'page-marker)
1003 (< (+ (point-max) 2) (buffer-size)))
1005 (goto-char (point-max))
1006 (gnus-insert-next-page-button)))))
1008 ;; Article mode commands
1010 (defun gnus-article-goto-next-page ()
1011 "Show the next page of the article."
1013 (when (gnus-article-next-page)
1014 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
1016 (defun gnus-article-goto-prev-page ()
1017 "Show the next page of the article."
1019 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
1020 (gnus-article-prev-page nil)))
1022 (defun gnus-article-next-page (&optional lines)
1023 "Show the next page of the current article.
1024 If end of article, return non-nil. Otherwise return nil.
1025 Argument LINES specifies lines to be scrolled up."
1027 (move-to-window-line -1)
1030 (and (pos-visible-in-window-p) ;Not continuation line.
1032 ;; Nothing in this page.
1033 (if (or (not gnus-break-pages)
1036 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
1038 (gnus-narrow-to-page 1) ;Go to next page.
1040 ;; More in this page.
1044 ;; Long lines may cause an end-of-buffer error.
1045 (goto-char (point-max))))
1046 (move-to-window-line 0)
1049 (defun gnus-article-prev-page (&optional lines)
1050 "Show previous page of current article.
1051 Argument LINES specifies lines to be scrolled down."
1053 (move-to-window-line 0)
1054 (if (and gnus-break-pages
1056 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
1058 (gnus-narrow-to-page -1) ;Go to previous page.
1059 (goto-char (point-max))
1065 (move-to-window-line 0))))
1067 (defun gnus-article-refer-article ()
1068 "Read article specified by message-id around point."
1070 (let ((point (point)))
1071 (search-forward ">" nil t) ;Move point to end of "<....>".
1072 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
1073 (let ((message-id (match-string 1)))
1075 (set-buffer gnus-summary-buffer)
1076 (gnus-summary-refer-article message-id))
1078 (error "No references around point"))))
1080 (defun gnus-article-show-summary ()
1081 "Reconfigure windows to show summary buffer."
1083 (gnus-configure-windows 'article)
1084 (gnus-summary-goto-subject gnus-current-article))
1086 (defun gnus-article-describe-briefly ()
1087 "Describe article mode commands briefly."
1090 (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")))
1092 (defun gnus-article-summary-command ()
1093 "Execute the last keystroke in the summary buffer."
1095 (let ((obuf (current-buffer))
1096 (owin (current-window-configuration))
1098 (switch-to-buffer gnus-summary-buffer 'norecord)
1099 (setq func (lookup-key (current-local-map) (this-command-keys)))
1100 (call-interactively func)
1102 (set-window-configuration owin)
1103 (set-window-point (get-buffer-window (current-buffer)) (point))))
1105 (defun gnus-article-summary-command-nosave ()
1106 "Execute the last keystroke in the summary buffer."
1109 (pop-to-buffer gnus-summary-buffer 'norecord)
1110 (setq func (lookup-key (current-local-map) (this-command-keys)))
1111 (call-interactively func)))
1113 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
1114 "Read a summary buffer key sequence and execute it from the article buffer."
1117 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
1118 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
1119 "=" "^" "\M-^" "|"))
1126 (set-buffer gnus-summary-buffer)
1127 (push (or key last-command-event) unread-command-events)
1128 (setq keys (read-key-sequence nil)))
1131 (if (or (member keys nosaves)
1132 (member keys nosave-but-article)
1133 (member keys nosave-in-article))
1135 (save-window-excursion
1136 (pop-to-buffer gnus-summary-buffer 'norecord)
1137 (setq func (lookup-key (current-local-map) keys)))
1140 (unless (member keys nosave-in-article)
1141 (set-buffer gnus-summary-buffer))
1142 (call-interactively func))
1143 (when (member keys nosave-but-article)
1144 (pop-to-buffer gnus-article-buffer 'norecord)))
1145 ;; These commands should restore window configuration.
1146 (let ((obuf (current-buffer))
1147 (owin (current-window-configuration))
1150 (if not-restore-window
1151 (pop-to-buffer gnus-summary-buffer 'norecord)
1152 (switch-to-buffer gnus-summary-buffer 'norecord))
1153 (setq in-buffer (current-buffer))
1154 (if (setq func (lookup-key (current-local-map) keys))
1155 (call-interactively func)
1157 (when (eq in-buffer (current-buffer))
1159 (unless not-restore-window
1160 (set-window-configuration owin))
1161 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
1163 (defun gnus-article-hide (&optional arg force)
1164 "Hide all the gruft in the current article.
1165 This means that PGP stuff, signatures, cited text and (some)
1166 headers will be hidden.
1167 If given a prefix, show the hidden text instead."
1168 (interactive (list current-prefix-arg 'force))
1169 (gnus-article-hide-headers arg)
1170 (gnus-article-hide-pgp arg)
1171 (gnus-article-hide-citation-maybe arg force)
1172 (gnus-article-hide-signature arg))
1174 (defun gnus-article-maybe-highlight ()
1175 "Do some article highlighting if `article-visual' is non-nil."
1176 (if (gnus-visual-p 'article-highlight 'highlight)
1177 (gnus-article-highlight-some)))
1179 (defun gnus-request-article-this-buffer (article group)
1180 "Get an article and insert it into this buffer."
1181 (let (do-update-line)
1185 (gnus-kill-all-overlays)
1186 (setq group (or group gnus-newsgroup-name))
1188 ;; Open server if it has closed.
1189 (gnus-check-server (gnus-find-method-for-group group))
1191 ;; Using `gnus-request-article' directly will insert the article into
1192 ;; `nntp-server-buffer' - so we'll save some time by not having to
1193 ;; copy it from the server buffer into the article buffer.
1195 ;; We only request an article by message-id when we do not have the
1196 ;; headers for it, so we'll have to get those.
1197 (when (stringp article)
1198 (let ((gnus-override-method gnus-refer-article-method))
1199 (gnus-read-header article)))
1201 ;; If the article number is negative, that means that this article
1202 ;; doesn't belong in this newsgroup (possibly), so we find its
1203 ;; message-id and request it by id instead of number.
1204 (when (and (numberp article)
1206 (get-buffer gnus-summary-buffer)
1207 (buffer-name (get-buffer gnus-summary-buffer)))
1209 (set-buffer gnus-summary-buffer)
1210 (let ((header (gnus-summary-article-header article)))
1213 ((memq article gnus-newsgroup-sparse)
1214 ;; This is a sparse gap article.
1215 (setq do-update-line article)
1216 (setq article (mail-header-id header))
1217 (let ((gnus-override-method gnus-refer-article-method))
1218 (gnus-read-header article))
1219 (setq gnus-newsgroup-sparse
1220 (delq article gnus-newsgroup-sparse)))
1222 ;; It's a real article.
1223 (setq article (mail-header-id header)))
1225 ;; It is an extracted pseudo-article.
1226 (setq article 'pseudo)
1227 (gnus-request-pseudo-article header))))
1229 (let ((method (gnus-find-method-for-group
1230 gnus-newsgroup-name)))
1231 (if (not (eq (car method) 'nneething))
1233 (let ((dir (concat (file-name-as-directory (nth 1 method))
1234 (mail-header-subject header))))
1235 (if (file-directory-p dir)
1237 (setq article 'nneething)
1238 (gnus-group-enter-directory dir)))))))))
1241 ;; Refuse to select canceled articles.
1242 ((and (numberp article)
1244 (get-buffer gnus-summary-buffer)
1245 (buffer-name (get-buffer gnus-summary-buffer))
1246 (eq (cdr (save-excursion
1247 (set-buffer gnus-summary-buffer)
1248 (assq article gnus-newsgroup-reads)))
1249 gnus-canceled-mark))
1251 ;; We first check `gnus-original-article-buffer'.
1252 ((and (get-buffer gnus-original-article-buffer)
1255 (set-buffer gnus-original-article-buffer)
1256 (and (equal (car gnus-original-article) group)
1257 (eq (cdr gnus-original-article) article))))
1258 (insert-buffer-substring gnus-original-article-buffer)
1260 ;; Check the backlog.
1261 ((and gnus-keep-backlog
1262 (gnus-backlog-request-article group article (current-buffer)))
1264 ;; Check asynchronous pre-fetch.
1265 ((gnus-async-request-fetched-article group article (current-buffer))
1266 (gnus-async-prefetch-next group article gnus-summary-buffer)
1269 ((and gnus-use-cache
1271 (gnus-cache-request-article article group))
1273 ;; Get the article and put into the article buffer.
1274 ((or (stringp article) (numberp article))
1275 (let ((gnus-override-method
1276 (and (stringp article) gnus-refer-article-method))
1277 (buffer-read-only nil))
1279 (gnus-kill-all-overlays)
1280 (when (gnus-request-article article group (current-buffer))
1281 (when (numberp article)
1282 (gnus-async-prefetch-next group article gnus-summary-buffer)
1283 (when gnus-keep-backlog
1284 (gnus-backlog-enter-article
1285 group article (current-buffer))))
1290 ;; Take the article from the original article buffer
1291 ;; and place it in the buffer it's supposed to be in.
1292 (when (and (get-buffer gnus-article-buffer)
1294 (equal (buffer-name (current-buffer))
1295 (buffer-name (get-buffer gnus-article-buffer))))
1297 (if (get-buffer gnus-original-article-buffer)
1298 (set-buffer (get-buffer gnus-original-article-buffer))
1299 (set-buffer (get-buffer-create gnus-original-article-buffer))
1300 (buffer-disable-undo (current-buffer))
1301 (setq major-mode 'gnus-original-article-mode)
1302 (setq buffer-read-only t)
1303 (gnus-add-current-to-buffer-list))
1304 (let (buffer-read-only)
1306 (insert-buffer-substring gnus-article-buffer))
1307 (setq gnus-original-article (cons group article))))
1309 ;; Update sparse articles.
1310 (when (and do-update-line
1311 (or (numberp article)
1313 (let ((buf (current-buffer)))
1314 (set-buffer gnus-summary-buffer)
1315 (gnus-summary-update-article do-update-line)
1316 (gnus-summary-goto-subject do-update-line nil t)
1317 (set-window-point (get-buffer-window (current-buffer) t)
1319 (set-buffer buf))))))
1321 (defun gnus-article-date-ut (&optional type highlight)
1322 "Convert DATE date to universal time in the current article.
1323 If TYPE is `local', convert to local time; if it is `lapsed', output
1324 how much time has lapsed since DATE."
1325 (interactive (list 'ut t))
1326 (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1328 (set-buffer gnus-article-buffer)
1329 (article-date-ut type highlight headers))))
1335 (defcustom gnus-article-edit-mode-hook nil
1336 "Hook run in article edit mode buffers."
1340 (defvar gnus-article-edit-done-function nil)
1342 (defvar gnus-article-edit-mode-map nil)
1344 (unless gnus-article-edit-mode-map
1345 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1347 (gnus-define-keys gnus-article-edit-mode-map
1348 "\C-c\C-c" gnus-article-edit-done
1349 "\C-c\C-k" gnus-article-edit-exit)
1351 (gnus-define-keys (gnus-article-edit-wash-map
1352 "\C-c\C-w" gnus-article-edit-mode-map)
1353 "f" gnus-article-edit-full-stops))
1355 (defun gnus-article-edit-mode ()
1356 "Major mode for editing articles.
1357 This is an extended text-mode.
1359 \\{gnus-article-edit-mode-map}"
1361 (kill-all-local-variables)
1362 (setq major-mode 'gnus-article-edit-mode)
1363 (setq mode-name "Article Edit")
1364 (use-local-map gnus-article-edit-mode-map)
1365 (make-local-variable 'gnus-article-edit-done-function)
1366 (make-local-variable 'gnus-prev-winconf)
1367 (setq buffer-read-only nil)
1368 (buffer-enable-undo)
1370 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1372 (defun gnus-article-edit (&optional force)
1373 "Edit the current article.
1374 This will have permanent effect only in mail groups.
1375 If FORCE is non-nil, allow editing of articles even in read-only
1378 (when (and (not force)
1379 (gnus-group-read-only-p))
1380 (error "The current newsgroup does not support article editing."))
1381 (gnus-article-edit-article
1383 (gnus-summary-edit-article-done
1384 ,(or (mail-header-references gnus-current-headers) "")
1385 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1387 (defun gnus-article-edit-article (exit-func)
1388 "Start editing the contents of the current article buffer."
1389 (let ((winconf (current-window-configuration)))
1390 (set-buffer gnus-article-buffer)
1391 (gnus-article-edit-mode)
1392 (set-text-properties (point-min) (point-max) nil)
1393 (gnus-configure-windows 'edit-article)
1394 (setq gnus-article-edit-done-function exit-func)
1395 (setq gnus-prev-winconf winconf)
1396 (gnus-message 6 "C-c C-c to end edits")))
1398 (defun gnus-article-edit-done ()
1399 "Update the article edits and exit."
1401 (let ((func gnus-article-edit-done-function)
1402 (buf (current-buffer))
1403 (start (window-start)))
1404 (gnus-article-edit-exit)
1407 (let ((buffer-read-only nil))
1410 (set-window-start (get-buffer-window buf) start)
1411 (set-window-point (get-buffer-window buf) (point))))
1413 (defun gnus-article-edit-exit ()
1414 "Exit the article editing without updating."
1416 ;; We remove all text props from the article buffer.
1417 (let ((buf (format "%s" (buffer-string)))
1418 (curbuf (current-buffer))
1420 (window-start (window-start)))
1423 (let ((winconf gnus-prev-winconf))
1425 ;; The cache and backlog have to be flushed somewhat.
1426 (when gnus-use-cache
1427 (gnus-cache-update-article
1428 (car gnus-article-current) (cdr gnus-article-current)))
1429 (when gnus-keep-backlog
1430 (gnus-backlog-remove-article
1431 (car gnus-article-current) (cdr gnus-article-current)))
1432 ;; Flush original article as well.
1434 (when (get-buffer gnus-original-article-buffer)
1435 (set-buffer gnus-original-article-buffer)
1436 (setq gnus-original-article nil)))
1437 (set-window-configuration winconf)
1438 ;; Tippy-toe some to make sure that point remains where it was.
1439 (let ((buf (current-buffer)))
1441 (set-window-start (get-buffer-window (current-buffer)) window-start)
1443 (set-buffer buf)))))
1445 (defun gnus-article-edit-full-stops ()
1446 "Interactively repair spacing at end of sentences."
1449 (goto-char (point-min))
1450 (search-forward-regexp "^$" nil t)
1451 (let ((case-fold-search nil))
1452 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1455 ;;; Article highlights
1458 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1460 ;;; Internal Variables:
1462 (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_=#$@~`%&*+|\\/]"
1463 "Regular expression that matches URLs."
1467 (defcustom gnus-button-alist
1468 `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
1469 t gnus-button-message-id 3)
1470 ("\\(<?\\(url: ?\\)?news://\\([^>\n\t ]*\\)>?\\)" 1 t
1471 gnus-button-fetch-group 3)
1472 ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1473 gnus-button-message-id 3)
1474 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-button-reply 2)
1475 ;; This is how URLs _should_ be embedded in text...
1476 ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1477 ;; Next regexp stolen from highlight-headers.el.
1478 ;; Modified by Vladimir Alexiev.
1479 (,gnus-button-url-regexp 0 t gnus-button-url 0))
1480 "Alist of regexps matching buttons in article bodies.
1482 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1483 REGEXP: is the string matching text around the button,
1484 BUTTON: is the number of the regexp grouping actually matching the button,
1485 FORM: is a lisp expression which must eval to true for the button to
1487 CALLBACK: is the function to call when the user push this button, and each
1488 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1490 CALLBACK can also be a variable, in that case the value of that
1491 variable it the real callback function."
1493 :type '(repeat (list regexp
1494 (integer :tag "Button")
1496 (function :tag "Callback")
1499 (integer :tag "Regexp group")))))
1501 (defcustom gnus-header-button-alist
1502 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1503 0 t gnus-button-message-id 0)
1504 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1505 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
1506 0 t gnus-button-mailto 0)
1507 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1508 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1509 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1510 gnus-button-message-id 3))
1511 "Alist of headers and regexps to match buttons in article heads.
1513 This alist is very similar to `gnus-button-alist', except that each
1514 alist has an additional HEADER element first in each entry:
1516 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1518 HEADER is a regexp to match a header. For a fuller explanation, see
1519 `gnus-button-alist'."
1521 :type '(repeat (list (regexp :tag "Header")
1523 (integer :tag "Button")
1525 (function :tag "Callback")
1528 (integer :tag "Regexp group")))))
1530 (defvar gnus-button-regexp nil)
1531 (defvar gnus-button-marker-list nil)
1532 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1534 (defvar gnus-button-last nil)
1535 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1539 (defun gnus-article-push-button (event)
1540 "Check text under the mouse pointer for a callback function.
1541 If the text under the mouse pointer has a `gnus-callback' property,
1542 call it with the value of the `gnus-data' text property."
1544 (set-buffer (window-buffer (posn-window (event-start event))))
1545 (let* ((pos (posn-point (event-start event)))
1546 (data (get-text-property pos 'gnus-data))
1547 (fun (get-text-property pos 'gnus-callback)))
1548 (if fun (funcall fun data))))
1550 (defun gnus-article-press-button ()
1551 "Check text at point for a callback function.
1552 If the text at point has a `gnus-callback' property,
1553 call it with the value of the `gnus-data' text property."
1555 (let* ((data (get-text-property (point) 'gnus-data))
1556 (fun (get-text-property (point) 'gnus-callback)))
1557 (if fun (funcall fun data))))
1559 (defun gnus-article-prev-button (n)
1560 "Move point to N buttons backward.
1561 If N is negative, move forward instead."
1563 (gnus-article-next-button (- n)))
1565 (defun gnus-article-next-button (n)
1566 "Move point to N buttons forward.
1567 If N is negative, move backward instead."
1569 (let ((function (if (< n 0) 'previous-single-property-change
1570 'next-single-property-change))
1571 (inhibit-point-motion-hooks t)
1573 (limit (if (< n 0) (point-min) (point-max))))
1575 (while (and (not (= limit (point)))
1577 ;; Skip past the current button.
1578 (when (get-text-property (point) 'gnus-callback)
1579 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1580 ;; Go to the next (or previous) button.
1581 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1582 ;; Put point at the start of the button.
1583 (when (and backward (not (get-text-property (point) 'gnus-callback)))
1584 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1585 ;; Skip past intangible buttons.
1586 (when (get-text-property (point) 'intangible)
1590 (gnus-message 5 "No more buttons"))
1593 (defun gnus-article-highlight (&optional force)
1594 "Highlight current article.
1595 This function calls `gnus-article-highlight-headers',
1596 `gnus-article-highlight-citation',
1597 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1598 do the highlighting. See the documentation for those functions."
1599 (interactive (list 'force))
1600 (gnus-article-highlight-headers)
1601 (gnus-article-highlight-citation force)
1602 (gnus-article-highlight-signature)
1603 (gnus-article-add-buttons force)
1604 (gnus-article-add-buttons-to-head))
1606 (defun gnus-article-highlight-some (&optional force)
1607 "Highlight current article.
1608 This function calls `gnus-article-highlight-headers',
1609 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1610 do the highlighting. See the documentation for those functions."
1611 (interactive (list 'force))
1612 (gnus-article-highlight-headers)
1613 (gnus-article-highlight-signature)
1614 (gnus-article-add-buttons))
1616 (defun gnus-article-highlight-headers ()
1617 "Highlight article headers as specified by `gnus-header-face-alist'."
1620 (set-buffer gnus-article-buffer)
1622 (let ((alist gnus-header-face-alist)
1623 (buffer-read-only nil)
1624 (case-fold-search t)
1625 (inhibit-point-motion-hooks t)
1626 entry regexp header-face field-face from hpoints fpoints)
1627 (goto-char (point-min))
1628 (when (search-forward "\n\n" nil t)
1629 (narrow-to-region (1- (point)) (point-min))
1630 (while (setq entry (pop alist))
1631 (goto-char (point-min))
1632 (setq regexp (concat "^\\("
1633 (if (string-equal "" (nth 0 entry))
1637 header-face (nth 1 entry)
1638 field-face (nth 2 entry))
1639 (while (and (re-search-forward regexp nil t)
1643 (or (search-forward ":" nil t)
1645 (when (and header-face
1646 (not (memq (point) hpoints)))
1647 (push (point) hpoints)
1648 (gnus-put-text-property from (point) 'face header-face))
1649 (when (and field-face
1650 (not (memq (setq from (point)) fpoints)))
1652 (if (re-search-forward "^[^ \t]" nil t)
1654 (goto-char (point-max)))
1655 (gnus-put-text-property from (point) 'face field-face)))))))))
1657 (defun gnus-article-highlight-signature ()
1658 "Highlight the signature in an article.
1659 It does this by highlighting everything after
1660 `gnus-signature-separator' using `gnus-signature-face'."
1663 (set-buffer gnus-article-buffer)
1664 (let ((buffer-read-only nil)
1665 (inhibit-point-motion-hooks t))
1667 (when (and gnus-signature-face
1668 (article-narrow-to-signature))
1669 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1670 'face gnus-signature-face)
1672 (article-search-signature)
1673 (let ((start (match-beginning 0))
1674 (end (set-marker (make-marker) (1+ (match-end 0)))))
1675 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1678 (defun gnus-article-add-buttons (&optional force)
1679 "Find external references in the article and make buttons of them.
1680 \"External references\" are things like Message-IDs and URLs, as
1681 specified by `gnus-button-alist'."
1682 (interactive (list 'force))
1684 (set-buffer gnus-article-buffer)
1685 ;; Remove all old markers.
1686 (while gnus-button-marker-list
1687 (set-marker (pop gnus-button-marker-list) nil))
1688 (let ((buffer-read-only nil)
1689 (inhibit-point-motion-hooks t)
1690 (case-fold-search t)
1691 (alist gnus-button-alist)
1693 (goto-char (point-min))
1694 ;; We skip the headers.
1695 (unless (search-forward "\n\n" nil t)
1696 (goto-char (point-max)))
1698 (while (setq entry (pop alist))
1699 (setq regexp (car entry))
1701 (while (re-search-forward regexp nil t)
1702 (let* ((start (and entry (match-beginning (nth 1 entry))))
1703 (end (and entry (match-end (nth 1 entry))))
1704 (from (match-beginning 0)))
1705 (when (or (eq t (nth 1 entry))
1706 (eval (nth 1 entry)))
1707 ;; That optional form returned non-nil, so we add the
1709 (gnus-article-add-button
1710 start end 'gnus-button-push
1711 (car (push (set-marker (make-marker) from)
1712 gnus-button-marker-list))))))))))
1714 ;; Add buttons to the head of an article.
1715 (defun gnus-article-add-buttons-to-head ()
1716 "Add buttons to the head of the article."
1719 (set-buffer gnus-article-buffer)
1720 (let ((buffer-read-only nil)
1721 (inhibit-point-motion-hooks t)
1722 (case-fold-search t)
1723 (alist gnus-header-button-alist)
1725 (nnheader-narrow-to-headers)
1727 ;; Each alist entry.
1728 (setq entry (car alist)
1730 (goto-char (point-min))
1731 (while (re-search-forward (car entry) nil t)
1732 ;; Each header matching the entry.
1733 (setq beg (match-beginning 0))
1734 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1735 (match-beginning 0))
1738 (while (re-search-forward (nth 1 entry) end t)
1739 ;; Each match within a header.
1740 (let* ((entry (cdr entry))
1741 (start (match-beginning (nth 1 entry)))
1742 (end (match-end (nth 1 entry)))
1743 (form (nth 2 entry)))
1744 (goto-char (match-end 0))
1746 (gnus-article-add-button
1747 start end (nth 3 entry)
1748 (buffer-substring (match-beginning (nth 4 entry))
1749 (match-end (nth 4 entry)))))))
1753 ;;; External functions:
1755 (defun gnus-article-add-button (from to fun &optional data)
1756 "Create a button between FROM and TO with callback FUN and data DATA."
1757 (and gnus-article-button-face
1758 (gnus-overlay-put (gnus-make-overlay from to)
1759 'face gnus-article-button-face))
1760 (gnus-add-text-properties
1762 (nconc (and gnus-article-mouse-face
1763 (list gnus-mouse-face-prop gnus-article-mouse-face))
1764 (list 'gnus-callback fun)
1765 (and data (list 'gnus-data data)))))
1767 ;;; Internal functions:
1769 (defun gnus-signature-toggle (end)
1771 (set-buffer gnus-article-buffer)
1772 (let ((buffer-read-only nil)
1773 (inhibit-point-motion-hooks t))
1774 (if (get-text-property end 'invisible)
1775 (article-unhide-text end (point-max))
1776 (article-hide-text end (point-max) gnus-hidden-properties)))))
1778 (defun gnus-button-entry ()
1779 ;; Return the first entry in `gnus-button-alist' matching this place.
1780 (let ((alist gnus-button-alist)
1783 (setq entry (pop alist))
1784 (if (looking-at (car entry))
1789 (defun gnus-button-push (marker)
1790 ;; Push button starting at MARKER.
1792 (set-buffer gnus-article-buffer)
1794 (let* ((entry (gnus-button-entry))
1795 (inhibit-point-motion-hooks t)
1797 (args (mapcar (lambda (group)
1798 (let ((string (buffer-substring
1799 (match-beginning group)
1800 (match-end group))))
1801 (gnus-set-text-properties
1802 0 (length string) nil string)
1809 (fboundp (symbol-value fun)))
1810 (apply (symbol-value fun) args))
1812 (gnus-message 1 "You must define `%S' to use this button"
1813 (cons fun args)))))))
1815 (defun gnus-button-message-id (message-id)
1818 (set-buffer gnus-summary-buffer)
1819 (gnus-summary-refer-article message-id)))
1821 (defun gnus-button-fetch-group (address)
1822 "Fetch GROUP specified by ADDRESS."
1823 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
1824 (error "Can't parse %s" address)
1825 (gnus-group-read-ephemeral-group
1826 (match-string 4 address)
1827 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
1828 (nntp-port-number ,(if (match-end 3)
1829 (match-string 3 address)
1832 (defun gnus-button-mailto (address)
1834 (set-buffer (gnus-copy-article-buffer))
1835 (message-reply address))
1837 (defun gnus-button-reply (address)
1838 ;; Reply to ADDRESS.
1839 (message-reply address))
1841 (defun gnus-button-url (address)
1843 (funcall browse-url-browser-function address))
1845 ;;; Next/prev buttons in the article buffer.
1847 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1848 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1850 (defvar gnus-prev-page-map nil)
1851 (unless gnus-prev-page-map
1852 (setq gnus-prev-page-map (make-sparse-keymap))
1853 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1854 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1856 (defun gnus-insert-prev-page-button ()
1857 (let ((buffer-read-only nil))
1859 gnus-prev-page-line-format nil
1860 `(gnus-prev t local-map ,gnus-prev-page-map
1861 gnus-callback gnus-article-button-prev-page))))
1863 (defvar gnus-next-page-map nil)
1864 (unless gnus-next-page-map
1865 (setq gnus-next-page-map (make-keymap))
1866 (suppress-keymap gnus-prev-page-map)
1867 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1868 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1870 (defun gnus-button-next-page ()
1871 "Go to the next page."
1873 (let ((win (selected-window)))
1874 (select-window (get-buffer-window gnus-article-buffer t))
1875 (gnus-article-next-page)
1876 (select-window win)))
1878 (defun gnus-button-prev-page ()
1879 "Go to the prev page."
1881 (let ((win (selected-window)))
1882 (select-window (get-buffer-window gnus-article-buffer t))
1883 (gnus-article-prev-page)
1884 (select-window win)))
1886 (defun gnus-insert-next-page-button ()
1887 (let ((buffer-read-only nil))
1888 (gnus-eval-format gnus-next-page-line-format nil
1889 `(gnus-next t local-map ,gnus-next-page-map
1891 gnus-article-button-next-page))))
1893 (defun gnus-article-button-next-page (arg)
1894 "Go to the next page."
1896 (let ((win (selected-window)))
1897 (select-window (get-buffer-window gnus-article-buffer t))
1898 (gnus-article-next-page)
1899 (select-window win)))
1901 (defun gnus-article-button-prev-page (arg)
1902 "Go to the prev page."
1904 (let ((win (selected-window)))
1905 (select-window (get-buffer-window gnus-article-buffer t))
1906 (gnus-article-prev-page)
1907 (select-window win)))
1911 ;;; gnus-art.el ends here