1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
35 (defgroup gnus-article nil
37 :link '(custom-manual "(gnus)The Article Buffer")
40 (defgroup gnus-article-hiding nil
41 "Hiding article parts."
42 :link '(custom-manual "(gnus)Article Hiding")
45 (defgroup gnus-article-highlight nil
46 "Article highlighting."
47 :link '(custom-manual "(gnus)Article Highlighting")
51 (defgroup gnus-article-signature nil
53 :link '(custom-manual "(gnus)Article Signature")
56 (defgroup gnus-article-headers nil
58 :link '(custom-manual "(gnus)Hiding Headers")
61 (defgroup gnus-article-washing nil
62 "Special commands on articles."
63 :link '(custom-manual "(gnus)Article Washing")
66 (defgroup gnus-article-emphasis nil
67 "Fontisizing articles."
68 :link '(custom-manual "(gnus)Article Fontisizing")
71 (defgroup gnus-article-saving nil
73 :link '(custom-manual "(gnus)Saving Articles")
76 (defgroup gnus-article-mime nil
77 "Worshiping the MIME wonder."
78 :link '(custom-manual "(gnus)Using MIME")
81 (defgroup gnus-article-buttons nil
82 "Pushable buttons in the article buffer."
83 :link '(custom-manual "(gnus)Article Buttons")
86 (defgroup gnus-article-various nil
87 "Other article options."
88 :link '(custom-manual "(gnus)Misc Article")
91 (defcustom gnus-ignored-headers
92 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
93 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
94 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
95 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
96 "All headers that match this regexp will be hidden.
97 This variable can also be a list of regexps of headers to be ignored.
98 If `gnus-visible-headers' is non-nil, this variable will be ignored."
99 :type '(choice :custom-show nil
102 :group 'gnus-article-hiding)
104 (defcustom gnus-visible-headers
105 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From"
106 "All headers that do not match this regexp will be hidden.
107 This variable can also be a list of regexp of headers to remain visible.
108 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
109 :type '(repeat :value-to-internal (lambda (widget value)
110 (custom-split-regexp-maybe value))
111 :match (lambda (widget value)
113 (widget-editable-list-match widget value)))
115 :group 'gnus-article-hiding)
117 (defcustom gnus-sorted-header-list
118 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
119 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
120 "This variable is a list of regular expressions.
121 If it is non-nil, headers that match the regular expressions will
122 be placed first in the article buffer in the sequence specified by
124 :type '(repeat regexp)
125 :group 'gnus-article-hiding)
127 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
128 "Headers that are only to be displayed if they have interesting data.
129 Possible values in this list are `empty', `newsgroups', `followup-to',
130 `reply-to', and `date'."
131 :type '(set (const :tag "Headers with no content." empty)
132 (const :tag "Newsgroups with only one group." newsgroups)
133 (const :tag "Followup-to identical to newsgroups." followup-to)
134 (const :tag "Reply-to identical to from." reply-to)
135 (const :tag "Date less than four days old." date))
136 :group 'gnus-article-hiding)
138 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
139 "Regexp matching signature separator.
140 This can also be a list of regexps. In that case, it will be checked
141 from head to tail looking for a separator. Searches will be done from
142 the end of the buffer."
143 :type '(repeat string)
144 :group 'gnus-article-signature)
146 (defcustom gnus-signature-limit nil
147 "Provide a limit to what is considered a signature.
148 If it is a number, no signature may not be longer (in characters) than
149 that number. If it is a floating point number, no signature may be
150 longer (in lines) than that number. If it is a function, the function
151 will be called without any parameters, and if it returns nil, there is
152 no signature in the buffer. If it is a string, it will be used as a
153 regexp. If it matches, the text in question is not a signature."
154 :type '(choice integer number function regexp)
155 :group 'gnus-article-signature)
157 (defcustom gnus-hidden-properties '(invisible t intangible t)
158 "Property list to use for hiding text."
160 :group 'gnus-article-hiding)
162 (defcustom gnus-article-x-face-command
163 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
164 "String or function to be executed to display an X-Face header.
165 If it is a string, the command will be executed in a sub-shell
166 asynchronously. The compressed face will be piped to this command."
167 :type 'string ;Leave function case to Lisp.
168 :group 'gnus-article-washing)
170 (defcustom gnus-article-x-face-too-ugly nil
171 "Regexp matching posters whose face shouldn't be shown automatically."
173 :group 'gnus-article-washing)
175 (defcustom gnus-emphasis-alist
177 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
179 '(("_" "_" underline)
182 ("_/" "/_" underline-italic)
183 ("_\\*" "\\*_" underline-bold)
184 ("\\*/" "/\\*" bold-italic)
185 ("_\\*/" "/\\*_" underline-bold-italic))))
186 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
187 2 3 gnus-emphasis-underline)
191 (format format (car spec) (cadr spec))
192 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
194 "Alist that says how to fontify certain phrases.
195 Each item looks like this:
197 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
199 The first element is a regular expression to be matched. The second
200 is a number that says what regular expression grouping used to find
201 the entire emphasized word. The third is a number that says what
202 regexp grouping should be displayed and highlighted. The fourth
203 is the face used for highlighting."
204 :type '(repeat (list :value ("" 0 0 default)
206 (integer :tag "Match group")
207 (integer :tag "Emphasize group")
209 :group 'gnus-article-emphasis)
211 (defface gnus-emphasis-bold '((t (:bold t)))
212 "Face used for displaying strong emphasized text (*word*)."
213 :group 'gnus-article-emphasis)
215 (defface gnus-emphasis-italic '((t (:italic t)))
216 "Face used for displaying italic emphasized text (/word/)."
217 :group 'gnus-article-emphasis)
219 (defface gnus-emphasis-underline '((t (:underline t)))
220 "Face used for displaying underlined emphasized text (_word_)."
221 :group 'gnus-article-emphasis)
223 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
224 "Face used for displaying underlined bold emphasized text (_*word*_)."
225 :group 'gnus-article-emphasis)
227 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
228 "Face used for displaying underlined italic emphasized text (_*word*_)."
229 :group 'gnus-article-emphasis)
231 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
232 "Face used for displaying bold italic emphasized text (/*word*/)."
233 :group 'gnus-article-emphasis)
235 (defface gnus-emphasis-underline-bold-italic
236 '((t (:bold t :italic t :underline t)))
237 "Face used for displaying underlined bold italic emphasized text.
238 Esample: (_/*word*/_)."
239 :group 'gnus-article-emphasis)
241 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
242 "Format for display of Date headers in article bodies.
243 See `format-time-zone' for the possible values."
245 :link '(custom-manual "(gnus)Article Date")
246 :group 'gnus-article-washing)
249 (autoload 'hexl-hex-string-to-integer "hexl")
250 (autoload 'timezone-make-date-arpa-standard "timezone")
251 (autoload 'mail-extract-address-components "mail-extr"))
253 (defcustom gnus-save-all-headers t
254 "*If non-nil, don't remove any headers before saving."
255 :group 'gnus-article-saving
258 (defcustom gnus-prompt-before-saving 'always
259 "*This variable says how much prompting is to be done when saving articles.
260 If it is nil, no prompting will be done, and the articles will be
261 saved to the default files. If this variable is `always', each and
262 every article that is saved will be preceded by a prompt, even when
263 saving large batches of articles. If this variable is neither nil not
264 `always', there the user will be prompted once for a file name for
265 each invocation of the saving commands."
266 :group 'gnus-article-saving
267 :type '(choice (item always)
268 (item :tag "never" nil)
269 (sexp :tag "once" :format "%t")))
271 (defcustom gnus-saved-headers gnus-visible-headers
272 "Headers to keep if `gnus-save-all-headers' is nil.
273 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
274 If that variable is nil, however, all headers that match this regexp
275 will be kept while the rest will be deleted before saving."
276 :group 'gnus-article-saving
277 :type '(repeat string))
279 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
280 "A function to save articles in your favourite format.
281 The function must be interactively callable (in other words, it must
282 be an Emacs command).
284 Gnus provides the following functions:
286 * gnus-summary-save-in-rmail (Rmail format)
287 * gnus-summary-save-in-mail (Unix mail format)
288 * gnus-summary-save-in-folder (MH folder)
289 * gnus-summary-save-in-file (article format)
290 * gnus-summary-save-in-vm (use VM's folder format)
291 * gnus-summary-write-to-file (article format -- overwrite)."
292 :group 'gnus-article-saving
293 :type '(radio (function-item gnus-summary-save-in-rmail)
294 (function-item gnus-summary-save-in-mail)
295 (function-item gnus-summary-save-in-folder)
296 (function-item gnus-summary-save-in-file)
297 (function-item gnus-summary-save-in-vm)
298 (function-item gnus-summary-write-to-file)))
300 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
301 "A function generating a file name to save articles in Rmail format.
302 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
303 :group 'gnus-article-saving
306 (defcustom gnus-mail-save-name 'gnus-plain-save-name
307 "A function generating a file name to save articles in Unix mail format.
308 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
309 :group 'gnus-article-saving
312 (defcustom gnus-folder-save-name 'gnus-folder-save-name
313 "A function generating a file name to save articles in MH folder.
314 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
315 :group 'gnus-article-saving
318 (defcustom gnus-file-save-name 'gnus-numeric-save-name
319 "A function generating a file name to save articles in article format.
320 The function is called with NEWSGROUP, HEADERS, and optional
322 :group 'gnus-article-saving
325 (defcustom gnus-split-methods
326 '((gnus-article-archive-name)
327 (gnus-article-nndoc-name))
328 "Variable used to suggest where articles are to be saved.
329 For instance, if you would like to save articles related to Gnus in
330 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
331 you could set this variable to something like:
333 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
334 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
336 This variable is an alist where the where the key is the match and the
337 value is a list of possible files to save in if the match is non-nil.
339 If the match is a string, it is used as a regexp match on the
340 article. If the match is a symbol, that symbol will be funcalled
341 from the buffer of the article to be saved with the newsgroup as the
342 parameter. If it is a list, it will be evaled in the same buffer.
344 If this form or function returns a string, this string will be used as
345 a possible file name; and if it returns a non-nil list, that list will
346 be used as possible file names."
347 :group 'gnus-article-saving
348 :type '(repeat (choice (list function)
349 (cons regexp (repeat string))
352 (defcustom gnus-strict-mime t
353 "*If nil, MIME-decode even if there is no Mime-Version header."
354 :group 'gnus-article-mime
357 (defcustom gnus-show-mime-method 'metamail-buffer
358 "Function to process a MIME message.
359 The function is called from the article buffer."
360 :group 'gnus-article-mime
363 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
364 "*Function to decode MIME encoded words.
365 The function is called from the article buffer."
366 :group 'gnus-article-mime
369 (defcustom gnus-page-delimiter "^\^L"
370 "*Regexp describing what to use as article page delimiters.
371 The default value is \"^\^L\", which is a form linefeed at the
372 beginning of a line."
374 :group 'gnus-article-various)
376 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
377 "*The format specification for the article mode line.
378 See `gnus-summary-mode-line-format' for a closer description."
380 :group 'gnus-article-various)
382 (defcustom gnus-article-mode-hook nil
383 "*A hook for Gnus article mode."
385 :group 'gnus-article-various)
387 (defcustom gnus-article-menu-hook nil
388 "*Hook run after the creation of the article mode menu."
390 :group 'gnus-article-various)
392 (defcustom gnus-article-prepare-hook nil
393 "*A hook called after an article has been prepared in the article buffer.
394 If you want to run a special decoding program like nkf, use this hook."
396 :group 'gnus-article-various)
398 (defcustom gnus-article-button-face 'bold
399 "Face used for highlighting buttons in the article buffer.
401 An article button is a piece of text that you can activate by pressing
402 `RET' or `mouse-2' above it."
404 :group 'gnus-article-buttons)
406 (defcustom gnus-article-mouse-face 'highlight
407 "Face used for mouse highlighting in the article buffer.
409 Article buttons will be displayed in this face when the cursor is
412 :group 'gnus-article-buttons)
414 (defcustom gnus-signature-face 'gnus-signature-face
415 "Face used for highlighting a signature in the article buffer.
416 Obsolete; use the face `gnus-signature-face' for customizations instead."
418 :group 'gnus-article-highlight
419 :group 'gnus-article-signature)
421 (defface gnus-signature-face
424 "Face used for highlighting a signature in the article buffer."
425 :group 'gnus-article-highlight
426 :group 'gnus-article-signature)
428 (defface gnus-header-from-face
431 (:foreground "spring green" :bold t))
434 (:foreground "red3" :bold t))
436 (:bold t :italic t)))
437 "Face used for displaying from headers."
438 :group 'gnus-article-headers
439 :group 'gnus-article-highlight)
441 (defface gnus-header-subject-face
444 (:foreground "SeaGreen3" :bold t))
447 (:foreground "red4" :bold t))
449 (:bold t :italic t)))
450 "Face used for displaying subject headers."
451 :group 'gnus-article-headers
452 :group 'gnus-article-highlight)
454 (defface gnus-header-newsgroups-face
457 (:foreground "yellow" :bold t :italic t))
460 (:foreground "MidnightBlue" :bold t :italic t))
462 (:bold t :italic t)))
463 "Face used for displaying newsgroups headers."
464 :group 'gnus-article-headers
465 :group 'gnus-article-highlight)
467 (defface gnus-header-name-face
470 (:foreground "SeaGreen"))
473 (:foreground "maroon"))
476 "Face used for displaying header names."
477 :group 'gnus-article-headers
478 :group 'gnus-article-highlight)
480 (defface gnus-header-content-face
483 (:foreground "forest green" :italic t))
486 (:foreground "indianred4" :italic t))
488 (:italic t))) "Face used for displaying header content."
489 :group 'gnus-article-headers
490 :group 'gnus-article-highlight)
492 (defcustom gnus-header-face-alist
493 '(("From" nil gnus-header-from-face)
494 ("Subject" nil gnus-header-subject-face)
495 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
496 ("" gnus-header-name-face gnus-header-content-face))
497 "Controls highlighting of article header.
499 An alist of the form (HEADER NAME CONTENT).
501 HEADER is a regular expression which should match the name of an
502 header header and NAME and CONTENT are either face names or nil.
504 The name of each header field will be displayed using the face
505 specified by the first element in the list where HEADER match the
506 header name and NAME is non-nil. Similarly, the content will be
507 displayed by the first non-nil matching CONTENT face."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight
510 :type '(repeat (list (regexp :tag "Header")
512 (item :tag "skip" nil)
513 (face :value default))
514 (choice :tag "Content"
515 (item :tag "skip" nil)
516 (face :value default)))))
518 ;;; Internal variables
520 (defvar gnus-article-mode-syntax-table
521 (let ((table (copy-syntax-table text-mode-syntax-table)))
522 (modify-syntax-entry ?- "w" table)
523 (modify-syntax-entry ?> ")" table)
524 (modify-syntax-entry ?< "(" table)
526 "Syntax table used in article mode buffers.
527 Initialized from `text-mode-syntax-table.")
529 (defvar gnus-save-article-buffer nil)
531 (defvar gnus-article-mode-line-format-alist
532 (nconc '((?w (gnus-article-wash-status) ?s))
533 gnus-summary-mode-line-format-alist))
535 (defvar gnus-number-of-articles-to-be-saved nil)
537 (defvar gnus-inhibit-hiding nil)
539 (defsubst gnus-article-hide-text (b e props)
540 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
541 (add-text-properties b e props)
542 (when (memq 'intangible props)
544 (max (1- b) (point-min))
545 b 'intangible (cddr (memq 'intangible props)))))
547 (defsubst gnus-article-unhide-text (b e)
548 "Remove hidden text properties from region between B and E."
549 (remove-text-properties b e gnus-hidden-properties)
550 (when (memq 'intangible gnus-hidden-properties)
551 (put-text-property (max (1- b) (point-min))
554 (defun gnus-article-hide-text-type (b e type)
555 "Hide text of TYPE between B and E."
556 (gnus-article-hide-text
557 b e (cons 'article-type (cons type gnus-hidden-properties))))
559 (defun gnus-article-unhide-text-type (b e type)
560 "Hide text of TYPE between B and E."
561 (remove-text-properties
562 b e (cons 'article-type (cons type gnus-hidden-properties)))
563 (when (memq 'intangible gnus-hidden-properties)
564 (put-text-property (max (1- b) (point-min))
567 (defun gnus-article-hide-text-of-type (type)
568 "Hide text of TYPE in the current buffer."
570 (let ((b (point-min))
572 (while (setq b (text-property-any b e 'article-type type))
573 (add-text-properties b (incf b) gnus-hidden-properties)))))
575 (defun gnus-article-delete-text-of-type (type)
576 "Delete text of TYPE in the current buffer."
578 (let ((e (point-min))
580 (while (setq b (text-property-any e (point-max) 'article-type type))
581 (setq e (text-property-not-all b (point-max) 'article-type type))
582 (delete-region b e)))))
584 (defun gnus-article-delete-invisible-text ()
585 "Delete all invisible text in the current buffer."
587 (let ((e (point-min))
589 (while (setq b (text-property-any e (point-max) 'invisible t))
590 (setq e (text-property-not-all b (point-max) 'invisible t))
591 (delete-region b e)))))
593 (defun gnus-article-text-type-exists-p (type)
594 "Say whether any text of type TYPE exists in the buffer."
595 (text-property-any (point-min) (point-max) 'article-type type))
597 (defsubst gnus-article-header-rank ()
598 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
599 (let ((list gnus-sorted-header-list)
602 (when (looking-at (car list))
604 (setq list (cdr list))
608 (defun article-hide-headers (&optional arg delete)
609 "Toggle whether to hide unwanted headers and possibly sort them as well.
610 If given a negative prefix, always show; if given a positive prefix,
612 (interactive (gnus-article-hidden-arg))
613 (if (gnus-article-check-hidden-text 'headers arg)
614 ;; Show boring headers as well.
615 (gnus-article-show-hidden-text 'boring-headers)
616 ;; This function might be inhibited.
617 (unless gnus-inhibit-hiding
620 (let ((buffer-read-only nil)
621 (props (nconc (list 'article-type 'headers)
622 gnus-hidden-properties))
623 (max (1+ (length gnus-sorted-header-list)))
624 (ignored (when (not gnus-visible-headers)
625 (cond ((stringp gnus-ignored-headers)
626 gnus-ignored-headers)
627 ((listp gnus-ignored-headers)
628 (mapconcat 'identity gnus-ignored-headers
631 (cond ((stringp gnus-visible-headers)
632 gnus-visible-headers)
633 ((and gnus-visible-headers
634 (listp gnus-visible-headers))
635 (mapconcat 'identity gnus-visible-headers "\\|"))))
636 (inhibit-point-motion-hooks t)
638 ;; First we narrow to just the headers.
640 (goto-char (point-min))
641 ;; Hide any "From " lines at the beginning of (mail) articles.
642 (while (looking-at "From ")
646 (delete-region (point-min) (point))
647 (gnus-article-hide-text (point-min) (point) props)))
648 ;; Then treat the rest of the header lines.
651 (if (search-forward "\n\n" nil t) ; if there's a body
652 (progn (forward-line -1) (point))
654 ;; Then we use the two regular expressions
655 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
656 ;; select which header lines is to remain visible in the
658 (goto-char (point-min))
659 (while (re-search-forward "^[^ \t]*:" nil t)
661 ;; Mark the rank of the header.
663 (point) (1+ (point)) 'message-rank
664 (if (or (and visible (looking-at visible))
666 (not (looking-at ignored))))
667 (gnus-article-header-rank)
670 (message-sort-headers-1)
671 (when (setq beg (text-property-any
672 (point-min) (point-max) 'message-rank (+ 2 max)))
673 ;; We make the unwanted headers invisible.
675 (delete-region beg (point-max))
676 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
677 (gnus-article-hide-text-type beg (point-max) 'headers))
678 ;; Work around XEmacs lossage.
679 (put-text-property (point-min) beg 'invisible nil))))))))
681 (defun article-hide-boring-headers (&optional arg)
682 "Toggle hiding of headers that aren't very interesting.
683 If given a negative prefix, always show; if given a positive prefix,
685 (interactive (gnus-article-hidden-arg))
686 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
687 (not gnus-show-all-headers))
690 (let ((buffer-read-only nil)
691 (list gnus-boring-article-headers)
692 (inhibit-point-motion-hooks t)
694 (nnheader-narrow-to-headers)
696 (setq elem (pop list))
697 (goto-char (point-min))
699 ;; Hide empty headers.
701 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
703 (gnus-article-hide-text-type
704 (progn (beginning-of-line) (point))
707 (if (re-search-forward "^[^ \t]" nil t)
711 ;; Hide boring Newsgroups header.
712 ((eq elem 'newsgroups)
713 (when (equal (gnus-fetch-field "newsgroups")
714 (gnus-group-real-name
715 (if (boundp 'gnus-newsgroup-name)
718 (gnus-article-hide-header "newsgroups")))
719 ((eq elem 'followup-to)
720 (when (equal (message-fetch-field "followup-to")
721 (message-fetch-field "newsgroups"))
722 (gnus-article-hide-header "followup-to")))
724 (let ((from (message-fetch-field "from"))
725 (reply-to (message-fetch-field "reply-to")))
730 (nth 1 (mail-extract-address-components from))
731 (nth 1 (mail-extract-address-components reply-to)))))
732 (gnus-article-hide-header "reply-to"))))
734 (let ((date (message-fetch-field "date")))
736 (< (gnus-days-between (current-time-string) date)
738 (gnus-article-hide-header "date")))))))))))
740 (defun gnus-article-hide-header (header)
742 (goto-char (point-min))
743 (when (re-search-forward (concat "^" header ":") nil t)
744 (gnus-article-hide-text-type
745 (progn (beginning-of-line) (point))
748 (if (re-search-forward "^[^ \t]" nil t)
753 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
754 (defun article-treat-overstrike ()
755 "Translate overstrikes into bold text."
758 (goto-char (point-min))
759 (when (search-forward "\n\n" nil t)
760 (let ((buffer-read-only nil))
761 (while (search-forward "\b" nil t)
762 (let ((next (following-char))
763 (previous (char-after (- (point) 2))))
764 ;; We do the boldification/underlining by hiding the
765 ;; overstrikes and putting the proper text property
769 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
770 (put-text-property (point) (1+ (point)) 'face 'bold))
772 (gnus-article-hide-text-type
773 (1- (point)) (1+ (point)) 'overstrike)
775 (- (point) 2) (1- (point)) 'face 'underline))
777 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
779 (point) (1+ (point)) 'face 'underline)))))))))
781 (defun article-fill ()
782 "Format too long lines."
785 (let ((buffer-read-only nil))
787 (goto-char (point-min))
788 (search-forward "\n\n" nil t)
790 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
791 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
792 (adaptive-fill-mode t))
794 (and (>= (current-column) (min fill-column (window-width)))
795 (/= (preceding-char) ?:)
796 (fill-paragraph nil))
799 (defun article-remove-cr ()
800 "Remove carriage returns from an article."
803 (let ((buffer-read-only nil))
804 (goto-char (point-min))
805 (while (search-forward "\r" nil t)
806 (replace-match "" t t)))))
808 (defun article-remove-trailing-blank-lines ()
809 "Remove all trailing blank lines from the article."
812 (let ((buffer-read-only nil))
813 (goto-char (point-max))
817 (while (and (not (bobp))
818 (looking-at "^[ \t]*$"))
823 (defun article-display-x-face (&optional force)
824 "Look for an X-Face header and display it if present."
825 (interactive (list 'force))
827 ;; Delete the old process, if any.
828 (when (process-status "article-x-face")
829 (delete-process "article-x-face"))
830 (let ((inhibit-point-motion-hooks t)
831 (case-fold-search nil)
834 (nnheader-narrow-to-headers)
835 (setq from (message-fetch-field "from"))
836 (goto-char (point-min))
837 (while (and gnus-article-x-face-command
839 ;; Check whether this face is censored.
840 (not gnus-article-x-face-too-ugly)
841 (and gnus-article-x-face-too-ugly from
842 (not (string-match gnus-article-x-face-too-ugly
844 ;; Has to be present.
845 (re-search-forward "^X-Face: " nil t))
846 ;; We now have the area of the buffer where the X-Face is stored.
848 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
850 ;; We display the face.
851 (if (symbolp gnus-article-x-face-command)
852 ;; The command is a lisp function, so we call it.
853 (if (gnus-functionp gnus-article-x-face-command)
854 (funcall gnus-article-x-face-command beg end)
855 (error "%s is not a function" gnus-article-x-face-command))
856 ;; The command is a string, so we interpret the command
857 ;; as a, well, command, and fork it off.
858 (let ((process-connection-type nil))
859 (process-kill-without-query
861 "article-x-face" nil shell-file-name shell-command-switch
862 gnus-article-x-face-command))
863 (process-send-region "article-x-face" beg end)
864 (process-send-eof "article-x-face"))))))))))
866 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
867 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
868 (defun article-decode-rfc1522 ()
869 "Hack to remove QP encoding from headers."
870 (let ((case-fold-search t)
871 (inhibit-point-motion-hooks t)
872 (buffer-read-only nil)
876 (goto-char (point-min))
877 (or (search-forward "\n\n" nil t) (point-max)))
878 (goto-char (point-min))
879 (while (re-search-forward
880 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
881 (setq string (match-string 1))
883 (narrow-to-region (match-beginning 0) (match-end 0))
884 (delete-region (point-min) (point-max))
886 (article-mime-decode-quoted-printable
887 (goto-char (point-min)) (point-max))
888 (subst-char-in-region (point-min) (point-max) ?_ ? )
889 (goto-char (point-max)))
890 (goto-char (point-min))))))
892 (defun article-de-quoted-unreadable (&optional force)
893 "Do a naive translation of a quoted-printable-encoded article.
894 This is in no way, shape or form meant as a replacement for real MIME
895 processing, but is simply a stop-gap measure until MIME support is
897 If FORCE, decode the article whether it is marked as quoted-printable
899 (interactive (list 'force))
901 (let ((case-fold-search t)
902 (buffer-read-only nil)
903 (type (gnus-fetch-field "content-transfer-encoding")))
904 (gnus-article-decode-rfc1522)
906 (and type (string-match "quoted-printable" (downcase type))))
907 (goto-char (point-min))
908 (search-forward "\n\n" nil 'move)
909 (article-mime-decode-quoted-printable (point) (point-max))))))
911 (defun article-mime-decode-quoted-printable-buffer ()
912 "Decode Quoted-Printable in the current buffer."
913 (article-mime-decode-quoted-printable (point-min) (point-max)))
915 (defun article-mime-decode-quoted-printable (from to)
916 "Decode Quoted-Printable in the region between FROM and TO."
919 (while (search-forward "=" to t)
920 (cond ((eq (following-char) ?\n)
923 ((looking-at "[0-9A-F][0-9A-F]")
924 (subst-char-in-region
925 (1- (point)) (point) ?=
926 (hexl-hex-string-to-integer
927 (buffer-substring (point) (+ 2 (point)))))
931 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
933 (defun article-hide-pgp (&optional arg)
934 "Toggle hiding of any PGP headers and signatures in the current article.
935 If given a negative prefix, always show; if given a positive prefix,
937 (interactive (gnus-article-hidden-arg))
938 (unless (gnus-article-check-hidden-text 'pgp arg)
940 (let ((inhibit-point-motion-hooks t)
941 buffer-read-only beg end)
943 (goto-char (point-min))
944 ;; Hide the "header".
945 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
946 (gnus-article-hide-text-type (1+ (match-beginning 0))
949 ;; Hide the actual signature.
950 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
951 (setq end (1+ (match-beginning 0)))
952 (gnus-article-hide-text-type
954 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
956 ;; Perhaps we shouldn't hide to the end of the buffer
957 ;; if there is no end to the signature?
960 ;; Hide "- " PGP quotation markers.
962 (narrow-to-region beg end)
963 (goto-char (point-min))
964 (while (re-search-forward "^- " nil t)
965 (gnus-article-hide-text-type
966 (match-beginning 0) (match-end 0) 'pgp))
969 (defun article-hide-pem (&optional arg)
970 "Toggle hiding of any PEM headers and signatures in the current article.
971 If given a negative prefix, always show; if given a positive prefix,
973 (interactive (gnus-article-hidden-arg))
974 (unless (gnus-article-check-hidden-text 'pem arg)
976 (let (buffer-read-only end)
978 (goto-char (point-min))
979 ;; hide the horrendously ugly "header".
980 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
983 (setq end (1+ (match-beginning 0)))
984 (gnus-article-hide-text-type
986 (if (search-forward "\n\n" nil t)
990 ;; hide the trailer as well
991 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
994 (gnus-article-hide-text-type
995 (match-beginning 0) (match-end 0) 'pem))))))
997 (defun article-hide-signature (&optional arg)
998 "Hide the signature in the current article.
999 If given a negative prefix, always show; if given a positive prefix,
1001 (interactive (gnus-article-hidden-arg))
1002 (unless (gnus-article-check-hidden-text 'signature arg)
1005 (let ((buffer-read-only nil))
1006 (when (gnus-article-narrow-to-signature)
1007 (gnus-article-hide-text-type
1008 (point-min) (point-max) 'signature)))))))
1010 (defun article-strip-leading-blank-lines ()
1011 "Remove all blank lines from the beginning of the article."
1014 (let ((inhibit-point-motion-hooks t)
1016 (goto-char (point-min))
1017 (when (search-forward "\n\n" nil t)
1018 (while (and (not (eobp))
1019 (looking-at "[ \t]*$"))
1020 (gnus-delete-line))))))
1022 (defun article-strip-multiple-blank-lines ()
1023 "Replace consecutive blank lines with one empty line."
1026 (let ((inhibit-point-motion-hooks t)
1028 ;; First make all blank lines empty.
1029 (goto-char (point-min))
1030 (search-forward "\n\n" nil t)
1031 (while (re-search-forward "^[ \t]+$" nil t)
1032 (replace-match "" nil t))
1033 ;; Then replace multiple empty lines with a single empty line.
1034 (goto-char (point-min))
1035 (search-forward "\n\n" nil t)
1036 (while (re-search-forward "\n\n\n+" nil t)
1037 (replace-match "\n\n" t t)))))
1039 (defun article-strip-leading-space ()
1040 "Remove all white space from the beginning of the lines in the article."
1043 (let ((inhibit-point-motion-hooks t)
1045 (goto-char (point-min))
1046 (search-forward "\n\n" nil t)
1047 (while (re-search-forward "^[ \t]+" nil t)
1048 (replace-match "" t t)))))
1050 (defun article-strip-blank-lines ()
1051 "Strip leading, trailing and multiple blank lines."
1053 (article-strip-leading-blank-lines)
1054 (article-remove-trailing-blank-lines)
1055 (article-strip-multiple-blank-lines))
1057 (defvar mime::preview/content-list)
1058 (defvar mime::preview-content-info/point-min)
1059 (defun gnus-article-narrow-to-signature ()
1060 "Narrow to the signature; return t if a signature is found, else nil."
1062 (when (and (boundp 'mime::preview/content-list)
1063 mime::preview/content-list)
1064 ;; We have a MIMEish article, so we use the MIME data to narrow.
1065 (let ((pcinfo (car (last mime::preview/content-list))))
1068 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1071 (when (gnus-article-search-signature)
1073 ;; Check whether we have some limits to what we consider
1074 ;; to be a signature.
1075 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1076 (list gnus-signature-limit)))
1078 (while (setq limit (pop limits))
1079 (if (or (and (integerp limit)
1080 (< (- (point-max) (point)) limit))
1082 (< (count-lines (point) (point-max)) limit))
1083 (and (gnus-functionp limit)
1085 (and (stringp limit)
1086 (not (re-search-forward limit nil t))))
1087 () ; This limit did not succeed.
1091 (narrow-to-region (point) (point-max))
1094 (defun gnus-article-search-signature ()
1095 "Search the current buffer for the signature separator.
1096 Put point at the beginning of the signature separator."
1097 (let ((cur (point)))
1098 (goto-char (point-max))
1099 (if (if (stringp gnus-signature-separator)
1100 (re-search-backward gnus-signature-separator nil t)
1101 (let ((seps gnus-signature-separator))
1103 (not (re-search-backward (car seps) nil t)))
1111 (autoload 'w3-parse-buffer "w3-parse"))
1113 (defun gnus-article-treat-html ()
1116 (let ((cbuf (current-buffer)))
1117 (set-buffer gnus-article-buffer)
1118 (let (buf buffer-read-only b e)
1119 (goto-char (point-min))
1121 (if (search-forward "\n\n" nil t)
1124 (setq e (point-max)))
1125 (nnheader-temp-write nil
1126 (insert-buffer-substring gnus-article-buffer b e)
1128 (save-window-excursion
1129 (w3-parse-buffer (current-buffer))
1130 (setq buf (buffer-string))))
1132 (delete-region (point-min) (point-max))
1133 (insert-buffer-substring buf)
1136 (goto-char (point-min))
1137 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1138 (set-buffer cbuf))))
1140 (defun gnus-article-hidden-arg ()
1141 "Return the current prefix arg as a number, or 0 if no prefix."
1142 (list (if current-prefix-arg
1143 (prefix-numeric-value current-prefix-arg)
1146 (defun gnus-article-check-hidden-text (type arg)
1147 "Return nil if hiding is necessary.
1148 Arg can be nil or a number. Nil and positive means hide, negative
1149 means show, 0 means toggle."
1153 (let ((hide (gnus-article-hidden-text-p type)))
1159 (gnus-article-show-hidden-text type))
1161 (if (eq hide 'hidden)
1162 (gnus-article-show-hidden-text type)
1165 (defun gnus-article-hidden-text-p (type)
1166 "Say whether the current buffer contains hidden text of type TYPE."
1167 (let ((start (point-min))
1168 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1170 (not (get-text-property pos 'invisible)))
1172 (text-property-any (1+ pos) (point-max) 'article-type type)))
1177 (defun gnus-article-show-hidden-text (type &optional hide)
1178 "Show all hidden text of type TYPE.
1179 If HIDE, hide the text instead."
1181 (let ((buffer-read-only nil)
1182 (inhibit-point-motion-hooks t)
1185 (while (setq beg (text-property-any end (point-max) 'article-type type))
1188 (text-property-not-all beg (point-max) 'article-type type)
1191 (gnus-article-hide-text beg end gnus-hidden-properties)
1192 (gnus-article-unhide-text beg end))
1196 (defconst article-time-units
1197 `((year . ,(* 365.25 24 60 60))
1198 (week . ,(* 7 24 60 60))
1199 (day . ,(* 24 60 60))
1203 "Mapping from time units to seconds.")
1205 (defun article-date-ut (&optional type highlight header)
1206 "Convert DATE date to universal time in the current article.
1207 If TYPE is `local', convert to local time; if it is `lapsed', output
1208 how much time has lapsed since DATE."
1209 (interactive (list 'ut t))
1210 (let* ((header (or header
1211 (mail-header-date gnus-current-headers)
1212 (message-fetch-field "date")
1214 (date (if (vectorp header) (mail-header-date header)
1216 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1217 (inhibit-point-motion-hooks t)
1219 (when (and date (not (string= date "")))
1222 (nnheader-narrow-to-headers)
1223 (let ((buffer-read-only nil))
1224 ;; Delete any old Date headers.
1225 (if (re-search-forward date-regexp nil t)
1227 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1228 eface (get-text-property (1- (gnus-point-at-eol))
1230 (message-remove-header date-regexp t)
1231 (beginning-of-line))
1232 (goto-char (point-max)))
1233 (insert (article-make-date-line date type))
1236 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1237 (put-text-property (match-beginning 1) (match-end 1)
1239 (put-text-property (match-beginning 2) (match-end 2)
1242 (defun article-make-date-line (date type)
1243 "Return a DATE line of TYPE."
1245 ;; Convert to the local timezone. We have to slap a
1246 ;; `condition-case' round the calls to the timezone
1247 ;; functions since they aren't particularly resistant to
1250 (concat "Date: " (condition-case ()
1251 (timezone-make-date-arpa-standard date)
1254 ;; Convert to Universal Time.
1258 (timezone-make-date-arpa-standard date nil "UT")
1261 ;; Get the original date from the article.
1262 ((eq type 'original)
1263 (concat "Date: " date "\n"))
1264 ;; Let the user define the format.
1268 (format-time-string gnus-article-time-format
1271 (timezone-make-date-arpa-standard
1274 ;; Do an X-Sent lapsed format.
1276 ;; If the date is seriously mangled, the timezone functions are
1277 ;; liable to bug out, so we ignore all errors.
1278 (let* ((now (current-time))
1283 (timezone-make-date-arpa-standard
1284 (current-time-string now)
1285 (current-time-zone now) "UT"))
1287 (timezone-make-date-arpa-standard
1289 (real-sec (and real-time
1290 (+ (* (float (car real-time)) 65536)
1292 (sec (and real-time (abs real-sec)))
1296 "X-Sent: Unknown\n")
1302 ;; This is a bit convoluted, but basically we go
1303 ;; through the time units for years, weeks, etc,
1304 ;; and divide things to see whether that results
1305 ;; in positive answers.
1308 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1309 ;; The (remaining) seconds are too few to
1310 ;; be divided into this time unit.
1312 ;; It's big enough, so we output it.
1313 (setq sec (- sec (* num (cdr unit))))
1315 (concat (if prev ", " "") (int-to-string
1317 " " (symbol-name (car unit))
1318 (if (> num 1) "s" ""))
1320 article-time-units "")
1321 ;; If dates are odd, then it might appear like the
1322 ;; article was sent in the future.
1325 " in the future\n"))))))
1327 (error "Unknown conversion type: %s" type))))
1329 (defun article-date-local (&optional highlight)
1330 "Convert the current article date to the local timezone."
1331 (interactive (list t))
1332 (article-date-ut 'local highlight))
1334 (defun article-date-original (&optional highlight)
1335 "Convert the current article date to what it was originally.
1336 This is only useful if you have used some other date conversion
1337 function and want to see what the date was before converting."
1338 (interactive (list t))
1339 (article-date-ut 'original highlight))
1341 (defun article-date-lapsed (&optional highlight)
1342 "Convert the current article date to time lapsed since it was sent."
1343 (interactive (list t))
1344 (article-date-ut 'lapsed highlight))
1346 (defun article-date-user (&optional highlight)
1347 "Convert the current article date to the user-defined format.
1348 This format is defined by the `gnus-article-time-format' variable."
1349 (interactive (list t))
1350 (article-date-ut 'user highlight))
1352 (defun article-show-all ()
1353 "Show all hidden text in the article buffer."
1356 (let ((buffer-read-only nil))
1357 (gnus-article-unhide-text (point-min) (point-max)))))
1359 (defun article-emphasize (&optional arg)
1360 "Emphasize text according to `gnus-emphasis-alist'."
1361 (interactive (gnus-article-hidden-arg))
1362 (unless (gnus-article-check-hidden-text 'emphasis arg)
1364 (let ((alist gnus-emphasis-alist)
1365 (buffer-read-only nil)
1366 (props (append '(article-type emphasis)
1367 gnus-hidden-properties))
1368 regexp elem beg invisible visible face)
1369 (goto-char (point-min))
1370 (search-forward "\n\n" nil t)
1372 (while (setq elem (pop alist))
1374 (setq regexp (car elem)
1375 invisible (nth 1 elem)
1376 visible (nth 2 elem)
1378 (while (re-search-forward regexp nil t)
1379 (when (and (match-beginning visible) (match-beginning invisible))
1380 (gnus-article-hide-text
1381 (match-beginning invisible) (match-end invisible) props)
1382 (gnus-article-unhide-text-type
1383 (match-beginning visible) (match-end visible) 'emphasis)
1384 (gnus-put-text-property-excluding-newlines
1385 (match-beginning visible) (match-end visible) 'face face)
1386 (goto-char (match-end invisible)))))))))
1388 (defvar gnus-summary-article-menu)
1389 (defvar gnus-summary-post-menu)
1391 ;;; Saving functions.
1393 (defun gnus-article-save (save-buffer file &optional num)
1394 "Save the currently selected article."
1395 (unless gnus-save-all-headers
1396 ;; Remove headers according to `gnus-saved-headers'.
1397 (let ((gnus-visible-headers
1398 (or gnus-saved-headers gnus-visible-headers))
1399 (gnus-article-buffer save-buffer))
1400 (gnus-article-hide-headers 1 t)))
1401 (save-window-excursion
1402 (if (not gnus-default-article-saver)
1403 (error "No default saver is defined.")
1404 ;; !!! Magic! The saving functions all save
1405 ;; `gnus-original-article-buffer' (or so they think), but we
1406 ;; bind that variable to our save-buffer.
1407 (set-buffer gnus-article-buffer)
1408 (let* ((gnus-save-article-buffer save-buffer)
1411 ((not gnus-prompt-before-saving) 'default)
1412 ((eq gnus-prompt-before-saving 'always) nil)
1414 (gnus-number-of-articles-to-be-saved
1415 (when (eq gnus-prompt-before-saving t)
1417 (set-buffer gnus-summary-buffer)
1418 (funcall gnus-default-article-saver filename)))))
1420 (defun gnus-read-save-file-name (prompt &optional filename
1421 function group headers variable)
1423 (funcall function group headers (symbol-value variable)))
1428 ((eq filename 'default)
1434 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1437 (if (and gnus-number-of-articles-to-be-saved
1438 (> gnus-number-of-articles-to-be-saved 1))
1439 (format "these %d articles"
1440 gnus-number-of-articles-to-be-saved)
1443 ;; Let the split methods have their say.
1445 ;; No split name was found.
1448 (concat prompt " (default "
1449 (file-name-nondirectory default-name) ") ")
1450 (file-name-directory default-name)
1452 ;; A single group name is returned.
1453 ((stringp split-name)
1455 (funcall function split-name headers
1456 (symbol-value variable)))
1458 (concat prompt " (default "
1459 (file-name-nondirectory default-name) ") ")
1460 (file-name-directory default-name)
1462 ;; A single split name was found
1463 ((= 1 (length split-name))
1464 (let* ((name (expand-file-name
1465 (car split-name) gnus-article-save-directory))
1466 (dir (cond ((file-directory-p name)
1467 (file-name-as-directory name))
1468 ((file-exists-p name) name)
1469 (t gnus-article-save-directory))))
1471 (concat prompt " (default " name ") ")
1473 ;; A list of splits was found.
1475 (setq split-name (nreverse split-name))
1477 (let ((file-name-history
1478 (nconc split-name file-name-history)))
1482 (concat prompt " (`M-p' for defaults) ")
1483 gnus-article-save-directory
1485 gnus-article-save-directory)))
1486 (car (push result file-name-history)))))))
1487 ;; Create the directory.
1488 (gnus-make-directory (file-name-directory file))
1489 ;; If we have read a directory, we append the default file name.
1490 (when (file-directory-p file)
1491 (setq file (concat (file-name-as-directory file)
1492 (file-name-nondirectory default-name))))
1493 ;; Possibly translate some characters.
1494 (nnheader-translate-file-chars file)))))
1495 (gnus-make-directory (file-name-directory result))
1496 (set variable result)))
1498 (defun gnus-article-archive-name (group)
1499 "Return the first instance of an \"Archive-name\" in the current buffer."
1500 (let ((case-fold-search t))
1501 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1502 (nnheader-concat gnus-article-save-directory
1503 (match-string 1)))))
1505 (defun gnus-article-nndoc-name (group)
1506 "If GROUP is an nndoc group, return the name of the parent group."
1507 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1508 (gnus-group-get-parameter group 'save-article-group)))
1510 (defun gnus-summary-save-in-rmail (&optional filename)
1511 "Append this article to Rmail file.
1512 Optional argument FILENAME specifies file name.
1513 Directory to save to is default to `gnus-article-save-directory'."
1515 (gnus-set-global-variables)
1516 (setq filename (gnus-read-save-file-name
1517 "Save %s in rmail file:" filename
1518 gnus-rmail-save-name gnus-newsgroup-name
1519 gnus-current-headers 'gnus-newsgroup-last-rmail))
1520 (gnus-eval-in-buffer-window gnus-save-article-buffer
1524 (gnus-output-to-rmail filename)))))
1526 (defun gnus-summary-save-in-mail (&optional filename)
1527 "Append this article to Unix mail file.
1528 Optional argument FILENAME specifies file name.
1529 Directory to save to is default to `gnus-article-save-directory'."
1531 (gnus-set-global-variables)
1532 (setq filename (gnus-read-save-file-name
1533 "Save %s in Unix mail file:" filename
1534 gnus-mail-save-name gnus-newsgroup-name
1535 gnus-current-headers 'gnus-newsgroup-last-mail))
1536 (gnus-eval-in-buffer-window gnus-save-article-buffer
1540 (if (and (file-readable-p filename)
1541 (mail-file-babyl-p filename))
1542 (gnus-output-to-rmail filename t)
1543 (gnus-output-to-mail filename))))))
1545 (defun gnus-summary-save-in-file (&optional filename overwrite)
1546 "Append this article to file.
1547 Optional argument FILENAME specifies file name.
1548 Directory to save to is default to `gnus-article-save-directory'."
1550 (gnus-set-global-variables)
1551 (setq filename (gnus-read-save-file-name
1552 "Save %s in file:" filename
1553 gnus-file-save-name gnus-newsgroup-name
1554 gnus-current-headers 'gnus-newsgroup-last-file))
1555 (gnus-eval-in-buffer-window gnus-save-article-buffer
1559 (when (and overwrite
1560 (file-exists-p filename))
1561 (delete-file filename))
1562 (gnus-output-to-file filename)))))
1564 (defun gnus-summary-write-to-file (&optional filename)
1565 "Write this article to a file.
1566 Optional argument FILENAME specifies file name.
1567 The directory to save in defaults to `gnus-article-save-directory'."
1569 (gnus-summary-save-in-file nil t))
1571 (defun gnus-summary-save-body-in-file (&optional filename)
1572 "Append this article body to a file.
1573 Optional argument FILENAME specifies file name.
1574 The directory to save in defaults to `gnus-article-save-directory'."
1576 (gnus-set-global-variables)
1577 (setq filename (gnus-read-save-file-name
1578 "Save %s body in file:" filename
1579 gnus-file-save-name gnus-newsgroup-name
1580 gnus-current-headers 'gnus-newsgroup-last-file))
1581 (gnus-eval-in-buffer-window gnus-save-article-buffer
1585 (goto-char (point-min))
1586 (when (search-forward "\n\n" nil t)
1587 (narrow-to-region (point) (point-max)))
1588 (gnus-output-to-file filename)))))
1590 (defun gnus-summary-save-in-pipe (&optional command)
1591 "Pipe this article to subprocess."
1593 (gnus-set-global-variables)
1595 (cond ((eq command 'default)
1596 gnus-last-shell-command)
1600 "Shell command on %s: "
1601 (if (and gnus-number-of-articles-to-be-saved
1602 (> gnus-number-of-articles-to-be-saved 1))
1603 (format "these %d articles"
1604 gnus-number-of-articles-to-be-saved)
1606 gnus-last-shell-command))))
1607 (when (string-equal command "")
1608 (setq command gnus-last-shell-command))
1609 (gnus-eval-in-buffer-window gnus-article-buffer
1612 (shell-command-on-region (point-min) (point-max) command nil)))
1613 (setq gnus-last-shell-command command))
1615 ;;; Article file names when saving.
1617 (defun gnus-capitalize-newsgroup (newsgroup)
1618 "Capitalize NEWSGROUP name."
1619 (when (not (zerop (length newsgroup)))
1620 (concat (char-to-string (upcase (aref newsgroup 0)))
1621 (substring newsgroup 1))))
1623 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1624 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1625 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1626 Otherwise, it is like ~/News/news/group/num."
1629 (concat (if (gnus-use-long-file-name 'not-save)
1630 (gnus-capitalize-newsgroup newsgroup)
1631 (gnus-newsgroup-directory-form newsgroup))
1632 "/" (int-to-string (mail-header-number headers)))
1633 gnus-article-save-directory)))
1635 (string-equal (file-name-directory default)
1636 (file-name-directory last-file))
1637 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1639 (or last-file default))))
1641 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1642 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1643 If variable `gnus-use-long-file-name' is non-nil, it is
1644 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1647 (concat (if (gnus-use-long-file-name 'not-save)
1649 (gnus-newsgroup-directory-form newsgroup))
1650 "/" (int-to-string (mail-header-number headers)))
1651 gnus-article-save-directory)))
1653 (string-equal (file-name-directory default)
1654 (file-name-directory last-file))
1655 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1657 (or last-file default))))
1659 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1660 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1661 If variable `gnus-use-long-file-name' is non-nil, it is
1662 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1665 (if (gnus-use-long-file-name 'not-save)
1666 (gnus-capitalize-newsgroup newsgroup)
1667 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1668 gnus-article-save-directory)))
1670 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1671 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1672 If variable `gnus-use-long-file-name' is non-nil, it is
1673 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1676 (if (gnus-use-long-file-name 'not-save)
1678 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1679 gnus-article-save-directory)))
1686 (setq afunc (car func)
1689 gfunc (intern (format "gnus-%s" func))))
1691 (if (not (fboundp afunc))
1693 `(lambda (&optional interactive &rest args)
1694 ,(documentation afunc t)
1695 (interactive (list t))
1697 (set-buffer gnus-article-buffer)
1699 (call-interactively ',afunc)
1700 (apply ',afunc args))))))))
1701 '(article-hide-headers
1702 article-hide-boring-headers
1703 article-treat-overstrike
1704 (article-fill . gnus-article-word-wrap)
1706 article-display-x-face
1707 article-de-quoted-unreadable
1708 article-mime-decode-quoted-printable
1711 article-hide-signature
1712 article-remove-trailing-blank-lines
1713 article-strip-leading-blank-lines
1714 article-strip-multiple-blank-lines
1715 article-strip-leading-space
1716 article-strip-blank-lines
1718 article-date-original
1723 (article-show-all . gnus-article-show-all-headers))))
1726 ;;; Gnus article mode
1729 (put 'gnus-article-mode 'mode-class 'special)
1732 (gnus-define-keys gnus-article-mode-map
1733 " " gnus-article-goto-next-page
1734 "\177" gnus-article-goto-prev-page
1735 [delete] gnus-article-goto-prev-page
1736 "\C-c^" gnus-article-refer-article
1737 "h" gnus-article-show-summary
1738 "s" gnus-article-show-summary
1739 "\C-c\C-m" gnus-article-mail
1740 "?" gnus-article-describe-briefly
1741 gnus-mouse-2 gnus-article-push-button
1742 "\r" gnus-article-press-button
1743 "\t" gnus-article-next-button
1744 "\M-\t" gnus-article-prev-button
1745 "e" gnus-article-edit
1746 "<" beginning-of-buffer
1748 "\C-c\C-i" gnus-info-find-node
1751 "\C-d" gnus-article-read-summary-keys
1752 "\M-*" gnus-article-read-summary-keys
1753 "\M-#" gnus-article-read-summary-keys
1754 "\M-^" gnus-article-read-summary-keys
1755 "\M-g" gnus-article-read-summary-keys)
1757 (substitute-key-definition
1758 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1760 (defun gnus-article-make-menu-bar ()
1761 (gnus-turn-off-edit-menu 'article)
1762 (unless (boundp 'gnus-article-article-menu)
1764 gnus-article-article-menu gnus-article-mode-map ""
1766 ["Scroll forwards" gnus-article-goto-next-page t]
1767 ["Scroll backwards" gnus-article-goto-prev-page t]
1768 ["Show summary" gnus-article-show-summary t]
1769 ["Fetch Message-ID at point" gnus-article-refer-article t]
1770 ["Mail to address at point" gnus-article-mail t]))
1773 gnus-article-treatment-menu gnus-article-mode-map ""
1775 ["Hide headers" gnus-article-hide-headers t]
1776 ["Hide signature" gnus-article-hide-signature t]
1777 ["Hide citation" gnus-article-hide-citation t]
1778 ["Treat overstrike" gnus-article-treat-overstrike t]
1779 ["Remove carriage return" gnus-article-remove-cr t]
1780 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1783 (when (boundp 'gnus-summary-article-menu)
1784 (define-key gnus-article-mode-map [menu-bar commands]
1785 (cons "Commands" gnus-summary-article-menu))))
1787 (when (boundp 'gnus-summary-post-menu)
1788 (define-key gnus-article-mode-map [menu-bar post]
1789 (cons "Post" gnus-summary-post-menu)))
1791 (run-hooks 'gnus-article-menu-hook)))
1793 (defun gnus-article-mode ()
1794 "Major mode for displaying an article.
1796 All normal editing commands are switched off.
1798 The following commands are available in addition to all summary mode
1800 \\<gnus-article-mode-map>
1801 \\[gnus-article-next-page]\t Scroll the article one page forwards
1802 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1803 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1804 \\[gnus-article-show-summary]\t Display the summary buffer
1805 \\[gnus-article-mail]\t Send a reply to the address near point
1806 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1807 \\[gnus-info-find-node]\t Go to the Gnus info node"
1809 (when (gnus-visual-p 'article-menu 'menu)
1810 (gnus-article-make-menu-bar))
1811 (kill-all-local-variables)
1812 (gnus-simplify-mode-line)
1813 (setq mode-name "Article")
1814 (setq major-mode 'gnus-article-mode)
1815 (make-local-variable 'minor-mode-alist)
1816 (unless (assq 'gnus-show-mime minor-mode-alist)
1817 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1818 (use-local-map gnus-article-mode-map)
1819 (gnus-update-format-specifications nil 'article-mode)
1820 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1821 (set (make-local-variable 'gnus-page-broken) nil)
1822 (set (make-local-variable 'gnus-button-marker-list) nil)
1823 (gnus-set-default-directory)
1824 (buffer-disable-undo (current-buffer))
1825 (setq buffer-read-only t)
1826 (set-syntax-table gnus-article-mode-syntax-table)
1827 (run-hooks 'gnus-article-mode-hook))
1829 (defun gnus-article-setup-buffer ()
1830 "Initialize the article buffer."
1831 (let* ((name (if gnus-single-article-buffer "*Article*"
1832 (concat "*Article " gnus-newsgroup-name "*")))
1834 (progn (string-match "\\*Article" name)
1835 (concat " *Original Article"
1836 (substring name (match-end 0))))))
1837 (setq gnus-article-buffer name)
1838 (setq gnus-original-article-buffer original)
1839 ;; This might be a variable local to the summary buffer.
1840 (unless gnus-single-article-buffer
1842 (set-buffer gnus-summary-buffer)
1843 (setq gnus-article-buffer name)
1844 (setq gnus-original-article-buffer original)
1845 (gnus-set-global-variables)))
1846 ;; Init original article buffer.
1848 (set-buffer (get-buffer-create gnus-original-article-buffer))
1849 (buffer-disable-undo (current-buffer))
1850 (setq major-mode 'gnus-original-article-mode)
1851 (gnus-add-current-to-buffer-list)
1852 (make-local-variable 'gnus-original-article))
1853 (if (get-buffer name)
1856 (buffer-disable-undo (current-buffer))
1857 (setq buffer-read-only t)
1858 (gnus-add-current-to-buffer-list)
1859 (unless (eq major-mode 'gnus-article-mode)
1860 (gnus-article-mode))
1863 (set-buffer (get-buffer-create name))
1864 (gnus-add-current-to-buffer-list)
1866 (make-local-variable 'gnus-summary-buffer)
1867 (current-buffer)))))
1869 ;; Set article window start at LINE, where LINE is the number of lines
1870 ;; from the head of the article.
1871 (defun gnus-article-set-window-start (&optional line)
1873 (get-buffer-window gnus-article-buffer t)
1875 (set-buffer gnus-article-buffer)
1876 (goto-char (point-min))
1879 (gnus-message 6 "Moved to bookmark")
1880 (search-forward "\n\n" nil t)
1884 (defun gnus-article-prepare (article &optional all-headers header)
1885 "Prepare ARTICLE in article mode buffer.
1886 ARTICLE should either be an article number or a Message-ID.
1887 If ARTICLE is an id, HEADER should be the article headers.
1888 If ALL-HEADERS is non-nil, no headers are hidden."
1890 ;; Make sure we start in a summary buffer.
1891 (unless (eq major-mode 'gnus-summary-mode)
1892 (set-buffer gnus-summary-buffer))
1893 (setq gnus-summary-buffer (current-buffer))
1894 ;; Make sure the connection to the server is alive.
1895 (unless (gnus-server-opened
1896 (gnus-find-method-for-group gnus-newsgroup-name))
1897 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1898 (gnus-request-group gnus-newsgroup-name t))
1899 (let* ((gnus-article (if header (mail-header-number header) article))
1900 (summary-buffer (current-buffer))
1901 (internal-hook gnus-article-internal-prepare-hook)
1902 (group gnus-newsgroup-name)
1905 (gnus-article-setup-buffer)
1906 (set-buffer gnus-article-buffer)
1907 ;; Deactivate active regions.
1908 (when (and (boundp 'transient-mark-mode)
1909 transient-mark-mode)
1910 (setq mark-active nil))
1911 (if (not (setq result (let ((buffer-read-only nil))
1912 (gnus-request-article-this-buffer
1914 ;; There is no such article.
1916 (when (and (numberp article)
1917 (not (memq article gnus-newsgroup-sparse)))
1918 (setq gnus-article-current
1919 (cons gnus-newsgroup-name article))
1920 (set-buffer gnus-summary-buffer)
1921 (setq gnus-current-article article)
1922 (gnus-summary-mark-article article gnus-canceled-mark))
1923 (unless (memq article gnus-newsgroup-sparse)
1925 1 "No such article (may have expired or been canceled)")))
1926 (if (or (eq result 'pseudo) (eq result 'nneething))
1929 (set-buffer summary-buffer)
1930 (setq gnus-last-article gnus-current-article
1931 gnus-newsgroup-history (cons gnus-current-article
1932 gnus-newsgroup-history)
1933 gnus-current-article 0
1934 gnus-current-headers nil
1935 gnus-article-current nil)
1936 (if (eq result 'nneething)
1937 (gnus-configure-windows 'summary)
1938 (gnus-configure-windows 'article))
1939 (gnus-set-global-variables))
1940 (gnus-set-mode-line 'article))
1941 ;; The result from the `request' was an actual article -
1942 ;; or at least some text that is now displayed in the
1944 (when (and (numberp article)
1945 (not (eq article gnus-current-article)))
1946 ;; Seems like a new article has been selected.
1947 ;; `gnus-current-article' must be an article number.
1949 (set-buffer summary-buffer)
1950 (setq gnus-last-article gnus-current-article
1951 gnus-newsgroup-history (cons gnus-current-article
1952 gnus-newsgroup-history)
1953 gnus-current-article article
1954 gnus-current-headers
1955 (gnus-summary-article-header gnus-current-article)
1956 gnus-article-current
1957 (cons gnus-newsgroup-name gnus-current-article))
1958 (unless (vectorp gnus-current-headers)
1959 (setq gnus-current-headers nil))
1960 (gnus-summary-show-thread)
1961 (run-hooks 'gnus-mark-article-hook)
1962 (gnus-set-mode-line 'summary)
1963 (when (gnus-visual-p 'article-highlight 'highlight)
1964 (run-hooks 'gnus-visual-mark-article-hook))
1965 ;; Set the global newsgroup variables here.
1966 ;; Suggested by Jim Sisolak
1967 ;; <sisolak@trans4.neep.wisc.edu>.
1968 (gnus-set-global-variables)
1969 (setq gnus-have-all-headers
1970 (or all-headers gnus-show-all-headers))
1972 (vectorp (gnus-summary-article-header article))
1973 (gnus-cache-possibly-enter-article
1975 (gnus-summary-article-header article)
1976 (memq article gnus-newsgroup-marked)
1977 (memq article gnus-newsgroup-dormant)
1978 (memq article gnus-newsgroup-unreads)))))
1979 (when (or (numberp article)
1981 ;; Hooks for getting information from the article.
1982 ;; This hook must be called before being narrowed.
1983 (let (buffer-read-only)
1984 (run-hooks 'internal-hook)
1985 (run-hooks 'gnus-article-prepare-hook)
1986 ;; Decode MIME message.
1987 (when gnus-show-mime
1988 (if (or (not gnus-strict-mime)
1989 (gnus-fetch-field "Mime-Version"))
1990 (funcall gnus-show-mime-method)
1991 (funcall gnus-decode-encoded-word-method)))
1992 ;; Perform the article display hooks.
1993 (run-hooks 'gnus-article-display-hook))
1995 (goto-char (point-min))
1996 (setq gnus-page-broken
1997 (when gnus-break-pages
1998 (gnus-narrow-to-page)
2000 (gnus-set-mode-line 'article)
2001 (gnus-configure-windows 'article)
2002 (goto-char (point-min))
2005 (defun gnus-article-wash-status ()
2006 "Return a string which display status of article washing."
2008 (set-buffer gnus-article-buffer)
2009 (let ((cite (gnus-article-hidden-text-p 'cite))
2010 (headers (gnus-article-hidden-text-p 'headers))
2011 (boring (gnus-article-hidden-text-p 'boring-headers))
2012 (pgp (gnus-article-hidden-text-p 'pgp))
2013 (pem (gnus-article-hidden-text-p 'pem))
2014 (signature (gnus-article-hidden-text-p 'signature))
2015 (overstrike (gnus-article-hidden-text-p 'overstrike))
2016 (emphasis (gnus-article-hidden-text-p 'emphasis))
2017 (mime gnus-show-mime))
2018 (format "%c%c%c%c%c%c%c"
2020 (if (or headers boring) ?h ? )
2021 (if (or pgp pem) ?p ? )
2022 (if signature ?s ? )
2023 (if overstrike ?o ? )
2025 (if emphasis ?e ? )))))
2027 (defun gnus-article-hide-headers-if-wanted ()
2028 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2029 Provided for backwards compatibility."
2030 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2032 (gnus-article-hide-headers)))
2036 (defun gnus-output-to-file (file-name)
2037 "Append the current article to a file named FILE-NAME."
2038 (let ((artbuf (current-buffer)))
2039 (nnheader-temp-write nil
2040 (insert-buffer-substring artbuf)
2041 ;; Append newline at end of the buffer as separator, and then
2043 (goto-char (point-max))
2045 (append-to-file (point-min) (point-max) file-name))))
2047 (defun gnus-narrow-to-page (&optional arg)
2048 "Narrow the article buffer to a page.
2049 If given a numerical ARG, move forward ARG pages."
2051 (setq arg (if arg (prefix-numeric-value arg) 0))
2053 (set-buffer gnus-article-buffer)
2054 (goto-char (point-min))
2056 ;; Remove any old next/prev buttons.
2057 (when (gnus-visual-p 'page-marker)
2058 (let ((buffer-read-only nil))
2059 (gnus-remove-text-with-property 'gnus-prev)
2060 (gnus-remove-text-with-property 'gnus-next)))
2063 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2065 (re-search-forward page-delimiter nil 'move arg)))
2066 (goto-char (match-end 0)))
2069 (if (re-search-forward page-delimiter nil 'move)
2072 (when (and (gnus-visual-p 'page-marker)
2073 (not (= (point-min) 1)))
2075 (goto-char (point-min))
2076 (gnus-insert-prev-page-button)))
2077 (when (and (gnus-visual-p 'page-marker)
2078 (< (+ (point-max) 2) (buffer-size)))
2080 (goto-char (point-max))
2081 (gnus-insert-next-page-button)))))
2083 ;; Article mode commands
2085 (defun gnus-article-goto-next-page ()
2086 "Show the next page of the article."
2088 (when (gnus-article-next-page)
2089 (goto-char (point-min))
2090 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2092 (defun gnus-article-goto-prev-page ()
2093 "Show the next page of the article."
2095 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2096 (gnus-article-prev-page nil)))
2098 (defun gnus-article-next-page (&optional lines)
2099 "Show the next page of the current article.
2100 If end of article, return non-nil. Otherwise return nil.
2101 Argument LINES specifies lines to be scrolled up."
2103 (move-to-window-line -1)
2106 (and (pos-visible-in-window-p) ;Not continuation line.
2108 ;; Nothing in this page.
2109 (if (or (not gnus-page-broken)
2112 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2114 (gnus-narrow-to-page 1) ;Go to next page.
2116 ;; More in this page.
2117 (let ((scroll-in-place nil))
2121 ;; Long lines may cause an end-of-buffer error.
2122 (goto-char (point-max)))))
2123 (move-to-window-line 0)
2126 (defun gnus-article-prev-page (&optional lines)
2127 "Show previous page of current article.
2128 Argument LINES specifies lines to be scrolled down."
2130 (move-to-window-line 0)
2131 (if (and gnus-page-broken
2133 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2135 (gnus-narrow-to-page -1) ;Go to previous page.
2136 (goto-char (point-max))
2138 (let ((scroll-in-place nil))
2142 (beginning-of-buffer
2143 (goto-char (point-min))))
2144 (move-to-window-line 0)))))
2146 (defun gnus-article-refer-article ()
2147 "Read article specified by message-id around point."
2149 (let ((point (point)))
2150 (search-forward ">" nil t) ;Move point to end of "<....>".
2151 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2152 (let ((message-id (match-string 1)))
2154 (set-buffer gnus-summary-buffer)
2155 (gnus-summary-refer-article message-id))
2157 (error "No references around point"))))
2159 (defun gnus-article-show-summary ()
2160 "Reconfigure windows to show summary buffer."
2162 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2163 (error "There is no summary buffer for this article buffer")
2164 (gnus-configure-windows 'article)
2165 (gnus-summary-goto-subject gnus-current-article)))
2167 (defun gnus-article-describe-briefly ()
2168 "Describe article mode commands briefly."
2171 (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")))
2173 (defun gnus-article-summary-command ()
2174 "Execute the last keystroke in the summary buffer."
2176 (let ((obuf (current-buffer))
2177 (owin (current-window-configuration))
2179 (switch-to-buffer gnus-summary-buffer 'norecord)
2180 (setq func (lookup-key (current-local-map) (this-command-keys)))
2181 (call-interactively func)
2183 (set-window-configuration owin)
2184 (set-window-point (get-buffer-window (current-buffer)) (point))))
2186 (defun gnus-article-summary-command-nosave ()
2187 "Execute the last keystroke in the summary buffer."
2190 (pop-to-buffer gnus-summary-buffer 'norecord)
2191 (setq func (lookup-key (current-local-map) (this-command-keys)))
2192 (call-interactively func)))
2194 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2195 "Read a summary buffer key sequence and execute it from the article buffer."
2198 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2199 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2200 "=" "^" "\M-^" "|"))
2207 (set-buffer gnus-summary-buffer)
2208 (let (gnus-pick-mode)
2209 (push (or key last-command-event) unread-command-events)
2210 (setq keys (read-key-sequence nil))))
2213 (if (or (member keys nosaves)
2214 (member keys nosave-but-article)
2215 (member keys nosave-in-article))
2217 (save-window-excursion
2218 (pop-to-buffer gnus-summary-buffer 'norecord)
2219 ;; We disable the pick minor mode commands.
2220 (let (gnus-pick-mode)
2221 (setq func (lookup-key (current-local-map) keys))))
2224 (unless (member keys nosave-in-article)
2225 (set-buffer gnus-summary-buffer))
2226 (call-interactively func))
2227 (when (member keys nosave-but-article)
2228 (pop-to-buffer gnus-article-buffer 'norecord)))
2229 ;; These commands should restore window configuration.
2230 (let ((obuf (current-buffer))
2231 (owin (current-window-configuration))
2234 (if not-restore-window
2235 (pop-to-buffer gnus-summary-buffer 'norecord)
2236 (switch-to-buffer gnus-summary-buffer 'norecord))
2237 (setq in-buffer (current-buffer))
2238 ;; We disable the pick minor mode commands.
2239 (if (setq func (let (gnus-pick-mode)
2240 (lookup-key (current-local-map) keys)))
2241 (call-interactively func)
2243 (when (eq in-buffer (current-buffer))
2245 (unless not-restore-window
2246 (set-window-configuration owin))
2247 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2249 (defun gnus-article-hide (&optional arg force)
2250 "Hide all the gruft in the current article.
2251 This means that PGP stuff, signatures, cited text and (some)
2252 headers will be hidden.
2253 If given a prefix, show the hidden text instead."
2254 (interactive (list current-prefix-arg 'force))
2255 (gnus-article-hide-headers arg)
2256 (gnus-article-hide-pgp arg)
2257 (gnus-article-hide-citation-maybe arg force)
2258 (gnus-article-hide-signature arg))
2260 (defun gnus-article-maybe-highlight ()
2261 "Do some article highlighting if `article-visual' is non-nil."
2262 (when (gnus-visual-p 'article-highlight 'highlight)
2263 (gnus-article-highlight-some)))
2265 (defun gnus-request-article-this-buffer (article group)
2266 "Get an article and insert it into this buffer."
2267 (let (do-update-line)
2271 (gnus-kill-all-overlays)
2272 (setq group (or group gnus-newsgroup-name))
2274 ;; Open server if it has closed.
2275 (gnus-check-server (gnus-find-method-for-group group))
2277 ;; Using `gnus-request-article' directly will insert the article into
2278 ;; `nntp-server-buffer' - so we'll save some time by not having to
2279 ;; copy it from the server buffer into the article buffer.
2281 ;; We only request an article by message-id when we do not have the
2282 ;; headers for it, so we'll have to get those.
2283 (when (stringp article)
2284 (let ((gnus-override-method gnus-refer-article-method))
2285 (gnus-read-header article)))
2287 ;; If the article number is negative, that means that this article
2288 ;; doesn't belong in this newsgroup (possibly), so we find its
2289 ;; message-id and request it by id instead of number.
2290 (when (and (numberp article)
2292 (get-buffer gnus-summary-buffer)
2293 (buffer-name (get-buffer gnus-summary-buffer)))
2295 (set-buffer gnus-summary-buffer)
2296 (let ((header (gnus-summary-article-header article)))
2299 ((memq article gnus-newsgroup-sparse)
2300 ;; This is a sparse gap article.
2301 (setq do-update-line article)
2302 (setq article (mail-header-id header))
2303 (let ((gnus-override-method gnus-refer-article-method))
2304 (gnus-read-header article))
2305 (setq gnus-newsgroup-sparse
2306 (delq article gnus-newsgroup-sparse)))
2308 ;; It's a real article.
2309 (setq article (mail-header-id header)))
2311 ;; It is an extracted pseudo-article.
2312 (setq article 'pseudo)
2313 (gnus-request-pseudo-article header))))
2315 (let ((method (gnus-find-method-for-group
2316 gnus-newsgroup-name)))
2317 (if (not (eq (car method) 'nneething))
2319 (let ((dir (concat (file-name-as-directory (nth 1 method))
2320 (mail-header-subject header))))
2321 (when (file-directory-p dir)
2322 (setq article 'nneething)
2323 (gnus-group-enter-directory dir))))))))
2326 ;; Refuse to select canceled articles.
2327 ((and (numberp article)
2329 (get-buffer gnus-summary-buffer)
2330 (buffer-name (get-buffer gnus-summary-buffer))
2331 (eq (cdr (save-excursion
2332 (set-buffer gnus-summary-buffer)
2333 (assq article gnus-newsgroup-reads)))
2334 gnus-canceled-mark))
2336 ;; We first check `gnus-original-article-buffer'.
2337 ((and (get-buffer gnus-original-article-buffer)
2340 (set-buffer gnus-original-article-buffer)
2341 (and (equal (car gnus-original-article) group)
2342 (eq (cdr gnus-original-article) article))))
2343 (insert-buffer-substring gnus-original-article-buffer)
2345 ;; Check the backlog.
2346 ((and gnus-keep-backlog
2347 (gnus-backlog-request-article group article (current-buffer)))
2349 ;; Check asynchronous pre-fetch.
2350 ((gnus-async-request-fetched-article group article (current-buffer))
2351 (gnus-async-prefetch-next group article gnus-summary-buffer)
2354 ((and gnus-use-cache
2356 (gnus-cache-request-article article group))
2358 ;; Get the article and put into the article buffer.
2359 ((or (stringp article) (numberp article))
2360 (let ((gnus-override-method
2361 (and (stringp article) gnus-refer-article-method))
2362 (buffer-read-only nil))
2364 (gnus-kill-all-overlays)
2365 (when (gnus-request-article article group (current-buffer))
2366 (when (numberp article)
2367 (gnus-async-prefetch-next group article gnus-summary-buffer)
2368 (when gnus-keep-backlog
2369 (gnus-backlog-enter-article
2370 group article (current-buffer))))
2375 ;; Take the article from the original article buffer
2376 ;; and place it in the buffer it's supposed to be in.
2377 (when (and (get-buffer gnus-article-buffer)
2379 (equal (buffer-name (current-buffer))
2380 (buffer-name (get-buffer gnus-article-buffer))))
2382 (if (get-buffer gnus-original-article-buffer)
2383 (set-buffer (get-buffer gnus-original-article-buffer))
2384 (set-buffer (get-buffer-create gnus-original-article-buffer))
2385 (buffer-disable-undo (current-buffer))
2386 (setq major-mode 'gnus-original-article-mode)
2387 (setq buffer-read-only t)
2388 (gnus-add-current-to-buffer-list))
2389 (let (buffer-read-only)
2391 (insert-buffer-substring gnus-article-buffer))
2392 (setq gnus-original-article (cons group article))))
2394 ;; Update sparse articles.
2395 (when (and do-update-line
2396 (or (numberp article)
2398 (let ((buf (current-buffer)))
2399 (set-buffer gnus-summary-buffer)
2400 (gnus-summary-update-article do-update-line)
2401 (gnus-summary-goto-subject do-update-line nil t)
2402 (set-window-point (get-buffer-window (current-buffer) t)
2404 (set-buffer buf))))))
2410 (defcustom gnus-article-edit-mode-hook nil
2411 "Hook run in article edit mode buffers."
2412 :group 'gnus-article-various
2415 (defvar gnus-article-edit-done-function nil)
2417 (defvar gnus-article-edit-mode-map nil)
2419 (unless gnus-article-edit-mode-map
2420 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2422 (gnus-define-keys gnus-article-edit-mode-map
2423 "\C-c\C-c" gnus-article-edit-done
2424 "\C-c\C-k" gnus-article-edit-exit)
2426 (gnus-define-keys (gnus-article-edit-wash-map
2427 "\C-c\C-w" gnus-article-edit-mode-map)
2428 "f" gnus-article-edit-full-stops))
2430 (defun gnus-article-edit-mode ()
2431 "Major mode for editing articles.
2432 This is an extended text-mode.
2434 \\{gnus-article-edit-mode-map}"
2436 (kill-all-local-variables)
2437 (setq major-mode 'gnus-article-edit-mode)
2438 (setq mode-name "Article Edit")
2439 (use-local-map gnus-article-edit-mode-map)
2440 (make-local-variable 'gnus-article-edit-done-function)
2441 (make-local-variable 'gnus-prev-winconf)
2442 (setq buffer-read-only nil)
2443 (buffer-enable-undo)
2445 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2447 (defun gnus-article-edit (&optional force)
2448 "Edit the current article.
2449 This will have permanent effect only in mail groups.
2450 If FORCE is non-nil, allow editing of articles even in read-only
2453 (when (and (not force)
2454 (gnus-group-read-only-p))
2455 (error "The current newsgroup does not support article editing."))
2456 (gnus-article-edit-article
2458 (gnus-summary-edit-article-done
2459 ,(or (mail-header-references gnus-current-headers) "")
2460 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2462 (defun gnus-article-edit-article (exit-func)
2463 "Start editing the contents of the current article buffer."
2464 (let ((winconf (current-window-configuration)))
2465 (set-buffer gnus-article-buffer)
2466 (gnus-article-edit-mode)
2467 (set-text-properties (point-min) (point-max) nil)
2468 (gnus-configure-windows 'edit-article)
2469 (setq gnus-article-edit-done-function exit-func)
2470 (setq gnus-prev-winconf winconf)
2471 (gnus-message 6 "C-c C-c to end edits")))
2473 (defun gnus-article-edit-done ()
2474 "Update the article edits and exit."
2476 (let ((func gnus-article-edit-done-function)
2477 (buf (current-buffer))
2478 (start (window-start)))
2479 (gnus-article-edit-exit)
2482 (let ((buffer-read-only nil))
2485 (set-window-start (get-buffer-window buf) start)
2486 (set-window-point (get-buffer-window buf) (point))))
2488 (defun gnus-article-edit-exit ()
2489 "Exit the article editing without updating."
2491 ;; We remove all text props from the article buffer.
2492 (let ((buf (format "%s" (buffer-string)))
2493 (curbuf (current-buffer))
2495 (window-start (window-start)))
2498 (let ((winconf gnus-prev-winconf))
2500 ;; The cache and backlog have to be flushed somewhat.
2501 (when gnus-use-cache
2502 (gnus-cache-update-article
2503 (car gnus-article-current) (cdr gnus-article-current)))
2504 (when gnus-keep-backlog
2505 (gnus-backlog-remove-article
2506 (car gnus-article-current) (cdr gnus-article-current)))
2507 ;; Flush original article as well.
2509 (when (get-buffer gnus-original-article-buffer)
2510 (set-buffer gnus-original-article-buffer)
2511 (setq gnus-original-article nil)))
2512 (set-window-configuration winconf)
2513 ;; Tippy-toe some to make sure that point remains where it was.
2514 (let ((buf (current-buffer)))
2516 (set-window-start (get-buffer-window (current-buffer)) window-start)
2518 (set-buffer buf)))))
2520 (defun gnus-article-edit-full-stops ()
2521 "Interactively repair spacing at end of sentences."
2524 (goto-char (point-min))
2525 (search-forward-regexp "^$" nil t)
2526 (let ((case-fold-search nil))
2527 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2530 ;;; Article highlights
2533 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2535 ;;; Internal Variables:
2537 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)"
2538 "Regular expression that matches URLs."
2539 :group 'gnus-article-buttons
2542 (defcustom gnus-button-alist
2543 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2544 gnus-button-message-id 2)
2545 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*+\\)" 0 t gnus-button-message-id 1)
2546 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2547 gnus-button-fetch-group 4)
2548 ("\\bnews:\\(//\\)?\\([^>\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2549 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2550 t gnus-button-message-id 3)
2551 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 1)
2552 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 2)
2553 ;; This is how URLs _should_ be embedded in text...
2554 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2556 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2557 "Alist of regexps matching buttons in article bodies.
2559 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2560 REGEXP: is the string matching text around the button,
2561 BUTTON: is the number of the regexp grouping actually matching the button,
2562 FORM: is a lisp expression which must eval to true for the button to
2564 CALLBACK: is the function to call when the user push this button, and each
2565 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2567 CALLBACK can also be a variable, in that case the value of that
2568 variable it the real callback function."
2569 :group 'gnus-article-buttons
2570 :type '(repeat (list regexp
2571 (integer :tag "Button")
2573 (function :tag "Callback")
2576 (integer :tag "Regexp group")))))
2578 (defcustom gnus-header-button-alist
2579 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2580 0 t gnus-button-message-id 0)
2581 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2582 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2583 0 t gnus-button-mailto 0)
2584 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2585 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2586 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2587 gnus-button-message-id 3))
2588 "Alist of headers and regexps to match buttons in article heads.
2590 This alist is very similar to `gnus-button-alist', except that each
2591 alist has an additional HEADER element first in each entry:
2593 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2595 HEADER is a regexp to match a header. For a fuller explanation, see
2596 `gnus-button-alist'."
2597 :group 'gnus-article-buttons
2598 :group 'gnus-article-headers
2599 :type '(repeat (list (regexp :tag "Header")
2601 (integer :tag "Button")
2603 (function :tag "Callback")
2606 (integer :tag "Regexp group")))))
2608 (defvar gnus-button-regexp nil)
2609 (defvar gnus-button-marker-list nil)
2610 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2612 (defvar gnus-button-last nil)
2613 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2617 (defun gnus-article-push-button (event)
2618 "Check text under the mouse pointer for a callback function.
2619 If the text under the mouse pointer has a `gnus-callback' property,
2620 call it with the value of the `gnus-data' text property."
2622 (set-buffer (window-buffer (posn-window (event-start event))))
2623 (let* ((pos (posn-point (event-start event)))
2624 (data (get-text-property pos 'gnus-data))
2625 (fun (get-text-property pos 'gnus-callback)))
2627 (funcall fun data))))
2629 (defun gnus-article-press-button ()
2630 "Check text at point for a callback function.
2631 If the text at point has a `gnus-callback' property,
2632 call it with the value of the `gnus-data' text property."
2634 (let* ((data (get-text-property (point) 'gnus-data))
2635 (fun (get-text-property (point) 'gnus-callback)))
2637 (funcall fun data))))
2639 (defun gnus-article-prev-button (n)
2640 "Move point to N buttons backward.
2641 If N is negative, move forward instead."
2643 (gnus-article-next-button (- n)))
2645 (defun gnus-article-next-button (n)
2646 "Move point to N buttons forward.
2647 If N is negative, move backward instead."
2649 (let ((function (if (< n 0) 'previous-single-property-change
2650 'next-single-property-change))
2651 (inhibit-point-motion-hooks t)
2653 (limit (if (< n 0) (point-min) (point-max))))
2655 (while (and (not (= limit (point)))
2657 ;; Skip past the current button.
2658 (when (get-text-property (point) 'gnus-callback)
2659 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2660 ;; Go to the next (or previous) button.
2661 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2662 ;; Put point at the start of the button.
2663 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2664 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2665 ;; Skip past intangible buttons.
2666 (when (get-text-property (point) 'intangible)
2670 (gnus-message 5 "No more buttons"))
2673 (defun gnus-article-highlight (&optional force)
2674 "Highlight current article.
2675 This function calls `gnus-article-highlight-headers',
2676 `gnus-article-highlight-citation',
2677 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2678 do the highlighting. See the documentation for those functions."
2679 (interactive (list 'force))
2680 (gnus-article-highlight-headers)
2681 (gnus-article-highlight-citation force)
2682 (gnus-article-highlight-signature)
2683 (gnus-article-add-buttons force)
2684 (gnus-article-add-buttons-to-head))
2686 (defun gnus-article-highlight-some (&optional force)
2687 "Highlight current article.
2688 This function calls `gnus-article-highlight-headers',
2689 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2690 do the highlighting. See the documentation for those functions."
2691 (interactive (list 'force))
2692 (gnus-article-highlight-headers)
2693 (gnus-article-highlight-signature)
2694 (gnus-article-add-buttons))
2696 (defun gnus-article-highlight-headers ()
2697 "Highlight article headers as specified by `gnus-header-face-alist'."
2700 (set-buffer gnus-article-buffer)
2702 (let ((alist gnus-header-face-alist)
2703 (buffer-read-only nil)
2704 (case-fold-search t)
2705 (inhibit-point-motion-hooks t)
2706 entry regexp header-face field-face from hpoints fpoints)
2707 (message-narrow-to-head)
2708 (while (setq entry (pop alist))
2709 (goto-char (point-min))
2710 (setq regexp (concat "^\\("
2711 (if (string-equal "" (nth 0 entry))
2715 header-face (nth 1 entry)
2716 field-face (nth 2 entry))
2717 (while (and (re-search-forward regexp nil t)
2721 (unless (search-forward ":" nil t)
2723 (when (and header-face
2724 (not (memq (point) hpoints)))
2725 (push (point) hpoints)
2726 (gnus-put-text-property from (point) 'face header-face))
2727 (when (and field-face
2728 (not (memq (setq from (point)) fpoints)))
2730 (if (re-search-forward "^[^ \t]" nil t)
2732 (goto-char (point-max)))
2733 (gnus-put-text-property from (point) 'face field-face))))))))
2735 (defun gnus-article-highlight-signature ()
2736 "Highlight the signature in an article.
2737 It does this by highlighting everything after
2738 `gnus-signature-separator' using `gnus-signature-face'."
2741 (set-buffer gnus-article-buffer)
2742 (let ((buffer-read-only nil)
2743 (inhibit-point-motion-hooks t))
2745 (when (and gnus-signature-face
2746 (gnus-article-narrow-to-signature))
2747 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2748 'face gnus-signature-face)
2750 (gnus-article-search-signature)
2751 (let ((start (match-beginning 0))
2752 (end (set-marker (make-marker) (1+ (match-end 0)))))
2753 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2756 (defun gnus-button-in-region-p (b e prop)
2757 "Say whether PROP exists in the region."
2758 (text-property-not-all b e prop nil))
2760 (defun gnus-article-add-buttons (&optional force)
2761 "Find external references in the article and make buttons of them.
2762 \"External references\" are things like Message-IDs and URLs, as
2763 specified by `gnus-button-alist'."
2764 (interactive (list 'force))
2766 (set-buffer gnus-article-buffer)
2767 (let ((buffer-read-only nil)
2768 (inhibit-point-motion-hooks t)
2769 (case-fold-search t)
2770 (alist gnus-button-alist)
2772 ;; Remove all old markers.
2774 (while (setq marker (pop gnus-button-marker-list))
2776 (when (setq entry (gnus-button-entry))
2777 (put-text-property (match-beginning (nth 1 entry))
2778 (match-end (nth 1 entry))
2779 'gnus-callback nil))
2780 (set-marker marker nil)))
2781 ;; We skip the headers.
2782 (goto-char (point-min))
2783 (unless (search-forward "\n\n" nil t)
2784 (goto-char (point-max)))
2786 (while (setq entry (pop alist))
2787 (setq regexp (car entry))
2789 (while (re-search-forward regexp nil t)
2790 (let* ((start (and entry (match-beginning (nth 1 entry))))
2791 (end (and entry (match-end (nth 1 entry))))
2792 (from (match-beginning 0)))
2793 (when (and (or (eq t (nth 2 entry))
2794 (eval (nth 2 entry)))
2795 (not (gnus-button-in-region-p
2796 start end 'gnus-callback)))
2797 ;; That optional form returned non-nil, so we add the
2799 (gnus-article-add-button
2800 start end 'gnus-button-push
2801 (car (push (set-marker (make-marker) from)
2802 gnus-button-marker-list))))))))))
2804 ;; Add buttons to the head of an article.
2805 (defun gnus-article-add-buttons-to-head ()
2806 "Add buttons to the head of the article."
2809 (set-buffer gnus-article-buffer)
2810 (let ((buffer-read-only nil)
2811 (inhibit-point-motion-hooks t)
2812 (case-fold-search t)
2813 (alist gnus-header-button-alist)
2815 (nnheader-narrow-to-headers)
2817 ;; Each alist entry.
2818 (setq entry (car alist)
2820 (goto-char (point-min))
2821 (while (re-search-forward (car entry) nil t)
2822 ;; Each header matching the entry.
2823 (setq beg (match-beginning 0))
2824 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2825 (match-beginning 0))
2828 (while (re-search-forward (nth 1 entry) end t)
2829 ;; Each match within a header.
2830 (let* ((entry (cdr entry))
2831 (start (match-beginning (nth 1 entry)))
2832 (end (match-end (nth 1 entry)))
2833 (form (nth 2 entry)))
2834 (goto-char (match-end 0))
2836 (gnus-article-add-button
2837 start end (nth 3 entry)
2838 (buffer-substring (match-beginning (nth 4 entry))
2839 (match-end (nth 4 entry)))))))
2843 ;;; External functions:
2845 (defun gnus-article-add-button (from to fun &optional data)
2846 "Create a button between FROM and TO with callback FUN and data DATA."
2847 (when gnus-article-button-face
2848 (gnus-overlay-put (gnus-make-overlay from to)
2849 'face gnus-article-button-face))
2850 (gnus-add-text-properties
2852 (nconc (and gnus-article-mouse-face
2853 (list gnus-mouse-face-prop gnus-article-mouse-face))
2854 (list 'gnus-callback fun)
2855 (and data (list 'gnus-data data)))))
2857 ;;; Internal functions:
2859 (defun gnus-signature-toggle (end)
2861 (set-buffer gnus-article-buffer)
2862 (let ((buffer-read-only nil)
2863 (inhibit-point-motion-hooks t))
2864 (if (get-text-property end 'invisible)
2865 (gnus-article-unhide-text end (point-max))
2866 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2868 (defun gnus-button-entry ()
2869 ;; Return the first entry in `gnus-button-alist' matching this place.
2870 (let ((alist gnus-button-alist)
2873 (setq entry (pop alist))
2874 (if (looking-at (car entry))
2879 (defun gnus-button-push (marker)
2880 ;; Push button starting at MARKER.
2882 (set-buffer gnus-article-buffer)
2884 (let* ((entry (gnus-button-entry))
2885 (inhibit-point-motion-hooks t)
2887 (args (mapcar (lambda (group)
2888 (let ((string (match-string group)))
2889 (gnus-set-text-properties
2890 0 (length string) nil string)
2897 (fboundp (symbol-value fun)))
2898 (apply (symbol-value fun) args))
2900 (gnus-message 1 "You must define `%S' to use this button"
2901 (cons fun args)))))))
2903 (defun gnus-button-message-id (message-id)
2906 (set-buffer gnus-summary-buffer)
2907 (gnus-summary-refer-article message-id)))
2909 (defun gnus-button-fetch-group (address)
2910 "Fetch GROUP specified by ADDRESS."
2911 (if (not (string-match "[:/]" address))
2912 ;; This is just a simple group url.
2913 (gnus-group-read-ephemeral-group address gnus-select-method)
2914 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
2916 (error "Can't parse %s" address)
2917 (gnus-group-read-ephemeral-group
2918 (match-string 4 address)
2919 `(nntp ,(match-string 1 address)
2920 (nntp-address ,(match-string 1 address))
2921 (nntp-port-number ,(if (match-end 3)
2922 (match-string 3 address)
2925 (defun gnus-split-string (string pattern)
2926 "Return a list of substrings of STRING which are separated by PATTERN."
2927 (let (parts (start 0))
2928 (while (string-match pattern string start)
2929 (setq parts (cons (substring string start (match-beginning 0)) parts)
2930 start (match-end 0)))
2931 (nreverse (cons (substring string start) parts))))
2933 (defun gnus-url-parse-query-string (query &optional downcase)
2934 (let (retval pairs cur key val)
2935 (setq pairs (gnus-split-string query "&"))
2937 (setq cur (car pairs)
2939 (if (not (string-match "=" cur))
2941 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2942 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2944 (setq key (downcase key)))
2945 (setq cur (assoc key retval))
2947 (setcdr cur (cons val (cdr cur)))
2948 (setq retval (cons (list key val) retval)))))
2951 (defun gnus-url-unhex (x)
2958 (defun gnus-url-unhex-string (str &optional allow-newlines)
2959 "Remove %XXX embedded spaces, etc in a url.
2960 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2961 decoding of carriage returns and line feeds in the string, which is normally
2962 forbidden in URL encoding."
2963 (setq str (or str ""))
2965 (case-fold-search t))
2966 (while (string-match "%[0-9a-f][0-9a-f]" str)
2967 (let* ((start (match-beginning 0))
2968 (ch1 (gnus-url-unhex (elt str (+ start 1))))
2970 (gnus-url-unhex (elt str (+ start 2))))))
2972 tmp (substring str 0 start)
2975 (char-to-string code))
2976 ((or (= code ?\n) (= code ?\r))
2978 (t (char-to-string code))))
2979 str (substring str (match-end 0)))))
2980 (setq tmp (concat tmp str))
2983 (defun gnus-url-mailto (url)
2984 ;; Send mail to someone
2985 (when (string-match "mailto:/*\\(.*\\)" url)
2986 (setq url (substring url (match-beginning 1) nil)))
2987 (let (to args source-url subject func)
2988 (if (string-match (regexp-quote "?") url)
2989 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2990 args (gnus-url-parse-query-string
2991 (substring url (match-end 0) nil) t))
2992 (setq to (gnus-url-unhex-string url)))
2993 (setq args (cons (list "to" to) args)
2994 subject (cdr-safe (assoc "subject" args)))
2997 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3000 (message-position-on-field (caar args)))
3001 (insert (mapconcat 'identity (cdar args) ", "))
3002 (setq args (cdr args)))
3005 (message-goto-subject))))
3007 (defun gnus-button-mailto (address)
3009 (set-buffer (gnus-copy-article-buffer))
3010 (message-reply address))
3012 (defun gnus-button-reply (address)
3013 ;; Reply to ADDRESS.
3014 (message-reply address))
3016 (defun gnus-button-url (address)
3018 (funcall browse-url-browser-function address))
3020 (defun gnus-button-embedded-url (address)
3022 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
3024 ;;; Next/prev buttons in the article buffer.
3026 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3027 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3029 (defvar gnus-prev-page-map nil)
3030 (unless gnus-prev-page-map
3031 (setq gnus-prev-page-map (make-sparse-keymap))
3032 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3033 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3035 (defun gnus-insert-prev-page-button ()
3036 (let ((buffer-read-only nil))
3038 gnus-prev-page-line-format nil
3039 `(gnus-prev t local-map ,gnus-prev-page-map
3040 gnus-callback gnus-article-button-prev-page))))
3042 (defvar gnus-next-page-map nil)
3043 (unless gnus-next-page-map
3044 (setq gnus-next-page-map (make-keymap))
3045 (suppress-keymap gnus-prev-page-map)
3046 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3047 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3049 (defun gnus-button-next-page ()
3050 "Go to the next page."
3052 (let ((win (selected-window)))
3053 (select-window (get-buffer-window gnus-article-buffer t))
3054 (gnus-article-next-page)
3055 (select-window win)))
3057 (defun gnus-button-prev-page ()
3058 "Go to the prev page."
3060 (let ((win (selected-window)))
3061 (select-window (get-buffer-window gnus-article-buffer t))
3062 (gnus-article-prev-page)
3063 (select-window win)))
3065 (defun gnus-insert-next-page-button ()
3066 (let ((buffer-read-only nil))
3067 (gnus-eval-format gnus-next-page-line-format nil
3068 `(gnus-next t local-map ,gnus-next-page-map
3070 gnus-article-button-next-page))))
3072 (defun gnus-article-button-next-page (arg)
3073 "Go to the next page."
3075 (let ((win (selected-window)))
3076 (select-window (get-buffer-window gnus-article-buffer t))
3077 (gnus-article-next-page)
3078 (select-window win)))
3080 (defun gnus-article-button-prev-page (arg)
3081 "Go to the prev page."
3083 (let ((win (selected-window)))
3084 (select-window (get-buffer-window gnus-article-buffer t))
3085 (gnus-article-prev-page)
3086 (select-window win)))
3092 (run-hooks 'gnus-art-load-hook)
3094 ;;; gnus-art.el ends here