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.
34 (defvar gnus-article-save-directory gnus-directory
35 "*Name of the directory articles will be saved in (default \"~/News\").")
37 (defvar gnus-save-all-headers t
38 "*If non-nil, don't remove any headers before saving.")
40 (defvar gnus-prompt-before-saving 'always
41 "*This variable says how much prompting is to be done when saving articles.
42 If it is nil, no prompting will be done, and the articles will be
43 saved to the default files. If this variable is `always', each and
44 every article that is saved will be preceded by a prompt, even when
45 saving large batches of articles. If this variable is neither nil not
46 `always', there the user will be prompted once for a file name for
47 each invocation of the saving commands.")
49 (defvar gnus-saved-headers gnus-visible-headers
50 "*Headers to keep if `gnus-save-all-headers' is nil.
51 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
52 If that variable is nil, however, all headers that match this regexp
53 will be kept while the rest will be deleted before saving.")
55 (defvar gnus-default-article-saver 'gnus-summary-save-in-rmail
56 "*A function to save articles in your favorite format.
57 The function must be interactively callable (in other words, it must
60 Gnus provides the following functions:
62 * gnus-summary-save-in-rmail (Rmail format)
63 * gnus-summary-save-in-mail (Unix mail format)
64 * gnus-summary-save-in-folder (MH folder)
65 * gnus-summary-save-in-file (article format).
66 * gnus-summary-save-in-vm (use VM's folder format).")
68 (defvar gnus-rmail-save-name (function gnus-plain-save-name)
69 "*A function generating a file name to save articles in Rmail format.
70 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
72 (defvar gnus-mail-save-name (function gnus-plain-save-name)
73 "*A function generating a file name to save articles in Unix mail format.
74 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
76 (defvar gnus-folder-save-name (function gnus-folder-save-name)
77 "*A function generating a file name to save articles in MH folder.
78 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.")
80 (defvar gnus-file-save-name (function gnus-numeric-save-name)
81 "*A function generating a file name to save articles in article format.
82 The function is called with NEWSGROUP, HEADERS, and optional
85 (defvar gnus-split-methods
86 '((gnus-article-archive-name))
87 "*Variable used to suggest where articles are to be saved.
88 For instance, if you would like to save articles related to Gnus in
89 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
90 you could set this variable to something like:
92 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
93 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
95 This variable is an alist where the where the key is the match and the
96 value is a list of possible files to save in if the match is non-nil.
98 If the match is a string, it is used as a regexp match on the
99 article. If the match is a symbol, that symbol will be funcalled
100 from the buffer of the article to be saved with the newsgroup as the
101 parameter. If it is a list, it will be evaled in the same buffer.
103 If this form or function returns a string, this string will be used as
104 a possible file name; and if it returns a non-nil list, that list will
105 be used as possible file names.")
107 (defvar gnus-strict-mime t
108 "*If nil, MIME-decode even if there is no Mime-Version header in the article.")
110 (defvar gnus-show-mime-method 'metamail-buffer
111 "*Function to process a MIME message.
112 The function is called from the article buffer.")
114 (defvar gnus-decode-encoded-word-method (lambda ())
115 "*Function to decode a MIME encoded-words.
116 The function is called from the article buffer.")
118 (defvar gnus-page-delimiter "^\^L"
119 "*Regexp describing what to use as article page delimiters.
120 The default value is \"^\^L\", which is a form linefeed at the
121 beginning of a line.")
123 (defvar gnus-article-mode-line-format "Gnus: %%b %S"
124 "*The format specification for the article mode line.
125 See `gnus-summary-mode-line-format' for a closer description.")
127 (defvar gnus-article-mode-hook nil
128 "*A hook for Gnus article mode.")
130 (defvar gnus-article-prepare-hook nil
131 "*A hook called after an article has been prepared in the article buffer.
132 If you want to run a special decoding program like nkf, use this hook.")
134 ;(defvar gnus-article-display-hook nil
135 ; "*A hook called after the article is displayed in the article buffer.
136 ;The hook is designed to change the contents of the article
137 ;buffer. Typical functions that this hook may contain are
138 ;`gnus-article-hide-headers' (hide selected headers),
139 ;`gnus-article-maybe-highlight' (perform fancy article highlighting),
140 ;`gnus-article-hide-signature' (hide signature) and
141 ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).")
142 ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted)
143 ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike)
144 ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight)
146 ;;; Internal variables
148 (defvar gnus-article-mode-line-format-alist
149 (nconc '((?w (gnus-article-wash-status) ?s))
150 gnus-summary-mode-line-format-alist))
152 ;;; Provide a mapping from `gnus-*' commands to Article commands.
159 (setq afunc (car func)
162 gfunc (intern (format "gnus-%s" func))))
164 `(lambda (&optional interactive &rest args)
165 ,(documentation afunc t)
166 (interactive (list t))
168 (set-buffer gnus-article-buffer)
170 (call-interactively ',afunc)
171 (apply ',afunc args)))))))
172 '(article-hide-headers
173 article-hide-boring-headers
174 article-treat-overstrike
175 (article-fill . gnus-article-word-wrap)
177 article-remove-trailing-blank-lines
178 article-display-x-face
179 article-de-quoted-unreadable
180 article-mime-decode-quoted-printable
183 article-hide-signature
184 article-strip-leading-blank-lines
186 article-date-original
189 (article-show-all . gnus-article-show-all-headers))))
191 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
193 ;;; Saving functions.
195 (defun gnus-article-save (save-buffer file)
196 "Save the currently selected article."
197 (unless gnus-save-all-headers
198 ;; Remove headers accoring to `gnus-saved-headers'.
199 (let ((gnus-visible-headers
200 (or gnus-saved-headers gnus-visible-headers))
201 (gnus-article-buffer save-buffer))
202 (gnus-article-hide-headers 1 t)))
203 (save-window-excursion
204 (if (not gnus-default-article-saver)
205 (error "No default saver is defined.")
206 ;; !!! Magic! The saving functions all save
207 ;; `gnus-original-article-buffer' (or so they think),
208 ;; but we bind that variable to our save-buffer.
209 (set-buffer gnus-article-buffer)
210 (let ((gnus-original-article-buffer save-buffer))
211 (set-buffer gnus-summary-buffer)
213 gnus-default-article-saver
215 ((not gnus-prompt-before-saving)
217 ((eq gnus-prompt-before-saving 'always)
221 (defun gnus-read-save-file-name (prompt default-name)
222 (let* ((split-name (gnus-get-split-value gnus-split-methods))
224 ;; Let the split methods have their say.
226 ;; No split name was found.
229 (concat prompt " (default "
230 (file-name-nondirectory default-name) ") ")
231 (file-name-directory default-name)
233 ;; A single split name was found
234 ((= 1 (length split-name))
235 (let* ((name (car split-name))
236 (dir (cond ((file-directory-p name)
237 (file-name-as-directory name))
238 ((file-exists-p name) name)
239 (t gnus-article-save-directory))))
241 (concat prompt " (default " name ") ")
243 ;; A list of splits was found.
245 (setq split-name (nreverse split-name))
247 (let ((file-name-history (nconc split-name file-name-history)))
250 (concat prompt " (`M-p' for defaults) ")
251 gnus-article-save-directory
253 (car (push result file-name-history)))))))
254 ;; Create the directory.
255 (unless (equal (directory-file-name file) file)
256 (make-directory (file-name-directory file) t))
257 ;; If we have read a directory, we append the default file name.
258 (when (file-directory-p file)
259 (setq file (concat (file-name-as-directory file)
260 (file-name-nondirectory default-name))))
261 ;; Possibly translate some characters.
262 (nnheader-translate-file-chars file)))
264 (defun gnus-article-archive-name (group)
265 "Return the first instance of an \"Archive-name\" in the current buffer."
266 (let ((case-fold-search t))
267 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
268 (nnheader-concat gnus-article-save-directory
271 (defun gnus-summary-save-in-rmail (&optional filename)
272 "Append this article to Rmail file.
273 Optional argument FILENAME specifies file name.
274 Directory to save to is default to `gnus-article-save-directory'."
276 (gnus-set-global-variables)
278 (funcall gnus-rmail-save-name gnus-newsgroup-name
279 gnus-current-headers gnus-newsgroup-last-rmail)))
281 (cond ((eq filename 'default)
284 (t (gnus-read-save-file-name
285 "Save in rmail file:" default-name))))
286 (make-directory (file-name-directory filename) t)
287 (gnus-eval-in-buffer-window gnus-original-article-buffer
291 (gnus-output-to-rmail filename))))
292 ;; Remember the directory name to save articles
293 (setq gnus-newsgroup-last-rmail filename)))
295 (defun gnus-summary-save-in-mail (&optional filename)
296 "Append this article to Unix mail file.
297 Optional argument FILENAME specifies file name.
298 Directory to save to is default to `gnus-article-save-directory'."
300 (gnus-set-global-variables)
302 (funcall gnus-mail-save-name gnus-newsgroup-name
303 gnus-current-headers gnus-newsgroup-last-mail)))
305 (cond ((eq filename 'default)
308 (t (gnus-read-save-file-name
309 "Save in Unix mail file:" default-name))))
311 (expand-file-name filename
313 (file-name-directory default-name))))
314 (make-directory (file-name-directory filename) t)
315 (gnus-eval-in-buffer-window gnus-original-article-buffer
319 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
320 (gnus-output-to-rmail filename)
321 (let ((mail-use-rfc822 t))
322 (rmail-output filename 1 t t))))))
323 ;; Remember the directory name to save articles.
324 (setq gnus-newsgroup-last-mail filename)))
326 (defun gnus-summary-save-in-file (&optional filename)
327 "Append this article to file.
328 Optional argument FILENAME specifies file name.
329 Directory to save to is default to `gnus-article-save-directory'."
331 (gnus-set-global-variables)
333 (funcall gnus-file-save-name gnus-newsgroup-name
334 gnus-current-headers gnus-newsgroup-last-file)))
336 (cond ((eq filename 'default)
339 (t (gnus-read-save-file-name
340 "Save in file:" default-name))))
341 (make-directory (file-name-directory filename) t)
342 (gnus-eval-in-buffer-window gnus-original-article-buffer
346 (gnus-output-to-file filename))))
347 ;; Remember the directory name to save articles.
348 (setq gnus-newsgroup-last-file filename)))
350 (defun gnus-summary-save-body-in-file (&optional filename)
351 "Append this article body to a file.
352 Optional argument FILENAME specifies file name.
353 The directory to save in defaults to `gnus-article-save-directory'."
355 (gnus-set-global-variables)
357 (funcall gnus-file-save-name gnus-newsgroup-name
358 gnus-current-headers gnus-newsgroup-last-file)))
360 (cond ((eq filename 'default)
363 (t (gnus-read-save-file-name
364 "Save body in file:" default-name))))
365 (make-directory (file-name-directory filename) t)
366 (gnus-eval-in-buffer-window gnus-original-article-buffer
370 (goto-char (point-min))
371 (and (search-forward "\n\n" nil t)
372 (narrow-to-region (point) (point-max)))
373 (gnus-output-to-file filename))))
374 ;; Remember the directory name to save articles.
375 (setq gnus-newsgroup-last-file filename)))
377 (defun gnus-summary-save-in-pipe (&optional command)
378 "Pipe this article to subprocess."
380 (gnus-set-global-variables)
382 (cond ((eq command 'default)
383 gnus-last-shell-command)
385 (t (read-string "Shell command on article: "
386 gnus-last-shell-command))))
387 (if (string-equal command "")
388 (setq command gnus-last-shell-command))
389 (gnus-eval-in-buffer-window gnus-article-buffer
392 (shell-command-on-region (point-min) (point-max) command nil)))
393 (setq gnus-last-shell-command command))
395 ;;; Article file names when saving.
397 (defun gnus-capitalize-newsgroup (newsgroup)
398 "Capitalize NEWSGROUP name."
399 (and (not (zerop (length newsgroup)))
400 (concat (char-to-string (upcase (aref newsgroup 0)))
401 (substring newsgroup 1))))
403 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
404 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
405 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
406 Otherwise, it is like ~/News/news/group/num."
409 (concat (if (gnus-use-long-file-name 'not-save)
410 (gnus-capitalize-newsgroup newsgroup)
411 (gnus-newsgroup-directory-form newsgroup))
412 "/" (int-to-string (mail-header-number headers)))
413 gnus-article-save-directory)))
415 (string-equal (file-name-directory default)
416 (file-name-directory last-file))
417 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
419 (or last-file default))))
421 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
422 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
423 If variable `gnus-use-long-file-name' is non-nil, it is
424 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
427 (concat (if (gnus-use-long-file-name 'not-save)
429 (gnus-newsgroup-directory-form newsgroup))
430 "/" (int-to-string (mail-header-number headers)))
431 gnus-article-save-directory)))
433 (string-equal (file-name-directory default)
434 (file-name-directory last-file))
435 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
437 (or last-file default))))
439 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
440 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
441 If variable `gnus-use-long-file-name' is non-nil, it is
442 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
445 (if (gnus-use-long-file-name 'not-save)
446 (gnus-capitalize-newsgroup newsgroup)
447 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
448 gnus-article-save-directory)))
450 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
451 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
452 If variable `gnus-use-long-file-name' is non-nil, it is
453 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
456 (if (gnus-use-long-file-name 'not-save)
458 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
459 gnus-article-save-directory)))
463 ;;; Gnus article mode
466 (put 'gnus-article-mode 'mode-class 'special)
469 (gnus-define-keys gnus-article-mode-map
470 " " gnus-article-goto-next-page
471 "\177" gnus-article-goto-prev-page
472 [delete] gnus-article-goto-prev-page
473 "\C-c^" gnus-article-refer-article
474 "h" gnus-article-show-summary
475 "s" gnus-article-show-summary
476 "\C-c\C-m" gnus-article-mail
477 "?" gnus-article-describe-briefly
478 gnus-mouse-2 gnus-article-push-button
479 "\r" gnus-article-press-button
480 "\t" gnus-article-next-button
481 "\M-\t" gnus-article-prev-button
482 "e" gnus-article-edit
483 "<" beginning-of-buffer
485 "\C-c\C-i" gnus-info-find-node
488 (substitute-key-definition
489 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
491 (defun gnus-article-mode ()
492 "Major mode for displaying an article.
494 All normal editing commands are switched off.
496 The following commands are available:
498 \\<gnus-article-mode-map>
499 \\[gnus-article-next-page]\t Scroll the article one page forwards
500 \\[gnus-article-prev-page]\t Scroll the article one page backwards
501 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
502 \\[gnus-article-show-summary]\t Display the summary buffer
503 \\[gnus-article-mail]\t Send a reply to the address near point
504 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
505 \\[gnus-info-find-node]\t Go to the Gnus info node"
507 (when (and menu-bar-mode
508 (gnus-visual-p 'article-menu 'menu))
509 (gnus-article-make-menu-bar))
510 (kill-all-local-variables)
511 (gnus-simplify-mode-line)
512 (setq mode-name "Article")
513 (setq major-mode 'gnus-article-mode)
514 (make-local-variable 'minor-mode-alist)
515 (or (assq 'gnus-show-mime minor-mode-alist)
516 (setq minor-mode-alist
517 (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
518 (use-local-map gnus-article-mode-map)
519 (gnus-update-format-specifications nil 'article-mode)
520 (make-local-variable 'page-delimiter)
521 (setq page-delimiter gnus-page-delimiter)
522 (buffer-disable-undo (current-buffer))
523 (setq buffer-read-only t) ;Disable modification
524 (run-hooks 'gnus-article-mode-hook))
526 (defun gnus-article-setup-buffer ()
527 "Initialize the article buffer."
528 (let* ((name (if gnus-single-article-buffer "*Article*"
529 (concat "*Article " gnus-newsgroup-name "*")))
531 (progn (string-match "\\*Article" name)
532 (concat " *Original Article"
533 (substring name (match-end 0))))))
534 (setq gnus-article-buffer name)
535 (setq gnus-original-article-buffer original)
536 ;; This might be a variable local to the summary buffer.
537 (unless gnus-single-article-buffer
539 (set-buffer gnus-summary-buffer)
540 (setq gnus-article-buffer name)
541 (setq gnus-original-article-buffer original)
542 (gnus-set-global-variables))
543 (make-local-variable 'gnus-summary-buffer))
544 ;; Init original article buffer.
546 (set-buffer (get-buffer-create gnus-original-article-buffer))
547 (buffer-disable-undo (current-buffer))
548 (setq major-mode 'gnus-original-article-mode)
549 (gnus-add-current-to-buffer-list)
550 (make-local-variable 'gnus-original-article))
551 (if (get-buffer name)
554 (buffer-disable-undo (current-buffer))
555 (setq buffer-read-only t)
556 (gnus-add-current-to-buffer-list)
557 (or (eq major-mode 'gnus-article-mode)
561 (set-buffer (get-buffer-create name))
562 (gnus-add-current-to-buffer-list)
566 ;; Set article window start at LINE, where LINE is the number of lines
567 ;; from the head of the article.
568 (defun gnus-article-set-window-start (&optional line)
570 (get-buffer-window gnus-article-buffer t)
572 (set-buffer gnus-article-buffer)
573 (goto-char (point-min))
576 (gnus-message 6 "Moved to bookmark")
577 (search-forward "\n\n" nil t)
581 (defun gnus-article-prepare (article &optional all-headers header)
582 "Prepare ARTICLE in article mode buffer.
583 ARTICLE should either be an article number or a Message-ID.
584 If ARTICLE is an id, HEADER should be the article headers.
585 If ALL-HEADERS is non-nil, no headers are hidden."
587 ;; Make sure we start in a summary buffer.
588 (unless (eq major-mode 'gnus-summary-mode)
589 (set-buffer gnus-summary-buffer))
590 (setq gnus-summary-buffer (current-buffer))
591 ;; Make sure the connection to the server is alive.
592 (unless (gnus-server-opened
593 (gnus-find-method-for-group gnus-newsgroup-name))
594 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
595 (gnus-request-group gnus-newsgroup-name t))
596 (let* ((article (if header (mail-header-number header) article))
597 (summary-buffer (current-buffer))
598 (internal-hook gnus-article-internal-prepare-hook)
599 (group gnus-newsgroup-name)
602 (gnus-article-setup-buffer)
603 (set-buffer gnus-article-buffer)
604 ;; Deactivate active regions.
605 (when (and (boundp 'transient-mark-mode)
607 (setq mark-active nil))
608 (if (not (setq result (let ((buffer-read-only nil))
609 (gnus-request-article-this-buffer
611 ;; There is no such article.
613 (when (and (numberp article)
614 (not (memq article gnus-newsgroup-sparse)))
615 (setq gnus-article-current
616 (cons gnus-newsgroup-name article))
617 (set-buffer gnus-summary-buffer)
618 (setq gnus-current-article article)
619 (gnus-summary-mark-article article gnus-canceled-mark))
620 (unless (memq article gnus-newsgroup-sparse)
622 1 "No such article (may have expired or been canceled)")))
623 (if (or (eq result 'pseudo) (eq result 'nneething))
626 (set-buffer summary-buffer)
627 (setq gnus-last-article gnus-current-article
628 gnus-newsgroup-history (cons gnus-current-article
629 gnus-newsgroup-history)
630 gnus-current-article 0
631 gnus-current-headers nil
632 gnus-article-current nil)
633 (if (eq result 'nneething)
634 (gnus-configure-windows 'summary)
635 (gnus-configure-windows 'article))
636 (gnus-set-global-variables))
637 (gnus-set-mode-line 'article))
638 ;; The result from the `request' was an actual article -
639 ;; or at least some text that is now displayed in the
641 (if (and (numberp article)
642 (not (eq article gnus-current-article)))
643 ;; Seems like a new article has been selected.
644 ;; `gnus-current-article' must be an article number.
646 (set-buffer summary-buffer)
647 (setq gnus-last-article gnus-current-article
648 gnus-newsgroup-history (cons gnus-current-article
649 gnus-newsgroup-history)
650 gnus-current-article article
652 (gnus-summary-article-header gnus-current-article)
654 (cons gnus-newsgroup-name gnus-current-article))
655 (unless (vectorp gnus-current-headers)
656 (setq gnus-current-headers nil))
657 (gnus-summary-show-thread)
658 (run-hooks 'gnus-mark-article-hook)
659 (gnus-set-mode-line 'summary)
660 (and (gnus-visual-p 'article-highlight 'highlight)
661 (run-hooks 'gnus-visual-mark-article-hook))
662 ;; Set the global newsgroup variables here.
663 ;; Suggested by Jim Sisolak
664 ;; <sisolak@trans4.neep.wisc.edu>.
665 (gnus-set-global-variables)
666 (setq gnus-have-all-headers
667 (or all-headers gnus-show-all-headers))
669 (vectorp (gnus-summary-article-header article))
670 (gnus-cache-possibly-enter-article
672 (gnus-summary-article-header article)
673 (memq article gnus-newsgroup-marked)
674 (memq article gnus-newsgroup-dormant)
675 (memq article gnus-newsgroup-unreads)))))
676 (when (or (numberp article)
678 ;; Hooks for getting information from the article.
679 ;; This hook must be called before being narrowed.
680 (let (buffer-read-only)
681 (run-hooks 'internal-hook)
682 (run-hooks 'gnus-article-prepare-hook)
683 ;; Decode MIME message.
685 (if (or (not gnus-strict-mime)
686 (gnus-fetch-field "Mime-Version"))
687 (funcall gnus-show-mime-method)
688 (funcall gnus-decode-encoded-word-method)))
689 ;; Perform the article display hooks.
690 (run-hooks 'gnus-article-display-hook))
692 (goto-char (point-min))
693 (and gnus-break-pages (gnus-narrow-to-page)))
694 (gnus-set-mode-line 'article)
695 (gnus-configure-windows 'article)
696 (goto-char (point-min))
699 (defun gnus-article-wash-status ()
700 "Return a string which display status of article washing."
702 (set-buffer gnus-article-buffer)
703 (let ((cite (article-hidden-text-p 'cite))
704 (headers (article-hidden-text-p 'headers))
705 (boring (article-hidden-text-p 'boring-headers))
706 (pgp (article-hidden-text-p 'pgp))
707 (pem (article-hidden-text-p 'pem))
708 (signature (article-hidden-text-p 'signature))
709 (overstrike (article-hidden-text-p 'overstrike))
710 (emphasis (article-hidden-text-p 'emphasis))
711 (mime gnus-show-mime))
712 (format "%c%c%c%c%c%c%c"
714 (if (or headers boring) ?h ? )
715 (if (or pgp pem) ?p ? )
717 (if overstrike ?o ? )
719 (if emphasis ?e ? )))))
721 (defun gnus-article-hide-headers-if-wanted ()
722 "Hide unwanted headers if `gnus-have-all-headers' is nil.
723 Provided for backwards compatibility."
724 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
726 (gnus-article-hide-headers)))
730 (defun gnus-output-to-rmail (file-name)
731 "Append the current article to an Rmail file named FILE-NAME."
733 ;; Most of these codes are borrowed from rmailout.el.
734 (setq file-name (expand-file-name file-name))
735 (setq rmail-default-rmail-file file-name)
736 (let ((artbuf (current-buffer))
737 (tmpbuf (get-buffer-create " *Gnus-output*")))
739 (or (get-file-buffer file-name)
740 (file-exists-p file-name)
741 (if (gnus-yes-or-no-p
742 (concat "\"" file-name "\" does not exist, create it? "))
743 (let ((file-buffer (create-file-buffer file-name)))
745 (set-buffer file-buffer)
746 (rmail-insert-rmail-file-header)
747 (let ((require-final-newline nil))
748 (write-region (point-min) (point-max) file-name t 1)))
749 (kill-buffer file-buffer))
750 (error "Output file does not exist")))
752 (buffer-disable-undo (current-buffer))
754 (insert-buffer-substring artbuf)
755 (gnus-convert-article-to-rmail)
756 ;; Decide whether to append to a file or to an Emacs buffer.
757 (let ((outbuf (get-file-buffer file-name)))
759 (append-to-file (point-min) (point-max) file-name)
760 ;; File has been visited, in buffer OUTBUF.
762 (let ((buffer-read-only nil)
763 (msg (and (boundp 'rmail-current-message)
764 (symbol-value 'rmail-current-message))))
765 ;; If MSG is non-nil, buffer is in RMAIL mode.
768 (narrow-to-region (point-max) (point-max))))
769 (insert-buffer-substring tmpbuf)
772 (goto-char (point-min))
774 (search-backward "\^_")
775 (narrow-to-region (point) (point-max))
776 (goto-char (1+ (point-min)))
777 (rmail-count-new-messages t)
778 (rmail-show-message msg)))))))
779 (kill-buffer tmpbuf)))
781 (defun gnus-output-to-file (file-name)
782 "Append the current article to a file named FILE-NAME."
783 (let ((artbuf (current-buffer)))
784 (nnheader-temp-write nil
785 (insert-buffer-substring artbuf)
786 ;; Append newline at end of the buffer as separator, and then
788 (goto-char (point-max))
790 (append-to-file (point-min) (point-max) file-name))))
792 (defun gnus-convert-article-to-rmail ()
793 "Convert article in current buffer to Rmail message format."
794 (let ((buffer-read-only nil))
795 ;; Convert article directly into Babyl format.
796 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
797 (goto-char (point-min))
798 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
799 (while (search-forward "\n\^_" nil t) ;single char
800 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
801 (goto-char (point-max))
804 (defun gnus-narrow-to-page (&optional arg)
805 "Narrow the article buffer to a page.
806 If given a numerical ARG, move forward ARG pages."
808 (setq arg (if arg (prefix-numeric-value arg) 0))
810 (set-buffer gnus-article-buffer)
811 (goto-char (point-min))
813 ;; Remove any old next/prev buttons.
814 (when (gnus-visual-p 'page-marker)
815 (let ((buffer-read-only nil))
816 (gnus-remove-text-with-property 'gnus-prev)
817 (gnus-remove-text-with-property 'gnus-next)))
820 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
822 (re-search-forward page-delimiter nil 'move arg)))
823 (goto-char (match-end 0)))
826 (if (re-search-forward page-delimiter nil 'move)
829 (when (and (gnus-visual-p 'page-marker)
830 (not (= (point-min) 1)))
832 (goto-char (point-min))
833 (gnus-insert-prev-page-button)))
834 (when (and (gnus-visual-p 'page-marker)
835 (< (+ (point-max) 2) (buffer-size)))
837 (goto-char (point-max))
838 (gnus-insert-next-page-button)))))
840 ;; Article mode commands
842 (defun gnus-article-goto-next-page ()
843 "Show the next page of the article."
845 (when (gnus-article-next-page)
846 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
848 (defun gnus-article-goto-prev-page ()
849 "Show the next page of the article."
851 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
852 (gnus-article-prev-page nil)))
854 (defun gnus-article-next-page (&optional lines)
855 "Show the next page of the current article.
856 If end of article, return non-nil. Otherwise return nil.
857 Argument LINES specifies lines to be scrolled up."
859 (move-to-window-line -1)
860 ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
863 (and (pos-visible-in-window-p) ;Not continuation line.
865 ;; Nothing in this page.
866 (if (or (not gnus-break-pages)
869 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
871 (gnus-narrow-to-page 1) ;Go to next page.
873 ;; More in this page.
877 ;; Long lines may cause an end-of-buffer error.
878 (goto-char (point-max))))
879 (move-to-window-line 0)
882 (defun gnus-article-prev-page (&optional lines)
883 "Show previous page of current article.
884 Argument LINES specifies lines to be scrolled down."
886 (move-to-window-line 0)
887 (if (and gnus-break-pages
889 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
891 (gnus-narrow-to-page -1) ;Go to previous page.
892 (goto-char (point-max))
898 (move-to-window-line 0))))
900 (defun gnus-article-refer-article ()
901 "Read article specified by message-id around point."
903 (let ((point (point)))
904 (search-forward ">" nil t) ;Move point to end of "<....>".
905 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
906 (let ((message-id (match-string 1)))
908 (set-buffer gnus-summary-buffer)
909 (gnus-summary-refer-article message-id))
911 (error "No references around point"))))
913 (defun gnus-article-show-summary ()
914 "Reconfigure windows to show summary buffer."
916 (gnus-configure-windows 'article)
917 (gnus-summary-goto-subject gnus-current-article))
919 (defun gnus-article-describe-briefly ()
920 "Describe article mode commands briefly."
923 (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")))
925 (defun gnus-article-summary-command ()
926 "Execute the last keystroke in the summary buffer."
928 (let ((obuf (current-buffer))
929 (owin (current-window-configuration))
931 (switch-to-buffer gnus-summary-buffer 'norecord)
932 (setq func (lookup-key (current-local-map) (this-command-keys)))
933 (call-interactively func)
935 (set-window-configuration owin)
936 (set-window-point (get-buffer-window (current-buffer)) (point))))
938 (defun gnus-article-summary-command-nosave ()
939 "Execute the last keystroke in the summary buffer."
942 (pop-to-buffer gnus-summary-buffer 'norecord)
943 (setq func (lookup-key (current-local-map) (this-command-keys)))
944 (call-interactively func)))
946 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
947 "Read a summary buffer key sequence and execute it from the article buffer."
950 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
951 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
957 (set-buffer gnus-summary-buffer)
958 (push (or key last-command-event) unread-command-events)
959 (setq keys (read-key-sequence nil)))
962 (if (or (member keys nosaves)
963 (member keys nosave-but-article))
965 (save-window-excursion
966 (pop-to-buffer gnus-summary-buffer 'norecord)
967 (setq func (lookup-key (current-local-map) keys)))
970 (set-buffer gnus-summary-buffer)
971 (call-interactively func))
972 (when (member keys nosave-but-article)
973 (pop-to-buffer gnus-article-buffer 'norecord)))
974 (let ((obuf (current-buffer))
975 (owin (current-window-configuration))
978 (if not-restore-window
979 (pop-to-buffer gnus-summary-buffer 'norecord)
980 (switch-to-buffer gnus-summary-buffer 'norecord))
981 (setq in-buffer (current-buffer))
982 (if (setq func (lookup-key (current-local-map) keys))
983 (call-interactively func)
985 (when (eq in-buffer (current-buffer))
987 (unless not-restore-window
988 (set-window-configuration owin))
989 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
991 (defun gnus-article-hide (&optional arg force)
992 "Hide all the gruft in the current article.
993 This means that PGP stuff, signatures, cited text and (some)
994 headers will be hidden.
995 If given a prefix, show the hidden text instead."
996 (interactive (list current-prefix-arg 'force))
997 (gnus-article-hide-headers arg)
998 (gnus-article-hide-pgp arg)
999 (gnus-article-hide-citation-maybe arg force)
1000 (gnus-article-hide-signature arg))
1002 (defun gnus-article-maybe-highlight ()
1003 "Do some article highlighting if `article-visual' is non-nil."
1004 (if (gnus-visual-p 'article-highlight 'highlight)
1005 (gnus-article-highlight-some)))
1007 (defun gnus-request-article-this-buffer (article group)
1008 "Get an article and insert it into this buffer."
1009 (let (do-update-line)
1013 (gnus-kill-all-overlays)
1014 (setq group (or group gnus-newsgroup-name))
1016 ;; Open server if it has closed.
1017 (gnus-check-server (gnus-find-method-for-group group))
1019 ;; Using `gnus-request-article' directly will insert the article into
1020 ;; `nntp-server-buffer' - so we'll save some time by not having to
1021 ;; copy it from the server buffer into the article buffer.
1023 ;; We only request an article by message-id when we do not have the
1024 ;; headers for it, so we'll have to get those.
1025 (when (stringp article)
1026 (let ((gnus-override-method gnus-refer-article-method))
1027 (gnus-read-header article)))
1029 ;; If the article number is negative, that means that this article
1030 ;; doesn't belong in this newsgroup (possibly), so we find its
1031 ;; message-id and request it by id instead of number.
1032 (when (and (numberp article)
1034 (get-buffer gnus-summary-buffer)
1035 (buffer-name (get-buffer gnus-summary-buffer)))
1037 (set-buffer gnus-summary-buffer)
1038 (let ((header (gnus-summary-article-header article)))
1041 ((memq article gnus-newsgroup-sparse)
1042 ;; This is a sparse gap article.
1043 (setq do-update-line article)
1044 (setq article (mail-header-id header))
1045 (let ((gnus-override-method gnus-refer-article-method))
1046 (gnus-read-header article))
1047 (setq gnus-newsgroup-sparse
1048 (delq article gnus-newsgroup-sparse)))
1050 ;; It's a real article.
1051 (setq article (mail-header-id header)))
1053 ;; It is an extracted pseudo-article.
1054 (setq article 'pseudo)
1055 (gnus-request-pseudo-article header))))
1057 (let ((method (gnus-find-method-for-group
1058 gnus-newsgroup-name)))
1059 (if (not (eq (car method) 'nneething))
1061 (let ((dir (concat (file-name-as-directory (nth 1 method))
1062 (mail-header-subject header))))
1063 (if (file-directory-p dir)
1065 (setq article 'nneething)
1066 (gnus-group-enter-directory dir)))))))))
1069 ;; Refuse to select canceled articles.
1070 ((and (numberp article)
1072 (get-buffer gnus-summary-buffer)
1073 (buffer-name (get-buffer gnus-summary-buffer))
1074 (eq (cdr (save-excursion
1075 (set-buffer gnus-summary-buffer)
1076 (assq article gnus-newsgroup-reads)))
1077 gnus-canceled-mark))
1079 ;; We first check `gnus-original-article-buffer'.
1080 ((and (get-buffer gnus-original-article-buffer)
1083 (set-buffer gnus-original-article-buffer)
1084 (and (equal (car gnus-original-article) group)
1085 (eq (cdr gnus-original-article) article))))
1086 (insert-buffer-substring gnus-original-article-buffer)
1088 ;; Check the backlog.
1089 ((and gnus-keep-backlog
1090 (gnus-backlog-request-article group article (current-buffer)))
1092 ;; Check asynchronous pre-fetch.
1093 ((gnus-async-request-fetched-article group article (current-buffer))
1094 (gnus-async-prefetch-next group article gnus-summary-buffer)
1097 ((and gnus-use-cache
1099 (gnus-cache-request-article article group))
1101 ;; Get the article and put into the article buffer.
1102 ((or (stringp article) (numberp article))
1103 (let ((gnus-override-method
1104 (and (stringp article) gnus-refer-article-method))
1105 (buffer-read-only nil))
1107 (gnus-kill-all-overlays)
1108 (when (gnus-request-article article group (current-buffer))
1109 (when (numberp article)
1110 (gnus-async-prefetch-next group article gnus-summary-buffer)
1111 (when gnus-keep-backlog
1112 (gnus-backlog-enter-article
1113 group article (current-buffer))))
1118 ;; Take the article from the original article buffer
1119 ;; and place it in the buffer it's supposed to be in.
1120 (when (and (get-buffer gnus-article-buffer)
1122 (equal (buffer-name (current-buffer))
1123 (buffer-name (get-buffer gnus-article-buffer))))
1125 (if (get-buffer gnus-original-article-buffer)
1126 (set-buffer (get-buffer gnus-original-article-buffer))
1127 (set-buffer (get-buffer-create gnus-original-article-buffer))
1128 (buffer-disable-undo (current-buffer))
1129 (setq major-mode 'gnus-original-article-mode)
1130 (setq buffer-read-only t)
1131 (gnus-add-current-to-buffer-list))
1132 (let (buffer-read-only)
1134 (insert-buffer-substring gnus-article-buffer))
1135 (setq gnus-original-article (cons group article))))
1137 ;; Update sparse articles.
1138 (when (and do-update-line
1139 (or (numberp article)
1141 (let ((buf (current-buffer)))
1142 (set-buffer gnus-summary-buffer)
1143 (gnus-summary-update-article do-update-line)
1144 (gnus-summary-goto-subject do-update-line nil t)
1145 (set-window-point (get-buffer-window (current-buffer) t)
1147 (set-buffer buf))))))
1149 (defun gnus-article-date-ut (&optional type highlight)
1150 "Convert DATE date to universal time in the current article.
1151 If TYPE is `local', convert to local time; if it is `lapsed', output
1152 how much time has lapsed since DATE."
1153 (interactive (list 'ut t))
1154 (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1156 (set-buffer gnus-article-buffer)
1157 (article-date-ut type highlight headers))))
1163 (defvar gnus-article-edit-mode-hook nil
1164 "*Hook run in article edit mode buffers.")
1166 (defvar gnus-article-edit-done-function nil)
1168 (defvar gnus-article-edit-mode-map nil)
1170 (unless gnus-article-edit-mode-map
1171 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1173 (gnus-define-keys gnus-article-edit-mode-map
1174 "\C-c\C-c" gnus-article-edit-done
1175 "\C-c\C-k" gnus-article-edit-exit)
1177 (gnus-define-keys (gnus-article-edit-wash-map
1178 "\C-c\C-w" gnus-article-edit-mode-map)
1179 "f" gnus-article-edit-full-stops))
1181 (defun gnus-article-edit-mode ()
1182 "Major mode for editing articles.
1183 This is an extended text-mode.
1185 \\{gnus-article-edit-mode-map}"
1187 (kill-all-local-variables)
1188 (setq major-mode 'gnus-article-edit-mode)
1189 (setq mode-name "Article Edit")
1190 (use-local-map gnus-article-edit-mode-map)
1191 (make-local-variable 'gnus-article-edit-done-function)
1192 (make-local-variable 'gnus-prev-winconf)
1193 (setq buffer-read-only nil)
1194 (buffer-enable-undo)
1196 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1198 (defun gnus-article-edit (&optional force)
1199 "Edit the current article.
1200 This will have permanent effect only in mail groups.
1201 If FORCE is non-nil, allow editing of articles even in read-only
1204 (when (and (not force)
1205 (gnus-group-read-only-p))
1206 (error "The current newsgroup does not support article editing."))
1207 (gnus-article-edit-article
1209 (gnus-summary-edit-article-done
1210 ,(or (mail-header-references gnus-current-headers) "")
1211 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1213 (defun gnus-article-edit-article (exit-func)
1214 "Start editing the contents of the current article buffer."
1215 (let ((winconf (current-window-configuration)))
1216 (set-buffer gnus-article-buffer)
1217 (gnus-article-edit-mode)
1218 (gnus-configure-windows 'edit-article)
1219 (setq gnus-article-edit-done-function exit-func)
1220 (setq gnus-prev-winconf winconf)
1221 (gnus-message 6 "C-c C-c to end edits")))
1223 (defun gnus-article-edit-done ()
1224 "Update the article edits and exit."
1226 (let ((func gnus-article-edit-done-function)
1227 (buf (current-buffer))
1228 (start (window-start)))
1229 (gnus-article-edit-exit)
1230 (let ((cur (current-buffer)))
1233 (let ((buffer-read-only nil))
1236 (set-window-start (get-buffer-window buf) start)
1237 (set-window-point (get-buffer-window buf) (point)))))
1239 (defun gnus-article-edit-exit ()
1240 "Exit the article editing without updating."
1242 ;; We remove all text props from the article buffer.
1243 (let ((buf (format "%s" (buffer-string)))
1244 (curbuf (current-buffer))
1246 (window-start (window-start)))
1249 (let ((winconf gnus-prev-winconf))
1251 ;; The cache and backlog have to be flushed somewhat.
1252 (when gnus-use-cache
1253 (gnus-cache-update-article
1254 (car gnus-article-current) (cdr gnus-article-current)))
1255 (when gnus-keep-backlog
1256 (gnus-backlog-remove-article
1257 (car gnus-article-current) (cdr gnus-article-current)))
1258 ;; Flush original article as well.
1260 (when (get-buffer gnus-original-article-buffer)
1261 (set-buffer gnus-original-article-buffer)
1262 (setq gnus-original-article nil)))
1263 (set-window-configuration winconf)
1264 ;; Tippy-toe some to make sure that point remains where it was.
1265 (let ((buf (current-buffer)))
1267 (set-window-start (get-buffer-window (current-buffer)) window-start)
1269 (set-buffer buf)))))
1271 (defun gnus-article-edit-full-stops ()
1272 "Interactively repair spacing at end of sentences."
1275 (goto-char (point-min))
1276 (search-forward-regexp "^$" nil t)
1277 (let ((case-fold-search nil))
1278 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1282 ;;; gnus-art.el ends here