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 (eq gnus-prompt-before-saving t) 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 (gnus-make-directory (file-name-directory file))
276 ;; If we have read a directory, we append the default file name.
277 (when (file-directory-p file)
278 (setq file (concat (file-name-as-directory file)
279 (file-name-nondirectory default-name))))
280 ;; Possibly translate some characters.
281 (nnheader-translate-file-chars file)))))
283 (defun gnus-article-archive-name (group)
284 "Return the first instance of an \"Archive-name\" in the current buffer."
285 (let ((case-fold-search t))
286 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
287 (nnheader-concat gnus-article-save-directory
290 (defun gnus-summary-save-in-rmail (&optional filename)
291 "Append this article to Rmail file.
292 Optional argument FILENAME specifies file name.
293 Directory to save to is default to `gnus-article-save-directory'."
295 (gnus-set-global-variables)
297 (funcall gnus-rmail-save-name gnus-newsgroup-name
298 gnus-current-headers gnus-newsgroup-last-rmail)))
299 (setq filename (gnus-read-save-file-name
300 "Save %s in rmail file:" default-name filename))
301 (gnus-make-directory (file-name-directory filename))
302 (gnus-eval-in-buffer-window gnus-original-article-buffer
306 (gnus-output-to-rmail filename))))
307 ;; Remember the directory name to save articles
308 (setq gnus-newsgroup-last-rmail filename)))
310 (defun gnus-summary-save-in-mail (&optional filename)
311 "Append this article to Unix mail file.
312 Optional argument FILENAME specifies file name.
313 Directory to save to is default to `gnus-article-save-directory'."
315 (gnus-set-global-variables)
317 (funcall gnus-mail-save-name gnus-newsgroup-name
318 gnus-current-headers gnus-newsgroup-last-mail)))
319 (setq filename (gnus-read-save-file-name
320 "Save %s in Unix mail file:" default-name filename))
322 (expand-file-name filename
324 (file-name-directory default-name))))
325 (gnus-make-directory (file-name-directory filename))
326 (gnus-eval-in-buffer-window gnus-original-article-buffer
330 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
331 (gnus-output-to-rmail filename)
332 (let ((mail-use-rfc822 t))
333 (rmail-output filename 1 t t))))))
334 ;; Remember the directory name to save articles.
335 (setq gnus-newsgroup-last-mail filename)))
337 (defun gnus-summary-save-in-file (&optional filename)
338 "Append this article to file.
339 Optional argument FILENAME specifies file name.
340 Directory to save to is default to `gnus-article-save-directory'."
342 (gnus-set-global-variables)
344 (funcall gnus-file-save-name gnus-newsgroup-name
345 gnus-current-headers gnus-newsgroup-last-file)))
346 (setq filename (gnus-read-save-file-name
347 "Save %s in file:" default-name filename))
348 (gnus-make-directory (file-name-directory filename))
349 (gnus-eval-in-buffer-window gnus-original-article-buffer
353 (gnus-output-to-file filename))))
354 ;; Remember the directory name to save articles.
355 (setq gnus-newsgroup-last-file filename)))
357 (defun gnus-summary-save-body-in-file (&optional filename)
358 "Append this article body to a file.
359 Optional argument FILENAME specifies file name.
360 The directory to save in defaults to `gnus-article-save-directory'."
362 (gnus-set-global-variables)
364 (funcall gnus-file-save-name gnus-newsgroup-name
365 gnus-current-headers gnus-newsgroup-last-file)))
366 (setq filename (gnus-read-save-file-name
367 "Save %s body in file:" default-name filename))
368 (gnus-make-directory (file-name-directory filename))
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 "\C-d" gnus-article-read-summary-keys
492 "\M-g" gnus-article-read-summary-keys)
494 (substitute-key-definition
495 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
497 (defun gnus-article-make-menu-bar ()
498 (gnus-turn-off-edit-menu 'article)
499 (unless (boundp 'gnus-article-article-menu)
501 gnus-article-article-menu gnus-article-mode-map ""
503 ["Scroll forwards" gnus-article-goto-next-page t]
504 ["Scroll backwards" gnus-article-goto-prev-page t]
505 ["Show summary" gnus-article-show-summary t]
506 ["Fetch Message-ID at point" gnus-article-refer-article t]
507 ["Mail to address at point" gnus-article-mail t]
511 gnus-article-treatment-menu gnus-article-mode-map ""
513 ["Hide headers" gnus-article-hide-headers t]
514 ["Hide signature" gnus-article-hide-signature t]
515 ["Hide citation" gnus-article-hide-citation t]
516 ["Treat overstrike" gnus-article-treat-overstrike t]
517 ["Remove carriage return" gnus-article-remove-cr t]
518 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
520 (run-hooks 'gnus-article-menu-hook)))
522 (defun gnus-article-mode ()
523 "Major mode for displaying an article.
525 All normal editing commands are switched off.
527 The following commands are available in addition to all summary mode
529 \\<gnus-article-mode-map>
530 \\[gnus-article-next-page]\t Scroll the article one page forwards
531 \\[gnus-article-prev-page]\t Scroll the article one page backwards
532 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
533 \\[gnus-article-show-summary]\t Display the summary buffer
534 \\[gnus-article-mail]\t Send a reply to the address near point
535 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
536 \\[gnus-info-find-node]\t Go to the Gnus info node"
538 (when (and menu-bar-mode
539 (gnus-visual-p 'article-menu 'menu))
540 (gnus-article-make-menu-bar))
541 (kill-all-local-variables)
542 (gnus-simplify-mode-line)
543 (setq mode-name "Article")
544 (setq major-mode 'gnus-article-mode)
545 (make-local-variable 'minor-mode-alist)
546 (unless (assq 'gnus-show-mime minor-mode-alist)
547 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
548 (use-local-map gnus-article-mode-map)
549 (gnus-update-format-specifications nil 'article-mode)
550 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
551 (gnus-set-default-directory)
552 (buffer-disable-undo (current-buffer))
553 (setq buffer-read-only t)
554 (run-hooks 'gnus-article-mode-hook))
556 (defun gnus-article-setup-buffer ()
557 "Initialize the article buffer."
558 (let* ((name (if gnus-single-article-buffer "*Article*"
559 (concat "*Article " gnus-newsgroup-name "*")))
561 (progn (string-match "\\*Article" name)
562 (concat " *Original Article"
563 (substring name (match-end 0))))))
564 (setq gnus-article-buffer name)
565 (setq gnus-original-article-buffer original)
566 ;; This might be a variable local to the summary buffer.
567 (unless gnus-single-article-buffer
569 (set-buffer gnus-summary-buffer)
570 (setq gnus-article-buffer name)
571 (setq gnus-original-article-buffer original)
572 (gnus-set-global-variables)))
573 ;; Init original article buffer.
575 (set-buffer (get-buffer-create gnus-original-article-buffer))
576 (buffer-disable-undo (current-buffer))
577 (setq major-mode 'gnus-original-article-mode)
578 (gnus-add-current-to-buffer-list)
579 (make-local-variable 'gnus-original-article))
580 (if (get-buffer name)
583 (buffer-disable-undo (current-buffer))
584 (setq buffer-read-only t)
585 (gnus-add-current-to-buffer-list)
586 (unless (eq major-mode 'gnus-article-mode)
590 (set-buffer (get-buffer-create name))
591 (gnus-add-current-to-buffer-list)
593 (make-local-variable 'gnus-summary-buffer)
596 ;; Set article window start at LINE, where LINE is the number of lines
597 ;; from the head of the article.
598 (defun gnus-article-set-window-start (&optional line)
600 (get-buffer-window gnus-article-buffer t)
602 (set-buffer gnus-article-buffer)
603 (goto-char (point-min))
606 (gnus-message 6 "Moved to bookmark")
607 (search-forward "\n\n" nil t)
611 (defun gnus-article-prepare (article &optional all-headers header)
612 "Prepare ARTICLE in article mode buffer.
613 ARTICLE should either be an article number or a Message-ID.
614 If ARTICLE is an id, HEADER should be the article headers.
615 If ALL-HEADERS is non-nil, no headers are hidden."
617 ;; Make sure we start in a summary buffer.
618 (unless (eq major-mode 'gnus-summary-mode)
619 (set-buffer gnus-summary-buffer))
620 (setq gnus-summary-buffer (current-buffer))
621 ;; Make sure the connection to the server is alive.
622 (unless (gnus-server-opened
623 (gnus-find-method-for-group gnus-newsgroup-name))
624 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
625 (gnus-request-group gnus-newsgroup-name t))
626 (let* ((article (if header (mail-header-number header) article))
627 (summary-buffer (current-buffer))
628 (internal-hook gnus-article-internal-prepare-hook)
629 (group gnus-newsgroup-name)
632 (gnus-article-setup-buffer)
633 (set-buffer gnus-article-buffer)
634 ;; Deactivate active regions.
635 (when (and (boundp 'transient-mark-mode)
637 (setq mark-active nil))
638 (if (not (setq result (let ((buffer-read-only nil))
639 (gnus-request-article-this-buffer
641 ;; There is no such article.
643 (when (and (numberp article)
644 (not (memq article gnus-newsgroup-sparse)))
645 (setq gnus-article-current
646 (cons gnus-newsgroup-name article))
647 (set-buffer gnus-summary-buffer)
648 (setq gnus-current-article article)
649 (gnus-summary-mark-article article gnus-canceled-mark))
650 (unless (memq article gnus-newsgroup-sparse)
652 1 "No such article (may have expired or been canceled)")))
653 (if (or (eq result 'pseudo) (eq result 'nneething))
656 (set-buffer summary-buffer)
657 (setq gnus-last-article gnus-current-article
658 gnus-newsgroup-history (cons gnus-current-article
659 gnus-newsgroup-history)
660 gnus-current-article 0
661 gnus-current-headers nil
662 gnus-article-current nil)
663 (if (eq result 'nneething)
664 (gnus-configure-windows 'summary)
665 (gnus-configure-windows 'article))
666 (gnus-set-global-variables))
667 (gnus-set-mode-line 'article))
668 ;; The result from the `request' was an actual article -
669 ;; or at least some text that is now displayed in the
671 (if (and (numberp article)
672 (not (eq article gnus-current-article)))
673 ;; Seems like a new article has been selected.
674 ;; `gnus-current-article' must be an article number.
676 (set-buffer summary-buffer)
677 (setq gnus-last-article gnus-current-article
678 gnus-newsgroup-history (cons gnus-current-article
679 gnus-newsgroup-history)
680 gnus-current-article article
682 (gnus-summary-article-header gnus-current-article)
684 (cons gnus-newsgroup-name gnus-current-article))
685 (unless (vectorp gnus-current-headers)
686 (setq gnus-current-headers nil))
687 (gnus-summary-show-thread)
688 (run-hooks 'gnus-mark-article-hook)
689 (gnus-set-mode-line 'summary)
690 (and (gnus-visual-p 'article-highlight 'highlight)
691 (run-hooks 'gnus-visual-mark-article-hook))
692 ;; Set the global newsgroup variables here.
693 ;; Suggested by Jim Sisolak
694 ;; <sisolak@trans4.neep.wisc.edu>.
695 (gnus-set-global-variables)
696 (setq gnus-have-all-headers
697 (or all-headers gnus-show-all-headers))
699 (vectorp (gnus-summary-article-header article))
700 (gnus-cache-possibly-enter-article
702 (gnus-summary-article-header article)
703 (memq article gnus-newsgroup-marked)
704 (memq article gnus-newsgroup-dormant)
705 (memq article gnus-newsgroup-unreads)))))
706 (when (or (numberp article)
708 ;; Hooks for getting information from the article.
709 ;; This hook must be called before being narrowed.
710 (let (buffer-read-only)
711 (run-hooks 'internal-hook)
712 (run-hooks 'gnus-article-prepare-hook)
713 ;; Decode MIME message.
715 (if (or (not gnus-strict-mime)
716 (gnus-fetch-field "Mime-Version"))
717 (funcall gnus-show-mime-method)
718 (funcall gnus-decode-encoded-word-method)))
719 ;; Perform the article display hooks.
720 (run-hooks 'gnus-article-display-hook))
722 (goto-char (point-min))
723 (and gnus-break-pages (gnus-narrow-to-page)))
724 (gnus-set-mode-line 'article)
725 (gnus-configure-windows 'article)
726 (goto-char (point-min))
729 (defun gnus-article-wash-status ()
730 "Return a string which display status of article washing."
732 (set-buffer gnus-article-buffer)
733 (let ((cite (article-hidden-text-p 'cite))
734 (headers (article-hidden-text-p 'headers))
735 (boring (article-hidden-text-p 'boring-headers))
736 (pgp (article-hidden-text-p 'pgp))
737 (pem (article-hidden-text-p 'pem))
738 (signature (article-hidden-text-p 'signature))
739 (overstrike (article-hidden-text-p 'overstrike))
740 (emphasis (article-hidden-text-p 'emphasis))
741 (mime gnus-show-mime))
742 (format "%c%c%c%c%c%c%c"
744 (if (or headers boring) ?h ? )
745 (if (or pgp pem) ?p ? )
747 (if overstrike ?o ? )
749 (if emphasis ?e ? )))))
751 (defun gnus-article-hide-headers-if-wanted ()
752 "Hide unwanted headers if `gnus-have-all-headers' is nil.
753 Provided for backwards compatibility."
754 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
756 (gnus-article-hide-headers)))
760 (defun gnus-output-to-rmail (file-name)
761 "Append the current article to an Rmail file named FILE-NAME."
763 ;; Most of these codes are borrowed from rmailout.el.
764 (setq file-name (expand-file-name file-name))
765 (setq rmail-default-rmail-file file-name)
766 (let ((artbuf (current-buffer))
767 (tmpbuf (get-buffer-create " *Gnus-output*")))
769 (or (get-file-buffer file-name)
770 (file-exists-p file-name)
771 (if (gnus-yes-or-no-p
772 (concat "\"" file-name "\" does not exist, create it? "))
773 (let ((file-buffer (create-file-buffer file-name)))
775 (set-buffer file-buffer)
776 (rmail-insert-rmail-file-header)
777 (let ((require-final-newline nil))
778 (write-region (point-min) (point-max) file-name t 1)))
779 (kill-buffer file-buffer))
780 (error "Output file does not exist")))
782 (buffer-disable-undo (current-buffer))
784 (insert-buffer-substring artbuf)
785 (gnus-convert-article-to-rmail)
786 ;; Decide whether to append to a file or to an Emacs buffer.
787 (let ((outbuf (get-file-buffer file-name)))
789 (append-to-file (point-min) (point-max) file-name)
790 ;; File has been visited, in buffer OUTBUF.
792 (let ((buffer-read-only nil)
793 (msg (and (boundp 'rmail-current-message)
794 (symbol-value 'rmail-current-message))))
795 ;; If MSG is non-nil, buffer is in RMAIL mode.
798 (narrow-to-region (point-max) (point-max))))
799 (insert-buffer-substring tmpbuf)
802 (goto-char (point-min))
804 (search-backward "\^_")
805 (narrow-to-region (point) (point-max))
806 (goto-char (1+ (point-min)))
807 (rmail-count-new-messages t)
808 (rmail-show-message msg)))))))
809 (kill-buffer tmpbuf)))
811 (defun gnus-output-to-file (file-name)
812 "Append the current article to a file named FILE-NAME."
813 (let ((artbuf (current-buffer)))
814 (nnheader-temp-write nil
815 (insert-buffer-substring artbuf)
816 ;; Append newline at end of the buffer as separator, and then
818 (goto-char (point-max))
820 (append-to-file (point-min) (point-max) file-name))))
822 (defun gnus-convert-article-to-rmail ()
823 "Convert article in current buffer to Rmail message format."
824 (let ((buffer-read-only nil))
825 ;; Convert article directly into Babyl format.
826 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
827 (goto-char (point-min))
828 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
829 (while (search-forward "\n\^_" nil t) ;single char
830 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
831 (goto-char (point-max))
834 (defun gnus-narrow-to-page (&optional arg)
835 "Narrow the article buffer to a page.
836 If given a numerical ARG, move forward ARG pages."
838 (setq arg (if arg (prefix-numeric-value arg) 0))
840 (set-buffer gnus-article-buffer)
841 (goto-char (point-min))
843 ;; Remove any old next/prev buttons.
844 (when (gnus-visual-p 'page-marker)
845 (let ((buffer-read-only nil))
846 (gnus-remove-text-with-property 'gnus-prev)
847 (gnus-remove-text-with-property 'gnus-next)))
850 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
852 (re-search-forward page-delimiter nil 'move arg)))
853 (goto-char (match-end 0)))
856 (if (re-search-forward page-delimiter nil 'move)
859 (when (and (gnus-visual-p 'page-marker)
860 (not (= (point-min) 1)))
862 (goto-char (point-min))
863 (gnus-insert-prev-page-button)))
864 (when (and (gnus-visual-p 'page-marker)
865 (< (+ (point-max) 2) (buffer-size)))
867 (goto-char (point-max))
868 (gnus-insert-next-page-button)))))
870 ;; Article mode commands
872 (defun gnus-article-goto-next-page ()
873 "Show the next page of the article."
875 (when (gnus-article-next-page)
876 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
878 (defun gnus-article-goto-prev-page ()
879 "Show the next page of the article."
881 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
882 (gnus-article-prev-page nil)))
884 (defun gnus-article-next-page (&optional lines)
885 "Show the next page of the current article.
886 If end of article, return non-nil. Otherwise return nil.
887 Argument LINES specifies lines to be scrolled up."
889 (move-to-window-line -1)
892 (and (pos-visible-in-window-p) ;Not continuation line.
894 ;; Nothing in this page.
895 (if (or (not gnus-break-pages)
898 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
900 (gnus-narrow-to-page 1) ;Go to next page.
902 ;; More in this page.
906 ;; Long lines may cause an end-of-buffer error.
907 (goto-char (point-max))))
908 (move-to-window-line 0)
911 (defun gnus-article-prev-page (&optional lines)
912 "Show previous page of current article.
913 Argument LINES specifies lines to be scrolled down."
915 (move-to-window-line 0)
916 (if (and gnus-break-pages
918 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
920 (gnus-narrow-to-page -1) ;Go to previous page.
921 (goto-char (point-max))
927 (move-to-window-line 0))))
929 (defun gnus-article-refer-article ()
930 "Read article specified by message-id around point."
932 (let ((point (point)))
933 (search-forward ">" nil t) ;Move point to end of "<....>".
934 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
935 (let ((message-id (match-string 1)))
937 (set-buffer gnus-summary-buffer)
938 (gnus-summary-refer-article message-id))
940 (error "No references around point"))))
942 (defun gnus-article-show-summary ()
943 "Reconfigure windows to show summary buffer."
945 (gnus-configure-windows 'article)
946 (gnus-summary-goto-subject gnus-current-article))
948 (defun gnus-article-describe-briefly ()
949 "Describe article mode commands briefly."
952 (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")))
954 (defun gnus-article-summary-command ()
955 "Execute the last keystroke in the summary buffer."
957 (let ((obuf (current-buffer))
958 (owin (current-window-configuration))
960 (switch-to-buffer gnus-summary-buffer 'norecord)
961 (setq func (lookup-key (current-local-map) (this-command-keys)))
962 (call-interactively func)
964 (set-window-configuration owin)
965 (set-window-point (get-buffer-window (current-buffer)) (point))))
967 (defun gnus-article-summary-command-nosave ()
968 "Execute the last keystroke in the summary buffer."
971 (pop-to-buffer gnus-summary-buffer 'norecord)
972 (setq func (lookup-key (current-local-map) (this-command-keys)))
973 (call-interactively func)))
975 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
976 "Read a summary buffer key sequence and execute it from the article buffer."
979 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
980 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
988 (set-buffer gnus-summary-buffer)
989 (push (or key last-command-event) unread-command-events)
990 (setq keys (read-key-sequence nil)))
993 (if (or (member keys nosaves)
994 (member keys nosave-but-article)
995 (member keys nosave-in-article))
997 (save-window-excursion
998 (pop-to-buffer gnus-summary-buffer 'norecord)
999 (setq func (lookup-key (current-local-map) keys)))
1002 (unless (member keys nosave-in-article)
1003 (set-buffer gnus-summary-buffer))
1004 (call-interactively func))
1005 (when (member keys nosave-but-article)
1006 (pop-to-buffer gnus-article-buffer 'norecord)))
1007 ;; These commands should restore window configuration.
1008 (let ((obuf (current-buffer))
1009 (owin (current-window-configuration))
1012 (if not-restore-window
1013 (pop-to-buffer gnus-summary-buffer 'norecord)
1014 (switch-to-buffer gnus-summary-buffer 'norecord))
1015 (setq in-buffer (current-buffer))
1016 (if (setq func (lookup-key (current-local-map) keys))
1017 (call-interactively func)
1019 (when (eq in-buffer (current-buffer))
1021 (unless not-restore-window
1022 (set-window-configuration owin))
1023 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
1025 (defun gnus-article-hide (&optional arg force)
1026 "Hide all the gruft in the current article.
1027 This means that PGP stuff, signatures, cited text and (some)
1028 headers will be hidden.
1029 If given a prefix, show the hidden text instead."
1030 (interactive (list current-prefix-arg 'force))
1031 (gnus-article-hide-headers arg)
1032 (gnus-article-hide-pgp arg)
1033 (gnus-article-hide-citation-maybe arg force)
1034 (gnus-article-hide-signature arg))
1036 (defun gnus-article-maybe-highlight ()
1037 "Do some article highlighting if `article-visual' is non-nil."
1038 (if (gnus-visual-p 'article-highlight 'highlight)
1039 (gnus-article-highlight-some)))
1041 (defun gnus-request-article-this-buffer (article group)
1042 "Get an article and insert it into this buffer."
1043 (let (do-update-line)
1047 (gnus-kill-all-overlays)
1048 (setq group (or group gnus-newsgroup-name))
1050 ;; Open server if it has closed.
1051 (gnus-check-server (gnus-find-method-for-group group))
1053 ;; Using `gnus-request-article' directly will insert the article into
1054 ;; `nntp-server-buffer' - so we'll save some time by not having to
1055 ;; copy it from the server buffer into the article buffer.
1057 ;; We only request an article by message-id when we do not have the
1058 ;; headers for it, so we'll have to get those.
1059 (when (stringp article)
1060 (let ((gnus-override-method gnus-refer-article-method))
1061 (gnus-read-header article)))
1063 ;; If the article number is negative, that means that this article
1064 ;; doesn't belong in this newsgroup (possibly), so we find its
1065 ;; message-id and request it by id instead of number.
1066 (when (and (numberp article)
1068 (get-buffer gnus-summary-buffer)
1069 (buffer-name (get-buffer gnus-summary-buffer)))
1071 (set-buffer gnus-summary-buffer)
1072 (let ((header (gnus-summary-article-header article)))
1075 ((memq article gnus-newsgroup-sparse)
1076 ;; This is a sparse gap article.
1077 (setq do-update-line article)
1078 (setq article (mail-header-id header))
1079 (let ((gnus-override-method gnus-refer-article-method))
1080 (gnus-read-header article))
1081 (setq gnus-newsgroup-sparse
1082 (delq article gnus-newsgroup-sparse)))
1084 ;; It's a real article.
1085 (setq article (mail-header-id header)))
1087 ;; It is an extracted pseudo-article.
1088 (setq article 'pseudo)
1089 (gnus-request-pseudo-article header))))
1091 (let ((method (gnus-find-method-for-group
1092 gnus-newsgroup-name)))
1093 (if (not (eq (car method) 'nneething))
1095 (let ((dir (concat (file-name-as-directory (nth 1 method))
1096 (mail-header-subject header))))
1097 (if (file-directory-p dir)
1099 (setq article 'nneething)
1100 (gnus-group-enter-directory dir)))))))))
1103 ;; Refuse to select canceled articles.
1104 ((and (numberp article)
1106 (get-buffer gnus-summary-buffer)
1107 (buffer-name (get-buffer gnus-summary-buffer))
1108 (eq (cdr (save-excursion
1109 (set-buffer gnus-summary-buffer)
1110 (assq article gnus-newsgroup-reads)))
1111 gnus-canceled-mark))
1113 ;; We first check `gnus-original-article-buffer'.
1114 ((and (get-buffer gnus-original-article-buffer)
1117 (set-buffer gnus-original-article-buffer)
1118 (and (equal (car gnus-original-article) group)
1119 (eq (cdr gnus-original-article) article))))
1120 (insert-buffer-substring gnus-original-article-buffer)
1122 ;; Check the backlog.
1123 ((and gnus-keep-backlog
1124 (gnus-backlog-request-article group article (current-buffer)))
1126 ;; Check asynchronous pre-fetch.
1127 ((gnus-async-request-fetched-article group article (current-buffer))
1128 (gnus-async-prefetch-next group article gnus-summary-buffer)
1131 ((and gnus-use-cache
1133 (gnus-cache-request-article article group))
1135 ;; Get the article and put into the article buffer.
1136 ((or (stringp article) (numberp article))
1137 (let ((gnus-override-method
1138 (and (stringp article) gnus-refer-article-method))
1139 (buffer-read-only nil))
1141 (gnus-kill-all-overlays)
1142 (when (gnus-request-article article group (current-buffer))
1143 (when (numberp article)
1144 (gnus-async-prefetch-next group article gnus-summary-buffer)
1145 (when gnus-keep-backlog
1146 (gnus-backlog-enter-article
1147 group article (current-buffer))))
1152 ;; Take the article from the original article buffer
1153 ;; and place it in the buffer it's supposed to be in.
1154 (when (and (get-buffer gnus-article-buffer)
1156 (equal (buffer-name (current-buffer))
1157 (buffer-name (get-buffer gnus-article-buffer))))
1159 (if (get-buffer gnus-original-article-buffer)
1160 (set-buffer (get-buffer gnus-original-article-buffer))
1161 (set-buffer (get-buffer-create gnus-original-article-buffer))
1162 (buffer-disable-undo (current-buffer))
1163 (setq major-mode 'gnus-original-article-mode)
1164 (setq buffer-read-only t)
1165 (gnus-add-current-to-buffer-list))
1166 (let (buffer-read-only)
1168 (insert-buffer-substring gnus-article-buffer))
1169 (setq gnus-original-article (cons group article))))
1171 ;; Update sparse articles.
1172 (when (and do-update-line
1173 (or (numberp article)
1175 (let ((buf (current-buffer)))
1176 (set-buffer gnus-summary-buffer)
1177 (gnus-summary-update-article do-update-line)
1178 (gnus-summary-goto-subject do-update-line nil t)
1179 (set-window-point (get-buffer-window (current-buffer) t)
1181 (set-buffer buf))))))
1183 (defun gnus-article-date-ut (&optional type highlight)
1184 "Convert DATE date to universal time in the current article.
1185 If TYPE is `local', convert to local time; if it is `lapsed', output
1186 how much time has lapsed since DATE."
1187 (interactive (list 'ut t))
1188 (let ((headers (or gnus-current-headers (gnus-summary-article-header))))
1190 (set-buffer gnus-article-buffer)
1191 (article-date-ut type highlight headers))))
1197 (defvar gnus-article-edit-mode-hook nil
1198 "*Hook run in article edit mode buffers.")
1200 (defvar gnus-article-edit-done-function nil)
1202 (defvar gnus-article-edit-mode-map nil)
1204 (unless gnus-article-edit-mode-map
1205 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
1207 (gnus-define-keys gnus-article-edit-mode-map
1208 "\C-c\C-c" gnus-article-edit-done
1209 "\C-c\C-k" gnus-article-edit-exit)
1211 (gnus-define-keys (gnus-article-edit-wash-map
1212 "\C-c\C-w" gnus-article-edit-mode-map)
1213 "f" gnus-article-edit-full-stops))
1215 (defun gnus-article-edit-mode ()
1216 "Major mode for editing articles.
1217 This is an extended text-mode.
1219 \\{gnus-article-edit-mode-map}"
1221 (kill-all-local-variables)
1222 (setq major-mode 'gnus-article-edit-mode)
1223 (setq mode-name "Article Edit")
1224 (use-local-map gnus-article-edit-mode-map)
1225 (make-local-variable 'gnus-article-edit-done-function)
1226 (make-local-variable 'gnus-prev-winconf)
1227 (setq buffer-read-only nil)
1228 (buffer-enable-undo)
1230 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
1232 (defun gnus-article-edit (&optional force)
1233 "Edit the current article.
1234 This will have permanent effect only in mail groups.
1235 If FORCE is non-nil, allow editing of articles even in read-only
1238 (when (and (not force)
1239 (gnus-group-read-only-p))
1240 (error "The current newsgroup does not support article editing."))
1241 (gnus-article-edit-article
1243 (gnus-summary-edit-article-done
1244 ,(or (mail-header-references gnus-current-headers) "")
1245 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
1247 (defun gnus-article-edit-article (exit-func)
1248 "Start editing the contents of the current article buffer."
1249 (let ((winconf (current-window-configuration)))
1250 (set-buffer gnus-article-buffer)
1251 (gnus-article-edit-mode)
1252 (set-text-properties (point-min) (point-max) nil)
1253 (gnus-configure-windows 'edit-article)
1254 (setq gnus-article-edit-done-function exit-func)
1255 (setq gnus-prev-winconf winconf)
1256 (gnus-message 6 "C-c C-c to end edits")))
1258 (defun gnus-article-edit-done ()
1259 "Update the article edits and exit."
1261 (let ((func gnus-article-edit-done-function)
1262 (buf (current-buffer))
1263 (start (window-start)))
1264 (gnus-article-edit-exit)
1267 (let ((buffer-read-only nil))
1270 (set-window-start (get-buffer-window buf) start)
1271 (set-window-point (get-buffer-window buf) (point))))
1273 (defun gnus-article-edit-exit ()
1274 "Exit the article editing without updating."
1276 ;; We remove all text props from the article buffer.
1277 (let ((buf (format "%s" (buffer-string)))
1278 (curbuf (current-buffer))
1280 (window-start (window-start)))
1283 (let ((winconf gnus-prev-winconf))
1285 ;; The cache and backlog have to be flushed somewhat.
1286 (when gnus-use-cache
1287 (gnus-cache-update-article
1288 (car gnus-article-current) (cdr gnus-article-current)))
1289 (when gnus-keep-backlog
1290 (gnus-backlog-remove-article
1291 (car gnus-article-current) (cdr gnus-article-current)))
1292 ;; Flush original article as well.
1294 (when (get-buffer gnus-original-article-buffer)
1295 (set-buffer gnus-original-article-buffer)
1296 (setq gnus-original-article nil)))
1297 (set-window-configuration winconf)
1298 ;; Tippy-toe some to make sure that point remains where it was.
1299 (let ((buf (current-buffer)))
1301 (set-window-start (get-buffer-window (current-buffer)) window-start)
1303 (set-buffer buf)))))
1305 (defun gnus-article-edit-full-stops ()
1306 "Interactively repair spacing at end of sentences."
1309 (goto-char (point-min))
1310 (search-forward-regexp "^$" nil t)
1311 (let ((case-fold-search nil))
1312 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
1315 ;;; Article highlights
1318 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
1320 ;;; Internal Variables:
1322 (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_=#$@~`%&*+|\\/]"
1323 "*Regular expression that matches URLs.")
1325 (defvar gnus-button-alist
1326 `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
1327 t gnus-button-message-id 3)
1328 ("\\(<?\\(url: ?\\)?news://\\([^>\n\t ]*\\)>?\\)" 1 t
1329 gnus-button-fetch-group 3)
1330 ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
1331 gnus-button-message-id 3)
1332 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-button-reply 2)
1333 ;; This is how URLs _should_ be embedded in text...
1334 ("<URL: *\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
1335 ;; Next regexp stolen from highlight-headers.el.
1336 ;; Modified by Vladimir Alexiev.
1337 (,gnus-button-url-regexp 0 t gnus-button-url 0))
1338 "Alist of regexps matching buttons in article bodies.
1340 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
1341 REGEXP: is the string matching text around the button,
1342 BUTTON: is the number of the regexp grouping actually matching the button,
1343 FORM: is a lisp expression which must eval to true for the button to
1345 CALLBACK: is the function to call when the user push this button, and each
1346 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
1348 CALLBACK can also be a variable, in that case the value of that
1349 variable it the real callback function.")
1351 (defvar gnus-header-button-alist
1352 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
1353 0 t gnus-button-message-id 0)
1354 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
1355 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
1356 0 t gnus-button-mailto 0)
1357 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1358 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
1359 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
1360 gnus-button-message-id 3))
1361 "Alist of headers and regexps to match buttons in article heads.
1363 This alist is very similar to `gnus-button-alist', except that each
1364 alist has an additional HEADER element first in each entry:
1366 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
1368 HEADER is a regexp to match a header. For a fuller explanation, see
1369 `gnus-button-alist'.")
1371 (defvar gnus-button-regexp nil)
1372 (defvar gnus-button-marker-list nil)
1373 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1375 (defvar gnus-button-last nil)
1376 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1380 (defun gnus-article-push-button (event)
1381 "Check text under the mouse pointer for a callback function.
1382 If the text under the mouse pointer has a `gnus-callback' property,
1383 call it with the value of the `gnus-data' text property."
1385 (set-buffer (window-buffer (posn-window (event-start event))))
1386 (let* ((pos (posn-point (event-start event)))
1387 (data (get-text-property pos 'gnus-data))
1388 (fun (get-text-property pos 'gnus-callback)))
1389 (if fun (funcall fun data))))
1391 (defun gnus-article-press-button ()
1392 "Check text at point for a callback function.
1393 If the text at point has a `gnus-callback' property,
1394 call it with the value of the `gnus-data' text property."
1396 (let* ((data (get-text-property (point) 'gnus-data))
1397 (fun (get-text-property (point) 'gnus-callback)))
1398 (if fun (funcall fun data))))
1400 (defun gnus-article-prev-button (n)
1401 "Move point to N buttons backward.
1402 If N is negative, move forward instead."
1404 (gnus-article-next-button (- n)))
1406 (defun gnus-article-next-button (n)
1407 "Move point to N buttons forward.
1408 If N is negative, move backward instead."
1410 (let ((function (if (< n 0) 'previous-single-property-change
1411 'next-single-property-change))
1412 (inhibit-point-motion-hooks t)
1414 (limit (if (< n 0) (point-min) (point-max))))
1416 (while (and (not (= limit (point)))
1418 ;; Skip past the current button.
1419 (when (get-text-property (point) 'gnus-callback)
1420 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1421 ;; Go to the next (or previous) button.
1422 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
1423 ;; Put point at the start of the button.
1424 (when (and backward (not (get-text-property (point) 'gnus-callback)))
1425 (goto-char (funcall function (point) 'gnus-callback nil limit)))
1426 ;; Skip past intangible buttons.
1427 (when (get-text-property (point) 'intangible)
1431 (gnus-message 5 "No more buttons"))
1434 (defun gnus-article-highlight (&optional force)
1435 "Highlight current article.
1436 This function calls `gnus-article-highlight-headers',
1437 `gnus-article-highlight-citation',
1438 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1439 do the highlighting. See the documentation for those functions."
1440 (interactive (list 'force))
1441 (gnus-article-highlight-headers)
1442 (gnus-article-highlight-citation force)
1443 (gnus-article-highlight-signature)
1444 (gnus-article-add-buttons force)
1445 (gnus-article-add-buttons-to-head))
1447 (defun gnus-article-highlight-some (&optional force)
1448 "Highlight current article.
1449 This function calls `gnus-article-highlight-headers',
1450 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
1451 do the highlighting. See the documentation for those functions."
1452 (interactive (list 'force))
1453 (gnus-article-highlight-headers)
1454 (gnus-article-highlight-signature)
1455 (gnus-article-add-buttons))
1457 (defun gnus-article-highlight-headers ()
1458 "Highlight article headers as specified by `gnus-header-face-alist'."
1461 (set-buffer gnus-article-buffer)
1463 (let ((alist gnus-header-face-alist)
1464 (buffer-read-only nil)
1465 (case-fold-search t)
1466 (inhibit-point-motion-hooks t)
1467 entry regexp header-face field-face from hpoints fpoints)
1468 (goto-char (point-min))
1469 (when (search-forward "\n\n" nil t)
1470 (narrow-to-region (1- (point)) (point-min))
1471 (while (setq entry (pop alist))
1472 (goto-char (point-min))
1473 (setq regexp (concat "^\\("
1474 (if (string-equal "" (nth 0 entry))
1478 header-face (nth 1 entry)
1479 field-face (nth 2 entry))
1480 (while (and (re-search-forward regexp nil t)
1484 (or (search-forward ":" nil t)
1486 (when (and header-face
1487 (not (memq (point) hpoints)))
1488 (push (point) hpoints)
1489 (gnus-put-text-property from (point) 'face header-face))
1490 (when (and field-face
1491 (not (memq (setq from (point)) fpoints)))
1493 (if (re-search-forward "^[^ \t]" nil t)
1495 (goto-char (point-max)))
1496 (gnus-put-text-property from (point) 'face field-face)))))))))
1498 (defun gnus-article-highlight-signature ()
1499 "Highlight the signature in an article.
1500 It does this by highlighting everything after
1501 `gnus-signature-separator' using `gnus-signature-face'."
1504 (set-buffer gnus-article-buffer)
1505 (let ((buffer-read-only nil)
1506 (inhibit-point-motion-hooks t))
1508 (when (and gnus-signature-face
1509 (article-narrow-to-signature))
1510 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
1511 'face gnus-signature-face)
1513 (article-search-signature)
1514 (let ((start (match-beginning 0))
1515 (end (set-marker (make-marker) (1+ (match-end 0)))))
1516 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
1519 (defun gnus-article-add-buttons (&optional force)
1520 "Find external references in the article and make buttons of them.
1521 \"External references\" are things like Message-IDs and URLs, as
1522 specified by `gnus-button-alist'."
1523 (interactive (list 'force))
1525 (set-buffer gnus-article-buffer)
1526 ;; Remove all old markers.
1527 (while gnus-button-marker-list
1528 (set-marker (pop gnus-button-marker-list) nil))
1529 (let ((buffer-read-only nil)
1530 (inhibit-point-motion-hooks t)
1531 (case-fold-search t)
1532 (alist gnus-button-alist)
1534 (goto-char (point-min))
1535 ;; We skip the headers.
1536 (unless (search-forward "\n\n" nil t)
1537 (goto-char (point-max)))
1539 (while (setq entry (pop alist))
1540 (setq regexp (car entry))
1542 (while (re-search-forward regexp nil t)
1543 (let* ((start (and entry (match-beginning (nth 1 entry))))
1544 (end (and entry (match-end (nth 1 entry))))
1545 (from (match-beginning 0)))
1546 (when (or (eq t (nth 1 entry))
1547 (eval (nth 1 entry)))
1548 ;; That optional form returned non-nil, so we add the
1550 (gnus-article-add-button
1551 start end 'gnus-button-push
1552 (car (push (set-marker (make-marker) from)
1553 gnus-button-marker-list))))))))))
1555 ;; Add buttons to the head of an article.
1556 (defun gnus-article-add-buttons-to-head ()
1557 "Add buttons to the head of the article."
1560 (set-buffer gnus-article-buffer)
1561 (let ((buffer-read-only nil)
1562 (inhibit-point-motion-hooks t)
1563 (case-fold-search t)
1564 (alist gnus-header-button-alist)
1566 (nnheader-narrow-to-headers)
1568 ;; Each alist entry.
1569 (setq entry (car alist)
1571 (goto-char (point-min))
1572 (while (re-search-forward (car entry) nil t)
1573 ;; Each header matching the entry.
1574 (setq beg (match-beginning 0))
1575 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
1576 (match-beginning 0))
1579 (while (re-search-forward (nth 1 entry) end t)
1580 ;; Each match within a header.
1581 (let* ((entry (cdr entry))
1582 (start (match-beginning (nth 1 entry)))
1583 (end (match-end (nth 1 entry)))
1584 (form (nth 2 entry)))
1585 (goto-char (match-end 0))
1587 (gnus-article-add-button
1588 start end (nth 3 entry)
1589 (buffer-substring (match-beginning (nth 4 entry))
1590 (match-end (nth 4 entry)))))))
1594 ;;; External functions:
1596 (defun gnus-article-add-button (from to fun &optional data)
1597 "Create a button between FROM and TO with callback FUN and data DATA."
1598 (and gnus-article-button-face
1599 (gnus-overlay-put (gnus-make-overlay from to)
1600 'face gnus-article-button-face))
1601 (gnus-add-text-properties
1603 (nconc (and gnus-article-mouse-face
1604 (list gnus-mouse-face-prop gnus-article-mouse-face))
1605 (list 'gnus-callback fun)
1606 (and data (list 'gnus-data data)))))
1608 ;;; Internal functions:
1610 (defun gnus-signature-toggle (end)
1612 (set-buffer gnus-article-buffer)
1613 (let ((buffer-read-only nil)
1614 (inhibit-point-motion-hooks t))
1615 (if (get-text-property end 'invisible)
1616 (article-unhide-text end (point-max))
1617 (article-hide-text end (point-max) gnus-hidden-properties)))))
1619 (defun gnus-button-entry ()
1620 ;; Return the first entry in `gnus-button-alist' matching this place.
1621 (let ((alist gnus-button-alist)
1624 (setq entry (pop alist))
1625 (if (looking-at (car entry))
1630 (defun gnus-button-push (marker)
1631 ;; Push button starting at MARKER.
1633 (set-buffer gnus-article-buffer)
1635 (let* ((entry (gnus-button-entry))
1636 (inhibit-point-motion-hooks t)
1638 (args (mapcar (lambda (group)
1639 (let ((string (buffer-substring
1640 (match-beginning group)
1641 (match-end group))))
1642 (gnus-set-text-properties
1643 0 (length string) nil string)
1650 (fboundp (symbol-value fun)))
1651 (apply (symbol-value fun) args))
1653 (gnus-message 1 "You must define `%S' to use this button"
1654 (cons fun args)))))))
1656 (defun gnus-button-message-id (message-id)
1659 (set-buffer gnus-summary-buffer)
1660 (gnus-summary-refer-article message-id)))
1662 (defun gnus-button-fetch-group (address)
1663 "Fetch GROUP specified by ADDRESS."
1664 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
1665 (error "Can't parse %s" address)
1666 (gnus-group-read-ephemeral-group
1667 (match-string 4 address)
1668 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
1669 (nntp-port-number ,(if (match-end 3)
1670 (match-string 3 address)
1673 (defun gnus-button-mailto (address)
1675 (set-buffer (gnus-copy-article-buffer))
1676 (message-reply address))
1678 (defun gnus-button-reply (address)
1679 ;; Reply to ADDRESS.
1680 (message-reply address))
1682 (defun gnus-button-url (address)
1684 (funcall browse-url-browser-function address))
1686 ;;; Next/prev buttons in the article buffer.
1688 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
1689 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
1691 (defvar gnus-prev-page-map nil)
1692 (unless gnus-prev-page-map
1693 (setq gnus-prev-page-map (make-sparse-keymap))
1694 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
1695 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
1697 (defun gnus-insert-prev-page-button ()
1698 (let ((buffer-read-only nil))
1700 gnus-prev-page-line-format nil
1701 `(gnus-prev t local-map ,gnus-prev-page-map
1702 gnus-callback gnus-article-button-prev-page))))
1704 (defvar gnus-next-page-map nil)
1705 (unless gnus-next-page-map
1706 (setq gnus-next-page-map (make-keymap))
1707 (suppress-keymap gnus-prev-page-map)
1708 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
1709 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
1711 (defun gnus-button-next-page ()
1712 "Go to the next page."
1714 (let ((win (selected-window)))
1715 (select-window (get-buffer-window gnus-article-buffer t))
1716 (gnus-article-next-page)
1717 (select-window win)))
1719 (defun gnus-button-prev-page ()
1720 "Go to the prev page."
1722 (let ((win (selected-window)))
1723 (select-window (get-buffer-window gnus-article-buffer t))
1724 (gnus-article-prev-page)
1725 (select-window win)))
1727 (defun gnus-insert-next-page-button ()
1728 (let ((buffer-read-only nil))
1729 (gnus-eval-format gnus-next-page-line-format nil
1730 `(gnus-next t local-map ,gnus-next-page-map
1732 gnus-article-button-next-page))))
1734 (defun gnus-article-button-next-page (arg)
1735 "Go to the next page."
1737 (let ((win (selected-window)))
1738 (select-window (get-buffer-window gnus-article-buffer t))
1739 (gnus-article-next-page)
1740 (select-window win)))
1742 (defun gnus-article-button-prev-page (arg)
1743 "Go to the prev page."
1745 (let ((win (selected-window)))
1746 (select-window (get-buffer-window gnus-article-buffer t))
1747 (gnus-article-prev-page)
1748 (select-window win)))
1752 ;;; gnus-art.el ends here