1 ;;; gnus-cite.el --- parse citations in articles for Gnus
2 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
4 ;; Author: Per Abhiddenware; you can redistribute it and/or modify
5 ;; it under the terms of the GNU General Public License as published by
6 ;; the Free Software Foundation; either version 2, or (at your option)
9 ;; GNU Emacs is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;; GNU General Public License for more details.
14 ;; You should have received a copy of the GNU General Public License
15 ;; along with GNU Emacs; see the file COPYING. If not, write to the
16 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 ;; Boston, MA 02111-1307, USA.
23 (eval-when-compile (require 'cl))
31 (defgroup gnus-cite nil
34 :link '(custom-manual "(gnus)Article Highlighting")
37 (defcustom gnus-cite-reply-regexp
38 "^\\(Subject: Re\\|In-Reply-To\\|References\\):"
39 "*If headers match this regexp it is reasonable to believe that
40 article has citations."
44 (defcustom gnus-cite-always-check nil
45 "Check article always for citations. Set it t to check all articles."
47 :type '(choice (const :tag "no" nil)
48 (const :tag "yes" t)))
50 (defcustom gnus-cited-text-button-line-format "%(%{[...]%}%)\n"
51 "Format of cited text buttons."
55 (defcustom gnus-cited-lines-visible nil
56 "The number of lines of hidden cited text to remain visible."
58 :type '(choice (const :tag "none" nil)
61 (defcustom gnus-cite-parse-max-size 25000
62 "Maximum article size (in bytes) where parsing citations is allowed.
63 Set it to nil to parse all articles."
65 :type '(choice (const :tag "all" nil)
68 (defcustom gnus-cite-prefix-regexp
69 "^[]>|:}+ ]*[]>|:}+]\\(.*>\\)?\\|^.*>"
70 "*Regexp matching the longest possible citation prefix on a line."
74 (defcustom gnus-cite-max-prefix 20
75 "Maximum possible length for a citation prefix."
79 (defcustom gnus-supercite-regexp
80 (concat "^\\(" gnus-cite-prefix-regexp "\\)? *"
81 ">>>>> +\"\\([^\"\n]+\\)\" +==")
82 "*Regexp matching normal Supercite attribution lines.
83 The first grouping must match prefixes added by other packages."
87 (defcustom gnus-supercite-secondary-regexp "^.*\"\\([^\"\n]+\\)\" +=="
88 "Regexp matching mangled Supercite attribution lines.
89 The first regexp group should match the Supercite attribution."
93 (defcustom gnus-cite-minimum-match-count 2
94 "Minimum number of identical prefixes before we believe it's a citation."
98 (defcustom gnus-cite-attribution-prefix
99 "In article\\|in <\\|On \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\),"
100 "*Regexp matching the beginning of an attribution line."
104 (defcustom gnus-cite-attribution-suffix
105 "\\(\\(wrote\\|writes\\|said\\|says\\|>\\)\\(:\\|\\.\\.\\.\\)\\)[ \t]*$"
106 "*Regexp matching the end of an attribution line.
107 The text matching the first grouping will be used as a button."
111 (defface gnus-cite-attribution-face '((t
113 "Face used for attribution lines.")
115 (defcustom gnus-cite-attribution-face 'gnus-cite-attribution-face
116 "Face used for attribution lines.
117 It is merged with the face for the cited text belonging to the attribution."
121 (defface gnus-cite-face-1 '((((class color)
123 (:foreground "light blue"))
126 (:foreground "MidnightBlue"))
131 (defface gnus-cite-face-2 '((((class color)
133 (:foreground "light cyan"))
136 (:foreground "firebrick"))
141 (defface gnus-cite-face-3 '((((class color)
143 (:foreground "light yellow"))
146 (:foreground "dark green"))
151 (defface gnus-cite-face-4 '((((class color)
153 (:foreground "light pink"))
156 (:foreground "OrangeRed"))
161 (defface gnus-cite-face-5 '((((class color)
163 (:foreground "pale green"))
166 (:foreground "dark khaki"))
171 (defface gnus-cite-face-6 '((((class color)
173 (:foreground "beige"))
176 (:foreground "dark violet"))
181 (defface gnus-cite-face-7 '((((class color)
183 (:foreground "orange"))
186 (:foreground "SteelBlue4"))
191 (defface gnus-cite-face-8 '((((class color)
193 (:foreground "magenta"))
196 (:foreground "magenta"))
201 (defface gnus-cite-face-9 '((((class color)
203 (:foreground "violet"))
206 (:foreground "violet"))
211 (defface gnus-cite-face-10 '((((class color)
213 (:foreground "medium purple"))
216 (:foreground "medium purple"))
221 (defface gnus-cite-face-11 '((((class color)
223 (:foreground "turquoise"))
226 (:foreground "turquoise"))
231 (defcustom gnus-cite-face-list
232 '(gnus-cite-face-1 gnus-cite-face-2 gnus-cite-face-3 gnus-cite-face-4
233 gnus-cite-face-5 gnus-cite-face-6 gnus-cite-face-7 gnus-cite-face-8
234 gnus-cite-face-9 gnus-cite-face-10 gnus-cite-face-11)
235 "*List of faces used for highlighting citations.
237 When there are citations from multiple articles in the same message,
238 Gnus will try to give each citation from each article its own face.
239 This should make it easier to see who wrote what."
241 :type '(repeat face))
243 (defcustom gnus-cite-hide-percentage 50
244 "Only hide excess citation if above this percentage of the body."
248 (defcustom gnus-cite-hide-absolute 10
249 "Only hide excess citation if above this number of lines in the body."
253 ;;; Internal Variables:
255 (defvar gnus-cite-article nil)
256 (defvar gnus-cite-overlay-list nil)
258 (defvar gnus-cite-prefix-alist nil)
259 ;; Alist of citation prefixes.
260 ;; The cdr is a list of lines with that prefix.
262 (defvar gnus-cite-attribution-alist nil)
263 ;; Alist of attribution lines.
264 ;; The car is a line number.
265 ;; The cdr is the prefix for the citation started by that line.
267 (defvar gnus-cite-loose-prefix-alist nil)
268 ;; Alist of citation prefixes that have no matching attribution.
269 ;; The cdr is a list of lines with that prefix.
271 (defvar gnus-cite-loose-attribution-alist nil)
272 ;; Alist of attribution lines that have no matching citation.
273 ;; Each member has the form (WROTE IN PREFIX TAG), where
274 ;; WROTE: is the attribution line number
275 ;; IN: is the line number of the previous line if part of the same attribution,
276 ;; PREFIX: Is the citation prefix of the attribution line(s), and
277 ;; TAG: Is a Supercite tag, if any.
279 (defvar gnus-cited-text-button-line-format-alist
280 `((?b (marker-position beg) ?d)
281 (?e (marker-position end) ?d)
282 (?l (- end beg) ?d)))
283 (defvar gnus-cited-text-button-line-format-spec nil)
287 (defun gnus-article-highlight-citation (&optional force)
288 "Highlight cited text.
289 Each citation in the article will be highlighted with a different face.
290 The faces are taken from `gnus-cite-face-list'.
291 Attribution lines are highlighted with the same face as the
292 corresponding citation merged with `gnus-cite-attribution-face'.
294 Text is considered cited if at least `gnus-cite-minimum-match-count'
295 lines matches `gnus-cite-prefix-regexp' with the same prefix.
297 Lines matching `gnus-cite-attribution-suffix' and perhaps
298 `gnus-cite-attribution-prefix' are considered attribution lines."
299 (interactive (list 'force))
301 (set-buffer gnus-article-buffer)
302 (gnus-cite-parse-maybe force)
303 (let ((buffer-read-only nil)
304 (alist gnus-cite-prefix-alist)
305 (faces gnus-cite-face-list)
306 (inhibit-point-motion-hooks t)
307 face entry prefix skip numbers number face-alist)
308 ;; Loop through citation prefixes.
310 (setq entry (car alist)
315 faces (or (cdr faces) gnus-cite-face-list)
316 face-alist (cons (cons prefix face) face-alist))
318 (setq number (car numbers)
319 numbers (cdr numbers))
320 (and (not (assq number gnus-cite-attribution-alist))
321 (not (assq number gnus-cite-loose-attribution-alist))
322 (gnus-cite-add-face number prefix face))))
323 ;; Loop through attribution lines.
324 (setq alist gnus-cite-attribution-alist)
326 (setq entry (car alist)
330 skip (gnus-cite-find-prefix number)
331 face (cdr (assoc prefix face-alist)))
332 ;; Add attribution button.
334 (when (re-search-forward gnus-cite-attribution-suffix
335 (save-excursion (end-of-line 1) (point))
337 (gnus-article-add-button (match-beginning 1) (match-end 1)
338 'gnus-cite-toggle prefix))
339 ;; Highlight attribution line.
340 (gnus-cite-add-face number skip face)
341 (gnus-cite-add-face number skip gnus-cite-attribution-face))
342 ;; Loop through attribution lines.
343 (setq alist gnus-cite-loose-attribution-alist)
345 (setq entry (car alist)
348 skip (gnus-cite-find-prefix number))
349 (gnus-cite-add-face number skip gnus-cite-attribution-face)))))
351 (defun gnus-dissect-cited-text ()
352 "Dissect the article buffer looking for cited text."
354 (set-buffer gnus-article-buffer)
355 (gnus-cite-parse-maybe)
356 (let ((alist gnus-cite-prefix-alist)
357 prefix numbers number marks m)
358 ;; Loop through citation prefixes.
360 (setq numbers (pop alist)
361 prefix (pop numbers))
363 (setq number (pop numbers))
364 (goto-char (point-min))
365 (forward-line number)
366 (push (cons (point-marker) "") marks)
368 (= (1- number) (car numbers)))
369 (setq number (pop numbers)))
370 (goto-char (point-min))
371 (forward-line (1- number))
372 (push (cons (point-marker) prefix) marks)))
373 ;; Skip to the beginning of the body.
374 (goto-char (point-min))
375 (search-forward "\n\n" nil t)
376 (push (cons (point-marker) "") marks)
377 ;; Find the end of the body.
378 (goto-char (point-max))
379 (gnus-article-search-signature)
380 (push (cons (point-marker) "") marks)
382 (setq marks (sort marks 'car-less-than-car))
383 (let ((omarks marks))
386 (if (= (caar omarks) (caadr omarks))
388 (unless (equal (cdar omarks) "")
389 (push (car omarks) marks))
390 (unless (equal (cdadr omarks) "")
391 (push (cadr omarks) marks))
392 (unless (and (equal (cdar omarks) "")
393 (equal (cdadr omarks) "")
395 (setq omarks (cdr omarks))))
396 (push (car omarks) marks))
397 (setq omarks (cdr omarks)))
399 (push (car omarks) marks))
400 (setq marks (setq m (nreverse marks)))
402 (if (and (equal (cdadr m) "")
403 (equal (cdar m) (cdaddr m))
404 (goto-char (caadr m))
406 (= (point) (caaddr m)))
411 (defun gnus-article-fill-cited-article (&optional force width)
412 "Do word wrapping in the current article.
413 If WIDTH (the numerical prefix), use that text width when filling."
414 (interactive (list t current-prefix-arg))
416 (set-buffer gnus-article-buffer)
417 (let ((buffer-read-only nil)
418 (inhibit-point-motion-hooks t)
419 (marks (gnus-dissect-cited-text))
420 (adaptive-fill-mode nil)
422 (fill-column (if width (prefix-numeric-value width) fill-column)))
426 (narrow-to-region (caar marks) (caadr marks))
427 (let ((adaptive-fill-regexp
428 (concat "^" (regexp-quote (cdar marks)) " *"))
429 (fill-prefix (cdar marks)))
430 (fill-region (point-min) (point-max)))
431 (set-marker (caar marks) nil)
432 (setq marks (cdr marks)))
434 (set-marker (caar marks) nil))
435 ;; All this information is now incorrect.
436 (setq gnus-cite-prefix-alist nil
437 gnus-cite-attribution-alist nil
438 gnus-cite-loose-prefix-alist nil
439 gnus-cite-loose-attribution-alist nil
440 gnus-cite-article nil)))))
442 (defun gnus-article-hide-citation (&optional arg force)
443 "Toggle hiding of all cited text except attribution lines.
444 See the documentation for `gnus-article-highlight-citation'.
445 If given a negative prefix, always show; if given a positive prefix,
447 (interactive (append (gnus-article-hidden-arg) (list 'force)))
448 (gnus-set-format 'cited-text-button t)
450 (set-buffer gnus-article-buffer)
452 ((gnus-article-check-hidden-text 'cite arg)
454 ((gnus-article-text-type-exists-p 'cite)
455 (let ((buffer-read-only nil))
456 (gnus-article-hide-text-of-type 'cite)))
458 (let ((buffer-read-only nil)
459 (marks (gnus-dissect-cited-text))
460 (inhibit-point-motion-hooks t)
461 (props (nconc (list 'article-type 'cite)
462 gnus-hidden-properties))
467 (while (and marks (string= (cdar marks) ""))
468 (setq marks (cdr marks)))
470 (setq beg (caar marks)))
471 (while (and marks (not (string= (cdar marks) "")))
472 (setq marks (cdr marks)))
474 (setq end (caar marks)))
475 ;; Skip past lines we want to leave visible.
476 (when (and beg end gnus-cited-lines-visible)
478 (forward-line gnus-cited-lines-visible)
481 (setq beg (point-marker))))
483 ;; We use markers for the end-points to facilitate later
484 ;; wrapping and mangling of text.
485 (setq beg (set-marker (make-marker) beg)
486 end (set-marker (make-marker) end))
487 (gnus-add-text-properties beg end props)
489 (unless (save-excursion (search-backward "\n\n" nil t))
494 (gnus-article-add-button
496 (progn (eval gnus-cited-text-button-line-format-spec) (point))
497 `gnus-article-toggle-cited-text
500 'article-type 'annotation)
501 (set-marker beg (point)))))))))
503 (defun gnus-article-toggle-cited-text (region)
504 "Toggle hiding the text in REGION."
505 (let (buffer-read-only)
507 (if (text-property-any
508 (car region) (1- (cdr region))
509 (car gnus-hidden-properties) (cadr gnus-hidden-properties))
510 'remove-text-properties 'gnus-add-text-properties)
511 (car region) (cdr region) gnus-hidden-properties)))
513 (defun gnus-article-hide-citation-maybe (&optional arg force)
514 "Toggle hiding of cited text that has an attribution line.
515 If given a negative prefix, always show; if given a positive prefix,
517 This will do nothing unless at least `gnus-cite-hide-percentage'
518 percent and at least `gnus-cite-hide-absolute' lines of the body is
519 cited text with attributions. When called interactively, these two
520 variables are ignored.
521 See also the documentation for `gnus-article-highlight-citation'."
522 (interactive (append (gnus-article-hidden-arg) '(force)))
523 (unless (gnus-article-check-hidden-text 'cite arg)
525 (set-buffer gnus-article-buffer)
526 (gnus-cite-parse-maybe force)
527 (goto-char (point-min))
528 (search-forward "\n\n" nil t)
529 (let ((start (point))
530 (atts gnus-cite-attribution-alist)
531 (buffer-read-only nil)
532 (inhibit-point-motion-hooks t)
535 (goto-char (point-max))
536 (gnus-article-search-signature)
537 (setq total (count-lines start (point)))
539 (setq hidden (+ hidden (length (cdr (assoc (cdar atts)
540 gnus-cite-prefix-alist))))
543 (and (> (* 100 hidden) (* gnus-cite-hide-percentage total))
544 (> hidden gnus-cite-hide-absolute)))
545 (setq atts gnus-cite-attribution-alist)
547 (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist))
550 (setq hidden (car total)
553 (unless (assq hidden gnus-cite-attribution-alist)
554 (gnus-add-text-properties
555 (point) (progn (forward-line 1) (point))
556 (nconc (list 'article-type 'cite)
557 gnus-hidden-properties))))))))))
559 (defun gnus-article-hide-citation-in-followups ()
560 "Hide cited text in non-root articles."
563 (set-buffer gnus-article-buffer)
564 (let ((article (cdr gnus-article-current)))
565 (unless (save-excursion
566 (set-buffer gnus-summary-buffer)
567 (gnus-article-displayed-root-p article))
568 (gnus-article-hide-citation)))))
570 ;;; Internal functions:
572 (defun gnus-cite-parse-maybe (&optional force)
573 ;; Parse if the buffer has changes since last time.
575 (equal gnus-cite-article gnus-article-current))
578 ;;Reset parser information.
579 (setq gnus-cite-prefix-alist nil
580 gnus-cite-attribution-alist nil
581 gnus-cite-loose-prefix-alist nil
582 gnus-cite-loose-attribution-alist nil)
583 (while gnus-cite-overlay-list
584 (gnus-delete-overlay (pop gnus-cite-overlay-list)))
585 ;; Parse if not too large.
587 gnus-cite-parse-max-size
588 (> (buffer-size) gnus-cite-parse-max-size))
590 (setq gnus-cite-article (cons (car gnus-article-current)
591 (cdr gnus-article-current)))
592 (gnus-cite-parse-wrapper))))
594 (defun gnus-cite-parse-wrapper ()
595 ;; Wrap chopped gnus-cite-parse
596 (goto-char (point-min))
597 (unless (search-forward "\n\n" nil t)
598 (goto-char (point-max)))
600 (gnus-cite-parse-attributions))
601 ;; Try to avoid check citation if there is no reason to believe
602 ;; that article has citations
603 (if (or gnus-cite-always-check
605 (re-search-backward gnus-cite-reply-regexp nil t))
606 gnus-cite-loose-attribution-alist)
607 (progn (save-excursion
610 (gnus-cite-connect-attributions)))))
612 (defun gnus-cite-parse ()
613 ;; Parse and connect citation prefixes and attribution lines.
615 ;; Parse current buffer searching for citation prefixes.
616 (let ((line (1+ (count-lines (point-min) (point))))
619 (goto-char (point-max))
620 (gnus-article-search-signature)
622 alist entry start begin end numbers prefix)
623 ;; Get all potential prefixes in `alist'.
624 (while (< (point) max)
627 end (progn (beginning-of-line 2) (point))
630 ;; Ignore standard Supercite attribution prefix.
631 (when (looking-at gnus-supercite-regexp)
633 (setq end (1+ (match-end 1)))
634 (setq end (1+ begin))))
635 ;; Ignore very long prefixes.
636 (when (> end (+ (point) gnus-cite-max-prefix))
637 (setq end (+ (point) gnus-cite-max-prefix)))
638 (while (re-search-forward gnus-cite-prefix-regexp (1- end) t)
640 (setq end (match-end 0)
641 prefix (buffer-substring begin end))
642 (gnus-set-text-properties 0 (length prefix) nil prefix)
643 (setq entry (assoc prefix alist))
645 (setcdr entry (cons line (cdr entry)))
646 (push (list prefix line) alist))
649 (setq line (1+ line)))
650 ;; We got all the potential prefixes. Now create
651 ;; `gnus-cite-prefix-alist' containing the oldest prefix for each
652 ;; line that appears at least gnus-cite-minimum-match-count
653 ;; times. First sort them by length. Longer is older.
654 (setq alist (sort alist (lambda (a b)
655 (> (length (car a)) (length (car b))))))
657 (setq entry (car alist)
661 (cond ((null numbers)
662 ;; No lines with this prefix that wasn't also part of
665 ((< (length numbers) gnus-cite-minimum-match-count)
666 ;; Too few lines with this prefix. We keep it a bit
667 ;; longer in case it is an exact match for an attribution
668 ;; line, but we don't remove the line from other
670 (push entry gnus-cite-prefix-alist))
673 gnus-cite-prefix-alist)
674 ;; Remove articles from other prefixes.
678 (setq current (car loop)
681 (gnus-set-difference (cdr current) numbers)))))))))
683 (defun gnus-cite-parse-attributions ()
685 ;; Parse attributions
686 (while (re-search-forward gnus-cite-attribution-suffix (point-max) t)
687 (let* ((start (match-beginning 0))
689 (wrote (count-lines (point-min) end))
690 (prefix (gnus-cite-find-prefix wrote))
691 ;; Check previous line for an attribution leader.
693 (beginning-of-line 1)
694 (when (looking-at gnus-supercite-secondary-regexp)
695 (buffer-substring (match-beginning 1)
699 (and (re-search-backward gnus-cite-attribution-prefix
701 (beginning-of-line 0)
704 (not (re-search-forward gnus-cite-attribution-suffix
706 (count-lines (point-min) (1+ (point)))))))
710 ;; don't add duplicates
711 (let ((al (buffer-substring (save-excursion (beginning-of-line 0)
714 (if (not (assoc al al-alist))
716 (push (list wrote in prefix tag)
717 gnus-cite-loose-attribution-alist)
718 (push (cons al t) al-alist))))))))
720 (defun gnus-cite-connect-attributions ()
721 ;; Connect attributions to citations
723 ;; No citations have been connected to attribution lines yet.
724 (setq gnus-cite-loose-prefix-alist (append gnus-cite-prefix-alist nil))
726 ;; Parse current buffer searching for attribution lines.
727 ;; Find exact supercite citations.
728 (gnus-cite-match-attributions 'small nil
732 (regexp-quote prefix) "[ \t]*"
733 (regexp-quote tag) ">"))))
734 ;; Find loose supercite citations after attributions.
735 (gnus-cite-match-attributions 'small t
741 ;; Find loose supercite citations anywhere.
742 (gnus-cite-match-attributions 'small nil
748 ;; Find nested citations after attributions.
749 (gnus-cite-match-attributions 'small-if-unique t
751 (concat "\\`" (regexp-quote prefix) ".+")))
752 ;; Find nested citations anywhere.
753 (gnus-cite-match-attributions 'small nil
755 (concat "\\`" (regexp-quote prefix) ".+")))
756 ;; Remove loose prefixes with too few lines.
757 (let ((alist gnus-cite-loose-prefix-alist)
760 (setq entry (car alist)
762 (when (< (length (cdr entry)) gnus-cite-minimum-match-count)
763 (setq gnus-cite-prefix-alist
764 (delq entry gnus-cite-prefix-alist)
765 gnus-cite-loose-prefix-alist
766 (delq entry gnus-cite-loose-prefix-alist)))))
767 ;; Find flat attributions.
768 (gnus-cite-match-attributions 'first t nil)
769 ;; Find any attributions (are we getting desperate yet?).
770 (gnus-cite-match-attributions 'first nil nil))
772 (defun gnus-cite-match-attributions (sort after fun)
773 ;; Match all loose attributions and citations (SORT AFTER FUN) .
775 ;; If SORT is `small', the citation with the shortest prefix will be
776 ;; used, if it is `first' the first prefix will be used, if it is
777 ;; `small-if-unique' the shortest prefix will be used if the
778 ;; attribution line does not share its own prefix with other
779 ;; loose attribution lines, otherwise the first prefix will be used.
781 ;; If AFTER is non-nil, only citations after the attribution line
782 ;; will be considered.
784 ;; If FUN is non-nil, it will be called with the arguments (WROTE
785 ;; PREFIX TAG) and expected to return a regular expression. Only
786 ;; citations whose prefix matches the regular expression will be
789 ;; WROTE is the attribution line number.
790 ;; PREFIX is the attribution line prefix.
791 ;; TAG is the Supercite tag on the attribution line.
792 (let ((atts gnus-cite-loose-attribution-alist)
794 att wrote in prefix tag regexp limit smallest best size)
802 regexp (if fun (funcall fun prefix tag) "")
803 size (cond ((eq sort 'small) t)
804 ((eq sort 'first) nil)
805 (t (< (length (gnus-cite-find-loose prefix)) 2)))
806 limit (if after wrote -1)
809 (let ((cites gnus-cite-loose-prefix-alist)
810 cite candidate numbers first compare)
812 (setq cite (car cites)
816 first (apply 'min numbers)
817 compare (if size (length candidate) first))
820 (string-match regexp candidate)
826 (setq gnus-cite-loose-attribution-alist
827 (delq att gnus-cite-loose-attribution-alist))
828 (push (cons wrote (car best)) gnus-cite-attribution-alist)
830 (push (cons in (car best)) gnus-cite-attribution-alist))
831 (when (memq best gnus-cite-loose-prefix-alist)
832 (let ((loop gnus-cite-prefix-alist)
835 (setq gnus-cite-loose-prefix-alist
836 (delq best gnus-cite-loose-prefix-alist))
838 (setq current (car loop)
840 (if (eq current best)
842 (setcdr current (gnus-set-difference (cdr current) numbers))
843 (when (null (cdr current))
844 (setq gnus-cite-loose-prefix-alist
845 (delq current gnus-cite-loose-prefix-alist)
846 atts (delq current atts)))))))))))
848 (defun gnus-cite-find-loose (prefix)
849 ;; Return a list of loose attribution lines prefixed by PREFIX.
850 (let* ((atts gnus-cite-loose-attribution-alist)
856 (when (string-equal (gnus-cite-find-prefix line) prefix)
860 (defun gnus-cite-add-face (number prefix face)
861 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
863 (let ((inhibit-point-motion-hooks t)
866 (unless (eobp) ; Sometimes things become confused.
867 (forward-char (length prefix))
868 (skip-chars-forward " \t")
871 (skip-chars-backward " \t")
874 (push (setq overlay (gnus-make-overlay from to))
875 gnus-cite-overlay-list)
876 (gnus-overlay-put overlay 'face face))))))
878 (defun gnus-cite-toggle (prefix)
880 (set-buffer gnus-article-buffer)
881 (gnus-cite-parse-maybe)
882 (let ((buffer-read-only nil)
883 (numbers (cdr (assoc prefix gnus-cite-prefix-alist)))
884 (inhibit-point-motion-hooks t)
887 (setq number (car numbers)
888 numbers (cdr numbers))
890 (cond ((get-text-property (point) 'invisible)
891 (remove-text-properties (point) (progn (forward-line 1) (point))
892 gnus-hidden-properties))
893 ((assq number gnus-cite-attribution-alist))
895 (gnus-add-text-properties
896 (point) (progn (forward-line 1) (point))
897 (nconc (list 'article-type 'cite)
898 gnus-hidden-properties))))))))
900 (defun gnus-cite-find-prefix (line)
901 ;; Return citation prefix for LINE.
902 (let ((alist gnus-cite-prefix-alist)
906 (setq entry (car alist)
908 (when (memq line (cdr entry))
909 (setq prefix (car entry))))
912 (defun gnus-cite-localize ()
913 "Make the citation variables local to the article buffer."
914 (let ((vars '(gnus-cite-article
915 gnus-cite-overlay-list gnus-cite-prefix-alist
916 gnus-cite-attribution-alist gnus-cite-loose-prefix-alist
917 gnus-cite-loose-attribution-alist)))
919 (make-local-variable (pop vars)))))
925 ;;; gnus-cite.el ends here