1 ;;; gnus-cite.el --- parse citations in articles for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Per Abhiddenware; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; GNU Emacs is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with GNU Emacs; see the file COPYING. If not, write to the
17 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 ;; Boston, MA 02111-1307, USA.
24 (eval-when-compile (require 'cl))
32 (defgroup gnus-cite nil
35 :link '(custom-manual "(gnus)Article Highlighting")
38 (defcustom gnus-cite-reply-regexp
39 "^\\(Subject: Re\\|In-Reply-To\\|References\\):"
40 "*If headers match this regexp it is reasonable to believe that
41 article has citations."
45 (defcustom gnus-cite-always-check nil
46 "Check article always for citations. Set it t to check all articles."
48 :type '(choice (const :tag "no" nil)
49 (const :tag "yes" t)))
51 (defcustom gnus-cited-opened-text-button-line-format "%(%{[-]%}%)\n"
52 "Format of opened cited text buttons."
56 (defcustom gnus-cited-closed-text-button-line-format "%(%{[+]%}%)\n"
57 "Format of closed cited text buttons."
61 (defcustom gnus-cited-lines-visible nil
62 "The number of lines of hidden cited text to remain visible.
63 Or a pair (cons) of numbers which are the number of lines at the top
64 and bottom of the text, respectively, to remain visible."
66 :type '(choice (const :tag "none" nil)
68 (cons :tag "Top and Bottom" integer integer)))
70 (defcustom gnus-cite-parse-max-size 25000
71 "Maximum article size (in bytes) where parsing citations is allowed.
72 Set it to nil to parse all articles."
74 :type '(choice (const :tag "all" nil)
77 (defcustom gnus-cite-prefix-regexp
78 "^[]>»|:}+ ]*[]>»|:}+]\\(.*>»\\)?\\|^.*>"
79 "*Regexp matching the longest possible citation prefix on a line."
83 (defcustom gnus-cite-max-prefix 20
84 "Maximum possible length for a citation prefix."
88 (defcustom gnus-supercite-regexp
89 (concat "^\\(" gnus-cite-prefix-regexp "\\)? *"
90 ">>>>> +\"\\([^\"\n]+\\)\" +==")
91 "*Regexp matching normal Supercite attribution lines.
92 The first grouping must match prefixes added by other packages."
96 (defcustom gnus-supercite-secondary-regexp "^.*\"\\([^\"\n]+\\)\" +=="
97 "Regexp matching mangled Supercite attribution lines.
98 The first regexp group should match the Supercite attribution."
102 (defcustom gnus-cite-minimum-match-count 2
103 "Minimum number of identical prefixes before we believe it's a citation."
107 (defcustom gnus-cite-attribution-prefix
108 "In article\\|in <\\|On \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\),\\|-----Original Message-----"
109 "*Regexp matching the beginning of an attribution line."
113 (defcustom gnus-cite-attribution-suffix
114 "\\(\\(wrote\\|writes\\|said\\|says\\|>\\)\\(:\\|\\.\\.\\.\\)\\|-----Original Message-----\\)[ \t]*$"
115 "*Regexp matching the end of an attribution line.
116 The text matching the first grouping will be used as a button."
120 (defface gnus-cite-attribution-face '((t
122 "Face used for attribution lines.")
124 (defcustom gnus-cite-attribution-face 'gnus-cite-attribution-face
125 "Face used for attribution lines.
126 It is merged with the face for the cited text belonging to the attribution."
130 (defface gnus-cite-face-1 '((((class color)
132 (:foreground "light blue"))
135 (:foreground "MidnightBlue"))
140 (defface gnus-cite-face-2 '((((class color)
142 (:foreground "light cyan"))
145 (:foreground "firebrick"))
150 (defface gnus-cite-face-3 '((((class color)
152 (:foreground "light yellow"))
155 (:foreground "dark green"))
160 (defface gnus-cite-face-4 '((((class color)
162 (:foreground "light pink"))
165 (:foreground "OrangeRed"))
170 (defface gnus-cite-face-5 '((((class color)
172 (:foreground "pale green"))
175 (:foreground "dark khaki"))
180 (defface gnus-cite-face-6 '((((class color)
182 (:foreground "beige"))
185 (:foreground "dark violet"))
190 (defface gnus-cite-face-7 '((((class color)
192 (:foreground "orange"))
195 (:foreground "SteelBlue4"))
200 (defface gnus-cite-face-8 '((((class color)
202 (:foreground "magenta"))
205 (:foreground "magenta"))
210 (defface gnus-cite-face-9 '((((class color)
212 (:foreground "violet"))
215 (:foreground "violet"))
220 (defface gnus-cite-face-10 '((((class color)
222 (:foreground "medium purple"))
225 (:foreground "medium purple"))
230 (defface gnus-cite-face-11 '((((class color)
232 (:foreground "turquoise"))
235 (:foreground "turquoise"))
240 (defcustom gnus-cite-face-list
241 '(gnus-cite-face-1 gnus-cite-face-2 gnus-cite-face-3 gnus-cite-face-4
242 gnus-cite-face-5 gnus-cite-face-6 gnus-cite-face-7 gnus-cite-face-8
243 gnus-cite-face-9 gnus-cite-face-10 gnus-cite-face-11)
244 "*List of faces used for highlighting citations.
246 When there are citations from multiple articles in the same message,
247 Gnus will try to give each citation from each article its own face.
248 This should make it easier to see who wrote what."
250 :type '(repeat face))
252 (defcustom gnus-cite-hide-percentage 50
253 "Only hide excess citation if above this percentage of the body."
257 (defcustom gnus-cite-hide-absolute 10
258 "Only hide excess citation if above this number of lines in the body."
262 ;;; Internal Variables:
264 (defvar gnus-cite-article nil)
265 (defvar gnus-cite-overlay-list nil)
267 (defvar gnus-cite-prefix-alist nil)
268 ;; Alist of citation prefixes.
269 ;; The cdr is a list of lines with that prefix.
271 (defvar gnus-cite-attribution-alist nil)
272 ;; Alist of attribution lines.
273 ;; The car is a line number.
274 ;; The cdr is the prefix for the citation started by that line.
276 (defvar gnus-cite-loose-prefix-alist nil)
277 ;; Alist of citation prefixes that have no matching attribution.
278 ;; The cdr is a list of lines with that prefix.
280 (defvar gnus-cite-loose-attribution-alist nil)
281 ;; Alist of attribution lines that have no matching citation.
282 ;; Each member has the form (WROTE IN PREFIX TAG), where
283 ;; WROTE: is the attribution line number
284 ;; IN: is the line number of the previous line if part of the same attribution,
285 ;; PREFIX: Is the citation prefix of the attribution line(s), and
286 ;; TAG: Is a Supercite tag, if any.
288 (defvar gnus-cited-opened-text-button-line-format-alist
289 `((?b (marker-position beg) ?d)
290 (?e (marker-position end) ?d)
291 (?n (count-lines beg end) ?d)
292 (?l (- end beg) ?d)))
293 (defvar gnus-cited-opened-text-button-line-format-spec nil)
294 (defvar gnus-cited-closed-text-button-line-format-alist
295 gnus-cited-opened-text-button-line-format-alist)
296 (defvar gnus-cited-closed-text-button-line-format-spec nil)
301 (defun gnus-article-highlight-citation (&optional force)
302 "Highlight cited text.
303 Each citation in the article will be highlighted with a different face.
304 The faces are taken from `gnus-cite-face-list'.
305 Attribution lines are highlighted with the same face as the
306 corresponding citation merged with `gnus-cite-attribution-face'.
308 Text is considered cited if at least `gnus-cite-minimum-match-count'
309 lines matches `gnus-cite-prefix-regexp' with the same prefix.
311 Lines matching `gnus-cite-attribution-suffix' and perhaps
312 `gnus-cite-attribution-prefix' are considered attribution lines."
313 (interactive (list 'force))
315 (set-buffer gnus-article-buffer)
316 (gnus-cite-parse-maybe force)
317 (let ((buffer-read-only nil)
318 (alist gnus-cite-prefix-alist)
319 (faces gnus-cite-face-list)
320 (inhibit-point-motion-hooks t)
321 face entry prefix skip numbers number face-alist)
322 ;; Loop through citation prefixes.
324 (setq entry (car alist)
329 faces (or (cdr faces) gnus-cite-face-list)
330 face-alist (cons (cons prefix face) face-alist))
332 (setq number (car numbers)
333 numbers (cdr numbers))
334 (and (not (assq number gnus-cite-attribution-alist))
335 (not (assq number gnus-cite-loose-attribution-alist))
336 (gnus-cite-add-face number prefix face))))
337 ;; Loop through attribution lines.
338 (setq alist gnus-cite-attribution-alist)
340 (setq entry (car alist)
344 skip (gnus-cite-find-prefix number)
345 face (cdr (assoc prefix face-alist)))
346 ;; Add attribution button.
347 (goto-char (point-min))
348 (forward-line (1- number))
349 (when (re-search-forward gnus-cite-attribution-suffix
350 (save-excursion (end-of-line 1) (point))
352 (gnus-article-add-button (match-beginning 1) (match-end 1)
353 'gnus-cite-toggle prefix))
354 ;; Highlight attribution line.
355 (gnus-cite-add-face number skip face)
356 (gnus-cite-add-face number skip gnus-cite-attribution-face))
357 ;; Loop through attribution lines.
358 (setq alist gnus-cite-loose-attribution-alist)
360 (setq entry (car alist)
363 skip (gnus-cite-find-prefix number))
364 (gnus-cite-add-face number skip gnus-cite-attribution-face)))))
366 (defun gnus-dissect-cited-text ()
367 "Dissect the article buffer looking for cited text."
369 (set-buffer gnus-article-buffer)
370 (gnus-cite-parse-maybe nil t)
371 (let ((alist gnus-cite-prefix-alist)
372 prefix numbers number marks m)
373 ;; Loop through citation prefixes.
375 (setq numbers (pop alist)
376 prefix (pop numbers))
378 (setq number (pop numbers))
379 (goto-char (point-min))
380 (forward-line number)
381 (push (cons (point-marker) "") marks)
383 (= (1- number) (car numbers)))
384 (setq number (pop numbers)))
385 (goto-char (point-min))
386 (forward-line (1- number))
387 (push (cons (point-marker) prefix) marks)))
388 ;; Skip to the beginning of the body.
390 (push (cons (point-marker) "") marks)
391 ;; Find the end of the body.
392 (goto-char (point-max))
393 (gnus-article-search-signature)
394 (push (cons (point-marker) "") marks)
396 (setq marks (sort marks 'car-less-than-car))
397 (let ((omarks marks))
400 (if (= (caar omarks) (caadr omarks))
402 (unless (equal (cdar omarks) "")
403 (push (car omarks) marks))
404 (unless (equal (cdadr omarks) "")
405 (push (cadr omarks) marks))
406 (unless (and (equal (cdar omarks) "")
407 (equal (cdadr omarks) "")
409 (setq omarks (cdr omarks))))
410 (push (car omarks) marks))
411 (setq omarks (cdr omarks)))
413 (push (car omarks) marks))
414 (setq marks (setq m (nreverse marks)))
416 (if (and (equal (cdadr m) "")
417 (equal (cdar m) (cdaddr m))
418 (goto-char (caadr m))
420 (= (point) (caaddr m)))
425 (defun gnus-article-fill-cited-article (&optional force width)
426 "Do word wrapping in the current article.
427 If WIDTH (the numerical prefix), use that text width when filling."
428 (interactive (list t current-prefix-arg))
430 (set-buffer gnus-article-buffer)
431 (let ((buffer-read-only nil)
432 (inhibit-point-motion-hooks t)
433 (marks (gnus-dissect-cited-text))
434 (adaptive-fill-mode nil)
436 (fill-column (if width (prefix-numeric-value width) fill-column)))
439 (narrow-to-region (caar marks) (caadr marks))
440 (let ((adaptive-fill-regexp
441 (concat "^" (regexp-quote (cdar marks)) " *"))
442 (fill-prefix (cdar marks)))
443 (fill-region (point-min) (point-max)))
444 (set-marker (caar marks) nil)
445 (setq marks (cdr marks)))
447 (set-marker (caar marks) nil))
448 ;; All this information is now incorrect.
449 (setq gnus-cite-prefix-alist nil
450 gnus-cite-attribution-alist nil
451 gnus-cite-loose-prefix-alist nil
452 gnus-cite-loose-attribution-alist nil
453 gnus-cite-article nil)))))
455 (defun gnus-article-hide-citation (&optional arg force)
456 "Toggle hiding of all cited text except attribution lines.
457 See the documentation for `gnus-article-highlight-citation'.
458 If given a negative prefix, always show; if given a positive prefix,
460 (interactive (append (gnus-article-hidden-arg) (list 'force)))
461 (gnus-set-format 'cited-opened-text-button t)
462 (gnus-set-format 'cited-closed-text-button t)
464 (set-buffer gnus-article-buffer)
466 ((gnus-article-check-hidden-text 'cite arg)
468 ((gnus-article-text-type-exists-p 'cite)
469 (let ((buffer-read-only nil))
470 (gnus-article-hide-text-of-type 'cite)))
472 (let ((buffer-read-only nil)
473 (marks (gnus-dissect-cited-text))
474 (inhibit-point-motion-hooks t)
475 (props (nconc (list 'article-type 'cite)
476 gnus-hidden-properties))
481 (while (and marks (string= (cdar marks) ""))
482 (setq marks (cdr marks)))
484 (setq beg (caar marks)))
485 (while (and marks (not (string= (cdar marks) "")))
486 (setq marks (cdr marks)))
488 (setq end (caar marks)))
489 ;; Skip past lines we want to leave visible.
490 (when (and beg end gnus-cited-lines-visible)
492 (forward-line (if (consp gnus-cited-lines-visible)
493 (car gnus-cited-lines-visible)
494 gnus-cited-lines-visible))
497 (setq beg (point-marker))
498 (when (consp gnus-cited-lines-visible)
500 (forward-line (- (cdr gnus-cited-lines-visible)))
503 (setq end (point-marker))))))
505 ;; We use markers for the end-points to facilitate later
506 ;; wrapping and mangling of text.
507 (setq beg (set-marker (make-marker) beg)
508 end (set-marker (make-marker) end))
509 (gnus-add-text-properties beg end props)
511 (unless (save-excursion (search-backward "\n\n" nil t))
514 (setq start (point-marker))
516 (gnus-article-add-button
518 (progn (eval gnus-cited-closed-text-button-line-format-spec)
520 `gnus-article-toggle-cited-text
521 (list (cons beg end) start))
523 'article-type 'annotation)
524 (set-marker beg (point)))))))))
526 (defun gnus-article-toggle-cited-text (args)
527 "Toggle hiding the text in REGION."
528 (let* ((region (car args))
535 (car gnus-hidden-properties) (cadr gnus-hidden-properties)))
536 (inhibit-point-motion-hooks t)
540 'remove-text-properties 'gnus-add-text-properties)
541 beg end gnus-hidden-properties)
548 (gnus-article-add-button
552 gnus-cited-opened-text-button-line-format-spec
553 gnus-cited-closed-text-button-line-format-spec))
555 `gnus-article-toggle-cited-text
558 'article-type 'annotation))))
560 (defun gnus-article-hide-citation-maybe (&optional arg force)
561 "Toggle hiding of cited text that has an attribution line.
562 If given a negative prefix, always show; if given a positive prefix,
564 This will do nothing unless at least `gnus-cite-hide-percentage'
565 percent and at least `gnus-cite-hide-absolute' lines of the body is
566 cited text with attributions. When called interactively, these two
567 variables are ignored.
568 See also the documentation for `gnus-article-highlight-citation'."
569 (interactive (append (gnus-article-hidden-arg) '(force)))
570 (unless (gnus-article-check-hidden-text 'cite arg)
572 (set-buffer gnus-article-buffer)
573 (gnus-cite-parse-maybe force)
575 (let ((start (point))
576 (atts gnus-cite-attribution-alist)
577 (buffer-read-only nil)
578 (inhibit-point-motion-hooks t)
581 (goto-char (point-max))
582 (gnus-article-search-signature)
583 (setq total (count-lines start (point)))
585 (setq hidden (+ hidden (length (cdr (assoc (cdar atts)
586 gnus-cite-prefix-alist))))
589 (and (> (* 100 hidden) (* gnus-cite-hide-percentage total))
590 (> hidden gnus-cite-hide-absolute)))
591 (setq atts gnus-cite-attribution-alist)
593 (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist))
596 (setq hidden (car total)
598 (goto-char (point-min))
599 (forward-line (1- hidden))
600 (unless (assq hidden gnus-cite-attribution-alist)
601 (gnus-add-text-properties
602 (point) (progn (forward-line 1) (point))
603 (nconc (list 'article-type 'cite)
604 gnus-hidden-properties))))))))))
606 (defun gnus-article-hide-citation-in-followups ()
607 "Hide cited text in non-root articles."
610 (set-buffer gnus-article-buffer)
611 (let ((article (cdr gnus-article-current)))
612 (unless (save-excursion
613 (set-buffer gnus-summary-buffer)
614 (gnus-article-displayed-root-p article))
615 (gnus-article-hide-citation)))))
617 ;;; Internal functions:
619 (defun gnus-cite-parse-maybe (&optional force no-overlay)
620 "Always parse the buffer."
622 ;;Reset parser information.
623 (setq gnus-cite-prefix-alist nil
624 gnus-cite-attribution-alist nil
625 gnus-cite-loose-prefix-alist nil
626 gnus-cite-loose-attribution-alist nil)
628 (gnus-cite-delete-overlays))
629 ;; Parse if not too large.
630 (if (and gnus-cite-parse-max-size
631 (> (buffer-size) gnus-cite-parse-max-size))
633 (setq gnus-cite-article (cons (car gnus-article-current)
634 (cdr gnus-article-current)))
635 (gnus-cite-parse-wrapper)))
637 (defun gnus-cite-delete-overlays ()
638 (dolist (overlay gnus-cite-overlay-list)
639 (when (or (not (gnus-overlay-end overlay))
640 (and (>= (gnus-overlay-end overlay) (point-min))
641 (<= (gnus-overlay-end overlay) (point-max))))
642 (setq gnus-cite-overlay-list (delete overlay gnus-cite-overlay-list))
643 (gnus-delete-overlay overlay))))
645 (defun gnus-cite-parse-wrapper ()
646 ;; Wrap chopped gnus-cite-parse.
648 (let ((inhibit-point-motion-hooks t))
650 (gnus-cite-parse-attributions))
654 (gnus-cite-connect-attributions))))
656 (defun gnus-cite-parse ()
657 ;; Parse and connect citation prefixes and attribution lines.
659 ;; Parse current buffer searching for citation prefixes.
660 (let ((line (1+ (count-lines (point-min) (point))))
663 (goto-char (point-max))
664 (gnus-article-search-signature)
666 alist entry start begin end numbers prefix)
667 ;; Get all potential prefixes in `alist'.
668 (while (< (point) max)
671 end (progn (beginning-of-line 2) (point))
674 ;; Ignore standard Supercite attribution prefix.
675 (when (looking-at gnus-supercite-regexp)
677 (setq end (1+ (match-end 1)))
678 (setq end (1+ begin))))
679 ;; Ignore very long prefixes.
680 (when (> end (+ (point) gnus-cite-max-prefix))
681 (setq end (+ (point) gnus-cite-max-prefix)))
682 (while (re-search-forward gnus-cite-prefix-regexp (1- end) t)
684 (setq end (match-end 0)
685 prefix (buffer-substring begin end))
686 (gnus-set-text-properties 0 (length prefix) nil prefix)
687 (setq entry (assoc prefix alist))
689 (setcdr entry (cons line (cdr entry)))
690 (push (list prefix line) alist))
693 (setq line (1+ line)))
694 ;; We got all the potential prefixes. Now create
695 ;; `gnus-cite-prefix-alist' containing the oldest prefix for each
696 ;; line that appears at least gnus-cite-minimum-match-count
697 ;; times. First sort them by length. Longer is older.
698 (setq alist (sort alist (lambda (a b)
699 (> (length (car a)) (length (car b))))))
701 (setq entry (car alist)
705 (cond ((null numbers)
706 ;; No lines with this prefix that wasn't also part of
709 ((< (length numbers) gnus-cite-minimum-match-count)
710 ;; Too few lines with this prefix. We keep it a bit
711 ;; longer in case it is an exact match for an attribution
712 ;; line, but we don't remove the line from other
714 (push entry gnus-cite-prefix-alist))
717 gnus-cite-prefix-alist)
718 ;; Remove articles from other prefixes.
722 (setq current (car loop)
725 (gnus-set-difference (cdr current) numbers)))))))))
727 (defun gnus-cite-parse-attributions ()
729 ;; Parse attributions
730 (while (re-search-forward gnus-cite-attribution-suffix (point-max) t)
731 (let* ((start (match-beginning 0))
733 (wrote (count-lines (point-min) end))
734 (prefix (gnus-cite-find-prefix wrote))
735 ;; Check previous line for an attribution leader.
737 (beginning-of-line 1)
738 (when (looking-at gnus-supercite-secondary-regexp)
739 (buffer-substring (match-beginning 1)
743 (and (re-search-backward gnus-cite-attribution-prefix
745 (beginning-of-line 0)
748 (not (re-search-forward gnus-cite-attribution-suffix
750 (count-lines (point-min) (1+ (point)))))))
754 ;; don't add duplicates
755 (let ((al (buffer-substring (save-excursion (beginning-of-line 0)
758 (if (not (assoc al al-alist))
760 (push (list wrote in prefix tag)
761 gnus-cite-loose-attribution-alist)
762 (push (cons al t) al-alist))))))))
764 (defun gnus-cite-connect-attributions ()
765 ;; Connect attributions to citations
767 ;; No citations have been connected to attribution lines yet.
768 (setq gnus-cite-loose-prefix-alist (append gnus-cite-prefix-alist nil))
770 ;; Parse current buffer searching for attribution lines.
771 ;; Find exact supercite citations.
772 (gnus-cite-match-attributions 'small nil
776 (regexp-quote prefix) "[ \t]*"
777 (regexp-quote tag) ">"))))
778 ;; Find loose supercite citations after attributions.
779 (gnus-cite-match-attributions 'small t
785 ;; Find loose supercite citations anywhere.
786 (gnus-cite-match-attributions 'small nil
792 ;; Find nested citations after attributions.
793 (gnus-cite-match-attributions 'small-if-unique t
795 (concat "\\`" (regexp-quote prefix) ".+")))
796 ;; Find nested citations anywhere.
797 (gnus-cite-match-attributions 'small nil
799 (concat "\\`" (regexp-quote prefix) ".+")))
800 ;; Remove loose prefixes with too few lines.
801 (let ((alist gnus-cite-loose-prefix-alist)
804 (setq entry (car alist)
806 (when (< (length (cdr entry)) gnus-cite-minimum-match-count)
807 (setq gnus-cite-prefix-alist
808 (delq entry gnus-cite-prefix-alist)
809 gnus-cite-loose-prefix-alist
810 (delq entry gnus-cite-loose-prefix-alist)))))
811 ;; Find flat attributions.
812 (gnus-cite-match-attributions 'first t nil)
813 ;; Find any attributions (are we getting desperate yet?).
814 (gnus-cite-match-attributions 'first nil nil))
816 (defun gnus-cite-match-attributions (sort after fun)
817 ;; Match all loose attributions and citations (SORT AFTER FUN) .
819 ;; If SORT is `small', the citation with the shortest prefix will be
820 ;; used, if it is `first' the first prefix will be used, if it is
821 ;; `small-if-unique' the shortest prefix will be used if the
822 ;; attribution line does not share its own prefix with other
823 ;; loose attribution lines, otherwise the first prefix will be used.
825 ;; If AFTER is non-nil, only citations after the attribution line
826 ;; will be considered.
828 ;; If FUN is non-nil, it will be called with the arguments (WROTE
829 ;; PREFIX TAG) and expected to return a regular expression. Only
830 ;; citations whose prefix matches the regular expression will be
833 ;; WROTE is the attribution line number.
834 ;; PREFIX is the attribution line prefix.
835 ;; TAG is the Supercite tag on the attribution line.
836 (let ((atts gnus-cite-loose-attribution-alist)
838 att wrote in prefix tag regexp limit smallest best size)
846 regexp (if fun (funcall fun prefix tag) "")
847 size (cond ((eq sort 'small) t)
848 ((eq sort 'first) nil)
849 (t (< (length (gnus-cite-find-loose prefix)) 2)))
850 limit (if after wrote -1)
853 (let ((cites gnus-cite-loose-prefix-alist)
854 cite candidate numbers first compare)
856 (setq cite (car cites)
860 first (apply 'min numbers)
861 compare (if size (length candidate) first))
864 (string-match regexp candidate)
870 (setq gnus-cite-loose-attribution-alist
871 (delq att gnus-cite-loose-attribution-alist))
872 (push (cons wrote (car best)) gnus-cite-attribution-alist)
874 (push (cons in (car best)) gnus-cite-attribution-alist))
875 (when (memq best gnus-cite-loose-prefix-alist)
876 (let ((loop gnus-cite-prefix-alist)
879 (setq gnus-cite-loose-prefix-alist
880 (delq best gnus-cite-loose-prefix-alist))
882 (setq current (car loop)
884 (if (eq current best)
886 (setcdr current (gnus-set-difference (cdr current) numbers))
887 (when (null (cdr current))
888 (setq gnus-cite-loose-prefix-alist
889 (delq current gnus-cite-loose-prefix-alist)
890 atts (delq current atts)))))))))))
892 (defun gnus-cite-find-loose (prefix)
893 ;; Return a list of loose attribution lines prefixed by PREFIX.
894 (let* ((atts gnus-cite-loose-attribution-alist)
900 (when (string-equal (gnus-cite-find-prefix line) prefix)
904 (defun gnus-cite-add-face (number prefix face)
905 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
907 (let ((inhibit-point-motion-hooks t)
909 (goto-char (point-min))
910 (when (zerop (forward-line (1- number)))
911 (forward-char (length prefix))
912 (skip-chars-forward " \t")
915 (skip-chars-backward " \t")
918 (push (setq overlay (gnus-make-overlay from to))
919 gnus-cite-overlay-list)
920 (gnus-overlay-put overlay 'face face))))))
922 (defun gnus-cite-toggle (prefix)
924 (set-buffer gnus-article-buffer)
925 (gnus-cite-parse-maybe nil t)
926 (let ((buffer-read-only nil)
927 (numbers (cdr (assoc prefix gnus-cite-prefix-alist)))
928 (inhibit-point-motion-hooks t)
931 (setq number (car numbers)
932 numbers (cdr numbers))
933 (goto-char (point-min))
934 (forward-line (1- number))
935 (cond ((get-text-property (point) 'invisible)
936 (remove-text-properties (point) (progn (forward-line 1) (point))
937 gnus-hidden-properties))
938 ((assq number gnus-cite-attribution-alist))
940 (gnus-add-text-properties
941 (point) (progn (forward-line 1) (point))
942 (nconc (list 'article-type 'cite)
943 gnus-hidden-properties))))))))
945 (defun gnus-cite-find-prefix (line)
946 ;; Return citation prefix for LINE.
947 (let ((alist gnus-cite-prefix-alist)
951 (setq entry (car alist)
953 (when (memq line (cdr entry))
954 (setq prefix (car entry))))
957 (defun gnus-cite-localize ()
958 "Make the citation variables local to the article buffer."
959 (let ((vars '(gnus-cite-article
960 gnus-cite-overlay-list gnus-cite-prefix-alist
961 gnus-cite-attribution-alist gnus-cite-loose-prefix-alist
962 gnus-cite-loose-attribution-alist)))
964 (make-local-variable (pop vars)))))
971 ;; coding: iso-8859-1
974 ;;; gnus-cite.el ends here