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-menu-hook nil
131 "*Hook run after the creation of the article mode menu.")
133 (defvar gnus-article-prepare-hook nil
134 "*A hook called after an article has been prepared in the article buffer.
135 If you want to run a special decoding program like nkf, use this hook.")
137 ;(defvar gnus-article-display-hook nil
138 ; "*A hook called after the article is displayed in the article buffer.
139 ;The hook is designed to change the contents of the article
140 ;buffer. Typical functions that this hook may contain are
141 ;`gnus-article-hide-headers' (hide selected headers),
142 ;`gnus-article-maybe-highlight' (perform fancy article highlighting),
143 ;`gnus-article-hide-signature' (hide signature) and
144 ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).")
145 ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted)
146 ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike)
147 ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight)
149 ;;; Internal variables
151 (defvar gnus-article-mode-line-format-alist
152 (nconc '((?w (gnus-article-wash-status) ?s))
153 gnus-summary-mode-line-format-alist))
155 ;;; Provide a mapping from `gnus-*' commands to Article commands.
162 (setq afunc (car func)
165 gfunc (intern (format "gnus-%s" func))))
167 `(lambda (&optional interactive &rest args)
168 ,(documentation afunc t)
169 (interactive (list t))
171 (set-buffer gnus-article-buffer)
173 (call-interactively ',afunc)
174 (apply ',afunc args)))))))
175 '(article-hide-headers
176 article-hide-boring-headers
177 article-treat-overstrike
178 (article-fill . gnus-article-word-wrap)
180 article-remove-trailing-blank-lines
181 article-display-x-face
182 article-de-quoted-unreadable
183 article-mime-decode-quoted-printable
186 article-hide-signature
187 article-strip-leading-blank-lines
189 article-date-original
192 (article-show-all . gnus-article-show-all-headers))))
194 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
196 ;;; Saving functions.
198 (defun gnus-article-save (save-buffer file)
199 "Save the currently selected article."
200 (unless gnus-save-all-headers
201 ;; Remove headers accoring to `gnus-saved-headers'.
202 (let ((gnus-visible-headers
203 (or gnus-saved-headers gnus-visible-headers))
204 (gnus-article-buffer save-buffer))
205 (gnus-article-hide-headers 1 t)))
206 (save-window-excursion
207 (if (not gnus-default-article-saver)
208 (error "No default saver is defined.")
209 ;; !!! Magic! The saving functions all save
210 ;; `gnus-original-article-buffer' (or so they think),
211 ;; but we bind that variable to our save-buffer.
212 (set-buffer gnus-article-buffer)
213 (let ((gnus-original-article-buffer save-buffer))
214 (set-buffer gnus-summary-buffer)
216 gnus-default-article-saver
218 ((not gnus-prompt-before-saving)
220 ((eq gnus-prompt-before-saving 'always)
224 (defun gnus-read-save-file-name (prompt default-name)
225 (let* ((split-name (gnus-get-split-value gnus-split-methods))
227 ;; Let the split methods have their say.
229 ;; No split name was found.
232 (concat prompt " (default "
233 (file-name-nondirectory default-name) ") ")
234 (file-name-directory default-name)
236 ;; A single split name was found
237 ((= 1 (length split-name))
238 (let* ((name (car split-name))
239 (dir (cond ((file-directory-p name)
240 (file-name-as-directory name))
241 ((file-exists-p name) name)
242 (t gnus-article-save-directory))))
244 (concat prompt " (default " name ") ")
246 ;; A list of splits was found.
248 (setq split-name (nreverse split-name))
250 (let ((file-name-history (nconc split-name file-name-history)))
253 (concat prompt " (`M-p' for defaults) ")
254 gnus-article-save-directory
256 (car (push result file-name-history)))))))
257 ;; Create the directory.
258 (unless (equal (directory-file-name file) file)
259 (make-directory (file-name-directory file) t))
260 ;; If we have read a directory, we append the default file name.
261 (when (file-directory-p file)
262 (setq file (concat (file-name-as-directory file)
263 (file-name-nondirectory default-name))))
264 ;; Possibly translate some characters.
265 (nnheader-translate-file-chars file)))
267 (defun gnus-article-archive-name (group)
268 "Return the first instance of an \"Archive-name\" in the current buffer."
269 (let ((case-fold-search t))
270 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
271 (nnheader-concat gnus-article-save-directory
274 (defun gnus-summary-save-in-rmail (&optional filename)
275 "Append this article to Rmail file.
276 Optional argument FILENAME specifies file name.
277 Directory to save to is default to `gnus-article-save-directory'."
279 (gnus-set-global-variables)
281 (funcall gnus-rmail-save-name gnus-newsgroup-name
282 gnus-current-headers gnus-newsgroup-last-rmail)))
284 (cond ((eq filename 'default)
287 (t (gnus-read-save-file-name
288 "Save in rmail file:" default-name))))
289 (make-directory (file-name-directory filename) t)
290 (gnus-eval-in-buffer-window gnus-original-article-buffer
294 (gnus-output-to-rmail filename))))
295 ;; Remember the directory name to save articles
296 (setq gnus-newsgroup-last-rmail filename)))
298 (defun gnus-summary-save-in-mail (&optional filename)
299 "Append this article to Unix mail file.
300 Optional argument FILENAME specifies file name.
301 Directory to save to is default to `gnus-article-save-directory'."
303 (gnus-set-global-variables)
305 (funcall gnus-mail-save-name gnus-newsgroup-name
306 gnus-current-headers gnus-newsgroup-last-mail)))
308 (cond ((eq filename 'default)
311 (t (gnus-read-save-file-name
312 "Save in Unix mail file:" default-name))))
314 (expand-file-name filename
316 (file-name-directory default-name))))
317 (make-directory (file-name-directory filename) t)
318 (gnus-eval-in-buffer-window gnus-original-article-buffer
322 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
323 (gnus-output-to-rmail filename)
324 (let ((mail-use-rfc822 t))
325 (rmail-output filename 1 t t))))))
326 ;; Remember the directory name to save articles.
327 (setq gnus-newsgroup-last-mail filename)))
329 (defun gnus-summary-save-in-file (&optional filename)
330 "Append this article to file.
331 Optional argument FILENAME specifies file name.
332 Directory to save to is default to `gnus-article-save-directory'."
334 (gnus-set-global-variables)
336 (funcall gnus-file-save-name gnus-newsgroup-name
337 gnus-current-headers gnus-newsgroup-last-file)))
339 (cond ((eq filename 'default)
342 (t (gnus-read-save-file-name
343 "Save in file:" default-name))))
344 (make-directory (file-name-directory filename) t)
345 (gnus-eval-in-buffer-window gnus-original-article-buffer
349 (gnus-output-to-file filename))))
350 ;; Remember the directory name to save articles.
351 (setq gnus-newsgroup-last-file filename)))
353 (defun gnus-summary-save-body-in-file (&optional filename)
354 "Append this article body to a file.
355 Optional argument FILENAME specifies file name.
356 The directory to save in defaults to `gnus-article-save-directory'."
358 (gnus-set-global-variables)
360 (funcall gnus-file-save-name gnus-newsgroup-name
361 gnus-current-headers gnus-newsgroup-last-file)))
363 (cond ((eq filename 'default)
366 (t (gnus-read-save-file-name
367 "Save body in file:" default-name))))
368 (make-directory (file-name-directory filename) t)
369 (gnus-eval-in-buffer-window gnus-original-article-buffer
373 (goto-char (point-min))
374 (and (search-forward "\n\n" nil t)
375 (narrow-to-region (point) (point-max)))
376 (gnus-output-to-file filename))))
377 ;; Remember the directory name to save articles.
378 (setq gnus-newsgroup-last-file filename)))
380 (defun gnus-summary-save-in-pipe (&optional command)
381 "Pipe this article to subprocess."
383 (gnus-set-global-variables)
385 (cond ((eq command 'default)
386 gnus-last-shell-command)
388 (t (read-string "Shell command on article: "
389 gnus-last-shell-command))))
390 (if (string-equal command "")
391 (setq command gnus-last-shell-command))
392 (gnus-eval-in-buffer-window gnus-article-buffer
395 (shell-command-on-region (point-min) (point-max) command nil)))
396 (setq gnus-last-shell-command command))
398 ;;; Article file names when saving.
400 (defun gnus-capitalize-newsgroup (newsgroup)
401 "Capitalize NEWSGROUP name."
402 (and (not (zerop (length newsgroup)))
403 (concat (char-to-string (upcase (aref newsgroup 0)))
404 (substring newsgroup 1))))
406 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
407 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
408 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
409 Otherwise, it is like ~/News/news/group/num."
412 (concat (if (gnus-use-long-file-name 'not-save)
413 (gnus-capitalize-newsgroup newsgroup)
414 (gnus-newsgroup-directory-form newsgroup))
415 "/" (int-to-string (mail-header-number headers)))
416 gnus-article-save-directory)))
418 (string-equal (file-name-directory default)
419 (file-name-directory last-file))
420 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
422 (or last-file default))))
424 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
425 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
426 If variable `gnus-use-long-file-name' is non-nil, it is
427 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
430 (concat (if (gnus-use-long-file-name 'not-save)
432 (gnus-newsgroup-directory-form newsgroup))
433 "/" (int-to-string (mail-header-number headers)))
434 gnus-article-save-directory)))
436 (string-equal (file-name-directory default)
437 (file-name-directory last-file))
438 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
440 (or last-file default))))
442 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
443 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
444 If variable `gnus-use-long-file-name' is non-nil, it is
445 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
448 (if (gnus-use-long-file-name 'not-save)
449 (gnus-capitalize-newsgroup newsgroup)
450 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
451 gnus-article-save-directory)))
453 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
454 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
455 If variable `gnus-use-long-file-name' is non-nil, it is
456 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
459 (if (gnus-use-long-file-name 'not-save)
461 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
462 gnus-article-save-directory)))
466 ;;; Gnus article mode
469 (put 'gnus-article-mode 'mode-class 'special)
472 (gnus-define-keys gnus-article-mode-map
473 " " gnus-article-goto-next-page
474 "\177" gnus-article-goto-prev-page
475 [delete] gnus-article-goto-prev-page
476 "\C-c^" gnus-article-refer-article
477 "h" gnus-article-show-summary
478 "s" gnus-article-show-summary
479 "\C-c\C-m" gnus-article-mail
480 "?" gnus-article-describe-briefly
481 gnus-mouse-2 gnus-article-push-button
482 "\r" gnus-article-press-button
483 "\t" gnus-article-next-button
484 "\M-\t" gnus-article-prev-button
485 "e" gnus-article-edit
486 "<" beginning-of-buffer
488 "\C-c\C-i" gnus-info-find-node
491 (substitute-key-definition
492 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
494 (defun gnus-article-make-menu-bar ()
495 (gnus-turn-off-edit-menu 'article)
496 (unless (boundp 'gnus-article-article-menu)
498 gnus-article-article-menu gnus-article-mode-map ""
500 ["Scroll forwards" gnus-article-goto-next-page t]
501 ["Scroll backwards" gnus-article-goto-prev-page t]
502 ["Show summary" gnus-article-show-summary t]
503 ["Fetch Message-ID at point" gnus-article-refer-article t]
504 ["Mail to address at point" gnus-article-mail t]
508 gnus-article-treatment-menu gnus-article-mode-map ""
510 ["Hide headers" gnus-article-hide-headers t]
511 ["Hide signature" gnus-article-hide-signature t]
512 ["Hide citation" gnus-article-hide-citation t]
513 ["Treat overstrike" gnus-article-treat-overstrike t]
514 ["Remove carriage return" gnus-article-remove-cr t]
515 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
517 (run-hooks 'gnus-article-menu-hook)))
519 (defun gnus-article-mode ()
520 "Major mode for displaying an article.
522 All normal editing commands are switched off.
524 The following commands are available in addition to all summary mode
526 \\<gnus-article-mode-map>
527 \\[gnus-article-next-page]\t Scroll the article one page forwards
528 \\[gnus-article-prev-page]\t Scroll the article one page backwards
529 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
530 \\[gnus-article-show-summary]\t Display the summary buffer
531 \\[gnus-article-mail]\t Send a reply to the address near point
532 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
533 \\[gnus-info-find-node]\t Go to the Gnus info node"
535 (when (and menu-bar-mode
536 (gnus-visual-p 'article-menu 'menu))
537 (gnus-article-make-menu-bar))
538 (kill-all-local-variables)
539 (gnus-simplify-mode-line)
540 (setq mode-name "Article")
541 (setq major-mode 'gnus-article-mode)
542 (make-local-variable 'minor-mode-alist)
543 (or (assq 'gnus-show-mime minor-mode-alist)
544 (setq minor-mode-alist
545 (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
546 (use-local-map gnus-article-mode-map)
547 (gnus-update-format-specifications nil 'article-mode)
548 (make-local-variable 'page-delimiter)
549 (setq page-delimiter gnus-page-delimiter)
550 (buffer-disable-undo (current-buffer))
551 (setq buffer-read-only t) ;Disable modification
552 (run-hooks 'gnus-article-mode-hook))
554 (defun gnus-article-setup-buffer ()
555 "Initialize the article buffer."
556 (let* ((name (if gnus-single-article-buffer "*Article*"
557 (concat "*Article " gnus-newsgroup-name "*")))
559 (progn (string-match "\\*Article" name)
560 (concat " *Original Article"
561 (substring name (match-end 0))))))
562 (setq gnus-article-buffer name)
563 (setq gnus-original-article-buffer original)
564 ;; This might be a variable local to the summary buffer.
565 (unless gnus-single-article-buffer
567 (set-buffer gnus-summary-buffer)
568 (setq gnus-article-buffer name)
569 (setq gnus-original-article-buffer original)
570 (gnus-set-global-variables))
571 (make-local-variable 'gnus-summary-buffer))
572 ;; Init original article buffer.
574 (set-buffer (get-buffer-create gnus-original-article-buffer))
575 (buffer-disable-undo (current-buffer))
576 (setq major-mode 'gnus-original-article-mode)
577 (gnus-add-current-to-buffer-list)
578 (make-local-variable 'gnus-original-article))
579 (if (get-buffer name)
582 (buffer-disable-undo (current-buffer))
583 (setq buffer-read-only t)
584 (gnus-add-current-to-buffer-list)
585 (or (eq major-mode 'gnus-article-mode)
589 (set-buffer (get-buffer-create name))
590 (gnus-add-current-to-buffer-list)
594 ;; Set article window start at LINE, where LINE is the number of lines
595 ;; from the head of the article.
596 (defun gnus-article-set-window-start (&optional line)
598 (get-buffer-window gnus-article-buffer t)
600 (set-buffer gnus-article-buffer)
601 (goto-char (point-min))
604 (gnus-message 6 "Moved to bookmark")
605 (search-forward "\n\n" nil t)
609 (defun gnus-article-prepare (article &optional all-headers header)
610 "Prepare ARTICLE in article mode buffer.
611 ARTICLE should either be an article number or a Message-ID.
612 If ARTICLE is an id, HEADER should be the article headers.
613 If ALL-HEADERS is non-nil, no headers are hidden."
615 ;; Make sure we start in a summary buffer.
616 (unless (eq major-mode 'gnus-summary-mode)
617 (set-buffer gnus-summary-buffer))
618 (setq gnus-summary-buffer (current-buffer))
619 ;; Make sure the connection to the server is alive.
620 (unless (gnus-server-opened
621 (gnus-find-method-for-group gnus-newsgroup-name))
622 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
623 (gnus-request-group gnus-newsgroup-name t))
624 (let* ((article (if header (mail-header-number header) article))
625 (summary-buffer (current-buffer))
626 (internal-hook gnus-article-internal-prepare-hook)
627 (group gnus-newsgroup-name)
630 (gnus-article-setup-buffer)
631 (set-buffer gnus-article-buffer)
632 ;; Deactivate active regions.
633 (when (and (boundp 'transient-mark-mode)
635 (setq mark-active nil))
636 (if (not (setq result (let ((buffer-read-only nil))
637 (gnus-request-article-this-buffer
639 ;; There is no such article.
641 (when (and (numberp article)
642 (not (memq article gnus-newsgroup-sparse)))
643 (setq gnus-article-current
644 (cons gnus-newsgroup-name article))
645 (set-buffer gnus-summary-buffer)
646 (setq gnus-current-article article)
647 (gnus-summary-mark-article article gnus-canceled-mark))
648 (unless (memq article gnus-newsgroup-sparse)
650 1 "No such article (may have expired or been canceled)")))
651 (if (or (eq result 'pseudo) (eq result 'nneething))
654 (set-buffer summary-buffer)
655 (setq gnus-last-article gnus-current-article
656 gnus-newsgroup-history (cons gnus-current-article
657 gnus-newsgroup-history)
658 gnus-current-article 0
659 gnus-current-headers nil
660 gnus-article-current nil)
661 (if (eq result 'nneething)
662 (gnus-configure-windows 'summary)
663 (gnus-configure-windows 'article))
664 (gnus-set-global-variables))
665 (gnus-set-mode-line 'article))
666 ;; The result from the `request' was an actual article -
667 ;; or at least some text that is now displayed in the
669 (if (and (numberp article)
670 (not (eq article gnus-current-article)))
671 ;; Seems like a new article has been selected.
672 ;; `gnus-current-article' must be an article number.
674 (set-buffer summary-buffer)
675 (setq gnus-last-article gnus-current-article
676 gnus-newsgroup-history (cons gnus-current-article
677 gnus-newsgroup-history)
678 gnus-current-article article
680 (gnus-summary-article-header gnus-current-article)
682 (cons gnus-newsgroup-name gnus-current-article))
683 (unless (vectorp gnus-current-headers)
684 (setq gnus-current-headers nil))
685 (gnus-summary-show-thread)
686 (run-hooks 'gnus-mark-article-hook)
687 (gnus-set-mode-line 'summary)
688 (and (gnus-visual-p 'article-highlight 'highlight)
689 (run-hooks 'gnus-visual-mark-article-hook))
690 ;; Set the global newsgroup variables here.
691 ;; Suggested by Jim Sisolak
692 ;; <sisolak@trans4.neep.wisc.edu>.
693 (gnus-set-global-variables)
694 (setq gnus-have-all-headers
695 (or all-headers gnus-show-all-headers))
697 (vectorp (gnus-summary-article-header article))
698 (gnus-cache-possibly-enter-article
700 (gnus-summary-article-header article)
701 (memq article gnus-newsgroup-marked)
702 (memq article gnus-newsgroup-dormant)
703 (memq article gnus-newsgroup-unreads)))))
704 (when (or (numberp article)
706 ;; Hooks for getting information from the article.
707 ;; This hook must be called before being narrowed.
708 (let (buffer-read-only)
709 (run-hooks 'internal-hook)
710 (run-hooks 'gnus-article-prepare-hook)
711 ;; Decode MIME message.
713 (if (or (not gnus-strict-mime)
714 (gnus-fetch-field "Mime-Version"))
715 (funcall gnus-show-mime-method)
716 (funcall gnus-decode-encoded-word-method)))
717 ;; Perform the article display hooks.
718 (run-hooks 'gnus-article-display-hook))
720 (goto-char (point-min))
721 (and gnus-break-pages (gnus-narrow-to-page)))
722 (gnus-set-mode-line 'article)
723 (gnus-configure-windows 'article)
724 (goto-char (point-min))
727 (defun gnus-article-wash-status ()
728 "Return a string which display status of article washing."
730 (set-buffer gnus-article-buffer)
731 (let ((cite (article-hidden-text-p 'cite))
732 (headers (article-hidden-text-p 'headers))
733 (boring (article-hidden-text-p 'boring-headers))
734 (pgp (article-hidden-text-p 'pgp))
735 (pem (article-hidden-text-p 'pem))
736 (signature (article-hidden-text-p 'signature))
737 (overstrike (article-hidden-text-p 'overstrike))
738 (emphasis (article-hidden-text-p 'emphasis))
739 (mime gnus-show-mime))
740 (format "%c%c%c%c%c%c%c"
742 (if (or headers boring) ?h ? )
743 (if (or pgp pem) ?p ? )
745 (if overstrike ?o ? )
747 (if emphasis ?e ? )))))
749 (defun gnus-article-hide-headers-if-wanted ()
750 "Hide unwanted headers if `gnus-have-all-headers' is nil.
751 Provided for backwards compatibility."
752 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
754 (gnus-article-hide-headers)))
758 (defun gnus-output-to-rmail (file-name)
759 "Append the current article to an Rmail file named FILE-NAME."
761 ;; Most of these codes are borrowed from rmailout.el.
762 (setq file-name (expand-file-name file-name))
763 (setq rmail-default-rmail-file file-name)
764 (let ((artbuf (current-buffer))
765 (tmpbuf (get-buffer-create " *Gnus-output*")))
767 (or (get-file-buffer file-name)
768 (file-exists-p file-name)
769 (if (gnus-yes-or-no-p
770 (concat "\"" file-name "\" does not exist, create it? "))
771 (let ((file-buffer (create-file-buffer file-name)))
773 (set-buffer file-buffer)
774 (rmail-insert-rmail-file-header)
775 (let ((require-final-newline nil))
776 (write-region (point-min) (point-max) file-name t 1)))
777 (kill-buffer file-buffer))
778 (error "Output file does not exist")))
780 (buffer-disable-undo (current-buffer))
782 (insert-buffer-substring artbuf)
783 (gnus-convert-article-to-rmail)
784 ;; Decide whether to append to a file or to an Emacs buffer.
785 (let ((outbuf (get-file-buffer file-name)))
787 (append-to-file (point-min) (point-max) file-name)
788 ;; File has been visited, in buffer OUTBUF.
790 (let ((buffer-read-only nil)
791 (msg (and (boundp 'rmail-current-message)
792 (symbol-value 'rmail-current-message))))
793 ;; If MSG is non-nil, buffer is in RMAIL mode.
796 (narrow-to-region (point-max) (point-max))))
797 (insert-buffer-substring tmpbuf)
800 (goto-char (point-min))
802 (search-backward "\^_")
803 (narrow-to-region (point) (point-max))
804 (goto-char (1+ (point-min)))
805 (rmail-count-new-messages t)
806 (rmail-show-message msg)))))))
807 (kill-buffer tmpbuf)))
809 (defun gnus-output-to-file (file-name)
810 "Append the current article to a file named FILE-NAME."
811 (let ((artbuf (current-buffer)))
812 (nnheader-temp-write nil
813 (insert-buffer-substring artbuf)
814 ;; Append newline at end of the buffer as separator, and then
816 (goto-char (point-max))
818 (append-to-file (point-min) (point-max) file-name))))
820 (defun gnus-convert-article-to-rmail ()
821 "Convert article in current buffer to Rmail message format."
822 (let ((buffer-read-only nil))
823 ;; Convert article directly into Babyl format.
824 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
825 (goto-char (point-min))
826 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
827 (while (search-forward "\n\^_" nil t) ;single char
828 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
829 (goto-char (point-max))
832 (defun gnus-narrow-to-page (&optional arg)
833 "Narrow the article buffer to a page.
834 If given a numerical ARG, move forward ARG pages."
836 (setq arg (if arg (prefix-numeric-value arg) 0))
838 (set-buffer gnus-article-buffer)
839 (goto-char (point-min))
841 ;; Remove any old next/prev buttons.
842 (when (gnus-visual-p 'page-marker)
843 (let ((buffer-read-only nil))
844 (gnus-remove-text-with-property 'gnus-prev)
845 (gnus-remove-text-with-property 'gnus-next)))
848 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
850 (re-search-forward page-delimiter nil 'move arg)))
851 (goto-char (match-end 0)))
854 (if (re-search-forward page-delimiter nil 'move)
857 (when (and (gnus-visual-p 'page-marker)
858 (not (= (point-min) 1)))
860 (goto-char (point-min))
861 (gnus-insert-prev-page-button)))
862 (when (and (gnus-visual-p 'page-marker)
863 (< (+ (point-max) 2) (buffer-size)))
865 (goto-char (point-max))
866 (gnus-insert-next-page-button)))))
868 ;; Article mode commands
870 (defun gnus-article-goto-next-page ()
871 "Show the next page of the article."
873 (when (gnus-article-next-page)
874 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
876 (defun gnus-article-goto-prev-page ()
877 "Show the next page of the article."
879 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
880 (gnus-article-prev-page nil)))
882 (defun gnus-article-next-page (&optional lines)
883 "Show the next page of the current article.
884 If end of article, return non-nil. Otherwise return nil.
885 Argument LINES specifies lines to be scrolled up."
887 (move-to-window-line -1)
888 ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
891 (and (pos-visible-in-window-p) ;Not continuation line.
893 ;; Nothing in this page.
894 (if (or (not gnus-break-pages)
897 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
899 (gnus-narrow-to-page 1) ;Go to next page.
901 ;; More in this page.
905 ;; Long lines may cause an end-of-buffer error.
906 (goto-char (point-max))))
907 (move-to-window-line 0)
910 (defun gnus-article-prev-page (&optional lines)
911 "Show previous page of current article.
912 Argument LINES specifies lines to be scrolled down."
914 (move-to-window-line 0)
915 (if (and gnus-break-pages
917 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
919 (gnus-narrow-to-page -1) ;Go to previous page.
920 (goto-char (point-max))
926 (move-to-window-line 0))))
928 (defun gnus-article-refer-article ()
929 "Read article specified by message-id around point."
931 (let ((point (point)))
932 (search-forward ">" nil t) ;Move point to end of "<....>".
933 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
934 (let ((message-id (match-string 1)))
936 (set-buffer gnus-summary-buffer)
937 (gnus-summary-refer-article message-id))
939 (error "No references around point"))))
941 (defun gnus-article-show-summary ()
942 "Reconfigure windows to show summary buffer."
944 (gnus-configure-windows 'article)
945 (gnus-summary-goto-subject gnus-current-article))
947 (defun gnus-article-describe-briefly ()
948 "Describe article mode commands briefly."
951 (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")))
953 (defun gnus-article-summary-command ()
954 "Execute the last keystroke in the summary buffer."
956 (let ((obuf (current-buffer))
957 (owin (current-window-configuration))
959 (switch-to-buffer gnus-summary-buffer 'norecord)
960 (setq func (lookup-key (current-local-map) (this-command-keys)))
961 (call-interactively func)
963 (set-window-configuration owin)
964 (set-window-point (get-buffer-window (current-buffer)) (point))))
966 (defun gnus-article-summary-command-nosave ()
967 "Execute the last keystroke in the summary buffer."
970 (pop-to-buffer gnus-summary-buffer 'norecord)
971 (setq func (lookup-key (current-local-map) (this-command-keys)))
972 (call-interactively func)))
974 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
975 "Read a summary buffer key sequence and execute it from the article buffer."
978 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
979 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
985 (set-buffer gnus-summary-buffer)
986 (push (or key last-command-event) unread-command-events)
987 (setq keys (read-key-sequence nil)))
990 (if (or (member keys nosaves)
991 (member keys nosave-but-article))
993 (save-window-excursion
994 (pop-to-buffer gnus-summary-buffer 'norecord)
995 (setq func (lookup-key (current-local-map) keys)))
998 (set-buffer gnus-summary-buffer)
999 (call-interactively func))
1000 (when (member keys nosave-but-article)
1001 (pop-to-buffer gnus-article-buffer 'norecord)))
1002 (let ((obuf (current-buffer))
1003 (owin (current-window-configuration))
1006 (if not-restore-window
1007 (pop-to-buffer gnus-summary-buffer 'norecord)
1008 (switch-to-buffer gnus-summary-buffer 'norecord))
1009 (setq in-buffer (current-buffer))
1010 (if (setq func (lookup-key (current-local-map) keys))
1011 (call-interactively func)
1013 (when (eq in-buffer (current-buffer))
1015 (unless not-restore-window
1016 (set-window-configuration owin))
1017 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
1019 (defun gnus-article-hide (&optional arg force)
1020 "Hide all the gruft in the current article.
1021 This means that PGP stuff, signatures, cited text and (some)
1022 headers will be hidden.
1023 If given a prefix, show the hidden text instead."
1024 (interactive (list current-prefix-arg 'force))
1025 (gnus-article-hide-headers arg)
1026 (gnus-article-hide-pgp arg)
1027 (gnus-article-hide-citation-maybe arg force)
1028 (gnus-article-hide-signature arg))
1030 (defun gnus-article-maybe-highlight ()
1031 "Do some article highlighting if `article-visual' is non-nil."
1032 (if (gnus-visual-p 'article-highlight 'highlight)
1033 (gnus-article-highlight-some)))
1035 (defun gnus-request-article-this-buffer (article group)
1036 "Get an article and insert it into this buffer."
1037 (let (do-update-line)
1041 (gnus-kill-all-overlays)
1042 (setq group (or group gnus-newsgroup-name))
1044 ;; Open server if it has closed.
1045 (gnus-check-server (gnus-find-method-for-group group))
1047 ;; Using `gnus-request-article' directly will insert the article into
1048 ;; `nntp-server-buffer' - so we'll save some time by not having to
1049 ;; copy it from the server buffer into the article buffer.
1051 ;; We only request an article by message-id when we do not have the
1052 ;; headers for it, so we'll have to get those.
1053 (when (stringp article)
1054 (let ((gnus-override-method gnus-refer-article-method))
1055 (gnus-read-header article)))
1057 ;; If the article number is negative, that means that this article
1058 ;; doesn't belong in this newsgroup (possibly), so we find its
1059 ;; message-id and request it by id instead of number.
1060 (when (and (numberp article)
1062 (get-buffer gnus-summary-buffer)
1063 (buffer-name (get-buffer gnus-summary-buffer)))
1065 (set-buffer gnus-summary-buffer)
1066 (let ((header (gnus-summary-article-header article)))
1069 ((memq article gnus-newsgroup-sparse)
1070 ;; This is a sparse gap article.
1071 (setq do-update-line article)
1072 (setq article (mail-header-id header))
1073 (let ((gnus-override-method gnus-refer-article-method))
1074 (gnus-read-header article))
1075 (setq gnus-newsgroup-sparse
1076 (delq article gnus-newsgroup-sparse)))
1078 ;; It's a real article.
1079 (setq article (mail-header-id header)))
1081 ;; It is an extracted pseudo-article.
1082 (setq article 'pseudo)
1083 (gnus-request-pseudo-article header))))
1085 (let ((method (gnus-find-method-for-group
1086 gnus-newsgroup-name)))
1087 (if (not (eq (car method) 'nneething))
1089 (let ((dir (concat (file-name-as-directory (nth 1 method))
1090 (mail-header-subject header))))
1091 (if (file-directory-p dir)
1093 (setq article 'nneething)
1094 (gnus-group-enter-directory dir)))))))))
1097 ;; Refuse to select canceled articles.
1098 ((and (numberp article)
1100 (get-buffer gnus-summary-buffer)
1101 (buffer-name (get-buffer gnus-summary-buffer))
1102 (eq (cdr (save-excursion
1103 (set-buffer gnus-summary-buffer)
1104 (assq article gnus-newsgroup-reads)))
1105 gnus-canceled-mark))
1107 ;; We first check `gnus-original-article-buffer'.
1108 ((and (get-buffer gnus-original-article-buffer)
1111 (set-buffer gnus-original-article-buffer)
1112 (and (equal (car gnus-original-article) group)
1113 (eq (cdr gnus-original-article) article))))
1114 (insert-buffer-substring gnus-original-article-buffer)
1116 ;; Check the backlog.
1117 ((and gnus-keep-backlog
1118 (gnus-backlog-request-article group article (current-buffer)))
1120 ;; Check asynchronous pre-fetch.
1121 ((gnus-async-request-fetched-article group article (current-buffer))
1122 (gnus-async-prefetch-next group article gnus-summary-buffer)
1125 ((and gnus-use-cache
1127 (gnus-cache-request-article article group))
1129 ;; Get the article and put into the article buffer.
1130 ((or (stringp article) (numberp article))
1131 (let ((gnus-override-method
1132 (and (stringp article) gnus-refer-article-method))
1133 (buffer-read-only nil))
1135 (gnus-kill-all-overlays)
1136 (when (gnus-request-article article group (current-buffer))
1137 (when (numberp article)
1138 (gnus-async-prefetch-next group article gnus-summary-buffer)
1139 (when gnus-keep-backlog
1140 (gnus-backlog-enter-article
1141 group article (current-buffer))))
1146 ;; Take the article from the original article buffer
1147 ;; and place it in the buffer it's supposed to be in.
1148 (when (and (get-buffer gnus-article-buffer)
1150 (equal (buffer-name (current-buffer))
1151 (buffer-name (get-buffer gnus-article-buffer))))
1153 (if (get-buffer gnus-original-article-buffer)
1154 (set-buffer (get-buffer gnus-original-article-buffer))
1155 (set-buffer (get-buffer-create gnus-original-article-buffer))
1156 (buffer-disable-undo (current-buffer))
1157 (setq major-mode 'gnus-original-article-mode)
1158 (setq buffer-read-only t)
1159 (gnus-add-current-to-buffer-list))
1160 (let (buffer-read-only)
1162 (insert-buffer-substring gnus-article-buffer))
1163 (setq gnus-original-article (cons group article))))
1165 ;; Update sparse articles.
1166 (when (and do-update-line
1167 (or (numberp article)
1169 (let ((buf (current-buffer)))
1170 (set-buffer gnus-summary-buffer)
1171 (gnus-summary-update-article do-update-line)
1172 (gnus-summary-goto-subject do-update-line nil t)
1173 (set-window-point (get-buffer-window (current-buffer) t)
1175 (set-buffer buf))))))
1177 (defun gnus-article-date-ut (&optional type highlight)
1178 "Convert DATE date to universal time in the current article.
1179 If TYPE is `local', convert to local time; if it is `lapsed', output
1180 how much time has lapsed since DATE."
1181 (interactive (list 'ut t))
1182 (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1184 (set-buffer gnus-article-buffer)
1185 (article-date-ut type highlight headers))))
1191 (defvar gnus-article-edit-mode-hook nil
1192 "*Hook run in article edit mode buffers.")
1194 (defvar gnus-article-edit-done-function nil)
1196 (defvar gnus-article-edit-mode-map nil)
1198 (unless gnus-article-edit-mode-map
1199 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1201 (gnus-define-keys gnus-article-edit-mode-map
1202 "\C-c\C-c" gnus-article-edit-done
1203 "\C-c\C-k" gnus-article-edit-exit)
1205 (gnus-define-keys (gnus-article-edit-wash-map
1206 "\C-c\C-w" gnus-article-edit-mode-map)
1207 "f" gnus-article-edit-full-stops))
1209 (defun gnus-article-edit-mode ()
1210 "Major mode for editing articles.
1211 This is an extended text-mode.
1213 \\{gnus-article-edit-mode-map}"
1215 (kill-all-local-variables)
1216 (setq major-mode 'gnus-article-edit-mode)
1217 (setq mode-name "Article Edit")
1218 (use-local-map gnus-article-edit-mode-map)
1219 (make-local-variable 'gnus-article-edit-done-function)
1220 (make-local-variable 'gnus-prev-winconf)
1221 (setq buffer-read-only nil)
1222 (buffer-enable-undo)
1224 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1226 (defun gnus-article-edit (&optional force)
1227 "Edit the current article.
1228 This will have permanent effect only in mail groups.
1229 If FORCE is non-nil, allow editing of articles even in read-only
1232 (when (and (not force)
1233 (gnus-group-read-only-p))
1234 (error "The current newsgroup does not support article editing."))
1235 (gnus-article-edit-article
1237 (gnus-summary-edit-article-done
1238 ,(or (mail-header-references gnus-current-headers) "")
1239 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1241 (defun gnus-article-edit-article (exit-func)
1242 "Start editing the contents of the current article buffer."
1243 (let ((winconf (current-window-configuration)))
1244 (set-buffer gnus-article-buffer)
1245 (gnus-article-edit-mode)
1246 (gnus-configure-windows 'edit-article)
1247 (setq gnus-article-edit-done-function exit-func)
1248 (setq gnus-prev-winconf winconf)
1249 (gnus-message 6 "C-c C-c to end edits")))
1251 (defun gnus-article-edit-done ()
1252 "Update the article edits and exit."
1254 (let ((func gnus-article-edit-done-function)
1255 (buf (current-buffer))
1256 (start (window-start)))
1257 (gnus-article-edit-exit)
1258 (let ((cur (current-buffer)))
1261 (let ((buffer-read-only nil))
1264 (set-window-start (get-buffer-window buf) start)
1265 (set-window-point (get-buffer-window buf) (point)))))
1267 (defun gnus-article-edit-exit ()
1268 "Exit the article editing without updating."
1270 ;; We remove all text props from the article buffer.
1271 (let ((buf (format "%s" (buffer-string)))
1272 (curbuf (current-buffer))
1274 (window-start (window-start)))
1277 (let ((winconf gnus-prev-winconf))
1279 ;; The cache and backlog have to be flushed somewhat.
1280 (when gnus-use-cache
1281 (gnus-cache-update-article
1282 (car gnus-article-current) (cdr gnus-article-current)))
1283 (when gnus-keep-backlog
1284 (gnus-backlog-remove-article
1285 (car gnus-article-current) (cdr gnus-article-current)))
1286 ;; Flush original article as well.
1288 (when (get-buffer gnus-original-article-buffer)
1289 (set-buffer gnus-original-article-buffer)
1290 (setq gnus-original-article nil)))
1291 (set-window-configuration winconf)
1292 ;; Tippy-toe some to make sure that point remains where it was.
1293 (let ((buf (current-buffer)))
1295 (set-window-start (get-buffer-window (current-buffer)) window-start)
1297 (set-buffer buf)))))
1299 (defun gnus-article-edit-full-stops ()
1300 "Interactively repair spacing at end of sentences."
1303 (goto-char (point-min))
1304 (search-forward-regexp "^$" nil t)
1305 (let ((case-fold-search nil))
1306 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1309 ;;; Article highlights
1312 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1314 ;;; Internal Variables:
1316 (defvar 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_=#$@~`%&*+|\\/]"
1317 "*Regular expression that matches URLs.")
1319 (defvar gnus-button-alist
1320 `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
1321 t gnus-button-message-id 3)
1322 ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1323 gnus-button-message-id 3)
1324 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-button-reply 2)
1325 ;; This is how URLs _should_ be embedded in text...
1326 ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1327 ;; Next regexp stolen from highlight-headers.el.
1328 ;; Modified by Vladimir Alexiev.
1329 (,gnus-button-url-regexp 0 t gnus-button-url 0))
1330 "Alist of regexps matching buttons in article bodies.
1332 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1333 REGEXP: is the string matching text around the button,
1334 BUTTON: is the number of the regexp grouping actually matching the button,
1335 FORM: is a lisp expression which must eval to true for the button to
1337 CALLBACK: is the function to call when the user push this button, and each
1338 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1340 CALLBACK can also be a variable, in that case the value of that
1341 variable it the real callback function.")
1343 (defvar gnus-header-button-alist
1344 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1345 0 t gnus-button-message-id 0)
1346 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1347 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
1348 0 t gnus-button-mailto 0)
1349 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1350 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1351 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1352 gnus-button-message-id 3))
1353 "Alist of headers and regexps to match buttons in article heads.
1355 This alist is very similar to `gnus-button-alist', except that each
1356 alist has an additional HEADER element first in each entry:
1358 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1360 HEADER is a regexp to match a header. For a fuller explanation, see
1361 `gnus-button-alist'.")
1363 (defvar gnus-button-regexp nil)
1364 (defvar gnus-button-marker-list nil)
1365 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1367 (defvar gnus-button-last nil)
1368 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1372 (defun gnus-article-push-button (event)
1373 "Check text under the mouse pointer for a callback function.
1374 If the text under the mouse pointer has a `gnus-callback' property,
1375 call it with the value of the `gnus-data' text property."
1377 (set-buffer (window-buffer (posn-window (event-start event))))
1378 (let* ((pos (posn-point (event-start event)))
1379 (data (get-text-property pos 'gnus-data))
1380 (fun (get-text-property pos 'gnus-callback)))
1381 (if fun (funcall fun data))))
1383 (defun gnus-article-press-button ()
1384 "Check text at point for a callback function.
1385 If the text at point has a `gnus-callback' property,
1386 call it with the value of the `gnus-data' text property."
1388 (let* ((data (get-text-property (point) 'gnus-data))
1389 (fun (get-text-property (point) 'gnus-callback)))
1390 (if fun (funcall fun data))))
1392 (defun gnus-article-prev-button (n)
1393 "Move point to N buttons backward.
1394 If N is negative, move forward instead."
1396 (gnus-article-next-button (- n)))
1398 (defun gnus-article-next-button (n)
1399 "Move point to N buttons forward.
1400 If N is negative, move backward instead."
1402 (let ((function (if (< n 0) 'previous-single-property-change
1403 'next-single-property-change))
1404 (inhibit-point-motion-hooks t)
1406 (limit (if (< n 0) (point-min) (point-max))))
1408 (while (and (not (= limit (point)))
1410 ;; Skip past the current button.
1411 (when (get-text-property (point) 'gnus-callback)
1412 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1413 ;; Go to the next (or previous) button.
1414 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1415 ;; Put point at the start of the button.
1416 (when (and backward (not (get-text-property (point) 'gnus-callback)))
1417 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1418 ;; Skip past intangible buttons.
1419 (when (get-text-property (point) 'intangible)
1423 (gnus-message 5 "No more buttons"))
1426 (defun gnus-article-highlight (&optional force)
1427 "Highlight current article.
1428 This function calls `gnus-article-highlight-headers',
1429 `gnus-article-highlight-citation',
1430 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1431 do the highlighting. See the documentation for those functions."
1432 (interactive (list 'force))
1433 (gnus-article-highlight-headers)
1434 (gnus-article-highlight-citation force)
1435 (gnus-article-highlight-signature)
1436 (gnus-article-add-buttons force)
1437 (gnus-article-add-buttons-to-head))
1439 (defun gnus-article-highlight-some (&optional force)
1440 "Highlight current article.
1441 This function calls `gnus-article-highlight-headers',
1442 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1443 do the highlighting. See the documentation for those functions."
1444 (interactive (list 'force))
1445 (gnus-article-highlight-headers)
1446 (gnus-article-highlight-signature)
1447 (gnus-article-add-buttons))
1449 (defun gnus-article-highlight-headers ()
1450 "Highlight article headers as specified by `gnus-header-face-alist'."
1453 (set-buffer gnus-article-buffer)
1455 (let ((alist gnus-header-face-alist)
1456 (buffer-read-only nil)
1457 (case-fold-search t)
1458 (inhibit-point-motion-hooks t)
1459 entry regexp header-face field-face from hpoints fpoints)
1460 (goto-char (point-min))
1461 (when (search-forward "\n\n" nil t)
1462 (narrow-to-region (1- (point)) (point-min))
1463 (while (setq entry (pop alist))
1464 (goto-char (point-min))
1465 (setq regexp (concat "^\\("
1466 (if (string-equal "" (nth 0 entry))
1470 header-face (nth 1 entry)
1471 field-face (nth 2 entry))
1472 (while (and (re-search-forward regexp nil t)
1476 (or (search-forward ":" nil t)
1478 (when (and header-face
1479 (not (memq (point) hpoints)))
1480 (push (point) hpoints)
1481 (gnus-put-text-property from (point) 'face header-face))
1482 (when (and field-face
1483 (not (memq (setq from (point)) fpoints)))
1485 (if (re-search-forward "^[^ \t]" nil t)
1487 (goto-char (point-max)))
1488 (gnus-put-text-property from (point) 'face field-face)))))))))
1490 (defun gnus-article-highlight-signature ()
1491 "Highlight the signature in an article.
1492 It does this by highlighting everything after
1493 `gnus-signature-separator' using `gnus-signature-face'."
1496 (set-buffer gnus-article-buffer)
1497 (let ((buffer-read-only nil)
1498 (inhibit-point-motion-hooks t))
1500 (when (and gnus-signature-face
1501 (article-narrow-to-signature))
1502 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1503 'face gnus-signature-face)
1505 (article-search-signature)
1506 (let ((start (match-beginning 0))
1507 (end (set-marker (make-marker) (1+ (match-end 0)))))
1508 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1511 (defun gnus-article-add-buttons (&optional force)
1512 "Find external references in the article and make buttons of them.
1513 \"External references\" are things like Message-IDs and URLs, as
1514 specified by `gnus-button-alist'."
1515 (interactive (list 'force))
1517 (set-buffer gnus-article-buffer)
1518 ;; Remove all old markers.
1519 (while gnus-button-marker-list
1520 (set-marker (pop gnus-button-marker-list) nil))
1521 (let ((buffer-read-only nil)
1522 (inhibit-point-motion-hooks t)
1523 (case-fold-search t)
1524 (alist gnus-button-alist)
1526 (goto-char (point-min))
1527 ;; We skip the headers.
1528 (unless (search-forward "\n\n" nil t)
1529 (goto-char (point-max)))
1531 (while (setq entry (pop alist))
1532 (setq regexp (car entry))
1534 (while (re-search-forward regexp nil t)
1535 (let* ((start (and entry (match-beginning (nth 1 entry))))
1536 (end (and entry (match-end (nth 1 entry))))
1537 (from (match-beginning 0)))
1538 (when (or (eq t (nth 1 entry))
1539 (eval (nth 1 entry)))
1540 ;; That optional form returned non-nil, so we add the
1542 (gnus-article-add-button
1543 start end 'gnus-button-push
1544 (car (push (set-marker (make-marker) from)
1545 gnus-button-marker-list))))))))))
1547 ;; Add buttons to the head of an article.
1548 (defun gnus-article-add-buttons-to-head ()
1549 "Add buttons to the head of the article."
1552 (set-buffer gnus-article-buffer)
1553 (let ((buffer-read-only nil)
1554 (inhibit-point-motion-hooks t)
1555 (case-fold-search t)
1556 (alist gnus-header-button-alist)
1558 (nnheader-narrow-to-headers)
1560 ;; Each alist entry.
1561 (setq entry (car alist)
1563 (goto-char (point-min))
1564 (while (re-search-forward (car entry) nil t)
1565 ;; Each header matching the entry.
1566 (setq beg (match-beginning 0))
1567 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1568 (match-beginning 0))
1571 (while (re-search-forward (nth 1 entry) end t)
1572 ;; Each match within a header.
1573 (let* ((from (match-beginning 0))
1575 (start (match-beginning (nth 1 entry)))
1576 (end (match-end (nth 1 entry)))
1577 (form (nth 2 entry)))
1578 (goto-char (match-end 0))
1580 (gnus-article-add-button
1581 start end (nth 3 entry)
1582 (buffer-substring (match-beginning (nth 4 entry))
1583 (match-end (nth 4 entry)))))))
1587 ;;; External functions:
1589 (defun gnus-article-add-button (from to fun &optional data)
1590 "Create a button between FROM and TO with callback FUN and data DATA."
1591 (and gnus-article-button-face
1592 (gnus-overlay-put (gnus-make-overlay from to)
1593 'face gnus-article-button-face))
1594 (gnus-add-text-properties
1596 (nconc (and gnus-article-mouse-face
1597 (list gnus-mouse-face-prop gnus-article-mouse-face))
1598 (list 'gnus-callback fun)
1599 (and data (list 'gnus-data data)))))
1601 ;;; Internal functions:
1603 (defun gnus-signature-toggle (end)
1605 (set-buffer gnus-article-buffer)
1606 (let ((buffer-read-only nil)
1607 (inhibit-point-motion-hooks t))
1608 (if (get-text-property end 'invisible)
1609 (article-unhide-text end (point-max))
1610 (article-hide-text end (point-max) gnus-hidden-properties)))))
1612 (defun gnus-button-entry ()
1613 ;; Return the first entry in `gnus-button-alist' matching this place.
1614 (let ((alist gnus-button-alist)
1617 (setq entry (pop alist))
1618 (if (looking-at (car entry))
1623 (defun gnus-button-push (marker)
1624 ;; Push button starting at MARKER.
1626 (set-buffer gnus-article-buffer)
1628 (let* ((entry (gnus-button-entry))
1629 (inhibit-point-motion-hooks t)
1631 (args (mapcar (lambda (group)
1632 (let ((string (buffer-substring
1633 (match-beginning group)
1634 (match-end group))))
1635 (gnus-set-text-properties
1636 0 (length string) nil string)
1643 (fboundp (symbol-value fun)))
1644 (apply (symbol-value fun) args))
1646 (gnus-message 1 "You must define `%S' to use this button"
1647 (cons fun args)))))))
1649 (defun gnus-button-message-id (message-id)
1652 (set-buffer gnus-summary-buffer)
1653 (gnus-summary-refer-article message-id)))
1655 (defun gnus-button-mailto (address)
1657 (set-buffer (gnus-copy-article-buffer))
1658 (message-reply address))
1660 (defun gnus-button-reply (address)
1661 ;; Reply to ADDRESS.
1662 (message-reply address))
1664 (defun gnus-button-url (address)
1666 (funcall browse-url-browser-function address browse-url-new-window-p))
1668 ;;; Next/prev buttons in the article buffer.
1670 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1671 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1673 (defvar gnus-prev-page-map nil)
1674 (unless gnus-prev-page-map
1675 (setq gnus-prev-page-map (make-sparse-keymap))
1676 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1677 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1679 (defun gnus-insert-prev-page-button ()
1680 (let ((buffer-read-only nil))
1682 gnus-prev-page-line-format nil
1683 `(gnus-prev t local-map ,gnus-prev-page-map
1684 gnus-callback gnus-article-button-prev-page))))
1686 (defvar gnus-next-page-map nil)
1687 (unless gnus-next-page-map
1688 (setq gnus-next-page-map (make-keymap))
1689 (suppress-keymap gnus-prev-page-map)
1690 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1691 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1693 (defun gnus-button-next-page ()
1694 "Go to the next page."
1696 (let ((win (selected-window)))
1697 (select-window (get-buffer-window gnus-article-buffer t))
1698 (gnus-article-next-page)
1699 (select-window win)))
1701 (defun gnus-button-prev-page ()
1702 "Go to the prev page."
1704 (let ((win (selected-window)))
1705 (select-window (get-buffer-window gnus-article-buffer t))
1706 (gnus-article-prev-page)
1707 (select-window win)))
1709 (defun gnus-insert-next-page-button ()
1710 (let ((buffer-read-only nil))
1711 (gnus-eval-format gnus-next-page-line-format nil
1712 `(gnus-next t local-map ,gnus-next-page-map
1714 gnus-article-button-next-page))))
1716 (defun gnus-article-button-next-page (arg)
1717 "Go to the next page."
1719 (let ((win (selected-window)))
1720 (select-window (get-buffer-window gnus-article-buffer t))
1721 (gnus-article-next-page)
1722 (select-window win)))
1724 (defun gnus-article-button-prev-page (arg)
1725 "Go to the prev page."
1727 (let ((win (selected-window)))
1728 (select-window (get-buffer-window gnus-article-buffer t))
1729 (gnus-article-prev-page)
1730 (select-window win)))
1734 ;;; gnus-art.el ends here