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 (defvar gnus-number-of-articles-to-be-saved nil)
157 ;;; Provide a mapping from `gnus-*' commands to Article commands.
164 (setq afunc (car func)
167 gfunc (intern (format "gnus-%s" func))))
169 `(lambda (&optional interactive &rest args)
170 ,(documentation afunc t)
171 (interactive (list t))
173 (set-buffer gnus-article-buffer)
175 (call-interactively ',afunc)
176 (apply ',afunc args)))))))
177 '(article-hide-headers
178 article-hide-boring-headers
179 article-treat-overstrike
180 (article-fill . gnus-article-word-wrap)
182 article-display-x-face
183 article-de-quoted-unreadable
184 article-mime-decode-quoted-printable
187 article-hide-signature
188 article-remove-trailing-blank-lines
189 article-strip-leading-blank-lines
190 article-strip-multiple-blank-lines
191 article-strip-blank-lines
193 article-date-original
196 (article-show-all . gnus-article-show-all-headers))))
198 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
200 ;;; Saving functions.
202 (defun gnus-article-save (save-buffer file &optional num)
203 "Save the currently selected article."
204 (unless gnus-save-all-headers
205 ;; Remove headers accoring to `gnus-saved-headers'.
206 (let ((gnus-visible-headers
207 (or gnus-saved-headers gnus-visible-headers))
208 (gnus-article-buffer save-buffer))
209 (gnus-article-hide-headers 1 t)))
210 (save-window-excursion
211 (if (not gnus-default-article-saver)
212 (error "No default saver is defined.")
213 ;; !!! Magic! The saving functions all save
214 ;; `gnus-original-article-buffer' (or so they think),
215 ;; but we bind that variable to our save-buffer.
216 (set-buffer gnus-article-buffer)
217 (let* ((gnus-original-article-buffer save-buffer)
220 ((not gnus-prompt-before-saving)
222 ((eq gnus-prompt-before-saving 'always)
225 (gnus-number-of-articles-to-be-saved
226 (when (stringp filename) num))) ; Magic
227 (set-buffer gnus-summary-buffer)
228 (funcall gnus-default-article-saver filename)))))
230 (defun gnus-read-save-file-name (prompt default-name &optional filename)
232 ((eq filename 'default)
236 (let* ((split-name (gnus-get-split-value gnus-split-methods))
238 (format prompt (if (and gnus-number-of-articles-to-be-saved
239 (> gnus-number-of-articles-to-be-saved 1))
240 (format "these %d articles"
241 gnus-number-of-articles-to-be-saved)
244 ;; Let the split methods have their say.
246 ;; No split name was found.
249 (concat prompt " (default "
250 (file-name-nondirectory default-name) ") ")
251 (file-name-directory default-name)
253 ;; A single split name was found
254 ((= 1 (length split-name))
255 (let* ((name (car split-name))
256 (dir (cond ((file-directory-p name)
257 (file-name-as-directory name))
258 ((file-exists-p name) name)
259 (t gnus-article-save-directory))))
261 (concat prompt " (default " name ") ")
263 ;; A list of splits was found.
265 (setq split-name (nreverse split-name))
267 (let ((file-name-history (nconc split-name file-name-history)))
270 (concat prompt " (`M-p' for defaults) ")
271 gnus-article-save-directory
273 (car (push result file-name-history)))))))
274 ;; Create the directory.
275 (unless (equal (directory-file-name file) file)
276 (make-directory (file-name-directory file) t))
277 ;; If we have read a directory, we append the default file name.
278 (when (file-directory-p file)
279 (setq file (concat (file-name-as-directory file)
280 (file-name-nondirectory default-name))))
281 ;; Possibly translate some characters.
282 (nnheader-translate-file-chars file)))))
284 (defun gnus-article-archive-name (group)
285 "Return the first instance of an \"Archive-name\" in the current buffer."
286 (let ((case-fold-search t))
287 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
288 (nnheader-concat gnus-article-save-directory
291 (defun gnus-summary-save-in-rmail (&optional filename)
292 "Append this article to Rmail file.
293 Optional argument FILENAME specifies file name.
294 Directory to save to is default to `gnus-article-save-directory'."
296 (gnus-set-global-variables)
298 (funcall gnus-rmail-save-name gnus-newsgroup-name
299 gnus-current-headers gnus-newsgroup-last-rmail)))
300 (setq filename (gnus-read-save-file-name
301 "Save %s in rmail file:" default-name filename))
302 (unless (file-exists-p (file-name-directory filename))
303 (make-directory (file-name-directory filename) t))
304 (gnus-eval-in-buffer-window gnus-original-article-buffer
308 (gnus-output-to-rmail filename))))
309 ;; Remember the directory name to save articles
310 (setq gnus-newsgroup-last-rmail filename)))
312 (defun gnus-summary-save-in-mail (&optional filename)
313 "Append this article to Unix mail file.
314 Optional argument FILENAME specifies file name.
315 Directory to save to is default to `gnus-article-save-directory'."
317 (gnus-set-global-variables)
319 (funcall gnus-mail-save-name gnus-newsgroup-name
320 gnus-current-headers gnus-newsgroup-last-mail)))
321 (setq filename (gnus-read-save-file-name
322 "Save %s in Unix mail file:" default-name filename))
324 (expand-file-name filename
326 (file-name-directory default-name))))
327 (unless (file-exists-p (file-name-directory filename))
328 (make-directory (file-name-directory filename) t))
329 (gnus-eval-in-buffer-window gnus-original-article-buffer
333 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
334 (gnus-output-to-rmail filename)
335 (let ((mail-use-rfc822 t))
336 (rmail-output filename 1 t t))))))
337 ;; Remember the directory name to save articles.
338 (setq gnus-newsgroup-last-mail filename)))
340 (defun gnus-summary-save-in-file (&optional filename)
341 "Append this article to file.
342 Optional argument FILENAME specifies file name.
343 Directory to save to is default to `gnus-article-save-directory'."
345 (gnus-set-global-variables)
347 (funcall gnus-file-save-name gnus-newsgroup-name
348 gnus-current-headers gnus-newsgroup-last-file)))
349 (setq filename (gnus-read-save-file-name
350 "Save %s in file:" default-name filename))
351 (unless (file-exists-p (file-name-directory filename))
352 (make-directory (file-name-directory filename) t))
353 (gnus-eval-in-buffer-window gnus-original-article-buffer
357 (gnus-output-to-file filename))))
358 ;; Remember the directory name to save articles.
359 (setq gnus-newsgroup-last-file filename)))
361 (defun gnus-summary-save-body-in-file (&optional filename)
362 "Append this article body to a file.
363 Optional argument FILENAME specifies file name.
364 The directory to save in defaults to `gnus-article-save-directory'."
366 (gnus-set-global-variables)
368 (funcall gnus-file-save-name gnus-newsgroup-name
369 gnus-current-headers gnus-newsgroup-last-file)))
370 (setq filename (gnus-read-save-file-name
371 "Save %s body in file:" default-name filename))
372 (unless (file-exists-p (file-name-directory filename))
373 (make-directory (file-name-directory filename) t))
374 (gnus-eval-in-buffer-window gnus-original-article-buffer
378 (goto-char (point-min))
379 (and (search-forward "\n\n" nil t)
380 (narrow-to-region (point) (point-max)))
381 (gnus-output-to-file filename))))
382 ;; Remember the directory name to save articles.
383 (setq gnus-newsgroup-last-file filename)))
385 (defun gnus-summary-save-in-pipe (&optional command)
386 "Pipe this article to subprocess."
388 (gnus-set-global-variables)
390 (cond ((eq command 'default)
391 gnus-last-shell-command)
393 (t (read-string "Shell command on article: "
394 gnus-last-shell-command))))
395 (if (string-equal command "")
396 (setq command gnus-last-shell-command))
397 (gnus-eval-in-buffer-window gnus-article-buffer
400 (shell-command-on-region (point-min) (point-max) command nil)))
401 (setq gnus-last-shell-command command))
403 ;;; Article file names when saving.
405 (defun gnus-capitalize-newsgroup (newsgroup)
406 "Capitalize NEWSGROUP name."
407 (and (not (zerop (length newsgroup)))
408 (concat (char-to-string (upcase (aref newsgroup 0)))
409 (substring newsgroup 1))))
411 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
412 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
413 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
414 Otherwise, it is like ~/News/news/group/num."
417 (concat (if (gnus-use-long-file-name 'not-save)
418 (gnus-capitalize-newsgroup newsgroup)
419 (gnus-newsgroup-directory-form newsgroup))
420 "/" (int-to-string (mail-header-number headers)))
421 gnus-article-save-directory)))
423 (string-equal (file-name-directory default)
424 (file-name-directory last-file))
425 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
427 (or last-file default))))
429 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
430 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
431 If variable `gnus-use-long-file-name' is non-nil, it is
432 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
435 (concat (if (gnus-use-long-file-name 'not-save)
437 (gnus-newsgroup-directory-form newsgroup))
438 "/" (int-to-string (mail-header-number headers)))
439 gnus-article-save-directory)))
441 (string-equal (file-name-directory default)
442 (file-name-directory last-file))
443 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
445 (or last-file default))))
447 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
448 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
449 If variable `gnus-use-long-file-name' is non-nil, it is
450 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
453 (if (gnus-use-long-file-name 'not-save)
454 (gnus-capitalize-newsgroup newsgroup)
455 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
456 gnus-article-save-directory)))
458 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
459 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
460 If variable `gnus-use-long-file-name' is non-nil, it is
461 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
464 (if (gnus-use-long-file-name 'not-save)
466 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
467 gnus-article-save-directory)))
471 ;;; Gnus article mode
474 (put 'gnus-article-mode 'mode-class 'special)
477 (gnus-define-keys gnus-article-mode-map
478 " " gnus-article-goto-next-page
479 "\177" gnus-article-goto-prev-page
480 [delete] gnus-article-goto-prev-page
481 "\C-c^" gnus-article-refer-article
482 "h" gnus-article-show-summary
483 "s" gnus-article-show-summary
484 "\C-c\C-m" gnus-article-mail
485 "?" gnus-article-describe-briefly
486 gnus-mouse-2 gnus-article-push-button
487 "\r" gnus-article-press-button
488 "\t" gnus-article-next-button
489 "\M-\t" gnus-article-prev-button
490 "e" gnus-article-edit
491 "<" beginning-of-buffer
493 "\C-c\C-i" gnus-info-find-node
496 (substitute-key-definition
497 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
499 (defun gnus-article-make-menu-bar ()
500 (gnus-turn-off-edit-menu 'article)
501 (unless (boundp 'gnus-article-article-menu)
503 gnus-article-article-menu gnus-article-mode-map ""
505 ["Scroll forwards" gnus-article-goto-next-page t]
506 ["Scroll backwards" gnus-article-goto-prev-page t]
507 ["Show summary" gnus-article-show-summary t]
508 ["Fetch Message-ID at point" gnus-article-refer-article t]
509 ["Mail to address at point" gnus-article-mail t]
513 gnus-article-treatment-menu gnus-article-mode-map ""
515 ["Hide headers" gnus-article-hide-headers t]
516 ["Hide signature" gnus-article-hide-signature t]
517 ["Hide citation" gnus-article-hide-citation t]
518 ["Treat overstrike" gnus-article-treat-overstrike t]
519 ["Remove carriage return" gnus-article-remove-cr t]
520 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
522 (run-hooks 'gnus-article-menu-hook)))
524 (defun gnus-article-mode ()
525 "Major mode for displaying an article.
527 All normal editing commands are switched off.
529 The following commands are available in addition to all summary mode
531 \\<gnus-article-mode-map>
532 \\[gnus-article-next-page]\t Scroll the article one page forwards
533 \\[gnus-article-prev-page]\t Scroll the article one page backwards
534 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
535 \\[gnus-article-show-summary]\t Display the summary buffer
536 \\[gnus-article-mail]\t Send a reply to the address near point
537 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
538 \\[gnus-info-find-node]\t Go to the Gnus info node"
540 (when (and menu-bar-mode
541 (gnus-visual-p 'article-menu 'menu))
542 (gnus-article-make-menu-bar))
543 (kill-all-local-variables)
544 (gnus-simplify-mode-line)
545 (setq mode-name "Article")
546 (setq major-mode 'gnus-article-mode)
547 (make-local-variable 'minor-mode-alist)
548 (or (assq 'gnus-show-mime minor-mode-alist)
549 (setq minor-mode-alist
550 (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
551 (use-local-map gnus-article-mode-map)
552 (gnus-update-format-specifications nil 'article-mode)
553 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
554 (gnus-set-default-directory)
555 (buffer-disable-undo (current-buffer))
556 (setq buffer-read-only t) ;Disable modification
557 (run-hooks 'gnus-article-mode-hook))
559 (defun gnus-article-setup-buffer ()
560 "Initialize the article buffer."
561 (let* ((name (if gnus-single-article-buffer "*Article*"
562 (concat "*Article " gnus-newsgroup-name "*")))
564 (progn (string-match "\\*Article" name)
565 (concat " *Original Article"
566 (substring name (match-end 0))))))
567 (setq gnus-article-buffer name)
568 (setq gnus-original-article-buffer original)
569 ;; This might be a variable local to the summary buffer.
570 (unless gnus-single-article-buffer
572 (set-buffer gnus-summary-buffer)
573 (setq gnus-article-buffer name)
574 (setq gnus-original-article-buffer original)
575 (gnus-set-global-variables))
576 (make-local-variable 'gnus-summary-buffer))
577 ;; Init original article buffer.
579 (set-buffer (get-buffer-create gnus-original-article-buffer))
580 (buffer-disable-undo (current-buffer))
581 (setq major-mode 'gnus-original-article-mode)
582 (gnus-add-current-to-buffer-list)
583 (make-local-variable 'gnus-original-article))
584 (if (get-buffer name)
587 (buffer-disable-undo (current-buffer))
588 (setq buffer-read-only t)
589 (gnus-add-current-to-buffer-list)
590 (or (eq major-mode 'gnus-article-mode)
594 (set-buffer (get-buffer-create name))
595 (gnus-add-current-to-buffer-list)
599 ;; Set article window start at LINE, where LINE is the number of lines
600 ;; from the head of the article.
601 (defun gnus-article-set-window-start (&optional line)
603 (get-buffer-window gnus-article-buffer t)
605 (set-buffer gnus-article-buffer)
606 (goto-char (point-min))
609 (gnus-message 6 "Moved to bookmark")
610 (search-forward "\n\n" nil t)
614 (defun gnus-article-prepare (article &optional all-headers header)
615 "Prepare ARTICLE in article mode buffer.
616 ARTICLE should either be an article number or a Message-ID.
617 If ARTICLE is an id, HEADER should be the article headers.
618 If ALL-HEADERS is non-nil, no headers are hidden."
620 ;; Make sure we start in a summary buffer.
621 (unless (eq major-mode 'gnus-summary-mode)
622 (set-buffer gnus-summary-buffer))
623 (setq gnus-summary-buffer (current-buffer))
624 ;; Make sure the connection to the server is alive.
625 (unless (gnus-server-opened
626 (gnus-find-method-for-group gnus-newsgroup-name))
627 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
628 (gnus-request-group gnus-newsgroup-name t))
629 (let* ((article (if header (mail-header-number header) article))
630 (summary-buffer (current-buffer))
631 (internal-hook gnus-article-internal-prepare-hook)
632 (group gnus-newsgroup-name)
635 (gnus-article-setup-buffer)
636 (set-buffer gnus-article-buffer)
637 ;; Deactivate active regions.
638 (when (and (boundp 'transient-mark-mode)
640 (setq mark-active nil))
641 (if (not (setq result (let ((buffer-read-only nil))
642 (gnus-request-article-this-buffer
644 ;; There is no such article.
646 (when (and (numberp article)
647 (not (memq article gnus-newsgroup-sparse)))
648 (setq gnus-article-current
649 (cons gnus-newsgroup-name article))
650 (set-buffer gnus-summary-buffer)
651 (setq gnus-current-article article)
652 (gnus-summary-mark-article article gnus-canceled-mark))
653 (unless (memq article gnus-newsgroup-sparse)
655 1 "No such article (may have expired or been canceled)")))
656 (if (or (eq result 'pseudo) (eq result 'nneething))
659 (set-buffer summary-buffer)
660 (setq gnus-last-article gnus-current-article
661 gnus-newsgroup-history (cons gnus-current-article
662 gnus-newsgroup-history)
663 gnus-current-article 0
664 gnus-current-headers nil
665 gnus-article-current nil)
666 (if (eq result 'nneething)
667 (gnus-configure-windows 'summary)
668 (gnus-configure-windows 'article))
669 (gnus-set-global-variables))
670 (gnus-set-mode-line 'article))
671 ;; The result from the `request' was an actual article -
672 ;; or at least some text that is now displayed in the
674 (if (and (numberp article)
675 (not (eq article gnus-current-article)))
676 ;; Seems like a new article has been selected.
677 ;; `gnus-current-article' must be an article number.
679 (set-buffer summary-buffer)
680 (setq gnus-last-article gnus-current-article
681 gnus-newsgroup-history (cons gnus-current-article
682 gnus-newsgroup-history)
683 gnus-current-article article
685 (gnus-summary-article-header gnus-current-article)
687 (cons gnus-newsgroup-name gnus-current-article))
688 (unless (vectorp gnus-current-headers)
689 (setq gnus-current-headers nil))
690 (gnus-summary-show-thread)
691 (run-hooks 'gnus-mark-article-hook)
692 (gnus-set-mode-line 'summary)
693 (and (gnus-visual-p 'article-highlight 'highlight)
694 (run-hooks 'gnus-visual-mark-article-hook))
695 ;; Set the global newsgroup variables here.
696 ;; Suggested by Jim Sisolak
697 ;; <sisolak@trans4.neep.wisc.edu>.
698 (gnus-set-global-variables)
699 (setq gnus-have-all-headers
700 (or all-headers gnus-show-all-headers))
702 (vectorp (gnus-summary-article-header article))
703 (gnus-cache-possibly-enter-article
705 (gnus-summary-article-header article)
706 (memq article gnus-newsgroup-marked)
707 (memq article gnus-newsgroup-dormant)
708 (memq article gnus-newsgroup-unreads)))))
709 (when (or (numberp article)
711 ;; Hooks for getting information from the article.
712 ;; This hook must be called before being narrowed.
713 (let (buffer-read-only)
714 (run-hooks 'internal-hook)
715 (run-hooks 'gnus-article-prepare-hook)
716 ;; Decode MIME message.
718 (if (or (not gnus-strict-mime)
719 (gnus-fetch-field "Mime-Version"))
720 (funcall gnus-show-mime-method)
721 (funcall gnus-decode-encoded-word-method)))
722 ;; Perform the article display hooks.
723 (run-hooks 'gnus-article-display-hook))
725 (goto-char (point-min))
726 (and gnus-break-pages (gnus-narrow-to-page)))
727 (gnus-set-mode-line 'article)
728 (gnus-configure-windows 'article)
729 (goto-char (point-min))
732 (defun gnus-article-wash-status ()
733 "Return a string which display status of article washing."
735 (set-buffer gnus-article-buffer)
736 (let ((cite (article-hidden-text-p 'cite))
737 (headers (article-hidden-text-p 'headers))
738 (boring (article-hidden-text-p 'boring-headers))
739 (pgp (article-hidden-text-p 'pgp))
740 (pem (article-hidden-text-p 'pem))
741 (signature (article-hidden-text-p 'signature))
742 (overstrike (article-hidden-text-p 'overstrike))
743 (emphasis (article-hidden-text-p 'emphasis))
744 (mime gnus-show-mime))
745 (format "%c%c%c%c%c%c%c"
747 (if (or headers boring) ?h ? )
748 (if (or pgp pem) ?p ? )
750 (if overstrike ?o ? )
752 (if emphasis ?e ? )))))
754 (defun gnus-article-hide-headers-if-wanted ()
755 "Hide unwanted headers if `gnus-have-all-headers' is nil.
756 Provided for backwards compatibility."
757 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
759 (gnus-article-hide-headers)))
763 (defun gnus-output-to-rmail (file-name)
764 "Append the current article to an Rmail file named FILE-NAME."
766 ;; Most of these codes are borrowed from rmailout.el.
767 (setq file-name (expand-file-name file-name))
768 (setq rmail-default-rmail-file file-name)
769 (let ((artbuf (current-buffer))
770 (tmpbuf (get-buffer-create " *Gnus-output*")))
772 (or (get-file-buffer file-name)
773 (file-exists-p file-name)
774 (if (gnus-yes-or-no-p
775 (concat "\"" file-name "\" does not exist, create it? "))
776 (let ((file-buffer (create-file-buffer file-name)))
778 (set-buffer file-buffer)
779 (rmail-insert-rmail-file-header)
780 (let ((require-final-newline nil))
781 (write-region (point-min) (point-max) file-name t 1)))
782 (kill-buffer file-buffer))
783 (error "Output file does not exist")))
785 (buffer-disable-undo (current-buffer))
787 (insert-buffer-substring artbuf)
788 (gnus-convert-article-to-rmail)
789 ;; Decide whether to append to a file or to an Emacs buffer.
790 (let ((outbuf (get-file-buffer file-name)))
792 (append-to-file (point-min) (point-max) file-name)
793 ;; File has been visited, in buffer OUTBUF.
795 (let ((buffer-read-only nil)
796 (msg (and (boundp 'rmail-current-message)
797 (symbol-value 'rmail-current-message))))
798 ;; If MSG is non-nil, buffer is in RMAIL mode.
801 (narrow-to-region (point-max) (point-max))))
802 (insert-buffer-substring tmpbuf)
805 (goto-char (point-min))
807 (search-backward "\^_")
808 (narrow-to-region (point) (point-max))
809 (goto-char (1+ (point-min)))
810 (rmail-count-new-messages t)
811 (rmail-show-message msg)))))))
812 (kill-buffer tmpbuf)))
814 (defun gnus-output-to-file (file-name)
815 "Append the current article to a file named FILE-NAME."
816 (let ((artbuf (current-buffer)))
817 (nnheader-temp-write nil
818 (insert-buffer-substring artbuf)
819 ;; Append newline at end of the buffer as separator, and then
821 (goto-char (point-max))
823 (append-to-file (point-min) (point-max) file-name))))
825 (defun gnus-convert-article-to-rmail ()
826 "Convert article in current buffer to Rmail message format."
827 (let ((buffer-read-only nil))
828 ;; Convert article directly into Babyl format.
829 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
830 (goto-char (point-min))
831 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
832 (while (search-forward "\n\^_" nil t) ;single char
833 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
834 (goto-char (point-max))
837 (defun gnus-narrow-to-page (&optional arg)
838 "Narrow the article buffer to a page.
839 If given a numerical ARG, move forward ARG pages."
841 (setq arg (if arg (prefix-numeric-value arg) 0))
843 (set-buffer gnus-article-buffer)
844 (goto-char (point-min))
846 ;; Remove any old next/prev buttons.
847 (when (gnus-visual-p 'page-marker)
848 (let ((buffer-read-only nil))
849 (gnus-remove-text-with-property 'gnus-prev)
850 (gnus-remove-text-with-property 'gnus-next)))
853 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
855 (re-search-forward page-delimiter nil 'move arg)))
856 (goto-char (match-end 0)))
859 (if (re-search-forward page-delimiter nil 'move)
862 (when (and (gnus-visual-p 'page-marker)
863 (not (= (point-min) 1)))
865 (goto-char (point-min))
866 (gnus-insert-prev-page-button)))
867 (when (and (gnus-visual-p 'page-marker)
868 (< (+ (point-max) 2) (buffer-size)))
870 (goto-char (point-max))
871 (gnus-insert-next-page-button)))))
873 ;; Article mode commands
875 (defun gnus-article-goto-next-page ()
876 "Show the next page of the article."
878 (when (gnus-article-next-page)
879 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
881 (defun gnus-article-goto-prev-page ()
882 "Show the next page of the article."
884 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
885 (gnus-article-prev-page nil)))
887 (defun gnus-article-next-page (&optional lines)
888 "Show the next page of the current article.
889 If end of article, return non-nil. Otherwise return nil.
890 Argument LINES specifies lines to be scrolled up."
892 (move-to-window-line -1)
895 (and (pos-visible-in-window-p) ;Not continuation line.
897 ;; Nothing in this page.
898 (if (or (not gnus-break-pages)
901 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
903 (gnus-narrow-to-page 1) ;Go to next page.
905 ;; More in this page.
909 ;; Long lines may cause an end-of-buffer error.
910 (goto-char (point-max))))
911 (move-to-window-line 0)
914 (defun gnus-article-prev-page (&optional lines)
915 "Show previous page of current article.
916 Argument LINES specifies lines to be scrolled down."
918 (move-to-window-line 0)
919 (if (and gnus-break-pages
921 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
923 (gnus-narrow-to-page -1) ;Go to previous page.
924 (goto-char (point-max))
930 (move-to-window-line 0))))
932 (defun gnus-article-refer-article ()
933 "Read article specified by message-id around point."
935 (let ((point (point)))
936 (search-forward ">" nil t) ;Move point to end of "<....>".
937 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
938 (let ((message-id (match-string 1)))
940 (set-buffer gnus-summary-buffer)
941 (gnus-summary-refer-article message-id))
943 (error "No references around point"))))
945 (defun gnus-article-show-summary ()
946 "Reconfigure windows to show summary buffer."
948 (gnus-configure-windows 'article)
949 (gnus-summary-goto-subject gnus-current-article))
951 (defun gnus-article-describe-briefly ()
952 "Describe article mode commands briefly."
955 (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")))
957 (defun gnus-article-summary-command ()
958 "Execute the last keystroke in the summary buffer."
960 (let ((obuf (current-buffer))
961 (owin (current-window-configuration))
963 (switch-to-buffer gnus-summary-buffer 'norecord)
964 (setq func (lookup-key (current-local-map) (this-command-keys)))
965 (call-interactively func)
967 (set-window-configuration owin)
968 (set-window-point (get-buffer-window (current-buffer)) (point))))
970 (defun gnus-article-summary-command-nosave ()
971 "Execute the last keystroke in the summary buffer."
974 (pop-to-buffer gnus-summary-buffer 'norecord)
975 (setq func (lookup-key (current-local-map) (this-command-keys)))
976 (call-interactively func)))
978 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
979 "Read a summary buffer key sequence and execute it from the article buffer."
982 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
983 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
989 (set-buffer gnus-summary-buffer)
990 (push (or key last-command-event) unread-command-events)
991 (setq keys (read-key-sequence nil)))
994 (if (or (member keys nosaves)
995 (member keys nosave-but-article))
997 (save-window-excursion
998 (pop-to-buffer gnus-summary-buffer 'norecord)
999 (setq func (lookup-key (current-local-map) keys)))
1002 (set-buffer gnus-summary-buffer)
1003 (call-interactively func))
1004 (when (member keys nosave-but-article)
1005 (pop-to-buffer gnus-article-buffer 'norecord)))
1006 (let ((obuf (current-buffer))
1007 (owin (current-window-configuration))
1010 (if not-restore-window
1011 (pop-to-buffer gnus-summary-buffer 'norecord)
1012 (switch-to-buffer gnus-summary-buffer 'norecord))
1013 (setq in-buffer (current-buffer))
1014 (if (setq func (lookup-key (current-local-map) keys))
1015 (call-interactively func)
1017 (when (eq in-buffer (current-buffer))
1019 (unless not-restore-window
1020 (set-window-configuration owin))
1021 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
1023 (defun gnus-article-hide (&optional arg force)
1024 "Hide all the gruft in the current article.
1025 This means that PGP stuff, signatures, cited text and (some)
1026 headers will be hidden.
1027 If given a prefix, show the hidden text instead."
1028 (interactive (list current-prefix-arg 'force))
1029 (gnus-article-hide-headers arg)
1030 (gnus-article-hide-pgp arg)
1031 (gnus-article-hide-citation-maybe arg force)
1032 (gnus-article-hide-signature arg))
1034 (defun gnus-article-maybe-highlight ()
1035 "Do some article highlighting if `article-visual' is non-nil."
1036 (if (gnus-visual-p 'article-highlight 'highlight)
1037 (gnus-article-highlight-some)))
1039 (defun gnus-request-article-this-buffer (article group)
1040 "Get an article and insert it into this buffer."
1041 (let (do-update-line)
1045 (gnus-kill-all-overlays)
1046 (setq group (or group gnus-newsgroup-name))
1048 ;; Open server if it has closed.
1049 (gnus-check-server (gnus-find-method-for-group group))
1051 ;; Using `gnus-request-article' directly will insert the article into
1052 ;; `nntp-server-buffer' - so we'll save some time by not having to
1053 ;; copy it from the server buffer into the article buffer.
1055 ;; We only request an article by message-id when we do not have the
1056 ;; headers for it, so we'll have to get those.
1057 (when (stringp article)
1058 (let ((gnus-override-method gnus-refer-article-method))
1059 (gnus-read-header article)))
1061 ;; If the article number is negative, that means that this article
1062 ;; doesn't belong in this newsgroup (possibly), so we find its
1063 ;; message-id and request it by id instead of number.
1064 (when (and (numberp article)
1066 (get-buffer gnus-summary-buffer)
1067 (buffer-name (get-buffer gnus-summary-buffer)))
1069 (set-buffer gnus-summary-buffer)
1070 (let ((header (gnus-summary-article-header article)))
1073 ((memq article gnus-newsgroup-sparse)
1074 ;; This is a sparse gap article.
1075 (setq do-update-line article)
1076 (setq article (mail-header-id header))
1077 (let ((gnus-override-method gnus-refer-article-method))
1078 (gnus-read-header article))
1079 (setq gnus-newsgroup-sparse
1080 (delq article gnus-newsgroup-sparse)))
1082 ;; It's a real article.
1083 (setq article (mail-header-id header)))
1085 ;; It is an extracted pseudo-article.
1086 (setq article 'pseudo)
1087 (gnus-request-pseudo-article header))))
1089 (let ((method (gnus-find-method-for-group
1090 gnus-newsgroup-name)))
1091 (if (not (eq (car method) 'nneething))
1093 (let ((dir (concat (file-name-as-directory (nth 1 method))
1094 (mail-header-subject header))))
1095 (if (file-directory-p dir)
1097 (setq article 'nneething)
1098 (gnus-group-enter-directory dir)))))))))
1101 ;; Refuse to select canceled articles.
1102 ((and (numberp article)
1104 (get-buffer gnus-summary-buffer)
1105 (buffer-name (get-buffer gnus-summary-buffer))
1106 (eq (cdr (save-excursion
1107 (set-buffer gnus-summary-buffer)
1108 (assq article gnus-newsgroup-reads)))
1109 gnus-canceled-mark))
1111 ;; We first check `gnus-original-article-buffer'.
1112 ((and (get-buffer gnus-original-article-buffer)
1115 (set-buffer gnus-original-article-buffer)
1116 (and (equal (car gnus-original-article) group)
1117 (eq (cdr gnus-original-article) article))))
1118 (insert-buffer-substring gnus-original-article-buffer)
1120 ;; Check the backlog.
1121 ((and gnus-keep-backlog
1122 (gnus-backlog-request-article group article (current-buffer)))
1124 ;; Check asynchronous pre-fetch.
1125 ((gnus-async-request-fetched-article group article (current-buffer))
1126 (gnus-async-prefetch-next group article gnus-summary-buffer)
1129 ((and gnus-use-cache
1131 (gnus-cache-request-article article group))
1133 ;; Get the article and put into the article buffer.
1134 ((or (stringp article) (numberp article))
1135 (let ((gnus-override-method
1136 (and (stringp article) gnus-refer-article-method))
1137 (buffer-read-only nil))
1139 (gnus-kill-all-overlays)
1140 (when (gnus-request-article article group (current-buffer))
1141 (when (numberp article)
1142 (gnus-async-prefetch-next group article gnus-summary-buffer)
1143 (when gnus-keep-backlog
1144 (gnus-backlog-enter-article
1145 group article (current-buffer))))
1150 ;; Take the article from the original article buffer
1151 ;; and place it in the buffer it's supposed to be in.
1152 (when (and (get-buffer gnus-article-buffer)
1154 (equal (buffer-name (current-buffer))
1155 (buffer-name (get-buffer gnus-article-buffer))))
1157 (if (get-buffer gnus-original-article-buffer)
1158 (set-buffer (get-buffer gnus-original-article-buffer))
1159 (set-buffer (get-buffer-create gnus-original-article-buffer))
1160 (buffer-disable-undo (current-buffer))
1161 (setq major-mode 'gnus-original-article-mode)
1162 (setq buffer-read-only t)
1163 (gnus-add-current-to-buffer-list))
1164 (let (buffer-read-only)
1166 (insert-buffer-substring gnus-article-buffer))
1167 (setq gnus-original-article (cons group article))))
1169 ;; Update sparse articles.
1170 (when (and do-update-line
1171 (or (numberp article)
1173 (let ((buf (current-buffer)))
1174 (set-buffer gnus-summary-buffer)
1175 (gnus-summary-update-article do-update-line)
1176 (gnus-summary-goto-subject do-update-line nil t)
1177 (set-window-point (get-buffer-window (current-buffer) t)
1179 (set-buffer buf))))))
1181 (defun gnus-article-date-ut (&optional type highlight)
1182 "Convert DATE date to universal time in the current article.
1183 If TYPE is `local', convert to local time; if it is `lapsed', output
1184 how much time has lapsed since DATE."
1185 (interactive (list 'ut t))
1186 (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1188 (set-buffer gnus-article-buffer)
1189 (article-date-ut type highlight headers))))
1195 (defvar gnus-article-edit-mode-hook nil
1196 "*Hook run in article edit mode buffers.")
1198 (defvar gnus-article-edit-done-function nil)
1200 (defvar gnus-article-edit-mode-map nil)
1202 (unless gnus-article-edit-mode-map
1203 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1205 (gnus-define-keys gnus-article-edit-mode-map
1206 "\C-c\C-c" gnus-article-edit-done
1207 "\C-c\C-k" gnus-article-edit-exit)
1209 (gnus-define-keys (gnus-article-edit-wash-map
1210 "\C-c\C-w" gnus-article-edit-mode-map)
1211 "f" gnus-article-edit-full-stops))
1213 (defun gnus-article-edit-mode ()
1214 "Major mode for editing articles.
1215 This is an extended text-mode.
1217 \\{gnus-article-edit-mode-map}"
1219 (kill-all-local-variables)
1220 (setq major-mode 'gnus-article-edit-mode)
1221 (setq mode-name "Article Edit")
1222 (use-local-map gnus-article-edit-mode-map)
1223 (make-local-variable 'gnus-article-edit-done-function)
1224 (make-local-variable 'gnus-prev-winconf)
1225 (setq buffer-read-only nil)
1226 (buffer-enable-undo)
1228 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1230 (defun gnus-article-edit (&optional force)
1231 "Edit the current article.
1232 This will have permanent effect only in mail groups.
1233 If FORCE is non-nil, allow editing of articles even in read-only
1236 (when (and (not force)
1237 (gnus-group-read-only-p))
1238 (error "The current newsgroup does not support article editing."))
1239 (gnus-article-edit-article
1241 (gnus-summary-edit-article-done
1242 ,(or (mail-header-references gnus-current-headers) "")
1243 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1245 (defun gnus-article-edit-article (exit-func)
1246 "Start editing the contents of the current article buffer."
1247 (let ((winconf (current-window-configuration)))
1248 (set-buffer gnus-article-buffer)
1249 (gnus-article-edit-mode)
1250 (set-text-properties (point-min) (point-max) nil)
1251 (gnus-configure-windows 'edit-article)
1252 (setq gnus-article-edit-done-function exit-func)
1253 (setq gnus-prev-winconf winconf)
1254 (gnus-message 6 "C-c C-c to end edits")))
1256 (defun gnus-article-edit-done ()
1257 "Update the article edits and exit."
1259 (let ((func gnus-article-edit-done-function)
1260 (buf (current-buffer))
1261 (start (window-start)))
1262 (gnus-article-edit-exit)
1263 (let ((cur (current-buffer)))
1266 (let ((buffer-read-only nil))
1269 (set-window-start (get-buffer-window buf) start)
1270 (set-window-point (get-buffer-window buf) (point)))))
1272 (defun gnus-article-edit-exit ()
1273 "Exit the article editing without updating."
1275 ;; We remove all text props from the article buffer.
1276 (let ((buf (format "%s" (buffer-string)))
1277 (curbuf (current-buffer))
1279 (window-start (window-start)))
1282 (let ((winconf gnus-prev-winconf))
1284 ;; The cache and backlog have to be flushed somewhat.
1285 (when gnus-use-cache
1286 (gnus-cache-update-article
1287 (car gnus-article-current) (cdr gnus-article-current)))
1288 (when gnus-keep-backlog
1289 (gnus-backlog-remove-article
1290 (car gnus-article-current) (cdr gnus-article-current)))
1291 ;; Flush original article as well.
1293 (when (get-buffer gnus-original-article-buffer)
1294 (set-buffer gnus-original-article-buffer)
1295 (setq gnus-original-article nil)))
1296 (set-window-configuration winconf)
1297 ;; Tippy-toe some to make sure that point remains where it was.
1298 (let ((buf (current-buffer)))
1300 (set-window-start (get-buffer-window (current-buffer)) window-start)
1302 (set-buffer buf)))))
1304 (defun gnus-article-edit-full-stops ()
1305 "Interactively repair spacing at end of sentences."
1308 (goto-char (point-min))
1309 (search-forward-regexp "^$" nil t)
1310 (let ((case-fold-search nil))
1311 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1314 ;;; Article highlights
1317 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1319 ;;; Internal Variables:
1321 (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_=#$@~`%&*+|\\/]"
1322 "*Regular expression that matches URLs.")
1324 (defvar gnus-button-alist
1325 `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
1326 t gnus-button-message-id 3)
1327 ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1328 gnus-button-message-id 3)
1329 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-button-reply 2)
1330 ;; This is how URLs _should_ be embedded in text...
1331 ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1332 ;; Next regexp stolen from highlight-headers.el.
1333 ;; Modified by Vladimir Alexiev.
1334 (,gnus-button-url-regexp 0 t gnus-button-url 0))
1335 "Alist of regexps matching buttons in article bodies.
1337 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1338 REGEXP: is the string matching text around the button,
1339 BUTTON: is the number of the regexp grouping actually matching the button,
1340 FORM: is a lisp expression which must eval to true for the button to
1342 CALLBACK: is the function to call when the user push this button, and each
1343 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1345 CALLBACK can also be a variable, in that case the value of that
1346 variable it the real callback function.")
1348 (defvar gnus-header-button-alist
1349 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1350 0 t gnus-button-message-id 0)
1351 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1352 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
1353 0 t gnus-button-mailto 0)
1354 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1355 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1356 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1357 gnus-button-message-id 3))
1358 "Alist of headers and regexps to match buttons in article heads.
1360 This alist is very similar to `gnus-button-alist', except that each
1361 alist has an additional HEADER element first in each entry:
1363 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1365 HEADER is a regexp to match a header. For a fuller explanation, see
1366 `gnus-button-alist'.")
1368 (defvar gnus-button-regexp nil)
1369 (defvar gnus-button-marker-list nil)
1370 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1372 (defvar gnus-button-last nil)
1373 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1377 (defun gnus-article-push-button (event)
1378 "Check text under the mouse pointer for a callback function.
1379 If the text under the mouse pointer has a `gnus-callback' property,
1380 call it with the value of the `gnus-data' text property."
1382 (set-buffer (window-buffer (posn-window (event-start event))))
1383 (let* ((pos (posn-point (event-start event)))
1384 (data (get-text-property pos 'gnus-data))
1385 (fun (get-text-property pos 'gnus-callback)))
1386 (if fun (funcall fun data))))
1388 (defun gnus-article-press-button ()
1389 "Check text at point for a callback function.
1390 If the text at point has a `gnus-callback' property,
1391 call it with the value of the `gnus-data' text property."
1393 (let* ((data (get-text-property (point) 'gnus-data))
1394 (fun (get-text-property (point) 'gnus-callback)))
1395 (if fun (funcall fun data))))
1397 (defun gnus-article-prev-button (n)
1398 "Move point to N buttons backward.
1399 If N is negative, move forward instead."
1401 (gnus-article-next-button (- n)))
1403 (defun gnus-article-next-button (n)
1404 "Move point to N buttons forward.
1405 If N is negative, move backward instead."
1407 (let ((function (if (< n 0) 'previous-single-property-change
1408 'next-single-property-change))
1409 (inhibit-point-motion-hooks t)
1411 (limit (if (< n 0) (point-min) (point-max))))
1413 (while (and (not (= limit (point)))
1415 ;; Skip past the current button.
1416 (when (get-text-property (point) 'gnus-callback)
1417 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1418 ;; Go to the next (or previous) button.
1419 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1420 ;; Put point at the start of the button.
1421 (when (and backward (not (get-text-property (point) 'gnus-callback)))
1422 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1423 ;; Skip past intangible buttons.
1424 (when (get-text-property (point) 'intangible)
1428 (gnus-message 5 "No more buttons"))
1431 (defun gnus-article-highlight (&optional force)
1432 "Highlight current article.
1433 This function calls `gnus-article-highlight-headers',
1434 `gnus-article-highlight-citation',
1435 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1436 do the highlighting. See the documentation for those functions."
1437 (interactive (list 'force))
1438 (gnus-article-highlight-headers)
1439 (gnus-article-highlight-citation force)
1440 (gnus-article-highlight-signature)
1441 (gnus-article-add-buttons force)
1442 (gnus-article-add-buttons-to-head))
1444 (defun gnus-article-highlight-some (&optional force)
1445 "Highlight current article.
1446 This function calls `gnus-article-highlight-headers',
1447 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1448 do the highlighting. See the documentation for those functions."
1449 (interactive (list 'force))
1450 (gnus-article-highlight-headers)
1451 (gnus-article-highlight-signature)
1452 (gnus-article-add-buttons))
1454 (defun gnus-article-highlight-headers ()
1455 "Highlight article headers as specified by `gnus-header-face-alist'."
1458 (set-buffer gnus-article-buffer)
1460 (let ((alist gnus-header-face-alist)
1461 (buffer-read-only nil)
1462 (case-fold-search t)
1463 (inhibit-point-motion-hooks t)
1464 entry regexp header-face field-face from hpoints fpoints)
1465 (goto-char (point-min))
1466 (when (search-forward "\n\n" nil t)
1467 (narrow-to-region (1- (point)) (point-min))
1468 (while (setq entry (pop alist))
1469 (goto-char (point-min))
1470 (setq regexp (concat "^\\("
1471 (if (string-equal "" (nth 0 entry))
1475 header-face (nth 1 entry)
1476 field-face (nth 2 entry))
1477 (while (and (re-search-forward regexp nil t)
1481 (or (search-forward ":" nil t)
1483 (when (and header-face
1484 (not (memq (point) hpoints)))
1485 (push (point) hpoints)
1486 (gnus-put-text-property from (point) 'face header-face))
1487 (when (and field-face
1488 (not (memq (setq from (point)) fpoints)))
1490 (if (re-search-forward "^[^ \t]" nil t)
1492 (goto-char (point-max)))
1493 (gnus-put-text-property from (point) 'face field-face)))))))))
1495 (defun gnus-article-highlight-signature ()
1496 "Highlight the signature in an article.
1497 It does this by highlighting everything after
1498 `gnus-signature-separator' using `gnus-signature-face'."
1501 (set-buffer gnus-article-buffer)
1502 (let ((buffer-read-only nil)
1503 (inhibit-point-motion-hooks t))
1505 (when (and gnus-signature-face
1506 (article-narrow-to-signature))
1507 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1508 'face gnus-signature-face)
1510 (article-search-signature)
1511 (let ((start (match-beginning 0))
1512 (end (set-marker (make-marker) (1+ (match-end 0)))))
1513 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1516 (defun gnus-article-add-buttons (&optional force)
1517 "Find external references in the article and make buttons of them.
1518 \"External references\" are things like Message-IDs and URLs, as
1519 specified by `gnus-button-alist'."
1520 (interactive (list 'force))
1522 (set-buffer gnus-article-buffer)
1523 ;; Remove all old markers.
1524 (while gnus-button-marker-list
1525 (set-marker (pop gnus-button-marker-list) nil))
1526 (let ((buffer-read-only nil)
1527 (inhibit-point-motion-hooks t)
1528 (case-fold-search t)
1529 (alist gnus-button-alist)
1531 (goto-char (point-min))
1532 ;; We skip the headers.
1533 (unless (search-forward "\n\n" nil t)
1534 (goto-char (point-max)))
1536 (while (setq entry (pop alist))
1537 (setq regexp (car entry))
1539 (while (re-search-forward regexp nil t)
1540 (let* ((start (and entry (match-beginning (nth 1 entry))))
1541 (end (and entry (match-end (nth 1 entry))))
1542 (from (match-beginning 0)))
1543 (when (or (eq t (nth 1 entry))
1544 (eval (nth 1 entry)))
1545 ;; That optional form returned non-nil, so we add the
1547 (gnus-article-add-button
1548 start end 'gnus-button-push
1549 (car (push (set-marker (make-marker) from)
1550 gnus-button-marker-list))))))))))
1552 ;; Add buttons to the head of an article.
1553 (defun gnus-article-add-buttons-to-head ()
1554 "Add buttons to the head of the article."
1557 (set-buffer gnus-article-buffer)
1558 (let ((buffer-read-only nil)
1559 (inhibit-point-motion-hooks t)
1560 (case-fold-search t)
1561 (alist gnus-header-button-alist)
1563 (nnheader-narrow-to-headers)
1565 ;; Each alist entry.
1566 (setq entry (car alist)
1568 (goto-char (point-min))
1569 (while (re-search-forward (car entry) nil t)
1570 ;; Each header matching the entry.
1571 (setq beg (match-beginning 0))
1572 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1573 (match-beginning 0))
1576 (while (re-search-forward (nth 1 entry) end t)
1577 ;; Each match within a header.
1578 (let* ((from (match-beginning 0))
1580 (start (match-beginning (nth 1 entry)))
1581 (end (match-end (nth 1 entry)))
1582 (form (nth 2 entry)))
1583 (goto-char (match-end 0))
1585 (gnus-article-add-button
1586 start end (nth 3 entry)
1587 (buffer-substring (match-beginning (nth 4 entry))
1588 (match-end (nth 4 entry)))))))
1592 ;;; External functions:
1594 (defun gnus-article-add-button (from to fun &optional data)
1595 "Create a button between FROM and TO with callback FUN and data DATA."
1596 (and gnus-article-button-face
1597 (gnus-overlay-put (gnus-make-overlay from to)
1598 'face gnus-article-button-face))
1599 (gnus-add-text-properties
1601 (nconc (and gnus-article-mouse-face
1602 (list gnus-mouse-face-prop gnus-article-mouse-face))
1603 (list 'gnus-callback fun)
1604 (and data (list 'gnus-data data)))))
1606 ;;; Internal functions:
1608 (defun gnus-signature-toggle (end)
1610 (set-buffer gnus-article-buffer)
1611 (let ((buffer-read-only nil)
1612 (inhibit-point-motion-hooks t))
1613 (if (get-text-property end 'invisible)
1614 (article-unhide-text end (point-max))
1615 (article-hide-text end (point-max) gnus-hidden-properties)))))
1617 (defun gnus-button-entry ()
1618 ;; Return the first entry in `gnus-button-alist' matching this place.
1619 (let ((alist gnus-button-alist)
1622 (setq entry (pop alist))
1623 (if (looking-at (car entry))
1628 (defun gnus-button-push (marker)
1629 ;; Push button starting at MARKER.
1631 (set-buffer gnus-article-buffer)
1633 (let* ((entry (gnus-button-entry))
1634 (inhibit-point-motion-hooks t)
1636 (args (mapcar (lambda (group)
1637 (let ((string (buffer-substring
1638 (match-beginning group)
1639 (match-end group))))
1640 (gnus-set-text-properties
1641 0 (length string) nil string)
1648 (fboundp (symbol-value fun)))
1649 (apply (symbol-value fun) args))
1651 (gnus-message 1 "You must define `%S' to use this button"
1652 (cons fun args)))))))
1654 (defun gnus-button-message-id (message-id)
1657 (set-buffer gnus-summary-buffer)
1658 (gnus-summary-refer-article message-id)))
1660 (defun gnus-button-mailto (address)
1662 (set-buffer (gnus-copy-article-buffer))
1663 (message-reply address))
1665 (defun gnus-button-reply (address)
1666 ;; Reply to ADDRESS.
1667 (message-reply address))
1669 (defun gnus-button-url (address)
1671 (funcall browse-url-browser-function address))
1673 ;;; Next/prev buttons in the article buffer.
1675 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1676 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1678 (defvar gnus-prev-page-map nil)
1679 (unless gnus-prev-page-map
1680 (setq gnus-prev-page-map (make-sparse-keymap))
1681 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1682 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1684 (defun gnus-insert-prev-page-button ()
1685 (let ((buffer-read-only nil))
1687 gnus-prev-page-line-format nil
1688 `(gnus-prev t local-map ,gnus-prev-page-map
1689 gnus-callback gnus-article-button-prev-page))))
1691 (defvar gnus-next-page-map nil)
1692 (unless gnus-next-page-map
1693 (setq gnus-next-page-map (make-keymap))
1694 (suppress-keymap gnus-prev-page-map)
1695 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1696 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1698 (defun gnus-button-next-page ()
1699 "Go to the next page."
1701 (let ((win (selected-window)))
1702 (select-window (get-buffer-window gnus-article-buffer t))
1703 (gnus-article-next-page)
1704 (select-window win)))
1706 (defun gnus-button-prev-page ()
1707 "Go to the prev page."
1709 (let ((win (selected-window)))
1710 (select-window (get-buffer-window gnus-article-buffer t))
1711 (gnus-article-prev-page)
1712 (select-window win)))
1714 (defun gnus-insert-next-page-button ()
1715 (let ((buffer-read-only nil))
1716 (gnus-eval-format gnus-next-page-line-format nil
1717 `(gnus-next t local-map ,gnus-next-page-map
1719 gnus-article-button-next-page))))
1721 (defun gnus-article-button-next-page (arg)
1722 "Go to the next page."
1724 (let ((win (selected-window)))
1725 (select-window (get-buffer-window gnus-article-buffer t))
1726 (gnus-article-next-page)
1727 (select-window win)))
1729 (defun gnus-article-button-prev-page (arg)
1730 "Go to the prev page."
1732 (let ((win (selected-window)))
1733 (select-window (get-buffer-window gnus-article-buffer t))
1734 (gnus-article-prev-page)
1735 (select-window win)))
1739 ;;; gnus-art.el ends here