1 ;;; gnus-cite.el --- parse citations in articles for Gnus
2 ;; Copyright (C) 1995,96,97 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.
34 (defgroup gnus-cite nil
37 :link
'(custom-manual "(gnus)Article Highlighting")
40 (defcustom gnus-cite-reply-regexp
41 "^\\(Subject: Re\\|In-Reply-To\\|References\\):"
42 "If headers match this regexp it is reasonable to believe that
43 article has citations."
47 (defcustom gnus-cite-always-check nil
48 "Check article always for citations. Set it t to check all articles."
50 :type
'(choice (const :tag
"no" nil
)
51 (const :tag
"yes" t
)))
53 (defcustom gnus-cited-text-button-line-format
"%(%{[...]%}%)\n"
54 "Format of cited text buttons."
58 (defcustom gnus-cited-lines-visible nil
59 "The number of lines of hidden cited text to remain visible."
61 :type
'(choice (const :tag
"none" nil
)
64 (defcustom gnus-cite-parse-max-size
25000
65 "Maximum article size (in bytes) where parsing citations is allowed.
66 Set it to nil to parse all articles."
68 :type
'(choice (const :tag
"all" nil
)
71 (defcustom gnus-cite-prefix-regexp
72 "^[]>|:}+ ]*[]>|:}+]\\(.*>\\)?\\|^.*>"
73 "Regexp matching the longest possible citation prefix on a line."
77 (defcustom gnus-cite-max-prefix
20
78 "Maximum possible length for a citation prefix."
82 (defcustom gnus-supercite-regexp
83 (concat "^\\(" gnus-cite-prefix-regexp
"\\)? *"
84 ">>>>> +\"\\([^\"\n]+\\)\" +==")
85 "Regexp matching normal Supercite attribution lines.
86 The first grouping must match prefixes added by other packages."
90 (defcustom gnus-supercite-secondary-regexp
"^.*\"\\([^\"\n]+\\)\" +=="
91 "Regexp matching mangled Supercite attribution lines.
92 The first regexp group should match the Supercite attribution."
96 (defcustom gnus-cite-minimum-match-count
2
97 "Minimum number of identical prefixes before we believe it's a citation."
101 (defcustom gnus-cite-attribution-prefix
"in article\\|in <"
102 "Regexp matching the beginning of an attribution line."
106 (defcustom gnus-cite-attribution-suffix
107 "\\(wrote\\|writes\\|said\\|says\\):[ \t]*$"
108 "Regexp matching the end of an attribution line.
109 The text matching the first grouping will be used as a button."
113 (defface gnus-cite-attribution-face
'((t
115 "Face used for attribution lines.")
117 (defcustom gnus-cite-attribution-face
'gnus-cite-attribution-face
118 "Face used for attribution lines.
119 It is merged with the face for the cited text belonging to the attribution."
123 (defface gnus-cite-face-1
'((((class color
)
125 (:foreground
"light blue"))
128 (:foreground
"MidnightBlue"))
133 (defface gnus-cite-face-2
'((((class color
)
135 (:foreground
"light cyan"))
138 (:foreground
"firebrick"))
143 (defface gnus-cite-face-3
'((((class color
)
145 (:foreground
"light yellow"))
148 (:foreground
"dark green"))
153 (defface gnus-cite-face-4
'((((class color
)
155 (:foreground
"light pink"))
158 (:foreground
"OrangeRed"))
163 (defface gnus-cite-face-5
'((((class color
)
165 (:foreground
"pale green"))
168 (:foreground
"dark khaki"))
173 (defface gnus-cite-face-6
'((((class color
)
175 (:foreground
"beige"))
178 (:foreground
"dark violet"))
183 (defface gnus-cite-face-7
'((((class color
)
185 (:foreground
"orange"))
188 (:foreground
"SteelBlue4"))
193 (defface gnus-cite-face-8
'((((class color
)
195 (:foreground
"magenta"))
198 (:foreground
"magenta"))
203 (defface gnus-cite-face-9
'((((class color
)
205 (:foreground
"violet"))
208 (:foreground
"violet"))
213 (defface gnus-cite-face-10
'((((class color
)
215 (:foreground
"medium purple"))
218 (:foreground
"medium purple"))
223 (defface gnus-cite-face-11
'((((class color
)
225 (:foreground
"turquoise"))
228 (:foreground
"turquoise"))
233 (defcustom gnus-cite-face-list
234 '(gnus-cite-face-1 gnus-cite-face-2 gnus-cite-face-3 gnus-cite-face-4
235 gnus-cite-face-5 gnus-cite-face-6 gnus-cite-face-7 gnus-cite-face-8
236 gnus-cite-face-9 gnus-cite-face-10 gnus-cite-face-11
)
237 "List of faces used for highlighting citations.
239 When there are citations from multiple articles in the same message,
240 Gnus will try to give each citation from each article its own face.
241 This should make it easier to see who wrote what."
243 :type
'(repeat face
))
245 (defcustom gnus-cite-hide-percentage
50
246 "Only hide excess citation if above this percentage of the body."
250 (defcustom gnus-cite-hide-absolute
10
251 "Only hide excess citation if above this number of lines in the body."
255 ;;; Internal Variables:
257 (defvar gnus-cite-article nil
)
259 (defvar gnus-cite-prefix-alist nil
)
260 ;; Alist of citation prefixes.
261 ;; The cdr is a list of lines with that prefix.
263 (defvar gnus-cite-attribution-alist nil
)
264 ;; Alist of attribution lines.
265 ;; The car is a line number.
266 ;; The cdr is the prefix for the citation started by that line.
268 (defvar gnus-cite-loose-prefix-alist nil
)
269 ;; Alist of citation prefixes that have no matching attribution.
270 ;; The cdr is a list of lines with that prefix.
272 (defvar gnus-cite-loose-attribution-alist nil
)
273 ;; Alist of attribution lines that have no matching citation.
274 ;; Each member has the form (WROTE IN PREFIX TAG), where
275 ;; WROTE: is the attribution line number
276 ;; IN: is the line number of the previous line if part of the same attribution,
277 ;; PREFIX: Is the citation prefix of the attribution line(s), and
278 ;; TAG: Is a Supercite tag, if any.
280 (defvar gnus-cited-text-button-line-format-alist
281 `((?b
(marker-position beg
) ?d
)
282 (?e
(marker-position end
) ?d
)
283 (?l
(- end beg
) ?d
)))
284 (defvar gnus-cited-text-button-line-format-spec nil
)
288 (defun gnus-article-highlight-citation (&optional force
)
289 "Highlight cited text.
290 Each citation in the article will be highlighted with a different face.
291 The faces are taken from `gnus-cite-face-list'.
292 Attribution lines are highlighted with the same face as the
293 corresponding citation merged with `gnus-cite-attribution-face'.
295 Text is considered cited if at least `gnus-cite-minimum-match-count'
296 lines matches `gnus-cite-prefix-regexp' with the same prefix.
298 Lines matching `gnus-cite-attribution-suffix' and perhaps
299 `gnus-cite-attribution-prefix' are considered attribution lines."
300 (interactive (list 'force
))
302 (set-buffer gnus-article-buffer
)
303 (gnus-cite-parse-maybe force
)
304 (let ((buffer-read-only nil
)
305 (alist gnus-cite-prefix-alist
)
306 (faces gnus-cite-face-list
)
307 (inhibit-point-motion-hooks t
)
308 face entry prefix skip numbers number face-alist
)
309 ;; Loop through citation prefixes.
311 (setq entry
(car alist
)
316 faces
(or (cdr faces
) gnus-cite-face-list
)
317 face-alist
(cons (cons prefix face
) face-alist
))
319 (setq number
(car numbers
)
320 numbers
(cdr numbers
))
321 (and (not (assq number gnus-cite-attribution-alist
))
322 (not (assq number gnus-cite-loose-attribution-alist
))
323 (gnus-cite-add-face number prefix face
))))
324 ;; Loop through attribution lines.
325 (setq alist gnus-cite-attribution-alist
)
327 (setq entry
(car alist
)
331 skip
(gnus-cite-find-prefix number
)
332 face
(cdr (assoc prefix face-alist
)))
333 ;; Add attribution button.
335 (when (re-search-forward gnus-cite-attribution-suffix
336 (save-excursion (end-of-line 1) (point))
338 (gnus-article-add-button (match-beginning 1) (match-end 1)
339 'gnus-cite-toggle prefix
))
340 ;; Highlight attribution line.
341 (gnus-cite-add-face number skip face
)
342 (gnus-cite-add-face number skip gnus-cite-attribution-face
))
343 ;; Loop through attribution lines.
344 (setq alist gnus-cite-loose-attribution-alist
)
346 (setq entry
(car alist
)
349 skip
(gnus-cite-find-prefix number
))
350 (gnus-cite-add-face number skip gnus-cite-attribution-face
)))))
352 (defun gnus-dissect-cited-text ()
353 "Dissect the article buffer looking for cited text."
355 (set-buffer gnus-article-buffer
)
356 (gnus-cite-parse-maybe)
357 (let ((alist gnus-cite-prefix-alist
)
358 prefix numbers number marks m
)
359 ;; Loop through citation prefixes.
361 (setq numbers
(pop alist
)
362 prefix
(pop numbers
))
364 (setq number
(pop numbers
))
365 (goto-char (point-min))
366 (forward-line number
)
367 (push (cons (point-marker) "") marks
)
369 (= (1- number
) (car numbers
)))
370 (setq number
(pop numbers
)))
371 (goto-char (point-min))
372 (forward-line (1- number
))
373 (push (cons (point-marker) prefix
) marks
)))
374 ;; Skip to the beginning of the body.
375 (goto-char (point-min))
376 (search-forward "\n\n" nil t
)
377 (push (cons (point-marker) "") marks
)
378 ;; Find the end of the body.
379 (goto-char (point-max))
380 (gnus-article-search-signature)
381 (push (cons (point-marker) "") marks
)
383 (setq marks
(sort marks
(lambda (m1 m2
) (< (car m1
) (car m2
)))))
384 (let ((omarks marks
))
387 (if (= (caar omarks
) (caadr omarks
))
389 (unless (equal (cdar omarks
) "")
390 (push (car omarks
) marks
))
391 (unless (equal (cdadr omarks
) "")
392 (push (cadr omarks
) marks
))
393 (unless (and (equal (cdar omarks
) "")
394 (equal (cdadr omarks
) "")
396 (setq omarks
(cdr omarks
))))
397 (push (car omarks
) marks
))
398 (setq omarks
(cdr omarks
)))
400 (push (car omarks
) marks
))
401 (setq marks
(setq m
(nreverse marks
)))
403 (if (and (equal (cdadr m
) "")
404 (equal (cdar m
) (cdaddr m
))
405 (goto-char (caadr m
))
407 (= (point) (caaddr m
)))
412 (defun gnus-article-fill-cited-article (&optional force width
)
413 "Do word wrapping in the current article.
414 If WIDTH (the numerical prefix), use that text width when filling."
415 (interactive (list t current-prefix-arg
))
417 (set-buffer gnus-article-buffer
)
418 (let ((buffer-read-only nil
)
419 (inhibit-point-motion-hooks t
)
420 (marks (gnus-dissect-cited-text))
421 (adaptive-fill-mode nil
)
423 (fill-column (if width
(prefix-numeric-value width
) fill-column
)))
427 (narrow-to-region (caar marks
) (caadr marks
))
428 (let ((adaptive-fill-regexp
429 (concat "^" (regexp-quote (cdar marks
)) " *"))
430 (fill-prefix (cdar marks
)))
431 (fill-region (point-min) (point-max)))
432 (set-marker (caar marks
) nil
)
433 (setq marks
(cdr marks
)))
435 (set-marker (caar marks
) nil
))
436 ;; All this information is now incorrect.
437 (setq gnus-cite-prefix-alist nil
438 gnus-cite-attribution-alist nil
439 gnus-cite-loose-prefix-alist nil
440 gnus-cite-loose-attribution-alist 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 (setq gnus-cited-text-button-line-format-spec
449 (gnus-parse-format gnus-cited-text-button-line-format
450 gnus-cited-text-button-line-format-alist t
))
452 (set-buffer gnus-article-buffer
)
454 ((gnus-article-check-hidden-text 'cite arg
)
456 ((gnus-article-text-type-exists-p 'cite
)
457 (let ((buffer-read-only nil
))
458 (gnus-article-hide-text-of-type 'cite
)))
460 (let ((buffer-read-only nil
)
461 (marks (gnus-dissect-cited-text))
462 (inhibit-point-motion-hooks t
)
463 (props (nconc (list 'article-type
'cite
)
464 gnus-hidden-properties
))
469 (while (and marks
(string= (cdar marks
) ""))
470 (setq marks
(cdr marks
)))
472 (setq beg
(caar marks
)))
473 (while (and marks
(not (string= (cdar marks
) "")))
474 (setq marks
(cdr marks
)))
476 (setq end
(caar marks
)))
477 ;; Skip past lines we want to leave visible.
478 (when (and beg end gnus-cited-lines-visible
)
480 (forward-line gnus-cited-lines-visible
)
483 (setq beg
(point-marker))))
485 (gnus-add-text-properties beg end props
)
487 (unless (save-excursion (search-backward "\n\n" nil t
))
492 (gnus-article-add-button
494 (progn (eval gnus-cited-text-button-line-format-spec
) (point))
495 `gnus-article-toggle-cited-text
(cons beg end
))
497 'article-type
'annotation
)
498 (set-marker beg
(point)))))))))
500 (defun gnus-article-toggle-cited-text (region)
501 "Toggle hiding the text in REGION."
502 (let (buffer-read-only)
504 (if (text-property-any
505 (car region
) (1- (cdr region
))
506 (car gnus-hidden-properties
) (cadr gnus-hidden-properties
))
507 'remove-text-properties
'gnus-add-text-properties
)
508 (car region
) (cdr region
) gnus-hidden-properties
)))
510 (defun gnus-article-hide-citation-maybe (&optional arg force
)
511 "Toggle hiding of cited text that has an attribution line.
512 If given a negative prefix, always show; if given a positive prefix,
514 This will do nothing unless at least `gnus-cite-hide-percentage'
515 percent and at least `gnus-cite-hide-absolute' lines of the body is
516 cited text with attributions. When called interactively, these two
517 variables are ignored.
518 See also the documentation for `gnus-article-highlight-citation'."
519 (interactive (append (gnus-article-hidden-arg) (list 'force
)))
520 (unless (gnus-article-check-hidden-text 'cite arg
)
522 (set-buffer gnus-article-buffer
)
523 (gnus-cite-parse-maybe force
)
524 (goto-char (point-min))
525 (search-forward "\n\n" nil t
)
526 (let ((start (point))
527 (atts gnus-cite-attribution-alist
)
528 (buffer-read-only nil
)
529 (inhibit-point-motion-hooks t
)
532 (goto-char (point-max))
533 (gnus-article-search-signature)
534 (setq total
(count-lines start
(point)))
536 (setq hiden
(+ hiden
(length (cdr (assoc (cdar atts
)
537 gnus-cite-prefix-alist
))))
540 (and (> (* 100 hiden
) (* gnus-cite-hide-percentage total
))
541 (> hiden gnus-cite-hide-absolute
)))
542 (setq atts gnus-cite-attribution-alist
)
544 (setq total
(cdr (assoc (cdar atts
) gnus-cite-prefix-alist
))
547 (setq hiden
(car total
)
550 (unless (assq hiden gnus-cite-attribution-alist
)
551 (gnus-add-text-properties
552 (point) (progn (forward-line 1) (point))
553 (nconc (list 'article-type
'cite
)
554 gnus-hidden-properties
))))))))))
556 (defun gnus-article-hide-citation-in-followups ()
557 "Hide cited text in non-root articles."
560 (set-buffer gnus-article-buffer
)
561 (let ((article (cdr gnus-article-current
)))
562 (unless (save-excursion
563 (set-buffer gnus-summary-buffer
)
564 (gnus-article-displayed-root-p article
))
565 (gnus-article-hide-citation)))))
567 ;;; Internal functions:
569 (defun gnus-cite-parse-maybe (&optional force
)
570 ;; Parse if the buffer has changes since last time.
571 (if (equal gnus-cite-article gnus-article-current
)
573 ;;Reset parser information.
574 (setq gnus-cite-prefix-alist nil
575 gnus-cite-attribution-alist nil
576 gnus-cite-loose-prefix-alist nil
577 gnus-cite-loose-attribution-alist nil
)
578 ;; Parse if not too large.
580 gnus-cite-parse-max-size
581 (> (buffer-size) gnus-cite-parse-max-size
))
583 (setq gnus-cite-article
(cons (car gnus-article-current
)
584 (cdr gnus-article-current
)))
585 (gnus-cite-parse-wrapper))))
587 (defun gnus-cite-parse-wrapper ()
588 ;; Wrap chopped gnus-cite-parse
589 (goto-char (point-min))
590 (unless (search-forward "\n\n" nil t
)
591 (goto-char (point-max)))
593 (gnus-cite-parse-attributions))
594 ;; Try to avoid check citation if there is no reason to believe
595 ;; that article has citations
596 (if (or gnus-cite-always-check
598 (re-search-backward gnus-cite-reply-regexp nil t
))
599 gnus-cite-loose-attribution-alist
)
600 (progn (save-excursion
603 (gnus-cite-connect-attributions)))))
605 (defun gnus-cite-parse ()
606 ;; Parse and connect citation prefixes and attribution lines.
608 ;; Parse current buffer searching for citation prefixes.
609 (let ((line (1+ (count-lines (point-min) (point))))
612 (goto-char (point-max))
613 (gnus-article-search-signature)
615 alist entry start begin end numbers prefix
)
616 ;; Get all potential prefixes in `alist'.
617 (while (< (point) max
)
620 end
(progn (beginning-of-line 2) (point))
623 ;; Ignore standard Supercite attribution prefix.
624 (when (looking-at gnus-supercite-regexp
)
626 (setq end
(1+ (match-end 1)))
627 (setq end
(1+ begin
))))
628 ;; Ignore very long prefixes.
629 (when (> end
(+ (point) gnus-cite-max-prefix
))
630 (setq end
(+ (point) gnus-cite-max-prefix
)))
631 (while (re-search-forward gnus-cite-prefix-regexp
(1- end
) t
)
633 (setq end
(match-end 0)
634 prefix
(buffer-substring begin end
))
635 (gnus-set-text-properties 0 (length prefix
) nil prefix
)
636 (setq entry
(assoc prefix alist
))
638 (setcdr entry
(cons line
(cdr entry
)))
639 (push (list prefix line
) alist
))
642 (setq line
(1+ line
)))
643 ;; We got all the potential prefixes. Now create
644 ;; `gnus-cite-prefix-alist' containing the oldest prefix for each
645 ;; line that appears at least gnus-cite-minimum-match-count
646 ;; times. First sort them by length. Longer is older.
647 (setq alist
(sort alist
(lambda (a b
)
648 (> (length (car a
)) (length (car b
))))))
650 (setq entry
(car alist
)
654 (cond ((null numbers
)
655 ;; No lines with this prefix that wasn't also part of
658 ((< (length numbers
) gnus-cite-minimum-match-count
)
659 ;; Too few lines with this prefix. We keep it a bit
660 ;; longer in case it is an exact match for an attribution
661 ;; line, but we don't remove the line from other
663 (push entry gnus-cite-prefix-alist
))
666 gnus-cite-prefix-alist
)
667 ;; Remove articles from other prefixes.
671 (setq current
(car loop
)
674 (gnus-set-difference (cdr current
) numbers
)))))))))
676 (defun gnus-cite-parse-attributions ()
678 ;; Parse attributions
679 (while (re-search-forward gnus-cite-attribution-suffix
(point-max) t
)
680 (let* ((start (match-beginning 0))
682 (wrote (count-lines (point-min) end
))
683 (prefix (gnus-cite-find-prefix wrote
))
684 ;; Check previous line for an attribution leader.
686 (beginning-of-line 1)
687 (when (looking-at gnus-supercite-secondary-regexp
)
688 (buffer-substring (match-beginning 1)
692 (and (re-search-backward gnus-cite-attribution-prefix
694 (beginning-of-line 0)
697 (not (re-search-forward gnus-cite-attribution-suffix
699 (count-lines (point-min) (1+ (point)))))))
703 ;; don't add duplicates
704 (let ((al (buffer-substring (save-excursion (beginning-of-line 0)
707 (if (not (assoc al al-alist
))
709 (push (list wrote in prefix tag
)
710 gnus-cite-loose-attribution-alist
)
711 (push (cons al t
) al-alist
))))))))
713 (defun gnus-cite-connect-attributions ()
714 ;; Connect attributions to citations
716 ;; No citations have been connected to attribution lines yet.
717 (setq gnus-cite-loose-prefix-alist
(append gnus-cite-prefix-alist nil
))
719 ;; Parse current buffer searching for attribution lines.
720 ;; Find exact supercite citations.
721 (gnus-cite-match-attributions 'small nil
725 (regexp-quote prefix
) "[ \t]*"
726 (regexp-quote tag
) ">"))))
727 ;; Find loose supercite citations after attributions.
728 (gnus-cite-match-attributions 'small t
734 ;; Find loose supercite citations anywhere.
735 (gnus-cite-match-attributions 'small nil
741 ;; Find nested citations after attributions.
742 (gnus-cite-match-attributions 'small-if-unique t
744 (concat "\\`" (regexp-quote prefix
) ".+")))
745 ;; Find nested citations anywhere.
746 (gnus-cite-match-attributions 'small nil
748 (concat "\\`" (regexp-quote prefix
) ".+")))
749 ;; Remove loose prefixes with too few lines.
750 (let ((alist gnus-cite-loose-prefix-alist
)
753 (setq entry
(car alist
)
755 (when (< (length (cdr entry
)) gnus-cite-minimum-match-count
)
756 (setq gnus-cite-prefix-alist
757 (delq entry gnus-cite-prefix-alist
)
758 gnus-cite-loose-prefix-alist
759 (delq entry gnus-cite-loose-prefix-alist
)))))
760 ;; Find flat attributions.
761 (gnus-cite-match-attributions 'first t nil
)
762 ;; Find any attributions (are we getting desperate yet?).
763 (gnus-cite-match-attributions 'first nil nil
))
765 (defun gnus-cite-match-attributions (sort after fun
)
766 ;; Match all loose attributions and citations (SORT AFTER FUN) .
768 ;; If SORT is `small', the citation with the shortest prefix will be
769 ;; used, if it is `first' the first prefix will be used, if it is
770 ;; `small-if-unique' the shortest prefix will be used if the
771 ;; attribution line does not share its own prefix with other
772 ;; loose attribution lines, otherwise the first prefix will be used.
774 ;; If AFTER is non-nil, only citations after the attribution line
775 ;; will be considered.
777 ;; If FUN is non-nil, it will be called with the arguments (WROTE
778 ;; PREFIX TAG) and expected to return a regular expression. Only
779 ;; citations whose prefix matches the regular expression will be
782 ;; WROTE is the attribution line number.
783 ;; PREFIX is the attribution line prefix.
784 ;; TAG is the Supercite tag on the attribution line.
785 (let ((atts gnus-cite-loose-attribution-alist
)
787 att wrote in prefix tag regexp limit smallest best size
)
795 regexp
(if fun
(funcall fun prefix tag
) "")
796 size
(cond ((eq sort
'small
) t
)
797 ((eq sort
'first
) nil
)
798 (t (< (length (gnus-cite-find-loose prefix
)) 2)))
799 limit
(if after wrote -
1)
802 (let ((cites gnus-cite-loose-prefix-alist
)
803 cite candidate numbers first compare
)
805 (setq cite
(car cites
)
809 first
(apply 'min numbers
)
810 compare
(if size
(length candidate
) first
))
813 (string-match regexp candidate
)
819 (setq gnus-cite-loose-attribution-alist
820 (delq att gnus-cite-loose-attribution-alist
))
821 (push (cons wrote
(car best
)) gnus-cite-attribution-alist
)
823 (push (cons in
(car best
)) gnus-cite-attribution-alist
))
824 (when (memq best gnus-cite-loose-prefix-alist
)
825 (let ((loop gnus-cite-prefix-alist
)
828 (setq gnus-cite-loose-prefix-alist
829 (delq best gnus-cite-loose-prefix-alist
))
831 (setq current
(car loop
)
833 (if (eq current best
)
835 (setcdr current
(gnus-set-difference (cdr current
) numbers
))
836 (when (null (cdr current
))
837 (setq gnus-cite-loose-prefix-alist
838 (delq current gnus-cite-loose-prefix-alist
)
839 atts
(delq current atts
)))))))))))
841 (defun gnus-cite-find-loose (prefix)
842 ;; Return a list of loose attribution lines prefixed by PREFIX.
843 (let* ((atts gnus-cite-loose-attribution-alist
)
849 (when (string-equal (gnus-cite-find-prefix line
) prefix
)
853 (defun gnus-cite-add-face (number prefix face
)
854 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
856 (let ((inhibit-point-motion-hooks t
)
859 (unless (eobp);; Sometimes things become confused.
860 (forward-char (length prefix
))
861 (skip-chars-forward " \t")
864 (skip-chars-backward " \t")
867 (gnus-overlay-put (gnus-make-overlay from to
) 'face face
))))))
869 (defun gnus-cite-toggle (prefix)
871 (set-buffer gnus-article-buffer
)
872 (let ((buffer-read-only nil
)
873 (numbers (cdr (assoc prefix gnus-cite-prefix-alist
)))
874 (inhibit-point-motion-hooks t
)
877 (setq number
(car numbers
)
878 numbers
(cdr numbers
))
880 (cond ((get-text-property (point) 'invisible
)
881 (remove-text-properties (point) (progn (forward-line 1) (point))
882 gnus-hidden-properties
))
883 ((assq number gnus-cite-attribution-alist
))
885 (gnus-add-text-properties
886 (point) (progn (forward-line 1) (point))
887 (nconc (list 'article-type
'cite
)
888 gnus-hidden-properties
))))))))
890 (defun gnus-cite-find-prefix (line)
891 ;; Return citation prefix for LINE.
892 (let ((alist gnus-cite-prefix-alist
)
896 (setq entry
(car alist
)
898 (when (memq line
(cdr entry
))
899 (setq prefix
(car entry
))))
902 (gnus-add-shutdown 'gnus-cache-close
'gnus
)
904 (defun gnus-cache-close ()
905 (setq gnus-cite-prefix-alist nil
))
911 ;;; gnus-cite.el ends here