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)
78 * gnus-summary-write-to-file (article format -- overwrite)."
80 :type '(radio (function-item gnus-summary-save-in-rmail)
81 (function-item gnus-summary-save-in-mail)
82 (function-item gnus-summary-save-in-folder)
83 (function-item gnus-summary-save-in-file)
84 (function-item gnus-summary-save-in-vm)
85 (function-item gnus-summary-write-to-file)))
87 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
88 "A function generating a file name to save articles in Rmail format.
89 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
93 (defcustom gnus-mail-save-name 'gnus-plain-save-name
94 "A function generating a file name to save articles in Unix mail format.
95 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
99 (defcustom gnus-folder-save-name 'gnus-folder-save-name
100 "A function generating a file name to save articles in MH folder.
101 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
105 (defcustom gnus-file-save-name 'gnus-numeric-save-name
106 "A function generating a file name to save articles in article format.
107 The function is called with NEWSGROUP, HEADERS, and optional
112 (defcustom gnus-split-methods
113 '((gnus-article-archive-name))
114 "Variable used to suggest where articles are to be saved.
115 For instance, if you would like to save articles related to Gnus in
116 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
117 you could set this variable to something like:
119 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
120 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
122 This variable is an alist where the where the key is the match and the
123 value is a list of possible files to save in if the match is non-nil.
125 If the match is a string, it is used as a regexp match on the
126 article. If the match is a symbol, that symbol will be funcalled
127 from the buffer of the article to be saved with the newsgroup as the
128 parameter. If it is a list, it will be evaled in the same buffer.
130 If this form or function returns a string, this string will be used as
131 a possible file name; and if it returns a non-nil list, that list will
132 be used as possible file names."
134 :type '(repeat (choice (list function)
135 (cons regexp (repeat string))
138 (defcustom gnus-strict-mime t
139 "*If nil, MIME-decode even if there is no Mime-Version header."
143 (defcustom gnus-show-mime-method 'metamail-buffer
144 "Function to process a MIME message.
145 The function is called from the article buffer."
149 (defcustom gnus-decode-encoded-word-method (lambda ())
150 "*Function to decode a MIME encoded-words.
151 The function is called from the article buffer."
155 (defcustom gnus-page-delimiter "^\^L"
156 "*Regexp describing what to use as article page delimiters.
157 The default value is \"^\^L\", which is a form linefeed at the
158 beginning of a line."
162 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
163 "*The format specification for the article mode line.
164 See `gnus-summary-mode-line-format' for a closer description."
168 (defcustom gnus-article-mode-hook nil
169 "*A hook for Gnus article mode."
173 (defcustom gnus-article-menu-hook nil
174 "*Hook run after the creation of the article mode menu."
178 (defcustom gnus-article-prepare-hook nil
179 "*A hook called after an article has been prepared in the article buffer.
180 If you want to run a special decoding program like nkf, use this hook."
184 (defcustom gnus-article-button-face 'bold
185 "Face used for highlighting buttons in the article buffer.
187 An article button is a piece of text that you can activate by pressing
188 `RET' or `mouse-2' above it."
192 (defcustom gnus-article-mouse-face 'highlight
193 "Face used for mouse highlighting in the article buffer.
195 Article buttons will be displayed in this face when the cursor is
200 (defcustom gnus-signature-face 'italic
201 "Face used for highlighting a signature in the article buffer."
205 (defface gnus-header-from-face
208 (:foreground "light blue" :bold t :italic t))
211 (:foreground "MidnightBlue" :bold t :italic t))
213 (:bold t :italic t)))
214 "Face used for displaying from headers."
217 (defface gnus-header-subject-face
220 (:foreground "pink" :bold t :italic t))
223 (:foreground "firebrick" :bold t :italic t))
225 (:bold t :italic t)))
226 "Face used for displaying subject headers."
229 (defface gnus-header-newsgroups-face
232 (:foreground "yellow" :bold t :italic t))
235 (:foreground "indianred" :bold t :italic t))
237 (:bold t :italic t)))
238 "Face used for displaying newsgroups headers."
241 (defface gnus-header-name-face
244 (:foreground "cyan" :bold t))
247 (:foreground "DarkGreen" :bold t))
250 "Face used for displaying header names."
253 (defface gnus-header-content-face
256 (:foreground "forest green" :italic t))
259 (:foreground "DarkGreen" :italic t))
261 (:italic t))) "Face used for displaying header content."
264 (defcustom gnus-header-face-alist
265 '(("From" nil gnus-header-from-face)
266 ("Subject" nil gnus-header-subject-face)
267 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
268 ("" gnus-header-name-face gnus-header-content-face))
269 "Controls highlighting of article header.
271 An alist of the form (HEADER NAME CONTENT).
273 HEADER is a regular expression which should match the name of an
274 header header and NAME and CONTENT are either face names or nil.
276 The name of each header field will be displayed using the face
277 specified by the first element in the list where HEADER match the
278 header name and NAME is non-nil. Similarly, the content will be
279 displayed by the first non-nil matching CONTENT face."
281 :type '(repeat (list (regexp :tag "Header")
283 (item :tag "skip" nil)
284 (face :value default))
285 (choice :tag "Content"
286 (item :tag "skip" nil)
287 (face :value default)))))
289 ;;; Internal variables
291 (defvar gnus-article-mode-line-format-alist
292 (nconc '((?w (gnus-article-wash-status) ?s))
293 gnus-summary-mode-line-format-alist))
295 (defvar gnus-number-of-articles-to-be-saved nil)
297 ;;; Provide a mapping from `gnus-*' commands to Article commands.
304 (setq afunc (car func)
307 gfunc (intern (format "gnus-%s" func))))
309 `(lambda (&optional interactive &rest args)
310 ,(documentation afunc t)
311 (interactive (list t))
313 (set-buffer gnus-article-buffer)
315 (call-interactively ',afunc)
316 (apply ',afunc args)))))))
317 '(article-hide-headers
318 article-hide-boring-headers
319 article-treat-overstrike
320 (article-fill . gnus-article-word-wrap)
322 article-display-x-face
323 article-de-quoted-unreadable
324 article-mime-decode-quoted-printable
327 article-hide-signature
328 article-remove-trailing-blank-lines
329 article-strip-leading-blank-lines
330 article-strip-multiple-blank-lines
331 article-strip-blank-lines
333 article-date-original
336 (article-show-all . gnus-article-show-all-headers))))
338 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
340 ;;; Saving functions.
342 (defun gnus-article-save (save-buffer file &optional num)
343 "Save the currently selected article."
344 (unless gnus-save-all-headers
345 ;; Remove headers according to `gnus-saved-headers'.
346 (let ((gnus-visible-headers
347 (or gnus-saved-headers gnus-visible-headers))
348 (gnus-article-buffer save-buffer))
349 (gnus-article-hide-headers 1 t)))
350 (save-window-excursion
351 (if (not gnus-default-article-saver)
352 (error "No default saver is defined.")
353 ;; !!! Magic! The saving functions all save
354 ;; `gnus-original-article-buffer' (or so they think),
355 ;; but we bind that variable to our save-buffer.
356 (set-buffer gnus-article-buffer)
357 (let* ((gnus-original-article-buffer save-buffer)
360 ((not gnus-prompt-before-saving)
362 ((eq gnus-prompt-before-saving 'always)
365 (gnus-number-of-articles-to-be-saved
366 (when (eq gnus-prompt-before-saving t)
368 (set-buffer gnus-summary-buffer)
369 (funcall gnus-default-article-saver filename)))))
371 (defun gnus-read-save-file-name (prompt default-name &optional filename)
373 ((eq filename 'default)
377 (let* ((split-name (gnus-get-split-value gnus-split-methods))
379 (format prompt (if (and gnus-number-of-articles-to-be-saved
380 (> gnus-number-of-articles-to-be-saved 1))
381 (format "these %d articles"
382 gnus-number-of-articles-to-be-saved)
385 ;; Let the split methods have their say.
387 ;; No split name was found.
390 (concat prompt " (default "
391 (file-name-nondirectory default-name) ") ")
392 (file-name-directory default-name)
394 ;; A single split name was found
395 ((= 1 (length split-name))
396 (let* ((name (car split-name))
397 (dir (cond ((file-directory-p name)
398 (file-name-as-directory name))
399 ((file-exists-p name) name)
400 (t gnus-article-save-directory))))
402 (concat prompt " (default " name ") ")
404 ;; A list of splits was found.
406 (setq split-name (nreverse split-name))
408 (let ((file-name-history (nconc split-name file-name-history)))
411 (concat prompt " (`M-p' for defaults) ")
412 gnus-article-save-directory
414 (car (push result file-name-history)))))))
415 ;; Create the directory.
416 (gnus-make-directory (file-name-directory file))
417 ;; If we have read a directory, we append the default file name.
418 (when (file-directory-p file)
419 (setq file (concat (file-name-as-directory file)
420 (file-name-nondirectory default-name))))
421 ;; Possibly translate some characters.
422 (nnheader-translate-file-chars file)))))
424 (defun gnus-article-archive-name (group)
425 "Return the first instance of an \"Archive-name\" in the current buffer."
426 (let ((case-fold-search t))
427 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
428 (nnheader-concat gnus-article-save-directory
431 (defun gnus-summary-save-in-rmail (&optional filename)
432 "Append this article to Rmail file.
433 Optional argument FILENAME specifies file name.
434 Directory to save to is default to `gnus-article-save-directory'."
436 (gnus-set-global-variables)
438 (funcall gnus-rmail-save-name gnus-newsgroup-name
439 gnus-current-headers gnus-newsgroup-last-rmail)))
440 (setq filename (gnus-read-save-file-name
441 "Save %s in rmail file:" default-name filename))
442 (gnus-make-directory (file-name-directory filename))
443 (gnus-eval-in-buffer-window gnus-original-article-buffer
447 (gnus-output-to-rmail filename))))
448 ;; Remember the directory name to save articles
449 (setq gnus-newsgroup-last-rmail filename)))
451 (defun gnus-summary-save-in-mail (&optional filename)
452 "Append this article to Unix mail file.
453 Optional argument FILENAME specifies file name.
454 Directory to save to is default to `gnus-article-save-directory'."
456 (gnus-set-global-variables)
458 (funcall gnus-mail-save-name gnus-newsgroup-name
459 gnus-current-headers gnus-newsgroup-last-mail)))
460 (setq filename (gnus-read-save-file-name
461 "Save %s in Unix mail file:" default-name filename))
463 (expand-file-name filename
465 (file-name-directory default-name))))
466 (gnus-make-directory (file-name-directory filename))
467 (gnus-eval-in-buffer-window gnus-original-article-buffer
471 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
472 (gnus-output-to-rmail filename)
473 (let ((mail-use-rfc822 t))
474 (rmail-output filename 1 t t))))))
475 ;; Remember the directory name to save articles.
476 (setq gnus-newsgroup-last-mail filename)))
478 (defun gnus-summary-save-in-file (&optional filename overwrite)
479 "Append this article to file.
480 Optional argument FILENAME specifies file name.
481 Directory to save to is default to `gnus-article-save-directory'."
483 (gnus-set-global-variables)
485 (funcall gnus-file-save-name gnus-newsgroup-name
486 gnus-current-headers gnus-newsgroup-last-file)))
487 (setq filename (gnus-read-save-file-name
488 "Save %s in file:" default-name filename))
489 (gnus-make-directory (file-name-directory filename))
490 (gnus-eval-in-buffer-window gnus-original-article-buffer
495 (file-exists-p filename))
496 (delete-file filename))
497 (gnus-output-to-file filename))))
498 ;; Remember the directory name to save articles.
499 (setq gnus-newsgroup-last-file filename)))
501 (defun gnus-summary-write-to-file (&optional filename)
502 "Append this article body to a file.
503 Optional argument FILENAME specifies file name.
504 The directory to save in defaults to `gnus-article-save-directory'."
506 (gnus-summary-save-in-file nil t))
508 (defun gnus-summary-save-in-pipe (&optional command)
509 "Pipe this article to subprocess."
511 (gnus-set-global-variables)
513 (cond ((eq command 'default)
514 gnus-last-shell-command)
516 (t (read-string "Shell command on article: "
517 gnus-last-shell-command))))
518 (when (string-equal command "")
519 (setq command gnus-last-shell-command))
520 (gnus-eval-in-buffer-window gnus-article-buffer
523 (shell-command-on-region (point-min) (point-max) command nil)))
524 (setq gnus-last-shell-command command))
526 ;;; Article file names when saving.
528 (defun gnus-capitalize-newsgroup (newsgroup)
529 "Capitalize NEWSGROUP name."
530 (when (not (zerop (length newsgroup)))
531 (concat (char-to-string (upcase (aref newsgroup 0)))
532 (substring newsgroup 1))))
534 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
535 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
536 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
537 Otherwise, it is like ~/News/news/group/num."
540 (concat (if (gnus-use-long-file-name 'not-save)
541 (gnus-capitalize-newsgroup newsgroup)
542 (gnus-newsgroup-directory-form newsgroup))
543 "/" (int-to-string (mail-header-number headers)))
544 gnus-article-save-directory)))
546 (string-equal (file-name-directory default)
547 (file-name-directory last-file))
548 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
550 (or last-file default))))
552 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
553 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
554 If variable `gnus-use-long-file-name' is non-nil, it is
555 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
558 (concat (if (gnus-use-long-file-name 'not-save)
560 (gnus-newsgroup-directory-form newsgroup))
561 "/" (int-to-string (mail-header-number headers)))
562 gnus-article-save-directory)))
564 (string-equal (file-name-directory default)
565 (file-name-directory last-file))
566 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
568 (or last-file default))))
570 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
571 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
572 If variable `gnus-use-long-file-name' is non-nil, it is
573 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
576 (if (gnus-use-long-file-name 'not-save)
577 (gnus-capitalize-newsgroup newsgroup)
578 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
579 gnus-article-save-directory)))
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)
589 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
590 gnus-article-save-directory)))
594 ;;; Gnus article mode
597 (put 'gnus-article-mode 'mode-class 'special)
600 (gnus-define-keys gnus-article-mode-map
601 " " gnus-article-goto-next-page
602 "\177" gnus-article-goto-prev-page
603 [delete] gnus-article-goto-prev-page
604 "\C-c^" gnus-article-refer-article
605 "h" gnus-article-show-summary
606 "s" gnus-article-show-summary
607 "\C-c\C-m" gnus-article-mail
608 "?" gnus-article-describe-briefly
609 gnus-mouse-2 gnus-article-push-button
610 "\r" gnus-article-press-button
611 "\t" gnus-article-next-button
612 "\M-\t" gnus-article-prev-button
613 "e" gnus-article-edit
614 "<" beginning-of-buffer
616 "\C-c\C-i" gnus-info-find-node
619 "\C-d" gnus-article-read-summary-keys
620 "\M-*" gnus-article-read-summary-keys
621 "\M-g" gnus-article-read-summary-keys)
623 (substitute-key-definition
624 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
626 (defun gnus-article-make-menu-bar ()
627 (gnus-turn-off-edit-menu 'article)
628 (unless (boundp 'gnus-article-article-menu)
630 gnus-article-article-menu gnus-article-mode-map ""
632 ["Scroll forwards" gnus-article-goto-next-page t]
633 ["Scroll backwards" gnus-article-goto-prev-page t]
634 ["Show summary" gnus-article-show-summary t]
635 ["Fetch Message-ID at point" gnus-article-refer-article t]
636 ["Mail to address at point" gnus-article-mail t]
640 gnus-article-treatment-menu gnus-article-mode-map ""
642 ["Hide headers" gnus-article-hide-headers t]
643 ["Hide signature" gnus-article-hide-signature t]
644 ["Hide citation" gnus-article-hide-citation t]
645 ["Treat overstrike" gnus-article-treat-overstrike t]
646 ["Remove carriage return" gnus-article-remove-cr t]
647 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
649 (run-hooks 'gnus-article-menu-hook)))
651 (defun gnus-article-mode ()
652 "Major mode for displaying an article.
654 All normal editing commands are switched off.
656 The following commands are available in addition to all summary mode
658 \\<gnus-article-mode-map>
659 \\[gnus-article-next-page]\t Scroll the article one page forwards
660 \\[gnus-article-prev-page]\t Scroll the article one page backwards
661 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
662 \\[gnus-article-show-summary]\t Display the summary buffer
663 \\[gnus-article-mail]\t Send a reply to the address near point
664 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
665 \\[gnus-info-find-node]\t Go to the Gnus info node"
667 (when (and menu-bar-mode
668 (gnus-visual-p 'article-menu 'menu))
669 (gnus-article-make-menu-bar))
670 (kill-all-local-variables)
671 (gnus-simplify-mode-line)
672 (setq mode-name "Article")
673 (setq major-mode 'gnus-article-mode)
674 (make-local-variable 'minor-mode-alist)
675 (unless (assq 'gnus-show-mime minor-mode-alist)
676 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
677 (use-local-map gnus-article-mode-map)
678 (gnus-update-format-specifications nil 'article-mode)
679 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
680 (gnus-set-default-directory)
681 (buffer-disable-undo (current-buffer))
682 (setq buffer-read-only t)
683 (run-hooks 'gnus-article-mode-hook))
685 (defun gnus-article-setup-buffer ()
686 "Initialize the article buffer."
687 (let* ((name (if gnus-single-article-buffer "*Article*"
688 (concat "*Article " gnus-newsgroup-name "*")))
690 (progn (string-match "\\*Article" name)
691 (concat " *Original Article"
692 (substring name (match-end 0))))))
693 (setq gnus-article-buffer name)
694 (setq gnus-original-article-buffer original)
695 ;; This might be a variable local to the summary buffer.
696 (unless gnus-single-article-buffer
698 (set-buffer gnus-summary-buffer)
699 (setq gnus-article-buffer name)
700 (setq gnus-original-article-buffer original)
701 (gnus-set-global-variables)))
702 ;; Init original article buffer.
704 (set-buffer (get-buffer-create gnus-original-article-buffer))
705 (buffer-disable-undo (current-buffer))
706 (setq major-mode 'gnus-original-article-mode)
707 (gnus-add-current-to-buffer-list)
708 (make-local-variable 'gnus-original-article))
709 (if (get-buffer name)
712 (buffer-disable-undo (current-buffer))
713 (setq buffer-read-only t)
714 (gnus-add-current-to-buffer-list)
715 (unless (eq major-mode 'gnus-article-mode)
719 (set-buffer (get-buffer-create name))
720 (gnus-add-current-to-buffer-list)
722 (make-local-variable 'gnus-summary-buffer)
725 ;; Set article window start at LINE, where LINE is the number of lines
726 ;; from the head of the article.
727 (defun gnus-article-set-window-start (&optional line)
729 (get-buffer-window gnus-article-buffer t)
731 (set-buffer gnus-article-buffer)
732 (goto-char (point-min))
735 (gnus-message 6 "Moved to bookmark")
736 (search-forward "\n\n" nil t)
740 (defun gnus-article-prepare (article &optional all-headers header)
741 "Prepare ARTICLE in article mode buffer.
742 ARTICLE should either be an article number or a Message-ID.
743 If ARTICLE is an id, HEADER should be the article headers.
744 If ALL-HEADERS is non-nil, no headers are hidden."
746 ;; Make sure we start in a summary buffer.
747 (unless (eq major-mode 'gnus-summary-mode)
748 (set-buffer gnus-summary-buffer))
749 (setq gnus-summary-buffer (current-buffer))
750 ;; Make sure the connection to the server is alive.
751 (unless (gnus-server-opened
752 (gnus-find-method-for-group gnus-newsgroup-name))
753 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
754 (gnus-request-group gnus-newsgroup-name t))
755 (let* ((article (if header (mail-header-number header) article))
756 (summary-buffer (current-buffer))
757 (internal-hook gnus-article-internal-prepare-hook)
758 (group gnus-newsgroup-name)
761 (gnus-article-setup-buffer)
762 (set-buffer gnus-article-buffer)
763 ;; Deactivate active regions.
764 (when (and (boundp 'transient-mark-mode)
766 (setq mark-active nil))
767 (if (not (setq result (let ((buffer-read-only nil))
768 (gnus-request-article-this-buffer
770 ;; There is no such article.
772 (when (and (numberp article)
773 (not (memq article gnus-newsgroup-sparse)))
774 (setq gnus-article-current
775 (cons gnus-newsgroup-name article))
776 (set-buffer gnus-summary-buffer)
777 (setq gnus-current-article article)
778 (gnus-summary-mark-article article gnus-canceled-mark))
779 (unless (memq article gnus-newsgroup-sparse)
781 1 "No such article (may have expired or been canceled)")))
782 (if (or (eq result 'pseudo) (eq result 'nneething))
785 (set-buffer summary-buffer)
786 (setq gnus-last-article gnus-current-article
787 gnus-newsgroup-history (cons gnus-current-article
788 gnus-newsgroup-history)
789 gnus-current-article 0
790 gnus-current-headers nil
791 gnus-article-current nil)
792 (if (eq result 'nneething)
793 (gnus-configure-windows 'summary)
794 (gnus-configure-windows 'article))
795 (gnus-set-global-variables))
796 (gnus-set-mode-line 'article))
797 ;; The result from the `request' was an actual article -
798 ;; or at least some text that is now displayed in the
800 (when (and (numberp article)
801 (not (eq article gnus-current-article)))
802 ;; Seems like a new article has been selected.
803 ;; `gnus-current-article' must be an article number.
805 (set-buffer summary-buffer)
806 (setq gnus-last-article gnus-current-article
807 gnus-newsgroup-history (cons gnus-current-article
808 gnus-newsgroup-history)
809 gnus-current-article article
811 (gnus-summary-article-header gnus-current-article)
813 (cons gnus-newsgroup-name gnus-current-article))
814 (unless (vectorp gnus-current-headers)
815 (setq gnus-current-headers nil))
816 (gnus-summary-show-thread)
817 (run-hooks 'gnus-mark-article-hook)
818 (gnus-set-mode-line 'summary)
819 (when (gnus-visual-p 'article-highlight 'highlight)
820 (run-hooks 'gnus-visual-mark-article-hook))
821 ;; Set the global newsgroup variables here.
822 ;; Suggested by Jim Sisolak
823 ;; <sisolak@trans4.neep.wisc.edu>.
824 (gnus-set-global-variables)
825 (setq gnus-have-all-headers
826 (or all-headers gnus-show-all-headers))
828 (vectorp (gnus-summary-article-header article))
829 (gnus-cache-possibly-enter-article
831 (gnus-summary-article-header article)
832 (memq article gnus-newsgroup-marked)
833 (memq article gnus-newsgroup-dormant)
834 (memq article gnus-newsgroup-unreads)))))
835 (when (or (numberp article)
837 ;; Hooks for getting information from the article.
838 ;; This hook must be called before being narrowed.
839 (let (buffer-read-only)
840 (run-hooks 'internal-hook)
841 (run-hooks 'gnus-article-prepare-hook)
842 ;; Decode MIME message.
844 (if (or (not gnus-strict-mime)
845 (gnus-fetch-field "Mime-Version"))
846 (funcall gnus-show-mime-method)
847 (funcall gnus-decode-encoded-word-method)))
848 ;; Perform the article display hooks.
849 (run-hooks 'gnus-article-display-hook))
851 (goto-char (point-min))
852 (when gnus-break-pages
853 (gnus-narrow-to-page)))
854 (gnus-set-mode-line 'article)
855 (gnus-configure-windows 'article)
856 (goto-char (point-min))
859 (defun gnus-article-wash-status ()
860 "Return a string which display status of article washing."
862 (set-buffer gnus-article-buffer)
863 (let ((cite (article-hidden-text-p 'cite))
864 (headers (article-hidden-text-p 'headers))
865 (boring (article-hidden-text-p 'boring-headers))
866 (pgp (article-hidden-text-p 'pgp))
867 (pem (article-hidden-text-p 'pem))
868 (signature (article-hidden-text-p 'signature))
869 (overstrike (article-hidden-text-p 'overstrike))
870 (emphasis (article-hidden-text-p 'emphasis))
871 (mime gnus-show-mime))
872 (format "%c%c%c%c%c%c%c"
874 (if (or headers boring) ?h ? )
875 (if (or pgp pem) ?p ? )
877 (if overstrike ?o ? )
879 (if emphasis ?e ? )))))
881 (defun gnus-article-hide-headers-if-wanted ()
882 "Hide unwanted headers if `gnus-have-all-headers' is nil.
883 Provided for backwards compatibility."
884 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
886 (gnus-article-hide-headers)))
890 (defun gnus-output-to-rmail (file-name)
891 "Append the current article to an Rmail file named FILE-NAME."
893 ;; Most of these codes are borrowed from rmailout.el.
894 (setq file-name (expand-file-name file-name))
895 (setq rmail-default-rmail-file file-name)
896 (let ((artbuf (current-buffer))
897 (tmpbuf (get-buffer-create " *Gnus-output*")))
899 (or (get-file-buffer file-name)
900 (file-exists-p file-name)
901 (if (gnus-yes-or-no-p
902 (concat "\"" file-name "\" does not exist, create it? "))
903 (let ((file-buffer (create-file-buffer file-name)))
905 (set-buffer file-buffer)
906 (rmail-insert-rmail-file-header)
907 (let ((require-final-newline nil))
908 (gnus-write-buffer file-name)))
909 (kill-buffer file-buffer))
910 (error "Output file does not exist")))
912 (buffer-disable-undo (current-buffer))
914 (insert-buffer-substring artbuf)
915 (gnus-convert-article-to-rmail)
916 ;; Decide whether to append to a file or to an Emacs buffer.
917 (let ((outbuf (get-file-buffer file-name)))
919 (append-to-file (point-min) (point-max) file-name)
920 ;; File has been visited, in buffer OUTBUF.
922 (let ((buffer-read-only nil)
923 (msg (and (boundp 'rmail-current-message)
924 (symbol-value 'rmail-current-message))))
925 ;; If MSG is non-nil, buffer is in RMAIL mode.
928 (narrow-to-region (point-max) (point-max)))
929 (insert-buffer-substring tmpbuf)
931 (goto-char (point-min))
933 (search-backward "\^_")
934 (narrow-to-region (point) (point-max))
935 (goto-char (1+ (point-min)))
936 (rmail-count-new-messages t)
937 (rmail-show-message msg))))))
938 (kill-buffer tmpbuf)))
940 (defun gnus-output-to-file (file-name)
941 "Append the current article to a file named FILE-NAME."
942 (let ((artbuf (current-buffer)))
943 (nnheader-temp-write nil
944 (insert-buffer-substring artbuf)
945 ;; Append newline at end of the buffer as separator, and then
947 (goto-char (point-max))
949 (append-to-file (point-min) (point-max) file-name))))
951 (defun gnus-convert-article-to-rmail ()
952 "Convert article in current buffer to Rmail message format."
953 (let ((buffer-read-only nil))
954 ;; Convert article directly into Babyl format.
955 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
956 (goto-char (point-min))
957 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
958 (while (search-forward "\n\^_" nil t) ;single char
959 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
960 (goto-char (point-max))
963 (defun gnus-narrow-to-page (&optional arg)
964 "Narrow the article buffer to a page.
965 If given a numerical ARG, move forward ARG pages."
967 (setq arg (if arg (prefix-numeric-value arg) 0))
969 (set-buffer gnus-article-buffer)
970 (goto-char (point-min))
972 ;; Remove any old next/prev buttons.
973 (when (gnus-visual-p 'page-marker)
974 (let ((buffer-read-only nil))
975 (gnus-remove-text-with-property 'gnus-prev)
976 (gnus-remove-text-with-property 'gnus-next)))
979 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
981 (re-search-forward page-delimiter nil 'move arg)))
982 (goto-char (match-end 0)))
985 (if (re-search-forward page-delimiter nil 'move)
988 (when (and (gnus-visual-p 'page-marker)
989 (not (= (point-min) 1)))
991 (goto-char (point-min))
992 (gnus-insert-prev-page-button)))
993 (when (and (gnus-visual-p 'page-marker)
994 (< (+ (point-max) 2) (buffer-size)))
996 (goto-char (point-max))
997 (gnus-insert-next-page-button)))))
999 ;; Article mode commands
1001 (defun gnus-article-goto-next-page ()
1002 "Show the next page of the article."
1004 (when (gnus-article-next-page)
1005 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
1007 (defun gnus-article-goto-prev-page ()
1008 "Show the next page of the article."
1010 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
1011 (gnus-article-prev-page nil)))
1013 (defun gnus-article-next-page (&optional lines)
1014 "Show the next page of the current article.
1015 If end of article, return non-nil. Otherwise return nil.
1016 Argument LINES specifies lines to be scrolled up."
1018 (move-to-window-line -1)
1021 (and (pos-visible-in-window-p) ;Not continuation line.
1023 ;; Nothing in this page.
1024 (if (or (not gnus-break-pages)
1027 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
1029 (gnus-narrow-to-page 1) ;Go to next page.
1031 ;; More in this page.
1035 ;; Long lines may cause an end-of-buffer error.
1036 (goto-char (point-max))))
1037 (move-to-window-line 0)
1040 (defun gnus-article-prev-page (&optional lines)
1041 "Show previous page of current article.
1042 Argument LINES specifies lines to be scrolled down."
1044 (move-to-window-line 0)
1045 (if (and gnus-break-pages
1047 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
1049 (gnus-narrow-to-page -1) ;Go to previous page.
1050 (goto-char (point-max))
1056 (move-to-window-line 0))))
1058 (defun gnus-article-refer-article ()
1059 "Read article specified by message-id around point."
1061 (let ((point (point)))
1062 (search-forward ">" nil t) ;Move point to end of "<....>".
1063 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
1064 (let ((message-id (match-string 1)))
1066 (set-buffer gnus-summary-buffer)
1067 (gnus-summary-refer-article message-id))
1069 (error "No references around point"))))
1071 (defun gnus-article-show-summary ()
1072 "Reconfigure windows to show summary buffer."
1074 (gnus-configure-windows 'article)
1075 (gnus-summary-goto-subject gnus-current-article))
1077 (defun gnus-article-describe-briefly ()
1078 "Describe article mode commands briefly."
1081 (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")))
1083 (defun gnus-article-summary-command ()
1084 "Execute the last keystroke in the summary buffer."
1086 (let ((obuf (current-buffer))
1087 (owin (current-window-configuration))
1089 (switch-to-buffer gnus-summary-buffer 'norecord)
1090 (setq func (lookup-key (current-local-map) (this-command-keys)))
1091 (call-interactively func)
1093 (set-window-configuration owin)
1094 (set-window-point (get-buffer-window (current-buffer)) (point))))
1096 (defun gnus-article-summary-command-nosave ()
1097 "Execute the last keystroke in the summary buffer."
1100 (pop-to-buffer gnus-summary-buffer 'norecord)
1101 (setq func (lookup-key (current-local-map) (this-command-keys)))
1102 (call-interactively func)))
1104 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
1105 "Read a summary buffer key sequence and execute it from the article buffer."
1108 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
1109 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
1110 "=" "^" "\M-^" "|"))
1117 (set-buffer gnus-summary-buffer)
1118 (push (or key last-command-event) unread-command-events)
1119 (setq keys (read-key-sequence nil)))
1122 (if (or (member keys nosaves)
1123 (member keys nosave-but-article)
1124 (member keys nosave-in-article))
1126 (save-window-excursion
1127 (pop-to-buffer gnus-summary-buffer 'norecord)
1128 (setq func (lookup-key (current-local-map) keys)))
1131 (unless (member keys nosave-in-article)
1132 (set-buffer gnus-summary-buffer))
1133 (call-interactively func))
1134 (when (member keys nosave-but-article)
1135 (pop-to-buffer gnus-article-buffer 'norecord)))
1136 ;; These commands should restore window configuration.
1137 (let ((obuf (current-buffer))
1138 (owin (current-window-configuration))
1141 (if not-restore-window
1142 (pop-to-buffer gnus-summary-buffer 'norecord)
1143 (switch-to-buffer gnus-summary-buffer 'norecord))
1144 (setq in-buffer (current-buffer))
1145 (if (setq func (lookup-key (current-local-map) keys))
1146 (call-interactively func)
1148 (when (eq in-buffer (current-buffer))
1150 (unless not-restore-window
1151 (set-window-configuration owin))
1152 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
1154 (defun gnus-article-hide (&optional arg force)
1155 "Hide all the gruft in the current article.
1156 This means that PGP stuff, signatures, cited text and (some)
1157 headers will be hidden.
1158 If given a prefix, show the hidden text instead."
1159 (interactive (list current-prefix-arg 'force))
1160 (gnus-article-hide-headers arg)
1161 (gnus-article-hide-pgp arg)
1162 (gnus-article-hide-citation-maybe arg force)
1163 (gnus-article-hide-signature arg))
1165 (defun gnus-article-maybe-highlight ()
1166 "Do some article highlighting if `article-visual' is non-nil."
1167 (when (gnus-visual-p 'article-highlight 'highlight)
1168 (gnus-article-highlight-some)))
1170 (defun gnus-request-article-this-buffer (article group)
1171 "Get an article and insert it into this buffer."
1172 (let (do-update-line)
1176 (gnus-kill-all-overlays)
1177 (setq group (or group gnus-newsgroup-name))
1179 ;; Open server if it has closed.
1180 (gnus-check-server (gnus-find-method-for-group group))
1182 ;; Using `gnus-request-article' directly will insert the article into
1183 ;; `nntp-server-buffer' - so we'll save some time by not having to
1184 ;; copy it from the server buffer into the article buffer.
1186 ;; We only request an article by message-id when we do not have the
1187 ;; headers for it, so we'll have to get those.
1188 (when (stringp article)
1189 (let ((gnus-override-method gnus-refer-article-method))
1190 (gnus-read-header article)))
1192 ;; If the article number is negative, that means that this article
1193 ;; doesn't belong in this newsgroup (possibly), so we find its
1194 ;; message-id and request it by id instead of number.
1195 (when (and (numberp article)
1197 (get-buffer gnus-summary-buffer)
1198 (buffer-name (get-buffer gnus-summary-buffer)))
1200 (set-buffer gnus-summary-buffer)
1201 (let ((header (gnus-summary-article-header article)))
1204 ((memq article gnus-newsgroup-sparse)
1205 ;; This is a sparse gap article.
1206 (setq do-update-line article)
1207 (setq article (mail-header-id header))
1208 (let ((gnus-override-method gnus-refer-article-method))
1209 (gnus-read-header article))
1210 (setq gnus-newsgroup-sparse
1211 (delq article gnus-newsgroup-sparse)))
1213 ;; It's a real article.
1214 (setq article (mail-header-id header)))
1216 ;; It is an extracted pseudo-article.
1217 (setq article 'pseudo)
1218 (gnus-request-pseudo-article header))))
1220 (let ((method (gnus-find-method-for-group
1221 gnus-newsgroup-name)))
1222 (if (not (eq (car method) 'nneething))
1224 (let ((dir (concat (file-name-as-directory (nth 1 method))
1225 (mail-header-subject header))))
1226 (when (file-directory-p dir)
1227 (setq article 'nneething)
1228 (gnus-group-enter-directory dir))))))))
1231 ;; Refuse to select canceled articles.
1232 ((and (numberp article)
1234 (get-buffer gnus-summary-buffer)
1235 (buffer-name (get-buffer gnus-summary-buffer))
1236 (eq (cdr (save-excursion
1237 (set-buffer gnus-summary-buffer)
1238 (assq article gnus-newsgroup-reads)))
1239 gnus-canceled-mark))
1241 ;; We first check `gnus-original-article-buffer'.
1242 ((and (get-buffer gnus-original-article-buffer)
1245 (set-buffer gnus-original-article-buffer)
1246 (and (equal (car gnus-original-article) group)
1247 (eq (cdr gnus-original-article) article))))
1248 (insert-buffer-substring gnus-original-article-buffer)
1250 ;; Check the backlog.
1251 ((and gnus-keep-backlog
1252 (gnus-backlog-request-article group article (current-buffer)))
1254 ;; Check asynchronous pre-fetch.
1255 ((gnus-async-request-fetched-article group article (current-buffer))
1256 (gnus-async-prefetch-next group article gnus-summary-buffer)
1259 ((and gnus-use-cache
1261 (gnus-cache-request-article article group))
1263 ;; Get the article and put into the article buffer.
1264 ((or (stringp article) (numberp article))
1265 (let ((gnus-override-method
1266 (and (stringp article) gnus-refer-article-method))
1267 (buffer-read-only nil))
1269 (gnus-kill-all-overlays)
1270 (when (gnus-request-article article group (current-buffer))
1271 (when (numberp article)
1272 (gnus-async-prefetch-next group article gnus-summary-buffer)
1273 (when gnus-keep-backlog
1274 (gnus-backlog-enter-article
1275 group article (current-buffer))))
1280 ;; Take the article from the original article buffer
1281 ;; and place it in the buffer it's supposed to be in.
1282 (when (and (get-buffer gnus-article-buffer)
1284 (equal (buffer-name (current-buffer))
1285 (buffer-name (get-buffer gnus-article-buffer))))
1287 (if (get-buffer gnus-original-article-buffer)
1288 (set-buffer (get-buffer gnus-original-article-buffer))
1289 (set-buffer (get-buffer-create gnus-original-article-buffer))
1290 (buffer-disable-undo (current-buffer))
1291 (setq major-mode 'gnus-original-article-mode)
1292 (setq buffer-read-only t)
1293 (gnus-add-current-to-buffer-list))
1294 (let (buffer-read-only)
1296 (insert-buffer-substring gnus-article-buffer))
1297 (setq gnus-original-article (cons group article))))
1299 ;; Update sparse articles.
1300 (when (and do-update-line
1301 (or (numberp article)
1303 (let ((buf (current-buffer)))
1304 (set-buffer gnus-summary-buffer)
1305 (gnus-summary-update-article do-update-line)
1306 (gnus-summary-goto-subject do-update-line nil t)
1307 (set-window-point (get-buffer-window (current-buffer) t)
1309 (set-buffer buf))))))
1311 (defun gnus-article-date-ut (&optional type highlight)
1312 "Convert DATE date to universal time in the current article.
1313 If TYPE is `local', convert to local time; if it is `lapsed', output
1314 how much time has lapsed since DATE."
1315 (interactive (list 'ut t))
1316 (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1318 (set-buffer gnus-article-buffer)
1319 (article-date-ut type highlight headers))))
1325 (defcustom gnus-article-edit-mode-hook nil
1326 "Hook run in article edit mode buffers."
1330 (defvar gnus-article-edit-done-function nil)
1332 (defvar gnus-article-edit-mode-map nil)
1334 (unless gnus-article-edit-mode-map
1335 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1337 (gnus-define-keys gnus-article-edit-mode-map
1338 "\C-c\C-c" gnus-article-edit-done
1339 "\C-c\C-k" gnus-article-edit-exit)
1341 (gnus-define-keys (gnus-article-edit-wash-map
1342 "\C-c\C-w" gnus-article-edit-mode-map)
1343 "f" gnus-article-edit-full-stops))
1345 (defun gnus-article-edit-mode ()
1346 "Major mode for editing articles.
1347 This is an extended text-mode.
1349 \\{gnus-article-edit-mode-map}"
1351 (kill-all-local-variables)
1352 (setq major-mode 'gnus-article-edit-mode)
1353 (setq mode-name "Article Edit")
1354 (use-local-map gnus-article-edit-mode-map)
1355 (make-local-variable 'gnus-article-edit-done-function)
1356 (make-local-variable 'gnus-prev-winconf)
1357 (setq buffer-read-only nil)
1358 (buffer-enable-undo)
1360 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1362 (defun gnus-article-edit (&optional force)
1363 "Edit the current article.
1364 This will have permanent effect only in mail groups.
1365 If FORCE is non-nil, allow editing of articles even in read-only
1368 (when (and (not force)
1369 (gnus-group-read-only-p))
1370 (error "The current newsgroup does not support article editing."))
1371 (gnus-article-edit-article
1373 (gnus-summary-edit-article-done
1374 ,(or (mail-header-references gnus-current-headers) "")
1375 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1377 (defun gnus-article-edit-article (exit-func)
1378 "Start editing the contents of the current article buffer."
1379 (let ((winconf (current-window-configuration)))
1380 (set-buffer gnus-article-buffer)
1381 (gnus-article-edit-mode)
1382 (set-text-properties (point-min) (point-max) nil)
1383 (gnus-configure-windows 'edit-article)
1384 (setq gnus-article-edit-done-function exit-func)
1385 (setq gnus-prev-winconf winconf)
1386 (gnus-message 6 "C-c C-c to end edits")))
1388 (defun gnus-article-edit-done ()
1389 "Update the article edits and exit."
1391 (let ((func gnus-article-edit-done-function)
1392 (buf (current-buffer))
1393 (start (window-start)))
1394 (gnus-article-edit-exit)
1397 (let ((buffer-read-only nil))
1400 (set-window-start (get-buffer-window buf) start)
1401 (set-window-point (get-buffer-window buf) (point))))
1403 (defun gnus-article-edit-exit ()
1404 "Exit the article editing without updating."
1406 ;; We remove all text props from the article buffer.
1407 (let ((buf (format "%s" (buffer-string)))
1408 (curbuf (current-buffer))
1410 (window-start (window-start)))
1413 (let ((winconf gnus-prev-winconf))
1415 ;; The cache and backlog have to be flushed somewhat.
1416 (when gnus-use-cache
1417 (gnus-cache-update-article
1418 (car gnus-article-current) (cdr gnus-article-current)))
1419 (when gnus-keep-backlog
1420 (gnus-backlog-remove-article
1421 (car gnus-article-current) (cdr gnus-article-current)))
1422 ;; Flush original article as well.
1424 (when (get-buffer gnus-original-article-buffer)
1425 (set-buffer gnus-original-article-buffer)
1426 (setq gnus-original-article nil)))
1427 (set-window-configuration winconf)
1428 ;; Tippy-toe some to make sure that point remains where it was.
1429 (let ((buf (current-buffer)))
1431 (set-window-start (get-buffer-window (current-buffer)) window-start)
1433 (set-buffer buf)))))
1435 (defun gnus-article-edit-full-stops ()
1436 "Interactively repair spacing at end of sentences."
1439 (goto-char (point-min))
1440 (search-forward-regexp "^$" nil t)
1441 (let ((case-fold-search nil))
1442 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1445 ;;; Article highlights
1448 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1450 ;;; Internal Variables:
1452 (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_=#$@~`%&*+|\\/]"
1453 "Regular expression that matches URLs."
1457 (defcustom gnus-button-alist
1458 `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
1459 t gnus-button-message-id 3)
1460 ("\\(<?\\(url: ?\\)?news://\\([^>\n\t ]*\\)>?\\)" 1 t
1461 gnus-button-fetch-group 3)
1462 ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1463 gnus-button-message-id 3)
1464 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-url-mailto 2)
1465 ;; This is how URLs _should_ be embedded in text...
1466 ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1467 ;; Next regexp stolen from highlight-headers.el.
1468 ;; Modified by Vladimir Alexiev.
1469 (,gnus-button-url-regexp 0 t gnus-button-url 0))
1470 "Alist of regexps matching buttons in article bodies.
1472 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1473 REGEXP: is the string matching text around the button,
1474 BUTTON: is the number of the regexp grouping actually matching the button,
1475 FORM: is a lisp expression which must eval to true for the button to
1477 CALLBACK: is the function to call when the user push this button, and each
1478 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1480 CALLBACK can also be a variable, in that case the value of that
1481 variable it the real callback function."
1483 :type '(repeat (list regexp
1484 (integer :tag "Button")
1486 (function :tag "Callback")
1489 (integer :tag "Regexp group")))))
1491 (defcustom gnus-header-button-alist
1492 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1493 0 t gnus-button-message-id 0)
1494 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1495 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
1496 0 t gnus-button-mailto 0)
1497 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1498 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1499 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1500 gnus-button-message-id 3))
1501 "Alist of headers and regexps to match buttons in article heads.
1503 This alist is very similar to `gnus-button-alist', except that each
1504 alist has an additional HEADER element first in each entry:
1506 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1508 HEADER is a regexp to match a header. For a fuller explanation, see
1509 `gnus-button-alist'."
1511 :type '(repeat (list (regexp :tag "Header")
1513 (integer :tag "Button")
1515 (function :tag "Callback")
1518 (integer :tag "Regexp group")))))
1520 (defvar gnus-button-regexp nil)
1521 (defvar gnus-button-marker-list nil)
1522 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1524 (defvar gnus-button-last nil)
1525 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1529 (defun gnus-article-push-button (event)
1530 "Check text under the mouse pointer for a callback function.
1531 If the text under the mouse pointer has a `gnus-callback' property,
1532 call it with the value of the `gnus-data' text property."
1534 (set-buffer (window-buffer (posn-window (event-start event))))
1535 (let* ((pos (posn-point (event-start event)))
1536 (data (get-text-property pos 'gnus-data))
1537 (fun (get-text-property pos 'gnus-callback)))
1539 (funcall fun data))))
1541 (defun gnus-article-press-button ()
1542 "Check text at point for a callback function.
1543 If the text at point has a `gnus-callback' property,
1544 call it with the value of the `gnus-data' text property."
1546 (let* ((data (get-text-property (point) 'gnus-data))
1547 (fun (get-text-property (point) 'gnus-callback)))
1549 (funcall fun data))))
1551 (defun gnus-article-prev-button (n)
1552 "Move point to N buttons backward.
1553 If N is negative, move forward instead."
1555 (gnus-article-next-button (- n)))
1557 (defun gnus-article-next-button (n)
1558 "Move point to N buttons forward.
1559 If N is negative, move backward instead."
1561 (let ((function (if (< n 0) 'previous-single-property-change
1562 'next-single-property-change))
1563 (inhibit-point-motion-hooks t)
1565 (limit (if (< n 0) (point-min) (point-max))))
1567 (while (and (not (= limit (point)))
1569 ;; Skip past the current button.
1570 (when (get-text-property (point) 'gnus-callback)
1571 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1572 ;; Go to the next (or previous) button.
1573 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1574 ;; Put point at the start of the button.
1575 (when (and backward (not (get-text-property (point) 'gnus-callback)))
1576 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1577 ;; Skip past intangible buttons.
1578 (when (get-text-property (point) 'intangible)
1582 (gnus-message 5 "No more buttons"))
1585 (defun gnus-article-highlight (&optional force)
1586 "Highlight current article.
1587 This function calls `gnus-article-highlight-headers',
1588 `gnus-article-highlight-citation',
1589 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1590 do the highlighting. See the documentation for those functions."
1591 (interactive (list 'force))
1592 (gnus-article-highlight-headers)
1593 (gnus-article-highlight-citation force)
1594 (gnus-article-highlight-signature)
1595 (gnus-article-add-buttons force)
1596 (gnus-article-add-buttons-to-head))
1598 (defun gnus-article-highlight-some (&optional force)
1599 "Highlight current article.
1600 This function calls `gnus-article-highlight-headers',
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-signature)
1606 (gnus-article-add-buttons))
1608 (defun gnus-article-highlight-headers ()
1609 "Highlight article headers as specified by `gnus-header-face-alist'."
1612 (set-buffer gnus-article-buffer)
1614 (let ((alist gnus-header-face-alist)
1615 (buffer-read-only nil)
1616 (case-fold-search t)
1617 (inhibit-point-motion-hooks t)
1618 entry regexp header-face field-face from hpoints fpoints)
1619 (goto-char (point-min))
1620 (when (search-forward "\n\n" nil t)
1621 (narrow-to-region (1- (point)) (point-min))
1622 (while (setq entry (pop alist))
1623 (goto-char (point-min))
1624 (setq regexp (concat "^\\("
1625 (if (string-equal "" (nth 0 entry))
1629 header-face (nth 1 entry)
1630 field-face (nth 2 entry))
1631 (while (and (re-search-forward regexp nil t)
1635 (unless (search-forward ":" nil t)
1637 (when (and header-face
1638 (not (memq (point) hpoints)))
1639 (push (point) hpoints)
1640 (gnus-put-text-property from (point) 'face header-face))
1641 (when (and field-face
1642 (not (memq (setq from (point)) fpoints)))
1644 (if (re-search-forward "^[^ \t]" nil t)
1646 (goto-char (point-max)))
1647 (gnus-put-text-property from (point) 'face field-face)))))))))
1649 (defun gnus-article-highlight-signature ()
1650 "Highlight the signature in an article.
1651 It does this by highlighting everything after
1652 `gnus-signature-separator' using `gnus-signature-face'."
1655 (set-buffer gnus-article-buffer)
1656 (let ((buffer-read-only nil)
1657 (inhibit-point-motion-hooks t))
1659 (when (and gnus-signature-face
1660 (article-narrow-to-signature))
1661 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1662 'face gnus-signature-face)
1664 (article-search-signature)
1665 (let ((start (match-beginning 0))
1666 (end (set-marker (make-marker) (1+ (match-end 0)))))
1667 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1670 (defun gnus-article-add-buttons (&optional force)
1671 "Find external references in the article and make buttons of them.
1672 \"External references\" are things like Message-IDs and URLs, as
1673 specified by `gnus-button-alist'."
1674 (interactive (list 'force))
1676 (set-buffer gnus-article-buffer)
1677 ;; Remove all old markers.
1678 (while gnus-button-marker-list
1679 (set-marker (pop gnus-button-marker-list) nil))
1680 (let ((buffer-read-only nil)
1681 (inhibit-point-motion-hooks t)
1682 (case-fold-search t)
1683 (alist gnus-button-alist)
1685 (goto-char (point-min))
1686 ;; We skip the headers.
1687 (unless (search-forward "\n\n" nil t)
1688 (goto-char (point-max)))
1690 (while (setq entry (pop alist))
1691 (setq regexp (car entry))
1693 (while (re-search-forward regexp nil t)
1694 (let* ((start (and entry (match-beginning (nth 1 entry))))
1695 (end (and entry (match-end (nth 1 entry))))
1696 (from (match-beginning 0)))
1697 (when (or (eq t (nth 1 entry))
1698 (eval (nth 1 entry)))
1699 ;; That optional form returned non-nil, so we add the
1701 (gnus-article-add-button
1702 start end 'gnus-button-push
1703 (car (push (set-marker (make-marker) from)
1704 gnus-button-marker-list))))))))))
1706 ;; Add buttons to the head of an article.
1707 (defun gnus-article-add-buttons-to-head ()
1708 "Add buttons to the head of the article."
1711 (set-buffer gnus-article-buffer)
1712 (let ((buffer-read-only nil)
1713 (inhibit-point-motion-hooks t)
1714 (case-fold-search t)
1715 (alist gnus-header-button-alist)
1717 (nnheader-narrow-to-headers)
1719 ;; Each alist entry.
1720 (setq entry (car alist)
1722 (goto-char (point-min))
1723 (while (re-search-forward (car entry) nil t)
1724 ;; Each header matching the entry.
1725 (setq beg (match-beginning 0))
1726 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1727 (match-beginning 0))
1730 (while (re-search-forward (nth 1 entry) end t)
1731 ;; Each match within a header.
1732 (let* ((entry (cdr entry))
1733 (start (match-beginning (nth 1 entry)))
1734 (end (match-end (nth 1 entry)))
1735 (form (nth 2 entry)))
1736 (goto-char (match-end 0))
1738 (gnus-article-add-button
1739 start end (nth 3 entry)
1740 (buffer-substring (match-beginning (nth 4 entry))
1741 (match-end (nth 4 entry)))))))
1745 ;;; External functions:
1747 (defun gnus-article-add-button (from to fun &optional data)
1748 "Create a button between FROM and TO with callback FUN and data DATA."
1749 (when gnus-article-button-face
1750 (gnus-overlay-put (gnus-make-overlay from to)
1751 'face gnus-article-button-face))
1752 (gnus-add-text-properties
1754 (nconc (and gnus-article-mouse-face
1755 (list gnus-mouse-face-prop gnus-article-mouse-face))
1756 (list 'gnus-callback fun)
1757 (and data (list 'gnus-data data)))))
1759 ;;; Internal functions:
1761 (defun gnus-signature-toggle (end)
1763 (set-buffer gnus-article-buffer)
1764 (let ((buffer-read-only nil)
1765 (inhibit-point-motion-hooks t))
1766 (if (get-text-property end 'invisible)
1767 (article-unhide-text end (point-max))
1768 (article-hide-text end (point-max) gnus-hidden-properties)))))
1770 (defun gnus-button-entry ()
1771 ;; Return the first entry in `gnus-button-alist' matching this place.
1772 (let ((alist gnus-button-alist)
1775 (setq entry (pop alist))
1776 (if (looking-at (car entry))
1781 (defun gnus-button-push (marker)
1782 ;; Push button starting at MARKER.
1784 (set-buffer gnus-article-buffer)
1786 (let* ((entry (gnus-button-entry))
1787 (inhibit-point-motion-hooks t)
1789 (args (mapcar (lambda (group)
1790 (let ((string (buffer-substring
1791 (match-beginning group)
1792 (match-end group))))
1793 (gnus-set-text-properties
1794 0 (length string) nil string)
1801 (fboundp (symbol-value fun)))
1802 (apply (symbol-value fun) args))
1804 (gnus-message 1 "You must define `%S' to use this button"
1805 (cons fun args)))))))
1807 (defun gnus-button-message-id (message-id)
1810 (set-buffer gnus-summary-buffer)
1811 (gnus-summary-refer-article message-id)))
1813 (defun gnus-button-fetch-group (address)
1814 "Fetch GROUP specified by ADDRESS."
1815 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
1816 (error "Can't parse %s" address)
1817 (gnus-group-read-ephemeral-group
1818 (match-string 4 address)
1819 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
1820 (nntp-port-number ,(if (match-end 3)
1821 (match-string 3 address)
1824 (defun gnus-split-string (string pattern)
1825 "Return a list of substrings of STRING which are separated by PATTERN."
1826 (let (parts (start 0))
1827 (while (string-match pattern string start)
1828 (setq parts (cons (substring string start (match-beginning 0)) parts)
1829 start (match-end 0)))
1830 (nreverse (cons (substring string start) parts))))
1832 (defun gnus-url-parse-query-string (query &optional downcase)
1833 (let (retval pairs cur key val)
1834 (setq pairs (gnus-split-string query "&"))
1836 (setq cur (car pairs)
1838 (if (not (string-match "=" cur))
1840 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
1841 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
1843 (setq key (downcase key)))
1844 (setq cur (assoc key retval))
1846 (setcdr cur (cons val (cdr cur)))
1847 (setq retval (cons (list key val) retval)))))
1850 (defun gnus-url-unhex (x)
1857 (defun gnus-url-unhex-string (str &optional allow-newlines)
1858 "Remove %XXX embedded spaces, etc in a url.
1859 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
1860 decoding of carriage returns and line feeds in the string, which is normally
1861 forbidden in URL encoding."
1862 (setq str (or str ""))
1864 (case-fold-search t))
1865 (while (string-match "%[0-9a-f][0-9a-f]" str)
1866 (let* ((start (match-beginning 0))
1867 (ch1 (gnus-url-unhex (elt str (+ start 1))))
1869 (gnus-url-unhex (elt str (+ start 2))))))
1871 tmp (substring str 0 start)
1874 (char-to-string code))
1875 ((or (= code ?\n) (= code ?\r))
1877 (t (char-to-string code))))
1878 str (substring str (match-end 0)))))
1879 (setq tmp (concat tmp str))
1882 (defun gnus-url-mailto (url)
1883 ;; Send mail to someone
1884 (if (not (string-match "mailto:/*\\(.*\\)" url))
1885 (error "Malformed mailto link: %s" url))
1886 (setq url (substring url (match-beginning 1) nil))
1887 (let (to args source-url subject func)
1888 (if (string-match (regexp-quote "?") url)
1889 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
1890 args (gnus-url-parse-query-string
1891 (substring url (match-end 0) nil) t))
1892 (setq to (gnus-url-unhex-string url)))
1893 (setq args (cons (list "to" to) args)
1894 subject (cdr-safe (assoc "subject" args)))
1897 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
1900 (message-position-on-field (caar args)))
1901 (insert (mapconcat 'identity (cdar args) ", "))
1902 (setq args (cdr args)))
1905 (message-goto-subject))))
1907 (defun gnus-button-mailto (address)
1909 (set-buffer (gnus-copy-article-buffer))
1910 (message-reply address))
1912 (defun gnus-button-reply (address)
1913 ;; Reply to ADDRESS.
1914 (message-reply address))
1916 (defun gnus-button-url (address)
1918 (funcall browse-url-browser-function address))
1920 ;;; Next/prev buttons in the article buffer.
1922 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1923 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1925 (defvar gnus-prev-page-map nil)
1926 (unless gnus-prev-page-map
1927 (setq gnus-prev-page-map (make-sparse-keymap))
1928 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1929 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1931 (defun gnus-insert-prev-page-button ()
1932 (let ((buffer-read-only nil))
1934 gnus-prev-page-line-format nil
1935 `(gnus-prev t local-map ,gnus-prev-page-map
1936 gnus-callback gnus-article-button-prev-page))))
1938 (defvar gnus-next-page-map nil)
1939 (unless gnus-next-page-map
1940 (setq gnus-next-page-map (make-keymap))
1941 (suppress-keymap gnus-prev-page-map)
1942 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1943 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1945 (defun gnus-button-next-page ()
1946 "Go to the next page."
1948 (let ((win (selected-window)))
1949 (select-window (get-buffer-window gnus-article-buffer t))
1950 (gnus-article-next-page)
1951 (select-window win)))
1953 (defun gnus-button-prev-page ()
1954 "Go to the prev page."
1956 (let ((win (selected-window)))
1957 (select-window (get-buffer-window gnus-article-buffer t))
1958 (gnus-article-prev-page)
1959 (select-window win)))
1961 (defun gnus-insert-next-page-button ()
1962 (let ((buffer-read-only nil))
1963 (gnus-eval-format gnus-next-page-line-format nil
1964 `(gnus-next t local-map ,gnus-next-page-map
1966 gnus-article-button-next-page))))
1968 (defun gnus-article-button-next-page (arg)
1969 "Go to the next page."
1971 (let ((win (selected-window)))
1972 (select-window (get-buffer-window gnus-article-buffer t))
1973 (gnus-article-next-page)
1974 (select-window win)))
1976 (defun gnus-article-button-prev-page (arg)
1977 "Go to the prev page."
1979 (let ((win (selected-window)))
1980 (select-window (get-buffer-window gnus-article-buffer t))
1981 (gnus-article-prev-page)
1982 (select-window win)))
1986 ;;; gnus-art.el ends here