1 ;;; gnus-cite.el --- parse citations in articles for Gnus
2 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
4 ;; Author: Per Abrahamsen <abraham@iesd.auc.dk>
5 ;; Keywords: news, mail
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.
28 (eval-when-compile (require 'cl))
36 (defgroup gnus-cite nil
39 :link '(custom-manual "(gnus)Article Highlighting")
42 (defcustom gnus-cite-reply-regexp
43 "^\\(Subject: Re\\|In-Reply-To\\|References\\):"
44 "*If headers match this regexp it is reasonable to believe that
45 article has citations."
49 (defcustom gnus-cite-always-check nil
50 "Check article always for citations. Set it t to check all articles."
52 :type '(choice (const :tag "no" nil)
53 (const :tag "yes" t)))
55 (defcustom gnus-cited-text-button-line-format "%(%{[...]%}%)\n"
56 "Format of cited text buttons."
60 (defcustom gnus-cited-lines-visible nil
61 "The number of lines of hidden cited text to remain visible."
63 :type '(choice (const :tag "none" nil)
66 (defcustom gnus-cite-parse-max-size 25000
67 "Maximum article size (in bytes) where parsing citations is allowed.
68 Set it to nil to parse all articles."
70 :type '(choice (const :tag "all" nil)
73 (defcustom gnus-cite-prefix-regexp
74 "^[]>|:}+ ]*[]>|:}+]\\(.*>\\)?\\|^.*>"
75 "*Regexp matching the longest possible citation prefix on a line."
79 (defcustom gnus-cite-max-prefix 20
80 "Maximum possible length for a citation prefix."
84 (defcustom gnus-supercite-regexp
85 (concat "^\\(" gnus-cite-prefix-regexp "\\)? *"
86 ">>>>> +\"\\([^\"\n]+\\)\" +==")
87 "*Regexp matching normal Supercite attribution lines.
88 The first grouping must match prefixes added by other packages."
92 (defcustom gnus-supercite-secondary-regexp "^.*\"\\([^\"\n]+\\)\" +=="
93 "Regexp matching mangled Supercite attribution lines.
94 The first regexp group should match the Supercite attribution."
98 (defcustom gnus-cite-minimum-match-count 2
99 "Minimum number of identical prefixes before we believe it's a citation."
103 (defcustom gnus-cite-attribution-prefix
104 "In article\\|in <\\|On \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\),"
105 "*Regexp matching the beginning of an attribution line."
109 (defcustom gnus-cite-attribution-suffix
110 "\\(\\(wrote\\|writes\\|said\\|says\\|>\\)\\(:\\|\\.\\.\\.\\)\\)[ \t]*$"
111 "*Regexp matching the end of an attribution line.
112 The text matching the first grouping will be used as a button."
116 (defface gnus-cite-attribution-face '((t
118 "Face used for attribution lines.")
120 (defcustom gnus-cite-attribution-face 'gnus-cite-attribution-face
121 "Face used for attribution lines.
122 It is merged with the face for the cited text belonging to the attribution."
126 (defface gnus-cite-face-1 '((((class color)
128 (:foreground "light blue"))
131 (:foreground "MidnightBlue"))
136 (defface gnus-cite-face-2 '((((class color)
138 (:foreground "light cyan"))
141 (:foreground "firebrick"))
146 (defface gnus-cite-face-3 '((((class color)
148 (:foreground "light yellow"))
151 (:foreground "dark green"))
156 (defface gnus-cite-face-4 '((((class color)
158 (:foreground "light pink"))
161 (:foreground "OrangeRed"))
166 (defface gnus-cite-face-5 '((((class color)
168 (:foreground "pale green"))
171 (:foreground "dark khaki"))
176 (defface gnus-cite-face-6 '((((class color)
178 (:foreground "beige"))
181 (:foreground "dark violet"))
186 (defface gnus-cite-face-7 '((((class color)
188 (:foreground "orange"))
191 (:foreground "SteelBlue4"))
196 (defface gnus-cite-face-8 '((((class color)
198 (:foreground "magenta"))
201 (:foreground "magenta"))
206 (defface gnus-cite-face-9 '((((class color)
208 (:foreground "violet"))
211 (:foreground "violet"))
216 (defface gnus-cite-face-10 '((((class color)
218 (:foreground "medium purple"))
221 (:foreground "medium purple"))
226 (defface gnus-cite-face-11 '((((class color)
228 (:foreground "turquoise"))
231 (:foreground "turquoise"))
236 (defcustom gnus-cite-face-list
237 '(gnus-cite-face-1 gnus-cite-face-2 gnus-cite-face-3 gnus-cite-face-4
238 gnus-cite-face-5 gnus-cite-face-6 gnus-cite-face-7 gnus-cite-face-8
239 gnus-cite-face-9 gnus-cite-face-10 gnus-cite-face-11)
240 "*List of faces used for highlighting citations.
242 When there are citations from multiple articles in the same message,
243 Gnus will try to give each citation from each article its own face.
244 This should make it easier to see who wrote what."
246 :type '(repeat face))
248 (defcustom gnus-cite-hide-percentage 50
249 "Only hide excess citation if above this percentage of the body."
253 (defcustom gnus-cite-hide-absolute 10
254 "Only hide excess citation if above this number of lines in the body."
258 ;;; Internal Variables:
260 (defvar gnus-cite-article nil)
261 (defvar gnus-cite-overlay-list nil)
263 (defvar gnus-cite-prefix-alist nil)
264 ;; Alist of citation prefixes.
265 ;; The cdr is a list of lines with that prefix.
267 (defvar gnus-cite-attribution-alist nil)
268 ;; Alist of attribution lines.
269 ;; The car is a line number.
270 ;; The cdr is the prefix for the citation started by that line.
272 (defvar gnus-cite-loose-prefix-alist nil)
273 ;; Alist of citation prefixes that have no matching attribution.
274 ;; The cdr is a list of lines with that prefix.
276 (defvar gnus-cite-loose-attribution-alist nil)
277 ;; Alist of attribution lines that have no matching citation.
278 ;; Each member has the form (WROTE IN PREFIX TAG), where
279 ;; WROTE: is the attribution line number
280 ;; IN: is the line number of the previous line if part of the same attribution,
281 ;; PREFIX: Is the citation prefix of the attribution line(s), and
282 ;; TAG: Is a Supercite tag, if any.
284 (defvar gnus-cited-text-button-line-format-alist
285 `((?b (marker-position beg) ?d)
286 (?e (marker-position end) ?d)
287 (?l (- end beg) ?d)))
288 (defvar gnus-cited-text-button-line-format-spec nil)
292 (defun gnus-article-highlight-citation (&optional force)
293 "Highlight cited text.
294 Each citation in the article will be highlighted with a different face.
295 The faces are taken from `gnus-cite-face-list'.
296 Attribution lines are highlighted with the same face as the
297 corresponding citation merged with `gnus-cite-attribution-face'.
299 Text is considered cited if at least `gnus-cite-minimum-match-count'
300 lines matches `gnus-cite-prefix-regexp' with the same prefix.
302 Lines matching `gnus-cite-attribution-suffix' and perhaps
303 `gnus-cite-attribution-prefix' are considered attribution lines."
304 (interactive (list 'force))
306 (set-buffer gnus-article-buffer)
307 (gnus-cite-parse-maybe force)
308 (let ((buffer-read-only nil)
309 (alist gnus-cite-prefix-alist)
310 (faces gnus-cite-face-list)
311 (inhibit-point-motion-hooks t)
312 face entry prefix skip numbers number face-alist)
313 ;; Loop through citation prefixes.
315 (setq entry (car alist)
320 faces (or (cdr faces) gnus-cite-face-list)
321 face-alist (cons (cons prefix face) face-alist))
323 (setq number (car numbers)
324 numbers (cdr numbers))
325 (and (not (assq number gnus-cite-attribution-alist))
326 (not (assq number gnus-cite-loose-attribution-alist))
327 (gnus-cite-add-face number prefix face))))
328 ;; Loop through attribution lines.
329 (setq alist gnus-cite-attribution-alist)
331 (setq entry (car alist)
335 skip (gnus-cite-find-prefix number)
336 face (cdr (assoc prefix face-alist)))
337 ;; Add attribution button.
339 (when (re-search-forward gnus-cite-attribution-suffix
340 (save-excursion (end-of-line 1) (point))
342 (gnus-article-add-button (match-beginning 1) (match-end 1)
343 'gnus-cite-toggle prefix))
344 ;; Highlight attribution line.
345 (gnus-cite-add-face number skip face)
346 (gnus-cite-add-face number skip gnus-cite-attribution-face))
347 ;; Loop through attribution lines.
348 (setq alist gnus-cite-loose-attribution-alist)
350 (setq entry (car alist)
353 skip (gnus-cite-find-prefix number))
354 (gnus-cite-add-face number skip gnus-cite-attribution-face)))))
356 (defun gnus-dissect-cited-text ()
357 "Dissect the article buffer looking for cited text."
359 (set-buffer gnus-article-buffer)
360 (gnus-cite-parse-maybe)
361 (let ((alist gnus-cite-prefix-alist)
362 prefix numbers number marks m)
363 ;; Loop through citation prefixes.
365 (setq numbers (pop alist)
366 prefix (pop numbers))
368 (setq number (pop numbers))
369 (goto-char (point-min))
370 (forward-line number)
371 (push (cons (point-marker) "") marks)
373 (= (1- number) (car numbers)))
374 (setq number (pop numbers)))
375 (goto-char (point-min))
376 (forward-line (1- number))
377 (push (cons (point-marker) prefix) marks)))
378 ;; Skip to the beginning of the body.
379 (goto-char (point-min))
380 (search-forward "\n\n" nil t)
381 (push (cons (point-marker) "") marks)
382 ;; Find the end of the body.
383 (goto-char (point-max))
384 (gnus-article-search-signature)
385 (push (cons (point-marker) "") marks)
387 (setq marks (sort marks 'car-less-than-car))
388 (let ((omarks marks))
391 (if (= (caar omarks) (caadr omarks))
393 (unless (equal (cdar omarks) "")
394 (push (car omarks) marks))
395 (unless (equal (cdadr omarks) "")
396 (push (cadr omarks) marks))
397 (unless (and (equal (cdar omarks) "")
398 (equal (cdadr omarks) "")
400 (setq omarks (cdr omarks))))
401 (push (car omarks) marks))
402 (setq omarks (cdr omarks)))
404 (push (car omarks) marks))
405 (setq marks (setq m (nreverse marks)))
407 (if (and (equal (cdadr m) "")
408 (equal (cdar m) (cdaddr m))
409 (goto-char (caadr m))
411 (= (point) (caaddr m)))
416 (defun gnus-article-fill-cited-article (&optional force width)
417 "Do word wrapping in the current article.
418 If WIDTH (the numerical prefix), use that text width when filling."
419 (interactive (list t current-prefix-arg))
421 (set-buffer gnus-article-buffer)
422 (let ((buffer-read-only nil)
423 (inhibit-point-motion-hooks t)
424 (marks (gnus-dissect-cited-text))
425 (adaptive-fill-mode nil)
427 (fill-column (if width (prefix-numeric-value width) fill-column)))
431 (narrow-to-region (caar marks) (caadr marks))
432 (let ((adaptive-fill-regexp
433 (concat "^" (regexp-quote (cdar marks)) " *"))
434 (fill-prefix (cdar marks)))
435 (fill-region (point-min) (point-max)))
436 (set-marker (caar marks) nil)
437 (setq marks (cdr marks)))
439 (set-marker (caar marks) nil))
440 ;; All this information is now incorrect.
441 (setq gnus-cite-prefix-alist nil
442 gnus-cite-attribution-alist nil
443 gnus-cite-loose-prefix-alist nil
444 gnus-cite-loose-attribution-alist nil
445 gnus-cite-article nil)))))
447 (defun gnus-article-hide-citation (&optional arg force)
448 "Toggle hiding of all cited text except attribution lines.
449 See the documentation for `gnus-article-highlight-citation'.
450 If given a negative prefix, always show; if given a positive prefix,
452 (interactive (append (gnus-article-hidden-arg) (list 'force)))
453 (gnus-set-format 'cited-text-button t)
455 (set-buffer gnus-article-buffer)
457 ((gnus-article-check-hidden-text 'cite arg)
459 ((gnus-article-text-type-exists-p 'cite)
460 (let ((buffer-read-only nil))
461 (gnus-article-hide-text-of-type 'cite)))
463 (let ((buffer-read-only nil)
464 (marks (gnus-dissect-cited-text))
465 (inhibit-point-motion-hooks t)
466 (props (nconc (list 'article-type 'cite)
467 gnus-hidden-properties))
472 (while (and marks (string= (cdar marks) ""))
473 (setq marks (cdr marks)))
475 (setq beg (caar marks)))
476 (while (and marks (not (string= (cdar marks) "")))
477 (setq marks (cdr marks)))
479 (setq end (caar marks)))
480 ;; Skip past lines we want to leave visible.
481 (when (and beg end gnus-cited-lines-visible)
483 (forward-line gnus-cited-lines-visible)
486 (setq beg (point-marker))))
488 ;; We use markers for the end-points to facilitate later
489 ;; wrapping and mangling of text.
490 (setq beg (set-marker (make-marker) beg)
491 end (set-marker (make-marker) end))
492 (gnus-add-text-properties beg end props)
494 (unless (save-excursion (search-backward "\n\n" nil t))
499 (gnus-article-add-button
501 (progn (eval gnus-cited-text-button-line-format-spec) (point))
502 `gnus-article-toggle-cited-text
505 'article-type 'annotation)
506 (set-marker beg (point)))))))))
508 (defun gnus-article-toggle-cited-text (region)
509 "Toggle hiding the text in REGION."
510 (let (buffer-read-only)
512 (if (text-property-any
513 (car region) (1- (cdr region))
514 (car gnus-hidden-properties) (cadr gnus-hidden-properties))
515 'remove-text-properties 'gnus-add-text-properties)
516 (car region) (cdr region) gnus-hidden-properties)))
518 (defun gnus-article-hide-citation-maybe (&optional arg force)
519 "Toggle hiding of cited text that has an attribution line.
520 If given a negative prefix, always show; if given a positive prefix,
522 This will do nothing unless at least `gnus-cite-hide-percentage'
523 percent and at least `gnus-cite-hide-absolute' lines of the body is
524 cited text with attributions. When called interactively, these two
525 variables are ignored.
526 See also the documentation for `gnus-article-highlight-citation'."
527 (interactive (append (gnus-article-hidden-arg) '(force)))
528 (unless (gnus-article-check-hidden-text 'cite arg)
530 (set-buffer gnus-article-buffer)
531 (gnus-cite-parse-maybe force)
532 (goto-char (point-min))
533 (search-forward "\n\n" nil t)
534 (let ((start (point))
535 (atts gnus-cite-attribution-alist)
536 (buffer-read-only nil)
537 (inhibit-point-motion-hooks t)
540 (goto-char (point-max))
541 (gnus-article-search-signature)
542 (setq total (count-lines start (point)))
544 (setq hiden (+ hiden (length (cdr (assoc (cdar atts)
545 gnus-cite-prefix-alist))))
548 (and (> (* 100 hiden) (* gnus-cite-hide-percentage total))
549 (> hiden gnus-cite-hide-absolute)))
550 (setq atts gnus-cite-attribution-alist)
552 (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist))
555 (setq hiden (car total)
558 (unless (assq hiden gnus-cite-attribution-alist)
559 (gnus-add-text-properties
560 (point) (progn (forward-line 1) (point))
561 (nconc (list 'article-type 'cite)
562 gnus-hidden-properties))))))))))
564 (defun gnus-article-hide-citation-in-followups ()
565 "Hide cited text in non-root articles."
568 (set-buffer gnus-article-buffer)
569 (let ((article (cdr gnus-article-current)))
570 (unless (save-excursion
571 (set-buffer gnus-summary-buffer)
572 (gnus-article-displayed-root-p article))
573 (gnus-article-hide-citation)))))
575 ;;; Internal functions:
577 (defun gnus-cite-parse-maybe (&optional force)
578 ;; Parse if the buffer has changes since last time.
580 (equal gnus-cite-article gnus-article-current))
583 ;;Reset parser information.
584 (setq gnus-cite-prefix-alist nil
585 gnus-cite-attribution-alist nil
586 gnus-cite-loose-prefix-alist nil
587 gnus-cite-loose-attribution-alist nil)
588 (while gnus-cite-overlay-list
589 (gnus-delete-overlay (pop gnus-cite-overlay-list)))
590 ;; Parse if not too large.
592 gnus-cite-parse-max-size
593 (> (buffer-size) gnus-cite-parse-max-size))
595 (setq gnus-cite-article (cons (car gnus-article-current)
596 (cdr gnus-article-current)))
597 (gnus-cite-parse-wrapper))))
599 (defun gnus-cite-parse-wrapper ()
600 ;; Wrap chopped gnus-cite-parse
601 (goto-char (point-min))
602 (unless (search-forward "\n\n" nil t)
603 (goto-char (point-max)))
605 (gnus-cite-parse-attributions))
606 ;; Try to avoid check citation if there is no reason to believe
607 ;; that article has citations
608 (if (or gnus-cite-always-check
610 (re-search-backward gnus-cite-reply-regexp nil t))
611 gnus-cite-loose-attribution-alist)
612 (progn (save-excursion
615 (gnus-cite-connect-attributions)))))
617 (defun gnus-cite-parse ()
618 ;; Parse and connect citation prefixes and attribution lines.
620 ;; Parse current buffer searching for citation prefixes.
621 (let ((line (1+ (count-lines (point-min) (point))))
624 (goto-char (point-max))
625 (gnus-article-search-signature)
627 alist entry start begin end numbers prefix)
628 ;; Get all potential prefixes in `alist'.
629 (while (< (point) max)
632 end (progn (beginning-of-line 2) (point))
635 ;; Ignore standard Supercite attribution prefix.
636 (when (looking-at gnus-supercite-regexp)
638 (setq end (1+ (match-end 1)))
639 (setq end (1+ begin))))
640 ;; Ignore very long prefixes.
641 (when (> end (+ (point) gnus-cite-max-prefix))
642 (setq end (+ (point) gnus-cite-max-prefix)))
643 (while (re-search-forward gnus-cite-prefix-regexp (1- end) t)
645 (setq end (match-end 0)
646 prefix (buffer-substring begin end))
647 (gnus-set-text-properties 0 (length prefix) nil prefix)
648 (setq entry (assoc prefix alist))
650 (setcdr entry (cons line (cdr entry)))
651 (push (list prefix line) alist))
654 (setq line (1+ line)))
655 ;; We got all the potential prefixes. Now create
656 ;; `gnus-cite-prefix-alist' containing the oldest prefix for each
657 ;; line that appears at least gnus-cite-minimum-match-count
658 ;; times. First sort them by length. Longer is older.
659 (setq alist (sort alist (lambda (a b)
660 (> (length (car a)) (length (car b))))))
662 (setq entry (car alist)
666 (cond ((null numbers)
667 ;; No lines with this prefix that wasn't also part of
670 ((< (length numbers) gnus-cite-minimum-match-count)
671 ;; Too few lines with this prefix. We keep it a bit
672 ;; longer in case it is an exact match for an attribution
673 ;; line, but we don't remove the line from other
675 (push entry gnus-cite-prefix-alist))
678 gnus-cite-prefix-alist)
679 ;; Remove articles from other prefixes.
683 (setq current (car loop)
686 (gnus-set-difference (cdr current) numbers)))))))))
688 (defun gnus-cite-parse-attributions ()
690 ;; Parse attributions
691 (while (re-search-forward gnus-cite-attribution-suffix (point-max) t)
692 (let* ((start (match-beginning 0))
694 (wrote (count-lines (point-min) end))
695 (prefix (gnus-cite-find-prefix wrote))
696 ;; Check previous line for an attribution leader.
698 (beginning-of-line 1)
699 (when (looking-at gnus-supercite-secondary-regexp)
700 (buffer-substring (match-beginning 1)
704 (and (re-search-backward gnus-cite-attribution-prefix
706 (beginning-of-line 0)
709 (not (re-search-forward gnus-cite-attribution-suffix
711 (count-lines (point-min) (1+ (point)))))))
715 ;; don't add duplicates
716 (let ((al (buffer-substring (save-excursion (beginning-of-line 0)
719 (if (not (assoc al al-alist))
721 (push (list wrote in prefix tag)
722 gnus-cite-loose-attribution-alist)
723 (push (cons al t) al-alist))))))))
725 (defun gnus-cite-connect-attributions ()
726 ;; Connect attributions to citations
728 ;; No citations have been connected to attribution lines yet.
729 (setq gnus-cite-loose-prefix-alist (append gnus-cite-prefix-alist nil))
731 ;; Parse current buffer searching for attribution lines.
732 ;; Find exact supercite citations.
733 (gnus-cite-match-attributions 'small nil
737 (regexp-quote prefix) "[ \t]*"
738 (regexp-quote tag) ">"))))
739 ;; Find loose supercite citations after attributions.
740 (gnus-cite-match-attributions 'small t
746 ;; Find loose supercite citations anywhere.
747 (gnus-cite-match-attributions 'small nil
753 ;; Find nested citations after attributions.
754 (gnus-cite-match-attributions 'small-if-unique t
756 (concat "\\`" (regexp-quote prefix) ".+")))
757 ;; Find nested citations anywhere.
758 (gnus-cite-match-attributions 'small nil
760 (concat "\\`" (regexp-quote prefix) ".+")))
761 ;; Remove loose prefixes with too few lines.
762 (let ((alist gnus-cite-loose-prefix-alist)
765 (setq entry (car alist)
767 (when (< (length (cdr entry)) gnus-cite-minimum-match-count)
768 (setq gnus-cite-prefix-alist
769 (delq entry gnus-cite-prefix-alist)
770 gnus-cite-loose-prefix-alist
771 (delq entry gnus-cite-loose-prefix-alist)))))
772 ;; Find flat attributions.
773 (gnus-cite-match-attributions 'first t nil)
774 ;; Find any attributions (are we getting desperate yet?).
775 (gnus-cite-match-attributions 'first nil nil))
777 (defun gnus-cite-match-attributions (sort after fun)
778 ;; Match all loose attributions and citations (SORT AFTER FUN) .
780 ;; If SORT is `small', the citation with the shortest prefix will be
781 ;; used, if it is `first' the first prefix will be used, if it is
782 ;; `small-if-unique' the shortest prefix will be used if the
783 ;; attribution line does not share its own prefix with other
784 ;; loose attribution lines, otherwise the first prefix will be used.
786 ;; If AFTER is non-nil, only citations after the attribution line
787 ;; will be considered.
789 ;; If FUN is non-nil, it will be called with the arguments (WROTE
790 ;; PREFIX TAG) and expected to return a regular expression. Only
791 ;; citations whose prefix matches the regular expression will be
794 ;; WROTE is the attribution line number.
795 ;; PREFIX is the attribution line prefix.
796 ;; TAG is the Supercite tag on the attribution line.
797 (let ((atts gnus-cite-loose-attribution-alist)
799 att wrote in prefix tag regexp limit smallest best size)
807 regexp (if fun (funcall fun prefix tag) "")
808 size (cond ((eq sort 'small) t)
809 ((eq sort 'first) nil)
810 (t (< (length (gnus-cite-find-loose prefix)) 2)))
811 limit (if after wrote -1)
814 (let ((cites gnus-cite-loose-prefix-alist)
815 cite candidate numbers first compare)
817 (setq cite (car cites)
821 first (apply 'min numbers)
822 compare (if size (length candidate) first))
825 (string-match regexp candidate)
831 (setq gnus-cite-loose-attribution-alist
832 (delq att gnus-cite-loose-attribution-alist))
833 (push (cons wrote (car best)) gnus-cite-attribution-alist)
835 (push (cons in (car best)) gnus-cite-attribution-alist))
836 (when (memq best gnus-cite-loose-prefix-alist)
837 (let ((loop gnus-cite-prefix-alist)
840 (setq gnus-cite-loose-prefix-alist
841 (delq best gnus-cite-loose-prefix-alist))
843 (setq current (car loop)
845 (if (eq current best)
847 (setcdr current (gnus-set-difference (cdr current) numbers))
848 (when (null (cdr current))
849 (setq gnus-cite-loose-prefix-alist
850 (delq current gnus-cite-loose-prefix-alist)
851 atts (delq current atts)))))))))))
853 (defun gnus-cite-find-loose (prefix)
854 ;; Return a list of loose attribution lines prefixed by PREFIX.
855 (let* ((atts gnus-cite-loose-attribution-alist)
861 (when (string-equal (gnus-cite-find-prefix line) prefix)
865 (defun gnus-cite-add-face (number prefix face)
866 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
868 (let ((inhibit-point-motion-hooks t)
871 (unless (eobp) ; Sometimes things become confused.
872 (goto-char (+ (point) (length prefix)))
873 (skip-chars-forward " \t")
876 (skip-chars-backward " \t")
879 (push (setq overlay (gnus-make-overlay from to))
880 gnus-cite-overlay-list)
881 (gnus-overlay-put overlay 'face face))))))
883 (defun gnus-cite-toggle (prefix)
885 (set-buffer gnus-article-buffer)
886 (gnus-cite-parse-maybe)
887 (let ((buffer-read-only nil)
888 (numbers (cdr (assoc prefix gnus-cite-prefix-alist)))
889 (inhibit-point-motion-hooks t)
892 (setq number (car numbers)
893 numbers (cdr numbers))
895 (cond ((get-text-property (point) 'invisible)
896 (remove-text-properties (point) (progn (forward-line 1) (point))
897 gnus-hidden-properties))
898 ((assq number gnus-cite-attribution-alist))
900 (gnus-add-text-properties
901 (point) (progn (forward-line 1) (point))
902 (nconc (list 'article-type 'cite)
903 gnus-hidden-properties))))))))
905 (defun gnus-cite-find-prefix (line)
906 ;; Return citation prefix for LINE.
907 (let ((alist gnus-cite-prefix-alist)
911 (setq entry (car alist)
913 (when (memq line (cdr entry))
914 (setq prefix (car entry))))
917 (defun gnus-cite-localize ()
918 "Make the citation variables local to the article buffer."
919 (let ((vars '(gnus-cite-article
920 gnus-cite-overlay-list gnus-cite-prefix-alist
921 gnus-cite-attribution-alist gnus-cite-loose-prefix-alist
922 gnus-cite-loose-attribution-alist)))
924 (make-local-variable (pop vars)))))
930 ;;; gnus-cite.el ends here