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 (defvar gnus-article-mode-syntax-table
290 (copy-syntax-table text-mode-syntax-table)
291 "Syntax table used in article mode buffers.
292 Initialized from `text-mode-syntax-table.")
294 ;;; Internal variables
296 (defvar gnus-article-mode-line-format-alist
297 (nconc '((?w (gnus-article-wash-status) ?s))
298 gnus-summary-mode-line-format-alist))
300 (defvar gnus-number-of-articles-to-be-saved nil)
302 ;;; Provide a mapping from `gnus-*' commands to Article commands.
309 (setq afunc (car func)
312 gfunc (intern (format "gnus-%s" func))))
314 `(lambda (&optional interactive &rest args)
315 ,(documentation afunc t)
316 (interactive (list t))
318 (set-buffer gnus-article-buffer)
320 (call-interactively ',afunc)
321 (apply ',afunc args)))))))
322 '(article-hide-headers
323 article-hide-boring-headers
324 article-treat-overstrike
325 (article-fill . gnus-article-word-wrap)
327 article-display-x-face
328 article-de-quoted-unreadable
329 article-mime-decode-quoted-printable
332 article-hide-signature
333 article-remove-trailing-blank-lines
334 article-strip-leading-blank-lines
335 article-strip-multiple-blank-lines
336 article-strip-blank-lines
338 article-date-original
341 (article-show-all . gnus-article-show-all-headers))))
343 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
345 ;;; Saving functions.
347 (defun gnus-article-save (save-buffer file &optional num)
348 "Save the currently selected article."
349 (unless gnus-save-all-headers
350 ;; Remove headers according to `gnus-saved-headers'.
351 (let ((gnus-visible-headers
352 (or gnus-saved-headers gnus-visible-headers))
353 (gnus-article-buffer save-buffer))
354 (gnus-article-hide-headers 1 t)))
355 (save-window-excursion
356 (if (not gnus-default-article-saver)
357 (error "No default saver is defined.")
358 ;; !!! Magic! The saving functions all save
359 ;; `gnus-original-article-buffer' (or so they think),
360 ;; but we bind that variable to our save-buffer.
361 (set-buffer gnus-article-buffer)
362 (let* ((gnus-original-article-buffer save-buffer)
365 ((not gnus-prompt-before-saving)
367 ((eq gnus-prompt-before-saving 'always)
370 (gnus-number-of-articles-to-be-saved
371 (when (eq gnus-prompt-before-saving t)
373 (set-buffer gnus-summary-buffer)
374 (funcall gnus-default-article-saver filename)))))
376 (defun gnus-read-save-file-name (prompt default-name &optional filename)
378 ((eq filename 'default)
382 (let* ((split-name (gnus-get-split-value gnus-split-methods))
384 (format prompt (if (and gnus-number-of-articles-to-be-saved
385 (> gnus-number-of-articles-to-be-saved 1))
386 (format "these %d articles"
387 gnus-number-of-articles-to-be-saved)
390 ;; Let the split methods have their say.
392 ;; No split name was found.
395 (concat prompt " (default "
396 (file-name-nondirectory default-name) ") ")
397 (file-name-directory default-name)
399 ;; A single split name was found
400 ((= 1 (length split-name))
401 (let* ((name (car split-name))
402 (dir (cond ((file-directory-p name)
403 (file-name-as-directory name))
404 ((file-exists-p name) name)
405 (t gnus-article-save-directory))))
407 (concat prompt " (default " name ") ")
409 ;; A list of splits was found.
411 (setq split-name (nreverse split-name))
413 (let ((file-name-history (nconc split-name file-name-history)))
416 (concat prompt " (`M-p' for defaults) ")
417 gnus-article-save-directory
419 (car (push result file-name-history)))))))
420 ;; Create the directory.
421 (gnus-make-directory (file-name-directory file))
422 ;; If we have read a directory, we append the default file name.
423 (when (file-directory-p file)
424 (setq file (concat (file-name-as-directory file)
425 (file-name-nondirectory default-name))))
426 ;; Possibly translate some characters.
427 (nnheader-translate-file-chars file)))))
429 (defun gnus-article-archive-name (group)
430 "Return the first instance of an \"Archive-name\" in the current buffer."
431 (let ((case-fold-search t))
432 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
433 (nnheader-concat gnus-article-save-directory
436 (defun gnus-summary-save-in-rmail (&optional filename)
437 "Append this article to Rmail file.
438 Optional argument FILENAME specifies file name.
439 Directory to save to is default to `gnus-article-save-directory'."
441 (gnus-set-global-variables)
443 (funcall gnus-rmail-save-name gnus-newsgroup-name
444 gnus-current-headers gnus-newsgroup-last-rmail)))
445 (setq filename (gnus-read-save-file-name
446 "Save %s in rmail file:" default-name filename))
447 (gnus-make-directory (file-name-directory filename))
448 (gnus-eval-in-buffer-window gnus-original-article-buffer
452 (gnus-output-to-rmail filename))))
453 ;; Remember the directory name to save articles
454 (setq gnus-newsgroup-last-rmail filename)))
456 (defun gnus-summary-save-in-mail (&optional filename)
457 "Append this article to Unix mail file.
458 Optional argument FILENAME specifies file name.
459 Directory to save to is default to `gnus-article-save-directory'."
461 (gnus-set-global-variables)
463 (funcall gnus-mail-save-name gnus-newsgroup-name
464 gnus-current-headers gnus-newsgroup-last-mail)))
465 (setq filename (gnus-read-save-file-name
466 "Save %s in Unix mail file:" default-name filename))
468 (expand-file-name filename
470 (file-name-directory default-name))))
471 (gnus-make-directory (file-name-directory filename))
472 (gnus-eval-in-buffer-window gnus-original-article-buffer
476 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
477 (gnus-output-to-rmail filename)
478 (let ((mail-use-rfc822 t))
479 (rmail-output filename 1 t t))))))
480 ;; Remember the directory name to save articles.
481 (setq gnus-newsgroup-last-mail filename)))
483 (defun gnus-summary-save-in-file (&optional filename overwrite)
484 "Append this article to file.
485 Optional argument FILENAME specifies file name.
486 Directory to save to is default to `gnus-article-save-directory'."
488 (gnus-set-global-variables)
490 (funcall gnus-file-save-name gnus-newsgroup-name
491 gnus-current-headers gnus-newsgroup-last-file)))
492 (setq filename (gnus-read-save-file-name
493 "Save %s in file:" default-name filename))
494 (gnus-make-directory (file-name-directory filename))
495 (gnus-eval-in-buffer-window gnus-original-article-buffer
500 (file-exists-p filename))
501 (delete-file filename))
502 (gnus-output-to-file filename))))
503 ;; Remember the directory name to save articles.
504 (setq gnus-newsgroup-last-file filename)))
506 (defun gnus-summary-write-to-file (&optional filename)
507 "Write this article to a file.
508 Optional argument FILENAME specifies file name.
509 The directory to save in defaults to `gnus-article-save-directory'."
511 (gnus-summary-save-in-file nil t))
514 (defun gnus-summary-save-body-in-file (&optional filename)
515 "Append this article body to a file.
516 Optional argument FILENAME specifies file name.
517 The directory to save in defaults to `gnus-article-save-directory'."
519 (gnus-set-global-variables)
521 (funcall gnus-file-save-name gnus-newsgroup-name
522 gnus-current-headers gnus-newsgroup-last-file)))
523 (setq filename (gnus-read-save-file-name
524 "Save %s body in file:" default-name filename))
525 (gnus-make-directory (file-name-directory filename))
526 (gnus-eval-in-buffer-window gnus-original-article-buffer
530 (goto-char (point-min))
531 (when (search-forward "\n\n" nil t)
532 (narrow-to-region (point) (point-max)))
533 (gnus-output-to-file filename))))
534 ;; Remember the directory name to save articles.
535 (setq gnus-newsgroup-last-file filename)))
537 (defun gnus-summary-save-in-pipe (&optional command)
538 "Pipe this article to subprocess."
540 (gnus-set-global-variables)
542 (cond ((eq command 'default)
543 gnus-last-shell-command)
545 (t (read-string "Shell command on article: "
546 gnus-last-shell-command))))
547 (when (string-equal command "")
548 (setq command gnus-last-shell-command))
549 (gnus-eval-in-buffer-window gnus-article-buffer
552 (shell-command-on-region (point-min) (point-max) command nil)))
553 (setq gnus-last-shell-command command))
555 ;;; Article file names when saving.
557 (defun gnus-capitalize-newsgroup (newsgroup)
558 "Capitalize NEWSGROUP name."
559 (when (not (zerop (length newsgroup)))
560 (concat (char-to-string (upcase (aref newsgroup 0)))
561 (substring newsgroup 1))))
563 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
564 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
565 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
566 Otherwise, it is like ~/News/news/group/num."
569 (concat (if (gnus-use-long-file-name 'not-save)
570 (gnus-capitalize-newsgroup newsgroup)
571 (gnus-newsgroup-directory-form newsgroup))
572 "/" (int-to-string (mail-header-number headers)))
573 gnus-article-save-directory)))
575 (string-equal (file-name-directory default)
576 (file-name-directory last-file))
577 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
579 (or last-file default))))
581 (defun gnus-numeric-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/num. Otherwise, it is like ~/News/news/group/num."
587 (concat (if (gnus-use-long-file-name 'not-save)
589 (gnus-newsgroup-directory-form newsgroup))
590 "/" (int-to-string (mail-header-number headers)))
591 gnus-article-save-directory)))
593 (string-equal (file-name-directory default)
594 (file-name-directory last-file))
595 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
597 (or last-file default))))
599 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
600 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
601 If variable `gnus-use-long-file-name' is non-nil, it is
602 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
605 (if (gnus-use-long-file-name 'not-save)
606 (gnus-capitalize-newsgroup newsgroup)
607 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
608 gnus-article-save-directory)))
610 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
611 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
612 If variable `gnus-use-long-file-name' is non-nil, it is
613 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
616 (if (gnus-use-long-file-name 'not-save)
618 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
619 gnus-article-save-directory)))
623 ;;; Gnus article mode
626 (put 'gnus-article-mode 'mode-class 'special)
629 (gnus-define-keys gnus-article-mode-map
630 " " gnus-article-goto-next-page
631 "\177" gnus-article-goto-prev-page
632 [delete] gnus-article-goto-prev-page
633 "\C-c^" gnus-article-refer-article
634 "h" gnus-article-show-summary
635 "s" gnus-article-show-summary
636 "\C-c\C-m" gnus-article-mail
637 "?" gnus-article-describe-briefly
638 gnus-mouse-2 gnus-article-push-button
639 "\r" gnus-article-press-button
640 "\t" gnus-article-next-button
641 "\M-\t" gnus-article-prev-button
642 "e" gnus-article-edit
643 "<" beginning-of-buffer
645 "\C-c\C-i" gnus-info-find-node
648 "\C-d" gnus-article-read-summary-keys
649 "\M-*" gnus-article-read-summary-keys
650 "\M-g" gnus-article-read-summary-keys)
652 (substitute-key-definition
653 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
655 (defun gnus-article-make-menu-bar ()
656 (gnus-turn-off-edit-menu 'article)
657 (unless (boundp 'gnus-article-article-menu)
659 gnus-article-article-menu gnus-article-mode-map ""
661 ["Scroll forwards" gnus-article-goto-next-page t]
662 ["Scroll backwards" gnus-article-goto-prev-page t]
663 ["Show summary" gnus-article-show-summary t]
664 ["Fetch Message-ID at point" gnus-article-refer-article t]
665 ["Mail to address at point" gnus-article-mail t]
669 gnus-article-treatment-menu gnus-article-mode-map ""
671 ["Hide headers" gnus-article-hide-headers t]
672 ["Hide signature" gnus-article-hide-signature t]
673 ["Hide citation" gnus-article-hide-citation t]
674 ["Treat overstrike" gnus-article-treat-overstrike t]
675 ["Remove carriage return" gnus-article-remove-cr t]
676 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
678 (run-hooks 'gnus-article-menu-hook)))
680 (defun gnus-article-mode ()
681 "Major mode for displaying an article.
683 All normal editing commands are switched off.
685 The following commands are available in addition to all summary mode
687 \\<gnus-article-mode-map>
688 \\[gnus-article-next-page]\t Scroll the article one page forwards
689 \\[gnus-article-prev-page]\t Scroll the article one page backwards
690 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
691 \\[gnus-article-show-summary]\t Display the summary buffer
692 \\[gnus-article-mail]\t Send a reply to the address near point
693 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
694 \\[gnus-info-find-node]\t Go to the Gnus info node"
696 (when (and menu-bar-mode
697 (gnus-visual-p 'article-menu 'menu))
698 (gnus-article-make-menu-bar))
699 (kill-all-local-variables)
700 (gnus-simplify-mode-line)
701 (setq mode-name "Article")
702 (setq major-mode 'gnus-article-mode)
703 (make-local-variable 'minor-mode-alist)
704 (unless (assq 'gnus-show-mime minor-mode-alist)
705 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
706 (use-local-map gnus-article-mode-map)
707 (gnus-update-format-specifications nil 'article-mode)
708 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
709 (gnus-set-default-directory)
710 (buffer-disable-undo (current-buffer))
711 (setq buffer-read-only t)
712 (set-syntax-table gnus-article-mode-syntax-table)
713 (run-hooks 'gnus-article-mode-hook))
715 (defun gnus-article-setup-buffer ()
716 "Initialize the article buffer."
717 (let* ((name (if gnus-single-article-buffer "*Article*"
718 (concat "*Article " gnus-newsgroup-name "*")))
720 (progn (string-match "\\*Article" name)
721 (concat " *Original Article"
722 (substring name (match-end 0))))))
723 (setq gnus-article-buffer name)
724 (setq gnus-original-article-buffer original)
725 ;; This might be a variable local to the summary buffer.
726 (unless gnus-single-article-buffer
728 (set-buffer gnus-summary-buffer)
729 (setq gnus-article-buffer name)
730 (setq gnus-original-article-buffer original)
731 (gnus-set-global-variables)))
732 ;; Init original article buffer.
734 (set-buffer (get-buffer-create gnus-original-article-buffer))
735 (buffer-disable-undo (current-buffer))
736 (setq major-mode 'gnus-original-article-mode)
737 (gnus-add-current-to-buffer-list)
738 (make-local-variable 'gnus-original-article))
739 (if (get-buffer name)
742 (buffer-disable-undo (current-buffer))
743 (setq buffer-read-only t)
744 (gnus-add-current-to-buffer-list)
745 (unless (eq major-mode 'gnus-article-mode)
749 (set-buffer (get-buffer-create name))
750 (gnus-add-current-to-buffer-list)
752 (make-local-variable 'gnus-summary-buffer)
755 ;; Set article window start at LINE, where LINE is the number of lines
756 ;; from the head of the article.
757 (defun gnus-article-set-window-start (&optional line)
759 (get-buffer-window gnus-article-buffer t)
761 (set-buffer gnus-article-buffer)
762 (goto-char (point-min))
765 (gnus-message 6 "Moved to bookmark")
766 (search-forward "\n\n" nil t)
770 (defun gnus-article-prepare (article &optional all-headers header)
771 "Prepare ARTICLE in article mode buffer.
772 ARTICLE should either be an article number or a Message-ID.
773 If ARTICLE is an id, HEADER should be the article headers.
774 If ALL-HEADERS is non-nil, no headers are hidden."
776 ;; Make sure we start in a summary buffer.
777 (unless (eq major-mode 'gnus-summary-mode)
778 (set-buffer gnus-summary-buffer))
779 (setq gnus-summary-buffer (current-buffer))
780 ;; Make sure the connection to the server is alive.
781 (unless (gnus-server-opened
782 (gnus-find-method-for-group gnus-newsgroup-name))
783 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
784 (gnus-request-group gnus-newsgroup-name t))
785 (let* ((article (if header (mail-header-number header) article))
786 (summary-buffer (current-buffer))
787 (internal-hook gnus-article-internal-prepare-hook)
788 (group gnus-newsgroup-name)
791 (gnus-article-setup-buffer)
792 (set-buffer gnus-article-buffer)
793 ;; Deactivate active regions.
794 (when (and (boundp 'transient-mark-mode)
796 (setq mark-active nil))
797 (if (not (setq result (let ((buffer-read-only nil))
798 (gnus-request-article-this-buffer
800 ;; There is no such article.
802 (when (and (numberp article)
803 (not (memq article gnus-newsgroup-sparse)))
804 (setq gnus-article-current
805 (cons gnus-newsgroup-name article))
806 (set-buffer gnus-summary-buffer)
807 (setq gnus-current-article article)
808 (gnus-summary-mark-article article gnus-canceled-mark))
809 (unless (memq article gnus-newsgroup-sparse)
811 1 "No such article (may have expired or been canceled)")))
812 (if (or (eq result 'pseudo) (eq result 'nneething))
815 (set-buffer summary-buffer)
816 (setq gnus-last-article gnus-current-article
817 gnus-newsgroup-history (cons gnus-current-article
818 gnus-newsgroup-history)
819 gnus-current-article 0
820 gnus-current-headers nil
821 gnus-article-current nil)
822 (if (eq result 'nneething)
823 (gnus-configure-windows 'summary)
824 (gnus-configure-windows 'article))
825 (gnus-set-global-variables))
826 (gnus-set-mode-line 'article))
827 ;; The result from the `request' was an actual article -
828 ;; or at least some text that is now displayed in the
830 (when (and (numberp article)
831 (not (eq article gnus-current-article)))
832 ;; Seems like a new article has been selected.
833 ;; `gnus-current-article' must be an article number.
835 (set-buffer summary-buffer)
836 (setq gnus-last-article gnus-current-article
837 gnus-newsgroup-history (cons gnus-current-article
838 gnus-newsgroup-history)
839 gnus-current-article article
841 (gnus-summary-article-header gnus-current-article)
843 (cons gnus-newsgroup-name gnus-current-article))
844 (unless (vectorp gnus-current-headers)
845 (setq gnus-current-headers nil))
846 (gnus-summary-show-thread)
847 (run-hooks 'gnus-mark-article-hook)
848 (gnus-set-mode-line 'summary)
849 (when (gnus-visual-p 'article-highlight 'highlight)
850 (run-hooks 'gnus-visual-mark-article-hook))
851 ;; Set the global newsgroup variables here.
852 ;; Suggested by Jim Sisolak
853 ;; <sisolak@trans4.neep.wisc.edu>.
854 (gnus-set-global-variables)
855 (setq gnus-have-all-headers
856 (or all-headers gnus-show-all-headers))
858 (vectorp (gnus-summary-article-header article))
859 (gnus-cache-possibly-enter-article
861 (gnus-summary-article-header article)
862 (memq article gnus-newsgroup-marked)
863 (memq article gnus-newsgroup-dormant)
864 (memq article gnus-newsgroup-unreads)))))
865 (when (or (numberp article)
867 ;; Hooks for getting information from the article.
868 ;; This hook must be called before being narrowed.
869 (let (buffer-read-only)
870 (run-hooks 'internal-hook)
871 (run-hooks 'gnus-article-prepare-hook)
872 ;; Decode MIME message.
874 (if (or (not gnus-strict-mime)
875 (gnus-fetch-field "Mime-Version"))
876 (funcall gnus-show-mime-method)
877 (funcall gnus-decode-encoded-word-method)))
878 ;; Perform the article display hooks.
879 (run-hooks 'gnus-article-display-hook))
881 (goto-char (point-min))
882 (when gnus-break-pages
883 (gnus-narrow-to-page)))
884 (gnus-set-mode-line 'article)
885 (gnus-configure-windows 'article)
886 (goto-char (point-min))
889 (defun gnus-article-wash-status ()
890 "Return a string which display status of article washing."
892 (set-buffer gnus-article-buffer)
893 (let ((cite (article-hidden-text-p 'cite))
894 (headers (article-hidden-text-p 'headers))
895 (boring (article-hidden-text-p 'boring-headers))
896 (pgp (article-hidden-text-p 'pgp))
897 (pem (article-hidden-text-p 'pem))
898 (signature (article-hidden-text-p 'signature))
899 (overstrike (article-hidden-text-p 'overstrike))
900 (emphasis (article-hidden-text-p 'emphasis))
901 (mime gnus-show-mime))
902 (format "%c%c%c%c%c%c%c"
904 (if (or headers boring) ?h ? )
905 (if (or pgp pem) ?p ? )
907 (if overstrike ?o ? )
909 (if emphasis ?e ? )))))
911 (defun gnus-article-hide-headers-if-wanted ()
912 "Hide unwanted headers if `gnus-have-all-headers' is nil.
913 Provided for backwards compatibility."
914 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
916 (gnus-article-hide-headers)))
920 (defun gnus-output-to-rmail (file-name)
921 "Append the current article to an Rmail file named FILE-NAME."
923 ;; Most of these codes are borrowed from rmailout.el.
924 (setq file-name (expand-file-name file-name))
925 (setq rmail-default-rmail-file file-name)
926 (let ((artbuf (current-buffer))
927 (tmpbuf (get-buffer-create " *Gnus-output*")))
929 (or (get-file-buffer file-name)
930 (file-exists-p file-name)
931 (if (gnus-yes-or-no-p
932 (concat "\"" file-name "\" does not exist, create it? "))
933 (let ((file-buffer (create-file-buffer file-name)))
935 (set-buffer file-buffer)
936 (rmail-insert-rmail-file-header)
937 (let ((require-final-newline nil))
938 (gnus-write-buffer file-name)))
939 (kill-buffer file-buffer))
940 (error "Output file does not exist")))
942 (buffer-disable-undo (current-buffer))
944 (insert-buffer-substring artbuf)
945 (gnus-convert-article-to-rmail)
946 ;; Decide whether to append to a file or to an Emacs buffer.
947 (let ((outbuf (get-file-buffer file-name)))
949 (append-to-file (point-min) (point-max) file-name)
950 ;; File has been visited, in buffer OUTBUF.
952 (let ((buffer-read-only nil)
953 (msg (and (boundp 'rmail-current-message)
954 (symbol-value 'rmail-current-message))))
955 ;; If MSG is non-nil, buffer is in RMAIL mode.
958 (narrow-to-region (point-max) (point-max)))
959 (insert-buffer-substring tmpbuf)
961 (goto-char (point-min))
963 (search-backward "\^_")
964 (narrow-to-region (point) (point-max))
965 (goto-char (1+ (point-min)))
966 (rmail-count-new-messages t)
967 (rmail-show-message msg))))))
968 (kill-buffer tmpbuf)))
970 (defun gnus-output-to-file (file-name)
971 "Append the current article to a file named FILE-NAME."
972 (let ((artbuf (current-buffer)))
973 (nnheader-temp-write nil
974 (insert-buffer-substring artbuf)
975 ;; Append newline at end of the buffer as separator, and then
977 (goto-char (point-max))
979 (append-to-file (point-min) (point-max) file-name))))
981 (defun gnus-convert-article-to-rmail ()
982 "Convert article in current buffer to Rmail message format."
983 (let ((buffer-read-only nil))
984 ;; Convert article directly into Babyl format.
985 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
986 (goto-char (point-min))
987 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
988 (while (search-forward "\n\^_" nil t) ;single char
989 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
990 (goto-char (point-max))
993 (defun gnus-narrow-to-page (&optional arg)
994 "Narrow the article buffer to a page.
995 If given a numerical ARG, move forward ARG pages."
997 (setq arg (if arg (prefix-numeric-value arg) 0))
999 (set-buffer gnus-article-buffer)
1000 (goto-char (point-min))
1002 ;; Remove any old next/prev buttons.
1003 (when (gnus-visual-p 'page-marker)
1004 (let ((buffer-read-only nil))
1005 (gnus-remove-text-with-property 'gnus-prev)
1006 (gnus-remove-text-with-property 'gnus-next)))
1009 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
1011 (re-search-forward page-delimiter nil 'move arg)))
1012 (goto-char (match-end 0)))
1015 (if (re-search-forward page-delimiter nil 'move)
1018 (when (and (gnus-visual-p 'page-marker)
1019 (not (= (point-min) 1)))
1021 (goto-char (point-min))
1022 (gnus-insert-prev-page-button)))
1023 (when (and (gnus-visual-p 'page-marker)
1024 (< (+ (point-max) 2) (buffer-size)))
1026 (goto-char (point-max))
1027 (gnus-insert-next-page-button)))))
1029 ;; Article mode commands
1031 (defun gnus-article-goto-next-page ()
1032 "Show the next page of the article."
1034 (when (gnus-article-next-page)
1035 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
1037 (defun gnus-article-goto-prev-page ()
1038 "Show the next page of the article."
1040 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
1041 (gnus-article-prev-page nil)))
1043 (defun gnus-article-next-page (&optional lines)
1044 "Show the next page of the current article.
1045 If end of article, return non-nil. Otherwise return nil.
1046 Argument LINES specifies lines to be scrolled up."
1048 (move-to-window-line -1)
1051 (and (pos-visible-in-window-p) ;Not continuation line.
1053 ;; Nothing in this page.
1054 (if (or (not gnus-break-pages)
1057 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
1059 (gnus-narrow-to-page 1) ;Go to next page.
1061 ;; More in this page.
1065 ;; Long lines may cause an end-of-buffer error.
1066 (goto-char (point-max))))
1067 (move-to-window-line 0)
1070 (defun gnus-article-prev-page (&optional lines)
1071 "Show previous page of current article.
1072 Argument LINES specifies lines to be scrolled down."
1074 (move-to-window-line 0)
1075 (if (and gnus-break-pages
1077 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
1079 (gnus-narrow-to-page -1) ;Go to previous page.
1080 (goto-char (point-max))
1086 (move-to-window-line 0))))
1088 (defun gnus-article-refer-article ()
1089 "Read article specified by message-id around point."
1091 (let ((point (point)))
1092 (search-forward ">" nil t) ;Move point to end of "<....>".
1093 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
1094 (let ((message-id (match-string 1)))
1096 (set-buffer gnus-summary-buffer)
1097 (gnus-summary-refer-article message-id))
1099 (error "No references around point"))))
1101 (defun gnus-article-show-summary ()
1102 "Reconfigure windows to show summary buffer."
1104 (gnus-configure-windows 'article)
1105 (gnus-summary-goto-subject gnus-current-article))
1107 (defun gnus-article-describe-briefly ()
1108 "Describe article mode commands briefly."
1111 (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")))
1113 (defun gnus-article-summary-command ()
1114 "Execute the last keystroke in the summary buffer."
1116 (let ((obuf (current-buffer))
1117 (owin (current-window-configuration))
1119 (switch-to-buffer gnus-summary-buffer 'norecord)
1120 (setq func (lookup-key (current-local-map) (this-command-keys)))
1121 (call-interactively func)
1123 (set-window-configuration owin)
1124 (set-window-point (get-buffer-window (current-buffer)) (point))))
1126 (defun gnus-article-summary-command-nosave ()
1127 "Execute the last keystroke in the summary buffer."
1130 (pop-to-buffer gnus-summary-buffer 'norecord)
1131 (setq func (lookup-key (current-local-map) (this-command-keys)))
1132 (call-interactively func)))
1134 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
1135 "Read a summary buffer key sequence and execute it from the article buffer."
1138 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
1139 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
1140 "=" "^" "\M-^" "|"))
1147 (set-buffer gnus-summary-buffer)
1148 (push (or key last-command-event) unread-command-events)
1149 (setq keys (read-key-sequence nil)))
1152 (if (or (member keys nosaves)
1153 (member keys nosave-but-article)
1154 (member keys nosave-in-article))
1156 (save-window-excursion
1157 (pop-to-buffer gnus-summary-buffer 'norecord)
1158 (setq func (lookup-key (current-local-map) keys)))
1161 (unless (member keys nosave-in-article)
1162 (set-buffer gnus-summary-buffer))
1163 (call-interactively func))
1164 (when (member keys nosave-but-article)
1165 (pop-to-buffer gnus-article-buffer 'norecord)))
1166 ;; These commands should restore window configuration.
1167 (let ((obuf (current-buffer))
1168 (owin (current-window-configuration))
1171 (if not-restore-window
1172 (pop-to-buffer gnus-summary-buffer 'norecord)
1173 (switch-to-buffer gnus-summary-buffer 'norecord))
1174 (setq in-buffer (current-buffer))
1175 (if (setq func (lookup-key (current-local-map) keys))
1176 (call-interactively func)
1178 (when (eq in-buffer (current-buffer))
1180 (unless not-restore-window
1181 (set-window-configuration owin))
1182 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
1184 (defun gnus-article-hide (&optional arg force)
1185 "Hide all the gruft in the current article.
1186 This means that PGP stuff, signatures, cited text and (some)
1187 headers will be hidden.
1188 If given a prefix, show the hidden text instead."
1189 (interactive (list current-prefix-arg 'force))
1190 (gnus-article-hide-headers arg)
1191 (gnus-article-hide-pgp arg)
1192 (gnus-article-hide-citation-maybe arg force)
1193 (gnus-article-hide-signature arg))
1195 (defun gnus-article-maybe-highlight ()
1196 "Do some article highlighting if `article-visual' is non-nil."
1197 (when (gnus-visual-p 'article-highlight 'highlight)
1198 (gnus-article-highlight-some)))
1200 (defun gnus-request-article-this-buffer (article group)
1201 "Get an article and insert it into this buffer."
1202 (let (do-update-line)
1206 (gnus-kill-all-overlays)
1207 (setq group (or group gnus-newsgroup-name))
1209 ;; Open server if it has closed.
1210 (gnus-check-server (gnus-find-method-for-group group))
1212 ;; Using `gnus-request-article' directly will insert the article into
1213 ;; `nntp-server-buffer' - so we'll save some time by not having to
1214 ;; copy it from the server buffer into the article buffer.
1216 ;; We only request an article by message-id when we do not have the
1217 ;; headers for it, so we'll have to get those.
1218 (when (stringp article)
1219 (let ((gnus-override-method gnus-refer-article-method))
1220 (gnus-read-header article)))
1222 ;; If the article number is negative, that means that this article
1223 ;; doesn't belong in this newsgroup (possibly), so we find its
1224 ;; message-id and request it by id instead of number.
1225 (when (and (numberp article)
1227 (get-buffer gnus-summary-buffer)
1228 (buffer-name (get-buffer gnus-summary-buffer)))
1230 (set-buffer gnus-summary-buffer)
1231 (let ((header (gnus-summary-article-header article)))
1234 ((memq article gnus-newsgroup-sparse)
1235 ;; This is a sparse gap article.
1236 (setq do-update-line article)
1237 (setq article (mail-header-id header))
1238 (let ((gnus-override-method gnus-refer-article-method))
1239 (gnus-read-header article))
1240 (setq gnus-newsgroup-sparse
1241 (delq article gnus-newsgroup-sparse)))
1243 ;; It's a real article.
1244 (setq article (mail-header-id header)))
1246 ;; It is an extracted pseudo-article.
1247 (setq article 'pseudo)
1248 (gnus-request-pseudo-article header))))
1250 (let ((method (gnus-find-method-for-group
1251 gnus-newsgroup-name)))
1252 (if (not (eq (car method) 'nneething))
1254 (let ((dir (concat (file-name-as-directory (nth 1 method))
1255 (mail-header-subject header))))
1256 (when (file-directory-p dir)
1257 (setq article 'nneething)
1258 (gnus-group-enter-directory dir))))))))
1261 ;; Refuse to select canceled articles.
1262 ((and (numberp article)
1264 (get-buffer gnus-summary-buffer)
1265 (buffer-name (get-buffer gnus-summary-buffer))
1266 (eq (cdr (save-excursion
1267 (set-buffer gnus-summary-buffer)
1268 (assq article gnus-newsgroup-reads)))
1269 gnus-canceled-mark))
1271 ;; We first check `gnus-original-article-buffer'.
1272 ((and (get-buffer gnus-original-article-buffer)
1275 (set-buffer gnus-original-article-buffer)
1276 (and (equal (car gnus-original-article) group)
1277 (eq (cdr gnus-original-article) article))))
1278 (insert-buffer-substring gnus-original-article-buffer)
1280 ;; Check the backlog.
1281 ((and gnus-keep-backlog
1282 (gnus-backlog-request-article group article (current-buffer)))
1284 ;; Check asynchronous pre-fetch.
1285 ((gnus-async-request-fetched-article group article (current-buffer))
1286 (gnus-async-prefetch-next group article gnus-summary-buffer)
1289 ((and gnus-use-cache
1291 (gnus-cache-request-article article group))
1293 ;; Get the article and put into the article buffer.
1294 ((or (stringp article) (numberp article))
1295 (let ((gnus-override-method
1296 (and (stringp article) gnus-refer-article-method))
1297 (buffer-read-only nil))
1299 (gnus-kill-all-overlays)
1300 (when (gnus-request-article article group (current-buffer))
1301 (when (numberp article)
1302 (gnus-async-prefetch-next group article gnus-summary-buffer)
1303 (when gnus-keep-backlog
1304 (gnus-backlog-enter-article
1305 group article (current-buffer))))
1310 ;; Take the article from the original article buffer
1311 ;; and place it in the buffer it's supposed to be in.
1312 (when (and (get-buffer gnus-article-buffer)
1314 (equal (buffer-name (current-buffer))
1315 (buffer-name (get-buffer gnus-article-buffer))))
1317 (if (get-buffer gnus-original-article-buffer)
1318 (set-buffer (get-buffer gnus-original-article-buffer))
1319 (set-buffer (get-buffer-create gnus-original-article-buffer))
1320 (buffer-disable-undo (current-buffer))
1321 (setq major-mode 'gnus-original-article-mode)
1322 (setq buffer-read-only t)
1323 (gnus-add-current-to-buffer-list))
1324 (let (buffer-read-only)
1326 (insert-buffer-substring gnus-article-buffer))
1327 (setq gnus-original-article (cons group article))))
1329 ;; Update sparse articles.
1330 (when (and do-update-line
1331 (or (numberp article)
1333 (let ((buf (current-buffer)))
1334 (set-buffer gnus-summary-buffer)
1335 (gnus-summary-update-article do-update-line)
1336 (gnus-summary-goto-subject do-update-line nil t)
1337 (set-window-point (get-buffer-window (current-buffer) t)
1339 (set-buffer buf))))))
1341 (defun gnus-article-date-ut (&optional type highlight)
1342 "Convert DATE date to universal time in the current article.
1343 If TYPE is `local', convert to local time; if it is `lapsed', output
1344 how much time has lapsed since DATE."
1345 (interactive (list 'ut t))
1346 (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1348 (set-buffer gnus-article-buffer)
1349 (article-date-ut type highlight headers))))
1355 (defcustom gnus-article-edit-mode-hook nil
1356 "Hook run in article edit mode buffers."
1360 (defvar gnus-article-edit-done-function nil)
1362 (defvar gnus-article-edit-mode-map nil)
1364 (unless gnus-article-edit-mode-map
1365 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1367 (gnus-define-keys gnus-article-edit-mode-map
1368 "\C-c\C-c" gnus-article-edit-done
1369 "\C-c\C-k" gnus-article-edit-exit)
1371 (gnus-define-keys (gnus-article-edit-wash-map
1372 "\C-c\C-w" gnus-article-edit-mode-map)
1373 "f" gnus-article-edit-full-stops))
1375 (defun gnus-article-edit-mode ()
1376 "Major mode for editing articles.
1377 This is an extended text-mode.
1379 \\{gnus-article-edit-mode-map}"
1381 (kill-all-local-variables)
1382 (setq major-mode 'gnus-article-edit-mode)
1383 (setq mode-name "Article Edit")
1384 (use-local-map gnus-article-edit-mode-map)
1385 (make-local-variable 'gnus-article-edit-done-function)
1386 (make-local-variable 'gnus-prev-winconf)
1387 (setq buffer-read-only nil)
1388 (buffer-enable-undo)
1390 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1392 (defun gnus-article-edit (&optional force)
1393 "Edit the current article.
1394 This will have permanent effect only in mail groups.
1395 If FORCE is non-nil, allow editing of articles even in read-only
1398 (when (and (not force)
1399 (gnus-group-read-only-p))
1400 (error "The current newsgroup does not support article editing."))
1401 (gnus-article-edit-article
1403 (gnus-summary-edit-article-done
1404 ,(or (mail-header-references gnus-current-headers) "")
1405 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1407 (defun gnus-article-edit-article (exit-func)
1408 "Start editing the contents of the current article buffer."
1409 (let ((winconf (current-window-configuration)))
1410 (set-buffer gnus-article-buffer)
1411 (gnus-article-edit-mode)
1412 (set-text-properties (point-min) (point-max) nil)
1413 (gnus-configure-windows 'edit-article)
1414 (setq gnus-article-edit-done-function exit-func)
1415 (setq gnus-prev-winconf winconf)
1416 (gnus-message 6 "C-c C-c to end edits")))
1418 (defun gnus-article-edit-done ()
1419 "Update the article edits and exit."
1421 (let ((func gnus-article-edit-done-function)
1422 (buf (current-buffer))
1423 (start (window-start)))
1424 (gnus-article-edit-exit)
1427 (let ((buffer-read-only nil))
1430 (set-window-start (get-buffer-window buf) start)
1431 (set-window-point (get-buffer-window buf) (point))))
1433 (defun gnus-article-edit-exit ()
1434 "Exit the article editing without updating."
1436 ;; We remove all text props from the article buffer.
1437 (let ((buf (format "%s" (buffer-string)))
1438 (curbuf (current-buffer))
1440 (window-start (window-start)))
1443 (let ((winconf gnus-prev-winconf))
1445 ;; The cache and backlog have to be flushed somewhat.
1446 (when gnus-use-cache
1447 (gnus-cache-update-article
1448 (car gnus-article-current) (cdr gnus-article-current)))
1449 (when gnus-keep-backlog
1450 (gnus-backlog-remove-article
1451 (car gnus-article-current) (cdr gnus-article-current)))
1452 ;; Flush original article as well.
1454 (when (get-buffer gnus-original-article-buffer)
1455 (set-buffer gnus-original-article-buffer)
1456 (setq gnus-original-article nil)))
1457 (set-window-configuration winconf)
1458 ;; Tippy-toe some to make sure that point remains where it was.
1459 (let ((buf (current-buffer)))
1461 (set-window-start (get-buffer-window (current-buffer)) window-start)
1463 (set-buffer buf)))))
1465 (defun gnus-article-edit-full-stops ()
1466 "Interactively repair spacing at end of sentences."
1469 (goto-char (point-min))
1470 (search-forward-regexp "^$" nil t)
1471 (let ((case-fold-search nil))
1472 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1475 ;;; Article highlights
1478 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1480 ;;; Internal Variables:
1482 (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_=#$@~`%&*+|\\/]"
1483 "Regular expression that matches URLs."
1487 (defcustom gnus-button-alist
1488 `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
1489 t gnus-button-message-id 3)
1490 ("\\(<?\\(url: ?\\)?news://\\([^>\n\t ]*\\)>?\\)" 1 t
1491 gnus-button-fetch-group 3)
1492 ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1493 gnus-button-message-id 3)
1494 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-url-mailto 2)
1495 ;; This is how URLs _should_ be embedded in text...
1496 ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1497 ;; Next regexp stolen from highlight-headers.el.
1498 ;; Modified by Vladimir Alexiev.
1499 (,gnus-button-url-regexp 0 t gnus-button-url 0))
1500 "Alist of regexps matching buttons in article bodies.
1502 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1503 REGEXP: is the string matching text around the button,
1504 BUTTON: is the number of the regexp grouping actually matching the button,
1505 FORM: is a lisp expression which must eval to true for the button to
1507 CALLBACK: is the function to call when the user push this button, and each
1508 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1510 CALLBACK can also be a variable, in that case the value of that
1511 variable it the real callback function."
1513 :type '(repeat (list regexp
1514 (integer :tag "Button")
1516 (function :tag "Callback")
1519 (integer :tag "Regexp group")))))
1521 (defcustom gnus-header-button-alist
1522 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1523 0 t gnus-button-message-id 0)
1524 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1525 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
1526 0 t gnus-button-mailto 0)
1527 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1528 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1529 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1530 gnus-button-message-id 3))
1531 "Alist of headers and regexps to match buttons in article heads.
1533 This alist is very similar to `gnus-button-alist', except that each
1534 alist has an additional HEADER element first in each entry:
1536 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1538 HEADER is a regexp to match a header. For a fuller explanation, see
1539 `gnus-button-alist'."
1541 :type '(repeat (list (regexp :tag "Header")
1543 (integer :tag "Button")
1545 (function :tag "Callback")
1548 (integer :tag "Regexp group")))))
1550 (defvar gnus-button-regexp nil)
1551 (defvar gnus-button-marker-list nil)
1552 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1554 (defvar gnus-button-last nil)
1555 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1559 (defun gnus-article-push-button (event)
1560 "Check text under the mouse pointer for a callback function.
1561 If the text under the mouse pointer has a `gnus-callback' property,
1562 call it with the value of the `gnus-data' text property."
1564 (set-buffer (window-buffer (posn-window (event-start event))))
1565 (let* ((pos (posn-point (event-start event)))
1566 (data (get-text-property pos 'gnus-data))
1567 (fun (get-text-property pos 'gnus-callback)))
1569 (funcall fun data))))
1571 (defun gnus-article-press-button ()
1572 "Check text at point for a callback function.
1573 If the text at point has a `gnus-callback' property,
1574 call it with the value of the `gnus-data' text property."
1576 (let* ((data (get-text-property (point) 'gnus-data))
1577 (fun (get-text-property (point) 'gnus-callback)))
1579 (funcall fun data))))
1581 (defun gnus-article-prev-button (n)
1582 "Move point to N buttons backward.
1583 If N is negative, move forward instead."
1585 (gnus-article-next-button (- n)))
1587 (defun gnus-article-next-button (n)
1588 "Move point to N buttons forward.
1589 If N is negative, move backward instead."
1591 (let ((function (if (< n 0) 'previous-single-property-change
1592 'next-single-property-change))
1593 (inhibit-point-motion-hooks t)
1595 (limit (if (< n 0) (point-min) (point-max))))
1597 (while (and (not (= limit (point)))
1599 ;; Skip past the current button.
1600 (when (get-text-property (point) 'gnus-callback)
1601 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1602 ;; Go to the next (or previous) button.
1603 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1604 ;; Put point at the start of the button.
1605 (when (and backward (not (get-text-property (point) 'gnus-callback)))
1606 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1607 ;; Skip past intangible buttons.
1608 (when (get-text-property (point) 'intangible)
1612 (gnus-message 5 "No more buttons"))
1615 (defun gnus-article-highlight (&optional force)
1616 "Highlight current article.
1617 This function calls `gnus-article-highlight-headers',
1618 `gnus-article-highlight-citation',
1619 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1620 do the highlighting. See the documentation for those functions."
1621 (interactive (list 'force))
1622 (gnus-article-highlight-headers)
1623 (gnus-article-highlight-citation force)
1624 (gnus-article-highlight-signature)
1625 (gnus-article-add-buttons force)
1626 (gnus-article-add-buttons-to-head))
1628 (defun gnus-article-highlight-some (&optional force)
1629 "Highlight current article.
1630 This function calls `gnus-article-highlight-headers',
1631 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1632 do the highlighting. See the documentation for those functions."
1633 (interactive (list 'force))
1634 (gnus-article-highlight-headers)
1635 (gnus-article-highlight-signature)
1636 (gnus-article-add-buttons))
1638 (defun gnus-article-highlight-headers ()
1639 "Highlight article headers as specified by `gnus-header-face-alist'."
1642 (set-buffer gnus-article-buffer)
1644 (let ((alist gnus-header-face-alist)
1645 (buffer-read-only nil)
1646 (case-fold-search t)
1647 (inhibit-point-motion-hooks t)
1648 entry regexp header-face field-face from hpoints fpoints)
1649 (goto-char (point-min))
1650 (when (search-forward "\n\n" nil t)
1651 (narrow-to-region (1- (point)) (point-min))
1652 (while (setq entry (pop alist))
1653 (goto-char (point-min))
1654 (setq regexp (concat "^\\("
1655 (if (string-equal "" (nth 0 entry))
1659 header-face (nth 1 entry)
1660 field-face (nth 2 entry))
1661 (while (and (re-search-forward regexp nil t)
1665 (unless (search-forward ":" nil t)
1667 (when (and header-face
1668 (not (memq (point) hpoints)))
1669 (push (point) hpoints)
1670 (gnus-put-text-property from (point) 'face header-face))
1671 (when (and field-face
1672 (not (memq (setq from (point)) fpoints)))
1674 (if (re-search-forward "^[^ \t]" nil t)
1676 (goto-char (point-max)))
1677 (gnus-put-text-property from (point) 'face field-face)))))))))
1679 (defun gnus-article-highlight-signature ()
1680 "Highlight the signature in an article.
1681 It does this by highlighting everything after
1682 `gnus-signature-separator' using `gnus-signature-face'."
1685 (set-buffer gnus-article-buffer)
1686 (let ((buffer-read-only nil)
1687 (inhibit-point-motion-hooks t))
1689 (when (and gnus-signature-face
1690 (article-narrow-to-signature))
1691 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1692 'face gnus-signature-face)
1694 (article-search-signature)
1695 (let ((start (match-beginning 0))
1696 (end (set-marker (make-marker) (1+ (match-end 0)))))
1697 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1700 (defun gnus-article-add-buttons (&optional force)
1701 "Find external references in the article and make buttons of them.
1702 \"External references\" are things like Message-IDs and URLs, as
1703 specified by `gnus-button-alist'."
1704 (interactive (list 'force))
1706 (set-buffer gnus-article-buffer)
1707 ;; Remove all old markers.
1708 (while gnus-button-marker-list
1709 (set-marker (pop gnus-button-marker-list) nil))
1710 (let ((buffer-read-only nil)
1711 (inhibit-point-motion-hooks t)
1712 (case-fold-search t)
1713 (alist gnus-button-alist)
1715 (goto-char (point-min))
1716 ;; We skip the headers.
1717 (unless (search-forward "\n\n" nil t)
1718 (goto-char (point-max)))
1720 (while (setq entry (pop alist))
1721 (setq regexp (car entry))
1723 (while (re-search-forward regexp nil t)
1724 (let* ((start (and entry (match-beginning (nth 1 entry))))
1725 (end (and entry (match-end (nth 1 entry))))
1726 (from (match-beginning 0)))
1727 (when (or (eq t (nth 1 entry))
1728 (eval (nth 1 entry)))
1729 ;; That optional form returned non-nil, so we add the
1731 (gnus-article-add-button
1732 start end 'gnus-button-push
1733 (car (push (set-marker (make-marker) from)
1734 gnus-button-marker-list))))))))))
1736 ;; Add buttons to the head of an article.
1737 (defun gnus-article-add-buttons-to-head ()
1738 "Add buttons to the head of the article."
1741 (set-buffer gnus-article-buffer)
1742 (let ((buffer-read-only nil)
1743 (inhibit-point-motion-hooks t)
1744 (case-fold-search t)
1745 (alist gnus-header-button-alist)
1747 (nnheader-narrow-to-headers)
1749 ;; Each alist entry.
1750 (setq entry (car alist)
1752 (goto-char (point-min))
1753 (while (re-search-forward (car entry) nil t)
1754 ;; Each header matching the entry.
1755 (setq beg (match-beginning 0))
1756 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1757 (match-beginning 0))
1760 (while (re-search-forward (nth 1 entry) end t)
1761 ;; Each match within a header.
1762 (let* ((entry (cdr entry))
1763 (start (match-beginning (nth 1 entry)))
1764 (end (match-end (nth 1 entry)))
1765 (form (nth 2 entry)))
1766 (goto-char (match-end 0))
1768 (gnus-article-add-button
1769 start end (nth 3 entry)
1770 (buffer-substring (match-beginning (nth 4 entry))
1771 (match-end (nth 4 entry)))))))
1775 ;;; External functions:
1777 (defun gnus-article-add-button (from to fun &optional data)
1778 "Create a button between FROM and TO with callback FUN and data DATA."
1779 (when gnus-article-button-face
1780 (gnus-overlay-put (gnus-make-overlay from to)
1781 'face gnus-article-button-face))
1782 (gnus-add-text-properties
1784 (nconc (and gnus-article-mouse-face
1785 (list gnus-mouse-face-prop gnus-article-mouse-face))
1786 (list 'gnus-callback fun)
1787 (and data (list 'gnus-data data)))))
1789 ;;; Internal functions:
1791 (defun gnus-signature-toggle (end)
1793 (set-buffer gnus-article-buffer)
1794 (let ((buffer-read-only nil)
1795 (inhibit-point-motion-hooks t))
1796 (if (get-text-property end 'invisible)
1797 (article-unhide-text end (point-max))
1798 (article-hide-text end (point-max) gnus-hidden-properties)))))
1800 (defun gnus-button-entry ()
1801 ;; Return the first entry in `gnus-button-alist' matching this place.
1802 (let ((alist gnus-button-alist)
1805 (setq entry (pop alist))
1806 (if (looking-at (car entry))
1811 (defun gnus-button-push (marker)
1812 ;; Push button starting at MARKER.
1814 (set-buffer gnus-article-buffer)
1816 (let* ((entry (gnus-button-entry))
1817 (inhibit-point-motion-hooks t)
1819 (args (mapcar (lambda (group)
1820 (let ((string (buffer-substring
1821 (match-beginning group)
1822 (match-end group))))
1823 (gnus-set-text-properties
1824 0 (length string) nil string)
1831 (fboundp (symbol-value fun)))
1832 (apply (symbol-value fun) args))
1834 (gnus-message 1 "You must define `%S' to use this button"
1835 (cons fun args)))))))
1837 (defun gnus-button-message-id (message-id)
1840 (set-buffer gnus-summary-buffer)
1841 (gnus-summary-refer-article message-id)))
1843 (defun gnus-button-fetch-group (address)
1844 "Fetch GROUP specified by ADDRESS."
1845 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
1846 (error "Can't parse %s" address)
1847 (gnus-group-read-ephemeral-group
1848 (match-string 4 address)
1849 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
1850 (nntp-port-number ,(if (match-end 3)
1851 (match-string 3 address)
1854 (defun gnus-split-string (string pattern)
1855 "Return a list of substrings of STRING which are separated by PATTERN."
1856 (let (parts (start 0))
1857 (while (string-match pattern string start)
1858 (setq parts (cons (substring string start (match-beginning 0)) parts)
1859 start (match-end 0)))
1860 (nreverse (cons (substring string start) parts))))
1862 (defun gnus-url-parse-query-string (query &optional downcase)
1863 (let (retval pairs cur key val)
1864 (setq pairs (gnus-split-string query "&"))
1866 (setq cur (car pairs)
1868 (if (not (string-match "=" cur))
1870 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
1871 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
1873 (setq key (downcase key)))
1874 (setq cur (assoc key retval))
1876 (setcdr cur (cons val (cdr cur)))
1877 (setq retval (cons (list key val) retval)))))
1880 (defun gnus-url-unhex (x)
1887 (defun gnus-url-unhex-string (str &optional allow-newlines)
1888 "Remove %XXX embedded spaces, etc in a url.
1889 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
1890 decoding of carriage returns and line feeds in the string, which is normally
1891 forbidden in URL encoding."
1892 (setq str (or str ""))
1894 (case-fold-search t))
1895 (while (string-match "%[0-9a-f][0-9a-f]" str)
1896 (let* ((start (match-beginning 0))
1897 (ch1 (gnus-url-unhex (elt str (+ start 1))))
1899 (gnus-url-unhex (elt str (+ start 2))))))
1901 tmp (substring str 0 start)
1904 (char-to-string code))
1905 ((or (= code ?\n) (= code ?\r))
1907 (t (char-to-string code))))
1908 str (substring str (match-end 0)))))
1909 (setq tmp (concat tmp str))
1912 (defun gnus-url-mailto (url)
1913 ;; Send mail to someone
1914 (if (not (string-match "mailto:/*\\(.*\\)" url))
1915 (error "Malformed mailto link: %s" url))
1916 (setq url (substring url (match-beginning 1) nil))
1917 (let (to args source-url subject func)
1918 (if (string-match (regexp-quote "?") url)
1919 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
1920 args (gnus-url-parse-query-string
1921 (substring url (match-end 0) nil) t))
1922 (setq to (gnus-url-unhex-string url)))
1923 (setq args (cons (list "to" to) args)
1924 subject (cdr-safe (assoc "subject" args)))
1927 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
1930 (message-position-on-field (caar args)))
1931 (insert (mapconcat 'identity (cdar args) ", "))
1932 (setq args (cdr args)))
1935 (message-goto-subject))))
1937 (defun gnus-button-mailto (address)
1939 (set-buffer (gnus-copy-article-buffer))
1940 (message-reply address))
1942 (defun gnus-button-reply (address)
1943 ;; Reply to ADDRESS.
1944 (message-reply address))
1946 (defun gnus-button-url (address)
1948 (funcall browse-url-browser-function address))
1950 ;;; Next/prev buttons in the article buffer.
1952 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1953 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1955 (defvar gnus-prev-page-map nil)
1956 (unless gnus-prev-page-map
1957 (setq gnus-prev-page-map (make-sparse-keymap))
1958 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1959 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1961 (defun gnus-insert-prev-page-button ()
1962 (let ((buffer-read-only nil))
1964 gnus-prev-page-line-format nil
1965 `(gnus-prev t local-map ,gnus-prev-page-map
1966 gnus-callback gnus-article-button-prev-page))))
1968 (defvar gnus-next-page-map nil)
1969 (unless gnus-next-page-map
1970 (setq gnus-next-page-map (make-keymap))
1971 (suppress-keymap gnus-prev-page-map)
1972 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1973 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1975 (defun gnus-button-next-page ()
1976 "Go to the next page."
1978 (let ((win (selected-window)))
1979 (select-window (get-buffer-window gnus-article-buffer t))
1980 (gnus-article-next-page)
1981 (select-window win)))
1983 (defun gnus-button-prev-page ()
1984 "Go to the prev page."
1986 (let ((win (selected-window)))
1987 (select-window (get-buffer-window gnus-article-buffer t))
1988 (gnus-article-prev-page)
1989 (select-window win)))
1991 (defun gnus-insert-next-page-button ()
1992 (let ((buffer-read-only nil))
1993 (gnus-eval-format gnus-next-page-line-format nil
1994 `(gnus-next t local-map ,gnus-next-page-map
1996 gnus-article-button-next-page))))
1998 (defun gnus-article-button-next-page (arg)
1999 "Go to the next page."
2001 (let ((win (selected-window)))
2002 (select-window (get-buffer-window gnus-article-buffer t))
2003 (gnus-article-next-page)
2004 (select-window win)))
2006 (defun gnus-article-button-prev-page (arg)
2007 "Go to the prev page."
2009 (let ((win (selected-window)))
2010 (select-window (get-buffer-window gnus-article-buffer t))
2011 (gnus-article-prev-page)
2012 (select-window win)))
2016 (run-hooks 'gnus-art-load-hook)
2018 ;;; gnus-art.el ends here