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 "Write this article 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))
509 (defun gnus-summary-save-body-in-file (&optional filename)
510 "Append this article body to a file.
511 Optional argument FILENAME specifies file name.
512 The directory to save in defaults to `gnus-article-save-directory'."
514 (gnus-set-global-variables)
516 (funcall gnus-file-save-name gnus-newsgroup-name
517 gnus-current-headers gnus-newsgroup-last-file)))
518 (setq filename (gnus-read-save-file-name
519 "Save %s body in file:" default-name filename))
520 (gnus-make-directory (file-name-directory filename))
521 (gnus-eval-in-buffer-window gnus-original-article-buffer
525 (goto-char (point-min))
526 (when (search-forward "\n\n" nil t)
527 (narrow-to-region (point) (point-max)))
528 (gnus-output-to-file filename))))
529 ;; Remember the directory name to save articles.
530 (setq gnus-newsgroup-last-file filename)))
532 (defun gnus-summary-save-in-pipe (&optional command)
533 "Pipe this article to subprocess."
535 (gnus-set-global-variables)
537 (cond ((eq command 'default)
538 gnus-last-shell-command)
540 (t (read-string "Shell command on article: "
541 gnus-last-shell-command))))
542 (when (string-equal command "")
543 (setq command gnus-last-shell-command))
544 (gnus-eval-in-buffer-window gnus-article-buffer
547 (shell-command-on-region (point-min) (point-max) command nil)))
548 (setq gnus-last-shell-command command))
550 ;;; Article file names when saving.
552 (defun gnus-capitalize-newsgroup (newsgroup)
553 "Capitalize NEWSGROUP name."
554 (when (not (zerop (length newsgroup)))
555 (concat (char-to-string (upcase (aref newsgroup 0)))
556 (substring newsgroup 1))))
558 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
559 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
560 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
561 Otherwise, it is like ~/News/news/group/num."
564 (concat (if (gnus-use-long-file-name 'not-save)
565 (gnus-capitalize-newsgroup newsgroup)
566 (gnus-newsgroup-directory-form newsgroup))
567 "/" (int-to-string (mail-header-number headers)))
568 gnus-article-save-directory)))
570 (string-equal (file-name-directory default)
571 (file-name-directory last-file))
572 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
574 (or last-file default))))
576 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
577 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
578 If variable `gnus-use-long-file-name' is non-nil, it is
579 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
582 (concat (if (gnus-use-long-file-name 'not-save)
584 (gnus-newsgroup-directory-form newsgroup))
585 "/" (int-to-string (mail-header-number headers)))
586 gnus-article-save-directory)))
588 (string-equal (file-name-directory default)
589 (file-name-directory last-file))
590 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
592 (or last-file default))))
594 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
595 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
596 If variable `gnus-use-long-file-name' is non-nil, it is
597 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
600 (if (gnus-use-long-file-name 'not-save)
601 (gnus-capitalize-newsgroup newsgroup)
602 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
603 gnus-article-save-directory)))
605 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
606 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
607 If variable `gnus-use-long-file-name' is non-nil, it is
608 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
611 (if (gnus-use-long-file-name 'not-save)
613 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
614 gnus-article-save-directory)))
618 ;;; Gnus article mode
621 (put 'gnus-article-mode 'mode-class 'special)
624 (gnus-define-keys gnus-article-mode-map
625 " " gnus-article-goto-next-page
626 "\177" gnus-article-goto-prev-page
627 [delete] gnus-article-goto-prev-page
628 "\C-c^" gnus-article-refer-article
629 "h" gnus-article-show-summary
630 "s" gnus-article-show-summary
631 "\C-c\C-m" gnus-article-mail
632 "?" gnus-article-describe-briefly
633 gnus-mouse-2 gnus-article-push-button
634 "\r" gnus-article-press-button
635 "\t" gnus-article-next-button
636 "\M-\t" gnus-article-prev-button
637 "e" gnus-article-edit
638 "<" beginning-of-buffer
640 "\C-c\C-i" gnus-info-find-node
643 "\C-d" gnus-article-read-summary-keys
644 "\M-*" gnus-article-read-summary-keys
645 "\M-g" gnus-article-read-summary-keys)
647 (substitute-key-definition
648 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
650 (defun gnus-article-make-menu-bar ()
651 (gnus-turn-off-edit-menu 'article)
652 (unless (boundp 'gnus-article-article-menu)
654 gnus-article-article-menu gnus-article-mode-map ""
656 ["Scroll forwards" gnus-article-goto-next-page t]
657 ["Scroll backwards" gnus-article-goto-prev-page t]
658 ["Show summary" gnus-article-show-summary t]
659 ["Fetch Message-ID at point" gnus-article-refer-article t]
660 ["Mail to address at point" gnus-article-mail t]
664 gnus-article-treatment-menu gnus-article-mode-map ""
666 ["Hide headers" gnus-article-hide-headers t]
667 ["Hide signature" gnus-article-hide-signature t]
668 ["Hide citation" gnus-article-hide-citation t]
669 ["Treat overstrike" gnus-article-treat-overstrike t]
670 ["Remove carriage return" gnus-article-remove-cr t]
671 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
673 (run-hooks 'gnus-article-menu-hook)))
675 (defun gnus-article-mode ()
676 "Major mode for displaying an article.
678 All normal editing commands are switched off.
680 The following commands are available in addition to all summary mode
682 \\<gnus-article-mode-map>
683 \\[gnus-article-next-page]\t Scroll the article one page forwards
684 \\[gnus-article-prev-page]\t Scroll the article one page backwards
685 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
686 \\[gnus-article-show-summary]\t Display the summary buffer
687 \\[gnus-article-mail]\t Send a reply to the address near point
688 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
689 \\[gnus-info-find-node]\t Go to the Gnus info node"
691 (when (and menu-bar-mode
692 (gnus-visual-p 'article-menu 'menu))
693 (gnus-article-make-menu-bar))
694 (kill-all-local-variables)
695 (gnus-simplify-mode-line)
696 (setq mode-name "Article")
697 (setq major-mode 'gnus-article-mode)
698 (make-local-variable 'minor-mode-alist)
699 (unless (assq 'gnus-show-mime minor-mode-alist)
700 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
701 (use-local-map gnus-article-mode-map)
702 (gnus-update-format-specifications nil 'article-mode)
703 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
704 (gnus-set-default-directory)
705 (buffer-disable-undo (current-buffer))
706 (setq buffer-read-only t)
707 (run-hooks 'gnus-article-mode-hook))
709 (defun gnus-article-setup-buffer ()
710 "Initialize the article buffer."
711 (let* ((name (if gnus-single-article-buffer "*Article*"
712 (concat "*Article " gnus-newsgroup-name "*")))
714 (progn (string-match "\\*Article" name)
715 (concat " *Original Article"
716 (substring name (match-end 0))))))
717 (setq gnus-article-buffer name)
718 (setq gnus-original-article-buffer original)
719 ;; This might be a variable local to the summary buffer.
720 (unless gnus-single-article-buffer
722 (set-buffer gnus-summary-buffer)
723 (setq gnus-article-buffer name)
724 (setq gnus-original-article-buffer original)
725 (gnus-set-global-variables)))
726 ;; Init original article buffer.
728 (set-buffer (get-buffer-create gnus-original-article-buffer))
729 (buffer-disable-undo (current-buffer))
730 (setq major-mode 'gnus-original-article-mode)
731 (gnus-add-current-to-buffer-list)
732 (make-local-variable 'gnus-original-article))
733 (if (get-buffer name)
736 (buffer-disable-undo (current-buffer))
737 (setq buffer-read-only t)
738 (gnus-add-current-to-buffer-list)
739 (unless (eq major-mode 'gnus-article-mode)
743 (set-buffer (get-buffer-create name))
744 (gnus-add-current-to-buffer-list)
746 (make-local-variable 'gnus-summary-buffer)
749 ;; Set article window start at LINE, where LINE is the number of lines
750 ;; from the head of the article.
751 (defun gnus-article-set-window-start (&optional line)
753 (get-buffer-window gnus-article-buffer t)
755 (set-buffer gnus-article-buffer)
756 (goto-char (point-min))
759 (gnus-message 6 "Moved to bookmark")
760 (search-forward "\n\n" nil t)
764 (defun gnus-article-prepare (article &optional all-headers header)
765 "Prepare ARTICLE in article mode buffer.
766 ARTICLE should either be an article number or a Message-ID.
767 If ARTICLE is an id, HEADER should be the article headers.
768 If ALL-HEADERS is non-nil, no headers are hidden."
770 ;; Make sure we start in a summary buffer.
771 (unless (eq major-mode 'gnus-summary-mode)
772 (set-buffer gnus-summary-buffer))
773 (setq gnus-summary-buffer (current-buffer))
774 ;; Make sure the connection to the server is alive.
775 (unless (gnus-server-opened
776 (gnus-find-method-for-group gnus-newsgroup-name))
777 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
778 (gnus-request-group gnus-newsgroup-name t))
779 (let* ((article (if header (mail-header-number header) article))
780 (summary-buffer (current-buffer))
781 (internal-hook gnus-article-internal-prepare-hook)
782 (group gnus-newsgroup-name)
785 (gnus-article-setup-buffer)
786 (set-buffer gnus-article-buffer)
787 ;; Deactivate active regions.
788 (when (and (boundp 'transient-mark-mode)
790 (setq mark-active nil))
791 (if (not (setq result (let ((buffer-read-only nil))
792 (gnus-request-article-this-buffer
794 ;; There is no such article.
796 (when (and (numberp article)
797 (not (memq article gnus-newsgroup-sparse)))
798 (setq gnus-article-current
799 (cons gnus-newsgroup-name article))
800 (set-buffer gnus-summary-buffer)
801 (setq gnus-current-article article)
802 (gnus-summary-mark-article article gnus-canceled-mark))
803 (unless (memq article gnus-newsgroup-sparse)
805 1 "No such article (may have expired or been canceled)")))
806 (if (or (eq result 'pseudo) (eq result 'nneething))
809 (set-buffer summary-buffer)
810 (setq gnus-last-article gnus-current-article
811 gnus-newsgroup-history (cons gnus-current-article
812 gnus-newsgroup-history)
813 gnus-current-article 0
814 gnus-current-headers nil
815 gnus-article-current nil)
816 (if (eq result 'nneething)
817 (gnus-configure-windows 'summary)
818 (gnus-configure-windows 'article))
819 (gnus-set-global-variables))
820 (gnus-set-mode-line 'article))
821 ;; The result from the `request' was an actual article -
822 ;; or at least some text that is now displayed in the
824 (when (and (numberp article)
825 (not (eq article gnus-current-article)))
826 ;; Seems like a new article has been selected.
827 ;; `gnus-current-article' must be an article number.
829 (set-buffer summary-buffer)
830 (setq gnus-last-article gnus-current-article
831 gnus-newsgroup-history (cons gnus-current-article
832 gnus-newsgroup-history)
833 gnus-current-article article
835 (gnus-summary-article-header gnus-current-article)
837 (cons gnus-newsgroup-name gnus-current-article))
838 (unless (vectorp gnus-current-headers)
839 (setq gnus-current-headers nil))
840 (gnus-summary-show-thread)
841 (run-hooks 'gnus-mark-article-hook)
842 (gnus-set-mode-line 'summary)
843 (when (gnus-visual-p 'article-highlight 'highlight)
844 (run-hooks 'gnus-visual-mark-article-hook))
845 ;; Set the global newsgroup variables here.
846 ;; Suggested by Jim Sisolak
847 ;; <sisolak@trans4.neep.wisc.edu>.
848 (gnus-set-global-variables)
849 (setq gnus-have-all-headers
850 (or all-headers gnus-show-all-headers))
852 (vectorp (gnus-summary-article-header article))
853 (gnus-cache-possibly-enter-article
855 (gnus-summary-article-header article)
856 (memq article gnus-newsgroup-marked)
857 (memq article gnus-newsgroup-dormant)
858 (memq article gnus-newsgroup-unreads)))))
859 (when (or (numberp article)
861 ;; Hooks for getting information from the article.
862 ;; This hook must be called before being narrowed.
863 (let (buffer-read-only)
864 (run-hooks 'internal-hook)
865 (run-hooks 'gnus-article-prepare-hook)
866 ;; Decode MIME message.
868 (if (or (not gnus-strict-mime)
869 (gnus-fetch-field "Mime-Version"))
870 (funcall gnus-show-mime-method)
871 (funcall gnus-decode-encoded-word-method)))
872 ;; Perform the article display hooks.
873 (run-hooks 'gnus-article-display-hook))
875 (goto-char (point-min))
876 (when gnus-break-pages
877 (gnus-narrow-to-page)))
878 (gnus-set-mode-line 'article)
879 (gnus-configure-windows 'article)
880 (goto-char (point-min))
883 (defun gnus-article-wash-status ()
884 "Return a string which display status of article washing."
886 (set-buffer gnus-article-buffer)
887 (let ((cite (article-hidden-text-p 'cite))
888 (headers (article-hidden-text-p 'headers))
889 (boring (article-hidden-text-p 'boring-headers))
890 (pgp (article-hidden-text-p 'pgp))
891 (pem (article-hidden-text-p 'pem))
892 (signature (article-hidden-text-p 'signature))
893 (overstrike (article-hidden-text-p 'overstrike))
894 (emphasis (article-hidden-text-p 'emphasis))
895 (mime gnus-show-mime))
896 (format "%c%c%c%c%c%c%c"
898 (if (or headers boring) ?h ? )
899 (if (or pgp pem) ?p ? )
901 (if overstrike ?o ? )
903 (if emphasis ?e ? )))))
905 (defun gnus-article-hide-headers-if-wanted ()
906 "Hide unwanted headers if `gnus-have-all-headers' is nil.
907 Provided for backwards compatibility."
908 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
910 (gnus-article-hide-headers)))
914 (defun gnus-output-to-rmail (file-name)
915 "Append the current article to an Rmail file named FILE-NAME."
917 ;; Most of these codes are borrowed from rmailout.el.
918 (setq file-name (expand-file-name file-name))
919 (setq rmail-default-rmail-file file-name)
920 (let ((artbuf (current-buffer))
921 (tmpbuf (get-buffer-create " *Gnus-output*")))
923 (or (get-file-buffer file-name)
924 (file-exists-p file-name)
925 (if (gnus-yes-or-no-p
926 (concat "\"" file-name "\" does not exist, create it? "))
927 (let ((file-buffer (create-file-buffer file-name)))
929 (set-buffer file-buffer)
930 (rmail-insert-rmail-file-header)
931 (let ((require-final-newline nil))
932 (gnus-write-buffer file-name)))
933 (kill-buffer file-buffer))
934 (error "Output file does not exist")))
936 (buffer-disable-undo (current-buffer))
938 (insert-buffer-substring artbuf)
939 (gnus-convert-article-to-rmail)
940 ;; Decide whether to append to a file or to an Emacs buffer.
941 (let ((outbuf (get-file-buffer file-name)))
943 (append-to-file (point-min) (point-max) file-name)
944 ;; File has been visited, in buffer OUTBUF.
946 (let ((buffer-read-only nil)
947 (msg (and (boundp 'rmail-current-message)
948 (symbol-value 'rmail-current-message))))
949 ;; If MSG is non-nil, buffer is in RMAIL mode.
952 (narrow-to-region (point-max) (point-max)))
953 (insert-buffer-substring tmpbuf)
955 (goto-char (point-min))
957 (search-backward "\^_")
958 (narrow-to-region (point) (point-max))
959 (goto-char (1+ (point-min)))
960 (rmail-count-new-messages t)
961 (rmail-show-message msg))))))
962 (kill-buffer tmpbuf)))
964 (defun gnus-output-to-file (file-name)
965 "Append the current article to a file named FILE-NAME."
966 (let ((artbuf (current-buffer)))
967 (nnheader-temp-write nil
968 (insert-buffer-substring artbuf)
969 ;; Append newline at end of the buffer as separator, and then
971 (goto-char (point-max))
973 (append-to-file (point-min) (point-max) file-name))))
975 (defun gnus-convert-article-to-rmail ()
976 "Convert article in current buffer to Rmail message format."
977 (let ((buffer-read-only nil))
978 ;; Convert article directly into Babyl format.
979 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
980 (goto-char (point-min))
981 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
982 (while (search-forward "\n\^_" nil t) ;single char
983 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
984 (goto-char (point-max))
987 (defun gnus-narrow-to-page (&optional arg)
988 "Narrow the article buffer to a page.
989 If given a numerical ARG, move forward ARG pages."
991 (setq arg (if arg (prefix-numeric-value arg) 0))
993 (set-buffer gnus-article-buffer)
994 (goto-char (point-min))
996 ;; Remove any old next/prev buttons.
997 (when (gnus-visual-p 'page-marker)
998 (let ((buffer-read-only nil))
999 (gnus-remove-text-with-property 'gnus-prev)
1000 (gnus-remove-text-with-property 'gnus-next)))
1003 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
1005 (re-search-forward page-delimiter nil 'move arg)))
1006 (goto-char (match-end 0)))
1009 (if (re-search-forward page-delimiter nil 'move)
1012 (when (and (gnus-visual-p 'page-marker)
1013 (not (= (point-min) 1)))
1015 (goto-char (point-min))
1016 (gnus-insert-prev-page-button)))
1017 (when (and (gnus-visual-p 'page-marker)
1018 (< (+ (point-max) 2) (buffer-size)))
1020 (goto-char (point-max))
1021 (gnus-insert-next-page-button)))))
1023 ;; Article mode commands
1025 (defun gnus-article-goto-next-page ()
1026 "Show the next page of the article."
1028 (when (gnus-article-next-page)
1029 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
1031 (defun gnus-article-goto-prev-page ()
1032 "Show the next page of the article."
1034 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
1035 (gnus-article-prev-page nil)))
1037 (defun gnus-article-next-page (&optional lines)
1038 "Show the next page of the current article.
1039 If end of article, return non-nil. Otherwise return nil.
1040 Argument LINES specifies lines to be scrolled up."
1042 (move-to-window-line -1)
1045 (and (pos-visible-in-window-p) ;Not continuation line.
1047 ;; Nothing in this page.
1048 (if (or (not gnus-break-pages)
1051 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
1053 (gnus-narrow-to-page 1) ;Go to next page.
1055 ;; More in this page.
1059 ;; Long lines may cause an end-of-buffer error.
1060 (goto-char (point-max))))
1061 (move-to-window-line 0)
1064 (defun gnus-article-prev-page (&optional lines)
1065 "Show previous page of current article.
1066 Argument LINES specifies lines to be scrolled down."
1068 (move-to-window-line 0)
1069 (if (and gnus-break-pages
1071 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
1073 (gnus-narrow-to-page -1) ;Go to previous page.
1074 (goto-char (point-max))
1080 (move-to-window-line 0))))
1082 (defun gnus-article-refer-article ()
1083 "Read article specified by message-id around point."
1085 (let ((point (point)))
1086 (search-forward ">" nil t) ;Move point to end of "<....>".
1087 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
1088 (let ((message-id (match-string 1)))
1090 (set-buffer gnus-summary-buffer)
1091 (gnus-summary-refer-article message-id))
1093 (error "No references around point"))))
1095 (defun gnus-article-show-summary ()
1096 "Reconfigure windows to show summary buffer."
1098 (gnus-configure-windows 'article)
1099 (gnus-summary-goto-subject gnus-current-article))
1101 (defun gnus-article-describe-briefly ()
1102 "Describe article mode commands briefly."
1105 (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")))
1107 (defun gnus-article-summary-command ()
1108 "Execute the last keystroke in the summary buffer."
1110 (let ((obuf (current-buffer))
1111 (owin (current-window-configuration))
1113 (switch-to-buffer gnus-summary-buffer 'norecord)
1114 (setq func (lookup-key (current-local-map) (this-command-keys)))
1115 (call-interactively func)
1117 (set-window-configuration owin)
1118 (set-window-point (get-buffer-window (current-buffer)) (point))))
1120 (defun gnus-article-summary-command-nosave ()
1121 "Execute the last keystroke in the summary buffer."
1124 (pop-to-buffer gnus-summary-buffer 'norecord)
1125 (setq func (lookup-key (current-local-map) (this-command-keys)))
1126 (call-interactively func)))
1128 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
1129 "Read a summary buffer key sequence and execute it from the article buffer."
1132 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
1133 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
1134 "=" "^" "\M-^" "|"))
1141 (set-buffer gnus-summary-buffer)
1142 (push (or key last-command-event) unread-command-events)
1143 (setq keys (read-key-sequence nil)))
1146 (if (or (member keys nosaves)
1147 (member keys nosave-but-article)
1148 (member keys nosave-in-article))
1150 (save-window-excursion
1151 (pop-to-buffer gnus-summary-buffer 'norecord)
1152 (setq func (lookup-key (current-local-map) keys)))
1155 (unless (member keys nosave-in-article)
1156 (set-buffer gnus-summary-buffer))
1157 (call-interactively func))
1158 (when (member keys nosave-but-article)
1159 (pop-to-buffer gnus-article-buffer 'norecord)))
1160 ;; These commands should restore window configuration.
1161 (let ((obuf (current-buffer))
1162 (owin (current-window-configuration))
1165 (if not-restore-window
1166 (pop-to-buffer gnus-summary-buffer 'norecord)
1167 (switch-to-buffer gnus-summary-buffer 'norecord))
1168 (setq in-buffer (current-buffer))
1169 (if (setq func (lookup-key (current-local-map) keys))
1170 (call-interactively func)
1172 (when (eq in-buffer (current-buffer))
1174 (unless not-restore-window
1175 (set-window-configuration owin))
1176 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
1178 (defun gnus-article-hide (&optional arg force)
1179 "Hide all the gruft in the current article.
1180 This means that PGP stuff, signatures, cited text and (some)
1181 headers will be hidden.
1182 If given a prefix, show the hidden text instead."
1183 (interactive (list current-prefix-arg 'force))
1184 (gnus-article-hide-headers arg)
1185 (gnus-article-hide-pgp arg)
1186 (gnus-article-hide-citation-maybe arg force)
1187 (gnus-article-hide-signature arg))
1189 (defun gnus-article-maybe-highlight ()
1190 "Do some article highlighting if `article-visual' is non-nil."
1191 (when (gnus-visual-p 'article-highlight 'highlight)
1192 (gnus-article-highlight-some)))
1194 (defun gnus-request-article-this-buffer (article group)
1195 "Get an article and insert it into this buffer."
1196 (let (do-update-line)
1200 (gnus-kill-all-overlays)
1201 (setq group (or group gnus-newsgroup-name))
1203 ;; Open server if it has closed.
1204 (gnus-check-server (gnus-find-method-for-group group))
1206 ;; Using `gnus-request-article' directly will insert the article into
1207 ;; `nntp-server-buffer' - so we'll save some time by not having to
1208 ;; copy it from the server buffer into the article buffer.
1210 ;; We only request an article by message-id when we do not have the
1211 ;; headers for it, so we'll have to get those.
1212 (when (stringp article)
1213 (let ((gnus-override-method gnus-refer-article-method))
1214 (gnus-read-header article)))
1216 ;; If the article number is negative, that means that this article
1217 ;; doesn't belong in this newsgroup (possibly), so we find its
1218 ;; message-id and request it by id instead of number.
1219 (when (and (numberp article)
1221 (get-buffer gnus-summary-buffer)
1222 (buffer-name (get-buffer gnus-summary-buffer)))
1224 (set-buffer gnus-summary-buffer)
1225 (let ((header (gnus-summary-article-header article)))
1228 ((memq article gnus-newsgroup-sparse)
1229 ;; This is a sparse gap article.
1230 (setq do-update-line article)
1231 (setq article (mail-header-id header))
1232 (let ((gnus-override-method gnus-refer-article-method))
1233 (gnus-read-header article))
1234 (setq gnus-newsgroup-sparse
1235 (delq article gnus-newsgroup-sparse)))
1237 ;; It's a real article.
1238 (setq article (mail-header-id header)))
1240 ;; It is an extracted pseudo-article.
1241 (setq article 'pseudo)
1242 (gnus-request-pseudo-article header))))
1244 (let ((method (gnus-find-method-for-group
1245 gnus-newsgroup-name)))
1246 (if (not (eq (car method) 'nneething))
1248 (let ((dir (concat (file-name-as-directory (nth 1 method))
1249 (mail-header-subject header))))
1250 (when (file-directory-p dir)
1251 (setq article 'nneething)
1252 (gnus-group-enter-directory dir))))))))
1255 ;; Refuse to select canceled articles.
1256 ((and (numberp article)
1258 (get-buffer gnus-summary-buffer)
1259 (buffer-name (get-buffer gnus-summary-buffer))
1260 (eq (cdr (save-excursion
1261 (set-buffer gnus-summary-buffer)
1262 (assq article gnus-newsgroup-reads)))
1263 gnus-canceled-mark))
1265 ;; We first check `gnus-original-article-buffer'.
1266 ((and (get-buffer gnus-original-article-buffer)
1269 (set-buffer gnus-original-article-buffer)
1270 (and (equal (car gnus-original-article) group)
1271 (eq (cdr gnus-original-article) article))))
1272 (insert-buffer-substring gnus-original-article-buffer)
1274 ;; Check the backlog.
1275 ((and gnus-keep-backlog
1276 (gnus-backlog-request-article group article (current-buffer)))
1278 ;; Check asynchronous pre-fetch.
1279 ((gnus-async-request-fetched-article group article (current-buffer))
1280 (gnus-async-prefetch-next group article gnus-summary-buffer)
1283 ((and gnus-use-cache
1285 (gnus-cache-request-article article group))
1287 ;; Get the article and put into the article buffer.
1288 ((or (stringp article) (numberp article))
1289 (let ((gnus-override-method
1290 (and (stringp article) gnus-refer-article-method))
1291 (buffer-read-only nil))
1293 (gnus-kill-all-overlays)
1294 (when (gnus-request-article article group (current-buffer))
1295 (when (numberp article)
1296 (gnus-async-prefetch-next group article gnus-summary-buffer)
1297 (when gnus-keep-backlog
1298 (gnus-backlog-enter-article
1299 group article (current-buffer))))
1304 ;; Take the article from the original article buffer
1305 ;; and place it in the buffer it's supposed to be in.
1306 (when (and (get-buffer gnus-article-buffer)
1308 (equal (buffer-name (current-buffer))
1309 (buffer-name (get-buffer gnus-article-buffer))))
1311 (if (get-buffer gnus-original-article-buffer)
1312 (set-buffer (get-buffer gnus-original-article-buffer))
1313 (set-buffer (get-buffer-create gnus-original-article-buffer))
1314 (buffer-disable-undo (current-buffer))
1315 (setq major-mode 'gnus-original-article-mode)
1316 (setq buffer-read-only t)
1317 (gnus-add-current-to-buffer-list))
1318 (let (buffer-read-only)
1320 (insert-buffer-substring gnus-article-buffer))
1321 (setq gnus-original-article (cons group article))))
1323 ;; Update sparse articles.
1324 (when (and do-update-line
1325 (or (numberp article)
1327 (let ((buf (current-buffer)))
1328 (set-buffer gnus-summary-buffer)
1329 (gnus-summary-update-article do-update-line)
1330 (gnus-summary-goto-subject do-update-line nil t)
1331 (set-window-point (get-buffer-window (current-buffer) t)
1333 (set-buffer buf))))))
1335 (defun gnus-article-date-ut (&optional type highlight)
1336 "Convert DATE date to universal time in the current article.
1337 If TYPE is `local', convert to local time; if it is `lapsed', output
1338 how much time has lapsed since DATE."
1339 (interactive (list 'ut t))
1340 (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1342 (set-buffer gnus-article-buffer)
1343 (article-date-ut type highlight headers))))
1349 (defcustom gnus-article-edit-mode-hook nil
1350 "Hook run in article edit mode buffers."
1354 (defvar gnus-article-edit-done-function nil)
1356 (defvar gnus-article-edit-mode-map nil)
1358 (unless gnus-article-edit-mode-map
1359 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1361 (gnus-define-keys gnus-article-edit-mode-map
1362 "\C-c\C-c" gnus-article-edit-done
1363 "\C-c\C-k" gnus-article-edit-exit)
1365 (gnus-define-keys (gnus-article-edit-wash-map
1366 "\C-c\C-w" gnus-article-edit-mode-map)
1367 "f" gnus-article-edit-full-stops))
1369 (defun gnus-article-edit-mode ()
1370 "Major mode for editing articles.
1371 This is an extended text-mode.
1373 \\{gnus-article-edit-mode-map}"
1375 (kill-all-local-variables)
1376 (setq major-mode 'gnus-article-edit-mode)
1377 (setq mode-name "Article Edit")
1378 (use-local-map gnus-article-edit-mode-map)
1379 (make-local-variable 'gnus-article-edit-done-function)
1380 (make-local-variable 'gnus-prev-winconf)
1381 (setq buffer-read-only nil)
1382 (buffer-enable-undo)
1384 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1386 (defun gnus-article-edit (&optional force)
1387 "Edit the current article.
1388 This will have permanent effect only in mail groups.
1389 If FORCE is non-nil, allow editing of articles even in read-only
1392 (when (and (not force)
1393 (gnus-group-read-only-p))
1394 (error "The current newsgroup does not support article editing."))
1395 (gnus-article-edit-article
1397 (gnus-summary-edit-article-done
1398 ,(or (mail-header-references gnus-current-headers) "")
1399 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1401 (defun gnus-article-edit-article (exit-func)
1402 "Start editing the contents of the current article buffer."
1403 (let ((winconf (current-window-configuration)))
1404 (set-buffer gnus-article-buffer)
1405 (gnus-article-edit-mode)
1406 (set-text-properties (point-min) (point-max) nil)
1407 (gnus-configure-windows 'edit-article)
1408 (setq gnus-article-edit-done-function exit-func)
1409 (setq gnus-prev-winconf winconf)
1410 (gnus-message 6 "C-c C-c to end edits")))
1412 (defun gnus-article-edit-done ()
1413 "Update the article edits and exit."
1415 (let ((func gnus-article-edit-done-function)
1416 (buf (current-buffer))
1417 (start (window-start)))
1418 (gnus-article-edit-exit)
1421 (let ((buffer-read-only nil))
1424 (set-window-start (get-buffer-window buf) start)
1425 (set-window-point (get-buffer-window buf) (point))))
1427 (defun gnus-article-edit-exit ()
1428 "Exit the article editing without updating."
1430 ;; We remove all text props from the article buffer.
1431 (let ((buf (format "%s" (buffer-string)))
1432 (curbuf (current-buffer))
1434 (window-start (window-start)))
1437 (let ((winconf gnus-prev-winconf))
1439 ;; The cache and backlog have to be flushed somewhat.
1440 (when gnus-use-cache
1441 (gnus-cache-update-article
1442 (car gnus-article-current) (cdr gnus-article-current)))
1443 (when gnus-keep-backlog
1444 (gnus-backlog-remove-article
1445 (car gnus-article-current) (cdr gnus-article-current)))
1446 ;; Flush original article as well.
1448 (when (get-buffer gnus-original-article-buffer)
1449 (set-buffer gnus-original-article-buffer)
1450 (setq gnus-original-article nil)))
1451 (set-window-configuration winconf)
1452 ;; Tippy-toe some to make sure that point remains where it was.
1453 (let ((buf (current-buffer)))
1455 (set-window-start (get-buffer-window (current-buffer)) window-start)
1457 (set-buffer buf)))))
1459 (defun gnus-article-edit-full-stops ()
1460 "Interactively repair spacing at end of sentences."
1463 (goto-char (point-min))
1464 (search-forward-regexp "^$" nil t)
1465 (let ((case-fold-search nil))
1466 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1469 ;;; Article highlights
1472 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1474 ;;; Internal Variables:
1476 (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_=#$@~`%&*+|\\/]"
1477 "Regular expression that matches URLs."
1481 (defcustom gnus-button-alist
1482 `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
1483 t gnus-button-message-id 3)
1484 ("\\(<?\\(url: ?\\)?news://\\([^>\n\t ]*\\)>?\\)" 1 t
1485 gnus-button-fetch-group 3)
1486 ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1487 gnus-button-message-id 3)
1488 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-url-mailto 2)
1489 ;; This is how URLs _should_ be embedded in text...
1490 ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1491 ;; Next regexp stolen from highlight-headers.el.
1492 ;; Modified by Vladimir Alexiev.
1493 (,gnus-button-url-regexp 0 t gnus-button-url 0))
1494 "Alist of regexps matching buttons in article bodies.
1496 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1497 REGEXP: is the string matching text around the button,
1498 BUTTON: is the number of the regexp grouping actually matching the button,
1499 FORM: is a lisp expression which must eval to true for the button to
1501 CALLBACK: is the function to call when the user push this button, and each
1502 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1504 CALLBACK can also be a variable, in that case the value of that
1505 variable it the real callback function."
1507 :type '(repeat (list regexp
1508 (integer :tag "Button")
1510 (function :tag "Callback")
1513 (integer :tag "Regexp group")))))
1515 (defcustom gnus-header-button-alist
1516 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1517 0 t gnus-button-message-id 0)
1518 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1519 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
1520 0 t gnus-button-mailto 0)
1521 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1522 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1523 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1524 gnus-button-message-id 3))
1525 "Alist of headers and regexps to match buttons in article heads.
1527 This alist is very similar to `gnus-button-alist', except that each
1528 alist has an additional HEADER element first in each entry:
1530 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1532 HEADER is a regexp to match a header. For a fuller explanation, see
1533 `gnus-button-alist'."
1535 :type '(repeat (list (regexp :tag "Header")
1537 (integer :tag "Button")
1539 (function :tag "Callback")
1542 (integer :tag "Regexp group")))))
1544 (defvar gnus-button-regexp nil)
1545 (defvar gnus-button-marker-list nil)
1546 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1548 (defvar gnus-button-last nil)
1549 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1553 (defun gnus-article-push-button (event)
1554 "Check text under the mouse pointer for a callback function.
1555 If the text under the mouse pointer has a `gnus-callback' property,
1556 call it with the value of the `gnus-data' text property."
1558 (set-buffer (window-buffer (posn-window (event-start event))))
1559 (let* ((pos (posn-point (event-start event)))
1560 (data (get-text-property pos 'gnus-data))
1561 (fun (get-text-property pos 'gnus-callback)))
1563 (funcall fun data))))
1565 (defun gnus-article-press-button ()
1566 "Check text at point for a callback function.
1567 If the text at point has a `gnus-callback' property,
1568 call it with the value of the `gnus-data' text property."
1570 (let* ((data (get-text-property (point) 'gnus-data))
1571 (fun (get-text-property (point) 'gnus-callback)))
1573 (funcall fun data))))
1575 (defun gnus-article-prev-button (n)
1576 "Move point to N buttons backward.
1577 If N is negative, move forward instead."
1579 (gnus-article-next-button (- n)))
1581 (defun gnus-article-next-button (n)
1582 "Move point to N buttons forward.
1583 If N is negative, move backward instead."
1585 (let ((function (if (< n 0) 'previous-single-property-change
1586 'next-single-property-change))
1587 (inhibit-point-motion-hooks t)
1589 (limit (if (< n 0) (point-min) (point-max))))
1591 (while (and (not (= limit (point)))
1593 ;; Skip past the current button.
1594 (when (get-text-property (point) 'gnus-callback)
1595 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1596 ;; Go to the next (or previous) button.
1597 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1598 ;; Put point at the start of the button.
1599 (when (and backward (not (get-text-property (point) 'gnus-callback)))
1600 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1601 ;; Skip past intangible buttons.
1602 (when (get-text-property (point) 'intangible)
1606 (gnus-message 5 "No more buttons"))
1609 (defun gnus-article-highlight (&optional force)
1610 "Highlight current article.
1611 This function calls `gnus-article-highlight-headers',
1612 `gnus-article-highlight-citation',
1613 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1614 do the highlighting. See the documentation for those functions."
1615 (interactive (list 'force))
1616 (gnus-article-highlight-headers)
1617 (gnus-article-highlight-citation force)
1618 (gnus-article-highlight-signature)
1619 (gnus-article-add-buttons force)
1620 (gnus-article-add-buttons-to-head))
1622 (defun gnus-article-highlight-some (&optional force)
1623 "Highlight current article.
1624 This function calls `gnus-article-highlight-headers',
1625 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1626 do the highlighting. See the documentation for those functions."
1627 (interactive (list 'force))
1628 (gnus-article-highlight-headers)
1629 (gnus-article-highlight-signature)
1630 (gnus-article-add-buttons))
1632 (defun gnus-article-highlight-headers ()
1633 "Highlight article headers as specified by `gnus-header-face-alist'."
1636 (set-buffer gnus-article-buffer)
1638 (let ((alist gnus-header-face-alist)
1639 (buffer-read-only nil)
1640 (case-fold-search t)
1641 (inhibit-point-motion-hooks t)
1642 entry regexp header-face field-face from hpoints fpoints)
1643 (goto-char (point-min))
1644 (when (search-forward "\n\n" nil t)
1645 (narrow-to-region (1- (point)) (point-min))
1646 (while (setq entry (pop alist))
1647 (goto-char (point-min))
1648 (setq regexp (concat "^\\("
1649 (if (string-equal "" (nth 0 entry))
1653 header-face (nth 1 entry)
1654 field-face (nth 2 entry))
1655 (while (and (re-search-forward regexp nil t)
1659 (unless (search-forward ":" nil t)
1661 (when (and header-face
1662 (not (memq (point) hpoints)))
1663 (push (point) hpoints)
1664 (gnus-put-text-property from (point) 'face header-face))
1665 (when (and field-face
1666 (not (memq (setq from (point)) fpoints)))
1668 (if (re-search-forward "^[^ \t]" nil t)
1670 (goto-char (point-max)))
1671 (gnus-put-text-property from (point) 'face field-face)))))))))
1673 (defun gnus-article-highlight-signature ()
1674 "Highlight the signature in an article.
1675 It does this by highlighting everything after
1676 `gnus-signature-separator' using `gnus-signature-face'."
1679 (set-buffer gnus-article-buffer)
1680 (let ((buffer-read-only nil)
1681 (inhibit-point-motion-hooks t))
1683 (when (and gnus-signature-face
1684 (article-narrow-to-signature))
1685 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1686 'face gnus-signature-face)
1688 (article-search-signature)
1689 (let ((start (match-beginning 0))
1690 (end (set-marker (make-marker) (1+ (match-end 0)))))
1691 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1694 (defun gnus-article-add-buttons (&optional force)
1695 "Find external references in the article and make buttons of them.
1696 \"External references\" are things like Message-IDs and URLs, as
1697 specified by `gnus-button-alist'."
1698 (interactive (list 'force))
1700 (set-buffer gnus-article-buffer)
1701 ;; Remove all old markers.
1702 (while gnus-button-marker-list
1703 (set-marker (pop gnus-button-marker-list) nil))
1704 (let ((buffer-read-only nil)
1705 (inhibit-point-motion-hooks t)
1706 (case-fold-search t)
1707 (alist gnus-button-alist)
1709 (goto-char (point-min))
1710 ;; We skip the headers.
1711 (unless (search-forward "\n\n" nil t)
1712 (goto-char (point-max)))
1714 (while (setq entry (pop alist))
1715 (setq regexp (car entry))
1717 (while (re-search-forward regexp nil t)
1718 (let* ((start (and entry (match-beginning (nth 1 entry))))
1719 (end (and entry (match-end (nth 1 entry))))
1720 (from (match-beginning 0)))
1721 (when (or (eq t (nth 1 entry))
1722 (eval (nth 1 entry)))
1723 ;; That optional form returned non-nil, so we add the
1725 (gnus-article-add-button
1726 start end 'gnus-button-push
1727 (car (push (set-marker (make-marker) from)
1728 gnus-button-marker-list))))))))))
1730 ;; Add buttons to the head of an article.
1731 (defun gnus-article-add-buttons-to-head ()
1732 "Add buttons to the head of the article."
1735 (set-buffer gnus-article-buffer)
1736 (let ((buffer-read-only nil)
1737 (inhibit-point-motion-hooks t)
1738 (case-fold-search t)
1739 (alist gnus-header-button-alist)
1741 (nnheader-narrow-to-headers)
1743 ;; Each alist entry.
1744 (setq entry (car alist)
1746 (goto-char (point-min))
1747 (while (re-search-forward (car entry) nil t)
1748 ;; Each header matching the entry.
1749 (setq beg (match-beginning 0))
1750 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1751 (match-beginning 0))
1754 (while (re-search-forward (nth 1 entry) end t)
1755 ;; Each match within a header.
1756 (let* ((entry (cdr entry))
1757 (start (match-beginning (nth 1 entry)))
1758 (end (match-end (nth 1 entry)))
1759 (form (nth 2 entry)))
1760 (goto-char (match-end 0))
1762 (gnus-article-add-button
1763 start end (nth 3 entry)
1764 (buffer-substring (match-beginning (nth 4 entry))
1765 (match-end (nth 4 entry)))))))
1769 ;;; External functions:
1771 (defun gnus-article-add-button (from to fun &optional data)
1772 "Create a button between FROM and TO with callback FUN and data DATA."
1773 (when gnus-article-button-face
1774 (gnus-overlay-put (gnus-make-overlay from to)
1775 'face gnus-article-button-face))
1776 (gnus-add-text-properties
1778 (nconc (and gnus-article-mouse-face
1779 (list gnus-mouse-face-prop gnus-article-mouse-face))
1780 (list 'gnus-callback fun)
1781 (and data (list 'gnus-data data)))))
1783 ;;; Internal functions:
1785 (defun gnus-signature-toggle (end)
1787 (set-buffer gnus-article-buffer)
1788 (let ((buffer-read-only nil)
1789 (inhibit-point-motion-hooks t))
1790 (if (get-text-property end 'invisible)
1791 (article-unhide-text end (point-max))
1792 (article-hide-text end (point-max) gnus-hidden-properties)))))
1794 (defun gnus-button-entry ()
1795 ;; Return the first entry in `gnus-button-alist' matching this place.
1796 (let ((alist gnus-button-alist)
1799 (setq entry (pop alist))
1800 (if (looking-at (car entry))
1805 (defun gnus-button-push (marker)
1806 ;; Push button starting at MARKER.
1808 (set-buffer gnus-article-buffer)
1810 (let* ((entry (gnus-button-entry))
1811 (inhibit-point-motion-hooks t)
1813 (args (mapcar (lambda (group)
1814 (let ((string (buffer-substring
1815 (match-beginning group)
1816 (match-end group))))
1817 (gnus-set-text-properties
1818 0 (length string) nil string)
1825 (fboundp (symbol-value fun)))
1826 (apply (symbol-value fun) args))
1828 (gnus-message 1 "You must define `%S' to use this button"
1829 (cons fun args)))))))
1831 (defun gnus-button-message-id (message-id)
1834 (set-buffer gnus-summary-buffer)
1835 (gnus-summary-refer-article message-id)))
1837 (defun gnus-button-fetch-group (address)
1838 "Fetch GROUP specified by ADDRESS."
1839 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
1840 (error "Can't parse %s" address)
1841 (gnus-group-read-ephemeral-group
1842 (match-string 4 address)
1843 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
1844 (nntp-port-number ,(if (match-end 3)
1845 (match-string 3 address)
1848 (defun gnus-split-string (string pattern)
1849 "Return a list of substrings of STRING which are separated by PATTERN."
1850 (let (parts (start 0))
1851 (while (string-match pattern string start)
1852 (setq parts (cons (substring string start (match-beginning 0)) parts)
1853 start (match-end 0)))
1854 (nreverse (cons (substring string start) parts))))
1856 (defun gnus-url-parse-query-string (query &optional downcase)
1857 (let (retval pairs cur key val)
1858 (setq pairs (gnus-split-string query "&"))
1860 (setq cur (car pairs)
1862 (if (not (string-match "=" cur))
1864 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
1865 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
1867 (setq key (downcase key)))
1868 (setq cur (assoc key retval))
1870 (setcdr cur (cons val (cdr cur)))
1871 (setq retval (cons (list key val) retval)))))
1874 (defun gnus-url-unhex (x)
1881 (defun gnus-url-unhex-string (str &optional allow-newlines)
1882 "Remove %XXX embedded spaces, etc in a url.
1883 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
1884 decoding of carriage returns and line feeds in the string, which is normally
1885 forbidden in URL encoding."
1886 (setq str (or str ""))
1888 (case-fold-search t))
1889 (while (string-match "%[0-9a-f][0-9a-f]" str)
1890 (let* ((start (match-beginning 0))
1891 (ch1 (gnus-url-unhex (elt str (+ start 1))))
1893 (gnus-url-unhex (elt str (+ start 2))))))
1895 tmp (substring str 0 start)
1898 (char-to-string code))
1899 ((or (= code ?\n) (= code ?\r))
1901 (t (char-to-string code))))
1902 str (substring str (match-end 0)))))
1903 (setq tmp (concat tmp str))
1906 (defun gnus-url-mailto (url)
1907 ;; Send mail to someone
1908 (if (not (string-match "mailto:/*\\(.*\\)" url))
1909 (error "Malformed mailto link: %s" url))
1910 (setq url (substring url (match-beginning 1) nil))
1911 (let (to args source-url subject func)
1912 (if (string-match (regexp-quote "?") url)
1913 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
1914 args (gnus-url-parse-query-string
1915 (substring url (match-end 0) nil) t))
1916 (setq to (gnus-url-unhex-string url)))
1917 (setq args (cons (list "to" to) args)
1918 subject (cdr-safe (assoc "subject" args)))
1921 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
1924 (message-position-on-field (caar args)))
1925 (insert (mapconcat 'identity (cdar args) ", "))
1926 (setq args (cdr args)))
1929 (message-goto-subject))))
1931 (defun gnus-button-mailto (address)
1933 (set-buffer (gnus-copy-article-buffer))
1934 (message-reply address))
1936 (defun gnus-button-reply (address)
1937 ;; Reply to ADDRESS.
1938 (message-reply address))
1940 (defun gnus-button-url (address)
1942 (funcall browse-url-browser-function address))
1944 ;;; Next/prev buttons in the article buffer.
1946 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1947 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1949 (defvar gnus-prev-page-map nil)
1950 (unless gnus-prev-page-map
1951 (setq gnus-prev-page-map (make-sparse-keymap))
1952 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1953 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1955 (defun gnus-insert-prev-page-button ()
1956 (let ((buffer-read-only nil))
1958 gnus-prev-page-line-format nil
1959 `(gnus-prev t local-map ,gnus-prev-page-map
1960 gnus-callback gnus-article-button-prev-page))))
1962 (defvar gnus-next-page-map nil)
1963 (unless gnus-next-page-map
1964 (setq gnus-next-page-map (make-keymap))
1965 (suppress-keymap gnus-prev-page-map)
1966 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1967 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1969 (defun gnus-button-next-page ()
1970 "Go to the next page."
1972 (let ((win (selected-window)))
1973 (select-window (get-buffer-window gnus-article-buffer t))
1974 (gnus-article-next-page)
1975 (select-window win)))
1977 (defun gnus-button-prev-page ()
1978 "Go to the prev page."
1980 (let ((win (selected-window)))
1981 (select-window (get-buffer-window gnus-article-buffer t))
1982 (gnus-article-prev-page)
1983 (select-window win)))
1985 (defun gnus-insert-next-page-button ()
1986 (let ((buffer-read-only nil))
1987 (gnus-eval-format gnus-next-page-line-format nil
1988 `(gnus-next t local-map ,gnus-next-page-map
1990 gnus-article-button-next-page))))
1992 (defun gnus-article-button-next-page (arg)
1993 "Go to the next page."
1995 (let ((win (selected-window)))
1996 (select-window (get-buffer-window gnus-article-buffer t))
1997 (gnus-article-next-page)
1998 (select-window win)))
2000 (defun gnus-article-button-prev-page (arg)
2001 "Go to the prev page."
2003 (let ((win (selected-window)))
2004 (select-window (get-buffer-window gnus-article-buffer t))
2005 (gnus-article-prev-page)
2006 (select-window win)))
2010 ;;; gnus-art.el ends here