1 ;;; gnus-cite.el --- parse citations in articles for Gnus -*- coding: iso-latin-1 -*-
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
4 ;; Free Software Foundation, Inc.
6 ;; Author: Per Abhiddenware
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl
))
37 (defgroup gnus-cite nil
40 :link
'(custom-manual "(gnus)Article Highlighting")
43 (defcustom gnus-cite-reply-regexp
44 "^\\(Subject: Re\\|In-Reply-To\\|References\\):"
45 "*If headers match this regexp it is reasonable to believe that
46 article has citations."
50 (defcustom gnus-cite-always-check nil
51 "Check article always for citations. Set it t to check all articles."
53 :type
'(choice (const :tag
"no" nil
)
54 (const :tag
"yes" t
)))
56 (defcustom gnus-cited-opened-text-button-line-format
"%(%{[-]%}%)\n"
57 "Format of opened cited text buttons."
61 (defcustom gnus-cited-closed-text-button-line-format
"%(%{[+]%}%)\n"
62 "Format of closed cited text buttons."
66 (defcustom gnus-cited-lines-visible nil
67 "The number of lines of hidden cited text to remain visible.
68 Or a pair (cons) of numbers which are the number of lines at the top
69 and bottom of the text, respectively, to remain visible."
71 :type
'(choice (const :tag
"none" nil
)
73 (cons :tag
"Top and Bottom" integer integer
)))
75 (defcustom gnus-cite-parse-max-size
25000
76 "Maximum article size (in bytes) where parsing citations is allowed.
77 Set it to nil to parse all articles."
79 :type
'(choice (const :tag
"all" nil
)
82 (defcustom gnus-cite-prefix-regexp
83 ;; The Latin-1 angle quote looks pretty dubious. -- fx
84 "^[]>»|:}+ ]*[]>»|:}+]\\(.*>»\\)?\\|^.*>"
85 "*Regexp matching the longest possible citation prefix on a line."
89 (defcustom gnus-cite-max-prefix
20
90 "Maximum possible length for a citation prefix."
94 (defcustom gnus-supercite-regexp
95 (concat "^\\(" gnus-cite-prefix-regexp
"\\)? *"
96 ">>>>> +\"\\([^\"\n]+\\)\" +==")
97 "*Regexp matching normal Supercite attribution lines.
98 The first grouping must match prefixes added by other packages."
102 (defcustom gnus-supercite-secondary-regexp
"^.*\"\\([^\"\n]+\\)\" +=="
103 "Regexp matching mangled Supercite attribution lines.
104 The first regexp group should match the Supercite attribution."
108 (defcustom gnus-cite-minimum-match-count
2
109 "Minimum number of identical prefixes before we believe it's a citation."
113 (defcustom gnus-cite-attribution-prefix
114 "In article\\|in <\\|On \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\),\\|-----Original Message-----"
115 "*Regexp matching the beginning of an attribution line."
119 (defcustom gnus-cite-attribution-suffix
120 "\\(\\(wrote\\|writes\\|said\\|says\\|>\\)\\(:\\|\\.\\.\\.\\)\\|-----Original Message-----\\)[ \t]*$"
121 "*Regexp matching the end of an attribution line.
122 The text matching the first grouping will be used as a button."
126 (defface gnus-cite-attribution-face
'((t
128 "Face used for attribution lines.")
130 (defcustom gnus-cite-attribution-face
'gnus-cite-attribution-face
131 "Face used for attribution lines.
132 It is merged with the face for the cited text belonging to the attribution."
136 (defface gnus-cite-face-1
'((((class color
)
138 (:foreground
"light blue"))
141 (:foreground
"MidnightBlue"))
146 (defface gnus-cite-face-2
'((((class color
)
148 (:foreground
"light cyan"))
151 (:foreground
"firebrick"))
156 (defface gnus-cite-face-3
'((((class color
)
158 (:foreground
"light yellow"))
161 (:foreground
"dark green"))
166 (defface gnus-cite-face-4
'((((class color
)
168 (:foreground
"light pink"))
171 (:foreground
"OrangeRed"))
176 (defface gnus-cite-face-5
'((((class color
)
178 (:foreground
"pale green"))
181 (:foreground
"dark khaki"))
186 (defface gnus-cite-face-6
'((((class color
)
188 (:foreground
"beige"))
191 (:foreground
"dark violet"))
196 (defface gnus-cite-face-7
'((((class color
)
198 (:foreground
"orange"))
201 (:foreground
"SteelBlue4"))
206 (defface gnus-cite-face-8
'((((class color
)
208 (:foreground
"magenta"))
211 (:foreground
"magenta"))
216 (defface gnus-cite-face-9
'((((class color
)
218 (:foreground
"violet"))
221 (:foreground
"violet"))
226 (defface gnus-cite-face-10
'((((class color
)
228 (:foreground
"medium purple"))
231 (:foreground
"medium purple"))
236 (defface gnus-cite-face-11
'((((class color
)
238 (:foreground
"turquoise"))
241 (:foreground
"turquoise"))
246 (defcustom gnus-cite-face-list
247 '(gnus-cite-face-1 gnus-cite-face-2 gnus-cite-face-3 gnus-cite-face-4
248 gnus-cite-face-5 gnus-cite-face-6 gnus-cite-face-7 gnus-cite-face-8
249 gnus-cite-face-9 gnus-cite-face-10 gnus-cite-face-11
)
250 "*List of faces used for highlighting citations.
252 When there are citations from multiple articles in the same message,
253 Gnus will try to give each citation from each article its own face.
254 This should make it easier to see who wrote what."
256 :type
'(repeat face
))
258 (defcustom gnus-cite-hide-percentage
50
259 "Only hide excess citation if above this percentage of the body."
263 (defcustom gnus-cite-hide-absolute
10
264 "Only hide excess citation if above this number of lines in the body."
268 ;;; Internal Variables:
270 (defvar gnus-cite-article nil
)
271 (defvar gnus-cite-overlay-list nil
)
273 (defvar gnus-cite-prefix-alist nil
)
274 ;; Alist of citation prefixes.
275 ;; The cdr is a list of lines with that prefix.
277 (defvar gnus-cite-attribution-alist nil
)
278 ;; Alist of attribution lines.
279 ;; The car is a line number.
280 ;; The cdr is the prefix for the citation started by that line.
282 (defvar gnus-cite-loose-prefix-alist nil
)
283 ;; Alist of citation prefixes that have no matching attribution.
284 ;; The cdr is a list of lines with that prefix.
286 (defvar gnus-cite-loose-attribution-alist nil
)
287 ;; Alist of attribution lines that have no matching citation.
288 ;; Each member has the form (WROTE IN PREFIX TAG), where
289 ;; WROTE: is the attribution line number
290 ;; IN: is the line number of the previous line if part of the same attribution,
291 ;; PREFIX: Is the citation prefix of the attribution line(s), and
292 ;; TAG: Is a Supercite tag, if any.
294 (defvar gnus-cited-opened-text-button-line-format-alist
295 `((?b
(marker-position beg
) ?d
)
296 (?e
(marker-position end
) ?d
)
297 (?n
(count-lines beg end
) ?d
)
298 (?l
(- end beg
) ?d
)))
299 (defvar gnus-cited-opened-text-button-line-format-spec nil
)
300 (defvar gnus-cited-closed-text-button-line-format-alist
301 gnus-cited-opened-text-button-line-format-alist
)
302 (defvar gnus-cited-closed-text-button-line-format-spec nil
)
307 (defun gnus-article-highlight-citation (&optional force
)
308 "Highlight cited text.
309 Each citation in the article will be highlighted with a different face.
310 The faces are taken from `gnus-cite-face-list'.
311 Attribution lines are highlighted with the same face as the
312 corresponding citation merged with `gnus-cite-attribution-face'.
314 Text is considered cited if at least `gnus-cite-minimum-match-count'
315 lines matches `gnus-cite-prefix-regexp' with the same prefix.
317 Lines matching `gnus-cite-attribution-suffix' and perhaps
318 `gnus-cite-attribution-prefix' are considered attribution lines."
319 (interactive (list 'force
))
321 (set-buffer gnus-article-buffer
)
322 (gnus-cite-parse-maybe force
)
323 (let ((buffer-read-only nil
)
324 (alist gnus-cite-prefix-alist
)
325 (faces gnus-cite-face-list
)
326 (inhibit-point-motion-hooks t
)
327 face entry prefix skip numbers number face-alist
)
328 ;; Loop through citation prefixes.
330 (setq entry
(car alist
)
335 faces
(or (cdr faces
) gnus-cite-face-list
)
336 face-alist
(cons (cons prefix face
) face-alist
))
338 (setq number
(car numbers
)
339 numbers
(cdr numbers
))
340 (and (not (assq number gnus-cite-attribution-alist
))
341 (not (assq number gnus-cite-loose-attribution-alist
))
342 (gnus-cite-add-face number prefix face
))))
343 ;; Loop through attribution lines.
344 (setq alist gnus-cite-attribution-alist
)
346 (setq entry
(car alist
)
350 skip
(gnus-cite-find-prefix number
)
351 face
(cdr (assoc prefix face-alist
)))
352 ;; Add attribution button.
353 (goto-char (point-min))
354 (forward-line (1- number
))
355 (when (re-search-forward gnus-cite-attribution-suffix
356 (save-excursion (end-of-line 1) (point))
358 (gnus-article-add-button (match-beginning 1) (match-end 1)
359 'gnus-cite-toggle prefix
))
360 ;; Highlight attribution line.
361 (gnus-cite-add-face number skip face
)
362 (gnus-cite-add-face number skip gnus-cite-attribution-face
))
363 ;; Loop through attribution lines.
364 (setq alist gnus-cite-loose-attribution-alist
)
366 (setq entry
(car alist
)
369 skip
(gnus-cite-find-prefix number
))
370 (gnus-cite-add-face number skip gnus-cite-attribution-face
)))))
372 (defun gnus-dissect-cited-text ()
373 "Dissect the article buffer looking for cited text."
375 (set-buffer gnus-article-buffer
)
376 (gnus-cite-parse-maybe nil t
)
377 (let ((alist gnus-cite-prefix-alist
)
378 prefix numbers number marks m
)
379 ;; Loop through citation prefixes.
381 (setq numbers
(pop alist
)
382 prefix
(pop numbers
))
384 (setq number
(pop numbers
))
385 (goto-char (point-min))
386 (forward-line number
)
387 (push (cons (point-marker) "") marks
)
389 (= (1- number
) (car numbers
)))
390 (setq number
(pop numbers
)))
391 (goto-char (point-min))
392 (forward-line (1- number
))
393 (push (cons (point-marker) prefix
) marks
)))
394 ;; Skip to the beginning of the body.
396 (push (cons (point-marker) "") marks
)
397 ;; Find the end of the body.
398 (goto-char (point-max))
399 (gnus-article-search-signature)
400 (push (cons (point-marker) "") marks
)
402 (setq marks
(sort marks
'car-less-than-car
))
403 (let ((omarks marks
))
406 (if (= (caar omarks
) (caadr omarks
))
408 (unless (equal (cdar omarks
) "")
409 (push (car omarks
) marks
))
410 (unless (equal (cdadr omarks
) "")
411 (push (cadr omarks
) marks
))
412 (unless (and (equal (cdar omarks
) "")
413 (equal (cdadr omarks
) "")
415 (setq omarks
(cdr omarks
))))
416 (push (car omarks
) marks
))
417 (setq omarks
(cdr omarks
)))
419 (push (car omarks
) marks
))
420 (setq marks
(setq m
(nreverse marks
)))
422 (if (and (equal (cdadr m
) "")
423 (equal (cdar m
) (cdaddr m
))
424 (goto-char (caadr m
))
426 (= (point) (caaddr m
)))
431 (defun gnus-article-fill-cited-article (&optional force width
)
432 "Do word wrapping in the current article.
433 If WIDTH (the numerical prefix), use that text width when filling."
434 (interactive (list t current-prefix-arg
))
436 (set-buffer gnus-article-buffer
)
437 (let ((buffer-read-only nil
)
438 (inhibit-point-motion-hooks t
)
439 (marks (gnus-dissect-cited-text))
440 (adaptive-fill-mode nil
)
442 (fill-column (if width
(prefix-numeric-value width
) fill-column
)))
445 (narrow-to-region (caar marks
) (caadr marks
))
446 (let ((adaptive-fill-regexp
447 (concat "^" (regexp-quote (cdar marks
)) " *"))
448 (fill-prefix (cdar marks
)))
449 (fill-region (point-min) (point-max)))
450 (set-marker (caar marks
) nil
)
451 (setq marks
(cdr marks
)))
453 (set-marker (caar marks
) nil
))
454 ;; All this information is now incorrect.
455 (setq gnus-cite-prefix-alist nil
456 gnus-cite-attribution-alist nil
457 gnus-cite-loose-prefix-alist nil
458 gnus-cite-loose-attribution-alist nil
459 gnus-cite-article nil
)))))
461 (defun gnus-article-hide-citation (&optional arg force
)
462 "Toggle hiding of all cited text except attribution lines.
463 See the documentation for `gnus-article-highlight-citation'.
464 If given a negative prefix, always show; if given a positive prefix,
466 (interactive (append (gnus-article-hidden-arg) (list 'force
)))
467 (gnus-set-format 'cited-opened-text-button t
)
468 (gnus-set-format 'cited-closed-text-button t
)
470 (set-buffer gnus-article-buffer
)
471 (let ((buffer-read-only nil
)
473 (inhibit-point-motion-hooks t
)
474 (props (nconc (list 'article-type
'cite
)
475 gnus-hidden-properties
))
479 (text-property-any point
(point-max)
481 'gnus-article-toggle-cited-text
))
484 (gnus-article-toggle-cited-text
485 (get-text-property point
'gnus-data
) arg
)
487 (setq point
(point)))
489 (setq marks
(gnus-dissect-cited-text))
493 (while (and marks
(string= (cdar marks
) ""))
494 (setq marks
(cdr marks
)))
496 (setq beg
(caar marks
)))
497 (while (and marks
(not (string= (cdar marks
) "")))
498 (setq marks
(cdr marks
)))
500 (setq end
(caar marks
)))
501 ;; Skip past lines we want to leave visible.
502 (when (and beg end gnus-cited-lines-visible
)
504 (forward-line (if (consp gnus-cited-lines-visible
)
505 (car gnus-cited-lines-visible
)
506 gnus-cited-lines-visible
))
509 (setq beg
(point-marker))
510 (when (consp gnus-cited-lines-visible
)
512 (forward-line (- (cdr gnus-cited-lines-visible
)))
515 (setq end
(point-marker))))))
517 ;; We use markers for the end-points to facilitate later
518 ;; wrapping and mangling of text.
519 (setq beg
(set-marker (make-marker) beg
)
520 end
(set-marker (make-marker) end
))
521 (gnus-add-text-properties-when 'article-type nil beg end props
)
523 (unless (save-excursion (search-backward "\n\n" nil t
))
526 (setq start
(point-marker))
528 (gnus-article-add-button
530 (progn (eval gnus-cited-closed-text-button-line-format-spec
)
532 `gnus-article-toggle-cited-text
533 (list (cons beg end
) start
))
535 'article-type
'annotation
)
536 (set-marker beg
(point))))))))
538 (defun gnus-article-toggle-cited-text (args &optional arg
)
539 "Toggle hiding the text in REGION.
540 ARG can be nil or a number. Positive means hide, negative
541 means show, nil means toggle."
542 (let* ((region (car args
))
547 (text-property-any beg
(1- end
) 'article-type
'cite
))
548 (inhibit-point-motion-hooks t
)
552 (and (> arg
0) (not hidden
))
553 (and (< arg
0) hidden
))
555 (gnus-remove-text-properties-when
556 'article-type
'cite beg end
557 (cons 'article-type
(cons 'cite
558 gnus-hidden-properties
)))
559 (gnus-add-text-properties-when
560 'article-type nil beg end
561 (cons 'article-type
(cons 'cite
562 gnus-hidden-properties
))))
569 (gnus-article-add-button
573 gnus-cited-opened-text-button-line-format-spec
574 gnus-cited-closed-text-button-line-format-spec
))
576 `gnus-article-toggle-cited-text
579 'article-type
'annotation
)))))
581 (defun gnus-article-hide-citation-maybe (&optional arg force
)
582 "Toggle hiding of cited text that has an attribution line.
583 If given a negative prefix, always show; if given a positive prefix,
585 This will do nothing unless at least `gnus-cite-hide-percentage'
586 percent and at least `gnus-cite-hide-absolute' lines of the body is
587 cited text with attributions. When called interactively, these two
588 variables are ignored.
589 See also the documentation for `gnus-article-highlight-citation'."
590 (interactive (append (gnus-article-hidden-arg) '(force)))
591 (unless (gnus-article-check-hidden-text 'cite arg
)
593 (set-buffer gnus-article-buffer
)
594 (gnus-cite-parse-maybe force
)
596 (let ((start (point))
597 (atts gnus-cite-attribution-alist
)
598 (buffer-read-only nil
)
599 (inhibit-point-motion-hooks t
)
602 (goto-char (point-max))
603 (gnus-article-search-signature)
604 (setq total
(count-lines start
(point)))
606 (setq hidden
(+ hidden
(length (cdr (assoc (cdar atts
)
607 gnus-cite-prefix-alist
))))
610 (and (> (* 100 hidden
) (* gnus-cite-hide-percentage total
))
611 (> hidden gnus-cite-hide-absolute
)))
612 (setq atts gnus-cite-attribution-alist
)
614 (setq total
(cdr (assoc (cdar atts
) gnus-cite-prefix-alist
))
617 (setq hidden
(car total
)
619 (goto-char (point-min))
620 (forward-line (1- hidden
))
621 (unless (assq hidden gnus-cite-attribution-alist
)
622 (gnus-add-text-properties
623 (point) (progn (forward-line 1) (point))
624 (nconc (list 'article-type
'cite
)
625 gnus-hidden-properties
))))))))))
627 (defun gnus-article-hide-citation-in-followups ()
628 "Hide cited text in non-root articles."
631 (set-buffer gnus-article-buffer
)
632 (let ((article (cdr gnus-article-current
)))
633 (unless (save-excursion
634 (set-buffer gnus-summary-buffer
)
635 (gnus-article-displayed-root-p article
))
636 (gnus-article-hide-citation)))))
638 ;;; Internal functions:
640 (defun gnus-cite-parse-maybe (&optional force no-overlay
)
641 "Always parse the buffer."
643 ;;Reset parser information.
644 (setq gnus-cite-prefix-alist nil
645 gnus-cite-attribution-alist nil
646 gnus-cite-loose-prefix-alist nil
647 gnus-cite-loose-attribution-alist nil
)
649 (gnus-cite-delete-overlays))
650 ;; Parse if not too large.
651 (if (and gnus-cite-parse-max-size
652 (> (buffer-size) gnus-cite-parse-max-size
))
654 (setq gnus-cite-article
(cons (car gnus-article-current
)
655 (cdr gnus-article-current
)))
656 (gnus-cite-parse-wrapper)))
658 (defun gnus-cite-delete-overlays ()
659 (dolist (overlay gnus-cite-overlay-list
)
660 (when (or (not (gnus-overlay-end overlay
))
661 (and (>= (gnus-overlay-end overlay
) (point-min))
662 (<= (gnus-overlay-end overlay
) (point-max))))
663 (setq gnus-cite-overlay-list
(delete overlay gnus-cite-overlay-list
))
664 (gnus-delete-overlay overlay
))))
666 (defun gnus-cite-parse-wrapper ()
667 ;; Wrap chopped gnus-cite-parse.
669 (let ((inhibit-point-motion-hooks t
))
671 (gnus-cite-parse-attributions))
675 (gnus-cite-connect-attributions))))
677 (defun gnus-cite-parse ()
678 ;; Parse and connect citation prefixes and attribution lines.
680 ;; Parse current buffer searching for citation prefixes.
681 (let ((line (1+ (count-lines (point-min) (point))))
684 (goto-char (point-max))
685 (gnus-article-search-signature)
687 alist entry start begin end numbers prefix
)
688 ;; Get all potential prefixes in `alist'.
689 (while (< (point) max
)
692 end
(progn (beginning-of-line 2) (point))
695 ;; Ignore standard Supercite attribution prefix.
696 (when (looking-at gnus-supercite-regexp
)
698 (setq end
(1+ (match-end 1)))
699 (setq end
(1+ begin
))))
700 ;; Ignore very long prefixes.
701 (when (> end
(+ (point) gnus-cite-max-prefix
))
702 (setq end
(+ (point) gnus-cite-max-prefix
)))
703 (while (re-search-forward gnus-cite-prefix-regexp
(1- end
) t
)
705 (setq end
(match-end 0)
706 prefix
(buffer-substring begin end
))
707 (gnus-set-text-properties 0 (length prefix
) nil prefix
)
708 (setq entry
(assoc prefix alist
))
710 (setcdr entry
(cons line
(cdr entry
)))
711 (push (list prefix line
) alist
))
714 (setq line
(1+ line
)))
715 ;; We got all the potential prefixes. Now create
716 ;; `gnus-cite-prefix-alist' containing the oldest prefix for each
717 ;; line that appears at least gnus-cite-minimum-match-count
718 ;; times. First sort them by length. Longer is older.
719 (setq alist
(sort alist
(lambda (a b
)
720 (> (length (car a
)) (length (car b
))))))
722 (setq entry
(car alist
)
726 (cond ((null numbers
)
727 ;; No lines with this prefix that wasn't also part of
730 ((< (length numbers
) gnus-cite-minimum-match-count
)
731 ;; Too few lines with this prefix. We keep it a bit
732 ;; longer in case it is an exact match for an attribution
733 ;; line, but we don't remove the line from other
735 (push entry gnus-cite-prefix-alist
))
738 gnus-cite-prefix-alist
)
739 ;; Remove articles from other prefixes.
743 (setq current
(car loop
)
746 (gnus-set-difference (cdr current
) numbers
)))))))))
748 (defun gnus-cite-parse-attributions ()
750 ;; Parse attributions
751 (while (re-search-forward gnus-cite-attribution-suffix
(point-max) t
)
752 (let* ((start (match-beginning 0))
754 (wrote (count-lines (point-min) end
))
755 (prefix (gnus-cite-find-prefix wrote
))
756 ;; Check previous line for an attribution leader.
758 (beginning-of-line 1)
759 (when (looking-at gnus-supercite-secondary-regexp
)
760 (buffer-substring (match-beginning 1)
764 (and (re-search-backward gnus-cite-attribution-prefix
766 (beginning-of-line 0)
769 (not (re-search-forward gnus-cite-attribution-suffix
771 (count-lines (point-min) (1+ (point)))))))
775 ;; don't add duplicates
776 (let ((al (buffer-substring (save-excursion (beginning-of-line 0)
779 (if (not (assoc al al-alist
))
781 (push (list wrote in prefix tag
)
782 gnus-cite-loose-attribution-alist
)
783 (push (cons al t
) al-alist
))))))))
785 (defun gnus-cite-connect-attributions ()
786 ;; Connect attributions to citations
788 ;; No citations have been connected to attribution lines yet.
789 (setq gnus-cite-loose-prefix-alist
(append gnus-cite-prefix-alist nil
))
791 ;; Parse current buffer searching for attribution lines.
792 ;; Find exact supercite citations.
793 (gnus-cite-match-attributions 'small nil
797 (regexp-quote prefix
) "[ \t]*"
798 (regexp-quote tag
) ">"))))
799 ;; Find loose supercite citations after attributions.
800 (gnus-cite-match-attributions 'small t
806 ;; Find loose supercite citations anywhere.
807 (gnus-cite-match-attributions 'small nil
813 ;; Find nested citations after attributions.
814 (gnus-cite-match-attributions 'small-if-unique t
816 (concat "\\`" (regexp-quote prefix
) ".+")))
817 ;; Find nested citations anywhere.
818 (gnus-cite-match-attributions 'small nil
820 (concat "\\`" (regexp-quote prefix
) ".+")))
821 ;; Remove loose prefixes with too few lines.
822 (let ((alist gnus-cite-loose-prefix-alist
)
825 (setq entry
(car alist
)
827 (when (< (length (cdr entry
)) gnus-cite-minimum-match-count
)
828 (setq gnus-cite-prefix-alist
829 (delq entry gnus-cite-prefix-alist
)
830 gnus-cite-loose-prefix-alist
831 (delq entry gnus-cite-loose-prefix-alist
)))))
832 ;; Find flat attributions.
833 (gnus-cite-match-attributions 'first t nil
)
834 ;; Find any attributions (are we getting desperate yet?).
835 (gnus-cite-match-attributions 'first nil nil
))
837 (defun gnus-cite-match-attributions (sort after fun
)
838 ;; Match all loose attributions and citations (SORT AFTER FUN) .
840 ;; If SORT is `small', the citation with the shortest prefix will be
841 ;; used, if it is `first' the first prefix will be used, if it is
842 ;; `small-if-unique' the shortest prefix will be used if the
843 ;; attribution line does not share its own prefix with other
844 ;; loose attribution lines, otherwise the first prefix will be used.
846 ;; If AFTER is non-nil, only citations after the attribution line
847 ;; will be considered.
849 ;; If FUN is non-nil, it will be called with the arguments (WROTE
850 ;; PREFIX TAG) and expected to return a regular expression. Only
851 ;; citations whose prefix matches the regular expression will be
854 ;; WROTE is the attribution line number.
855 ;; PREFIX is the attribution line prefix.
856 ;; TAG is the Supercite tag on the attribution line.
857 (let ((atts gnus-cite-loose-attribution-alist
)
859 att wrote in prefix tag regexp limit smallest best size
)
867 regexp
(if fun
(funcall fun prefix tag
) "")
868 size
(cond ((eq sort
'small
) t
)
869 ((eq sort
'first
) nil
)
870 (t (< (length (gnus-cite-find-loose prefix
)) 2)))
871 limit
(if after wrote -
1)
874 (let ((cites gnus-cite-loose-prefix-alist
)
875 cite candidate numbers first compare
)
877 (setq cite
(car cites
)
881 first
(apply 'min numbers
)
882 compare
(if size
(length candidate
) first
))
885 (string-match regexp candidate
)
891 (setq gnus-cite-loose-attribution-alist
892 (delq att gnus-cite-loose-attribution-alist
))
893 (push (cons wrote
(car best
)) gnus-cite-attribution-alist
)
895 (push (cons in
(car best
)) gnus-cite-attribution-alist
))
896 (when (memq best gnus-cite-loose-prefix-alist
)
897 (let ((loop gnus-cite-prefix-alist
)
900 (setq gnus-cite-loose-prefix-alist
901 (delq best gnus-cite-loose-prefix-alist
))
903 (setq current
(car loop
)
905 (if (eq current best
)
907 (setcdr current
(gnus-set-difference (cdr current
) numbers
))
908 (when (null (cdr current
))
909 (setq gnus-cite-loose-prefix-alist
910 (delq current gnus-cite-loose-prefix-alist
)
911 atts
(delq current atts
)))))))))))
913 (defun gnus-cite-find-loose (prefix)
914 ;; Return a list of loose attribution lines prefixed by PREFIX.
915 (let* ((atts gnus-cite-loose-attribution-alist
)
921 (when (string-equal (gnus-cite-find-prefix line
) prefix
)
925 (defun gnus-cite-add-face (number prefix face
)
926 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
928 (let ((inhibit-point-motion-hooks t
)
930 (goto-char (point-min))
931 (when (zerop (forward-line (1- number
)))
932 (forward-char (length prefix
))
933 (skip-chars-forward " \t")
936 (skip-chars-backward " \t")
939 (push (setq overlay
(gnus-make-overlay from to
))
940 gnus-cite-overlay-list
)
941 (gnus-overlay-put overlay
'face face
))))))
943 (defun gnus-cite-toggle (prefix)
945 (set-buffer gnus-article-buffer
)
946 (gnus-cite-parse-maybe nil t
)
947 (let ((buffer-read-only nil
)
948 (numbers (cdr (assoc prefix gnus-cite-prefix-alist
)))
949 (inhibit-point-motion-hooks t
)
952 (setq number
(car numbers
)
953 numbers
(cdr numbers
))
954 (goto-char (point-min))
955 (forward-line (1- number
))
956 (cond ((get-text-property (point) 'invisible
)
957 (remove-text-properties (point) (progn (forward-line 1) (point))
958 gnus-hidden-properties
))
959 ((assq number gnus-cite-attribution-alist
))
961 (gnus-add-text-properties
962 (point) (progn (forward-line 1) (point))
963 (nconc (list 'article-type
'cite
)
964 gnus-hidden-properties
))))))))
966 (defun gnus-cite-find-prefix (line)
967 ;; Return citation prefix for LINE.
968 (let ((alist gnus-cite-prefix-alist
)
972 (setq entry
(car alist
)
974 (when (memq line
(cdr entry
))
975 (setq prefix
(car entry
))))
978 (defun gnus-cite-localize ()
979 "Make the citation variables local to the article buffer."
980 (let ((vars '(gnus-cite-article
981 gnus-cite-overlay-list gnus-cite-prefix-alist
982 gnus-cite-attribution-alist gnus-cite-loose-prefix-alist
983 gnus-cite-loose-attribution-alist
)))
985 (make-local-variable (pop vars
)))))
992 ;; coding: iso-8859-1
995 ;;; gnus-cite.el ends here