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 "^[]>»|:}+ ]*[]>»|:}+]\\(.*>»\\)?\\|^.*>"
84 "*Regexp matching the longest possible citation prefix on a line."
88 (defcustom gnus-cite-max-prefix 20
89 "Maximum possible length for a citation prefix."
93 (defcustom gnus-supercite-regexp
94 (concat "^\\(" gnus-cite-prefix-regexp "\\)? *"
95 ">>>>> +\"\\([^\"\n]+\\)\" +==")
96 "*Regexp matching normal Supercite attribution lines.
97 The first grouping must match prefixes added by other packages."
101 (defcustom gnus-supercite-secondary-regexp "^.*\"\\([^\"\n]+\\)\" +=="
102 "Regexp matching mangled Supercite attribution lines.
103 The first regexp group should match the Supercite attribution."
107 (defcustom gnus-cite-minimum-match-count 2
108 "Minimum number of identical prefixes before we believe it's a citation."
112 (defcustom gnus-cite-attribution-prefix
113 "In article\\|in <\\|On \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\),\\|-----Original Message-----"
114 "*Regexp matching the beginning of an attribution line."
118 (defcustom gnus-cite-attribution-suffix
119 "\\(\\(wrote\\|writes\\|said\\|says\\|>\\)\\(:\\|\\.\\.\\.\\)\\|-----Original Message-----\\)[ \t]*$"
120 "*Regexp matching the end of an attribution line.
121 The text matching the first grouping will be used as a button."
125 (defface gnus-cite-attribution-face '((t
127 "Face used for attribution lines.")
129 (defcustom gnus-cite-attribution-face 'gnus-cite-attribution-face
130 "Face used for attribution lines.
131 It is merged with the face for the cited text belonging to the attribution."
135 (defface gnus-cite-face-1 '((((class color)
137 (:foreground "light blue"))
140 (:foreground "MidnightBlue"))
145 (defface gnus-cite-face-2 '((((class color)
147 (:foreground "light cyan"))
150 (:foreground "firebrick"))
155 (defface gnus-cite-face-3 '((((class color)
157 (:foreground "light yellow"))
160 (:foreground "dark green"))
165 (defface gnus-cite-face-4 '((((class color)
167 (:foreground "light pink"))
170 (:foreground "OrangeRed"))
175 (defface gnus-cite-face-5 '((((class color)
177 (:foreground "pale green"))
180 (:foreground "dark khaki"))
185 (defface gnus-cite-face-6 '((((class color)
187 (:foreground "beige"))
190 (:foreground "dark violet"))
195 (defface gnus-cite-face-7 '((((class color)
197 (:foreground "orange"))
200 (:foreground "SteelBlue4"))
205 (defface gnus-cite-face-8 '((((class color)
207 (:foreground "magenta"))
210 (:foreground "magenta"))
215 (defface gnus-cite-face-9 '((((class color)
217 (:foreground "violet"))
220 (:foreground "violet"))
225 (defface gnus-cite-face-10 '((((class color)
227 (:foreground "medium purple"))
230 (:foreground "medium purple"))
235 (defface gnus-cite-face-11 '((((class color)
237 (:foreground "turquoise"))
240 (:foreground "turquoise"))
245 (defcustom gnus-cite-face-list
246 '(gnus-cite-face-1 gnus-cite-face-2 gnus-cite-face-3 gnus-cite-face-4
247 gnus-cite-face-5 gnus-cite-face-6 gnus-cite-face-7 gnus-cite-face-8
248 gnus-cite-face-9 gnus-cite-face-10 gnus-cite-face-11)
249 "*List of faces used for highlighting citations.
251 When there are citations from multiple articles in the same message,
252 Gnus will try to give each citation from each article its own face.
253 This should make it easier to see who wrote what."
255 :type '(repeat face))
257 (defcustom gnus-cite-hide-percentage 50
258 "Only hide excess citation if above this percentage of the body."
262 (defcustom gnus-cite-hide-absolute 10
263 "Only hide excess citation if above this number of lines in the body."
267 ;;; Internal Variables:
269 (defvar gnus-cite-article nil)
270 (defvar gnus-cite-overlay-list nil)
272 (defvar gnus-cite-prefix-alist nil)
273 ;; Alist of citation prefixes.
274 ;; The cdr is a list of lines with that prefix.
276 (defvar gnus-cite-attribution-alist nil)
277 ;; Alist of attribution lines.
278 ;; The car is a line number.
279 ;; The cdr is the prefix for the citation started by that line.
281 (defvar gnus-cite-loose-prefix-alist nil)
282 ;; Alist of citation prefixes that have no matching attribution.
283 ;; The cdr is a list of lines with that prefix.
285 (defvar gnus-cite-loose-attribution-alist nil)
286 ;; Alist of attribution lines that have no matching citation.
287 ;; Each member has the form (WROTE IN PREFIX TAG), where
288 ;; WROTE: is the attribution line number
289 ;; IN: is the line number of the previous line if part of the same attribution,
290 ;; PREFIX: Is the citation prefix of the attribution line(s), and
291 ;; TAG: Is a Supercite tag, if any.
293 (defvar gnus-cited-opened-text-button-line-format-alist
294 `((?b (marker-position beg) ?d)
295 (?e (marker-position end) ?d)
296 (?n (count-lines beg end) ?d)
297 (?l (- end beg) ?d)))
298 (defvar gnus-cited-opened-text-button-line-format-spec nil)
299 (defvar gnus-cited-closed-text-button-line-format-alist
300 gnus-cited-opened-text-button-line-format-alist)
301 (defvar gnus-cited-closed-text-button-line-format-spec nil)
306 (defun gnus-article-highlight-citation (&optional force)
307 "Highlight cited text.
308 Each citation in the article will be highlighted with a different face.
309 The faces are taken from `gnus-cite-face-list'.
310 Attribution lines are highlighted with the same face as the
311 corresponding citation merged with `gnus-cite-attribution-face'.
313 Text is considered cited if at least `gnus-cite-minimum-match-count'
314 lines matches `gnus-cite-prefix-regexp' with the same prefix.
316 Lines matching `gnus-cite-attribution-suffix' and perhaps
317 `gnus-cite-attribution-prefix' are considered attribution lines."
318 (interactive (list 'force))
320 (set-buffer gnus-article-buffer)
321 (gnus-cite-parse-maybe force)
322 (let ((buffer-read-only nil)
323 (alist gnus-cite-prefix-alist)
324 (faces gnus-cite-face-list)
325 (inhibit-point-motion-hooks t)
326 face entry prefix skip numbers number face-alist)
327 ;; Loop through citation prefixes.
329 (setq entry (car alist)
334 faces (or (cdr faces) gnus-cite-face-list)
335 face-alist (cons (cons prefix face) face-alist))
337 (setq number (car numbers)
338 numbers (cdr numbers))
339 (and (not (assq number gnus-cite-attribution-alist))
340 (not (assq number gnus-cite-loose-attribution-alist))
341 (gnus-cite-add-face number prefix face))))
342 ;; Loop through attribution lines.
343 (setq alist gnus-cite-attribution-alist)
345 (setq entry (car alist)
349 skip (gnus-cite-find-prefix number)
350 face (cdr (assoc prefix face-alist)))
351 ;; Add attribution button.
352 (goto-char (point-min))
353 (forward-line (1- number))
354 (when (re-search-forward gnus-cite-attribution-suffix
355 (save-excursion (end-of-line 1) (point))
357 (gnus-article-add-button (match-beginning 1) (match-end 1)
358 'gnus-cite-toggle prefix))
359 ;; Highlight attribution line.
360 (gnus-cite-add-face number skip face)
361 (gnus-cite-add-face number skip gnus-cite-attribution-face))
362 ;; Loop through attribution lines.
363 (setq alist gnus-cite-loose-attribution-alist)
365 (setq entry (car alist)
368 skip (gnus-cite-find-prefix number))
369 (gnus-cite-add-face number skip gnus-cite-attribution-face)))))
371 (defun gnus-dissect-cited-text ()
372 "Dissect the article buffer looking for cited text."
374 (set-buffer gnus-article-buffer)
375 (gnus-cite-parse-maybe nil t)
376 (let ((alist gnus-cite-prefix-alist)
377 prefix numbers number marks m)
378 ;; Loop through citation prefixes.
380 (setq numbers (pop alist)
381 prefix (pop numbers))
383 (setq number (pop numbers))
384 (goto-char (point-min))
385 (forward-line number)
386 (push (cons (point-marker) "") marks)
388 (= (1- number) (car numbers)))
389 (setq number (pop numbers)))
390 (goto-char (point-min))
391 (forward-line (1- number))
392 (push (cons (point-marker) prefix) marks)))
393 ;; Skip to the beginning of the body.
395 (push (cons (point-marker) "") marks)
396 ;; Find the end of the body.
397 (goto-char (point-max))
398 (gnus-article-search-signature)
399 (push (cons (point-marker) "") marks)
401 (setq marks (sort marks 'car-less-than-car))
402 (let ((omarks marks))
405 (if (= (caar omarks) (caadr omarks))
407 (unless (equal (cdar omarks) "")
408 (push (car omarks) marks))
409 (unless (equal (cdadr omarks) "")
410 (push (cadr omarks) marks))
411 (unless (and (equal (cdar omarks) "")
412 (equal (cdadr omarks) "")
414 (setq omarks (cdr omarks))))
415 (push (car omarks) marks))
416 (setq omarks (cdr omarks)))
418 (push (car omarks) marks))
419 (setq marks (setq m (nreverse marks)))
421 (if (and (equal (cdadr m) "")
422 (equal (cdar m) (cdaddr m))
423 (goto-char (caadr m))
425 (= (point) (caaddr m)))
430 (defun gnus-article-fill-cited-article (&optional force width)
431 "Do word wrapping in the current article.
432 If WIDTH (the numerical prefix), use that text width when filling."
433 (interactive (list t current-prefix-arg))
435 (set-buffer gnus-article-buffer)
436 (let ((buffer-read-only nil)
437 (inhibit-point-motion-hooks t)
438 (marks (gnus-dissect-cited-text))
439 (adaptive-fill-mode nil)
441 (fill-column (if width (prefix-numeric-value width) fill-column)))
444 (narrow-to-region (caar marks) (caadr marks))
445 (let ((adaptive-fill-regexp
446 (concat "^" (regexp-quote (cdar marks)) " *"))
447 (fill-prefix (cdar marks)))
448 (fill-region (point-min) (point-max)))
449 (set-marker (caar marks) nil)
450 (setq marks (cdr marks)))
452 (set-marker (caar marks) nil))
453 ;; All this information is now incorrect.
454 (setq gnus-cite-prefix-alist nil
455 gnus-cite-attribution-alist nil
456 gnus-cite-loose-prefix-alist nil
457 gnus-cite-loose-attribution-alist nil
458 gnus-cite-article nil)))))
460 (defun gnus-article-hide-citation (&optional arg force)
461 "Toggle hiding of all cited text except attribution lines.
462 See the documentation for `gnus-article-highlight-citation'.
463 If given a negative prefix, always show; if given a positive prefix,
465 (interactive (append (gnus-article-hidden-arg) (list 'force)))
466 (gnus-set-format 'cited-opened-text-button t)
467 (gnus-set-format 'cited-closed-text-button t)
469 (set-buffer gnus-article-buffer)
470 (let ((buffer-read-only nil)
472 (inhibit-point-motion-hooks t)
473 (props (nconc (list 'article-type 'cite)
474 gnus-hidden-properties))
478 (text-property-any point (point-max)
480 'gnus-article-toggle-cited-text))
483 (gnus-article-toggle-cited-text
484 (get-text-property point 'gnus-data) arg)
486 (setq point (point)))
488 (setq marks (gnus-dissect-cited-text))
492 (while (and marks (string= (cdar marks) ""))
493 (setq marks (cdr marks)))
495 (setq beg (caar marks)))
496 (while (and marks (not (string= (cdar marks) "")))
497 (setq marks (cdr marks)))
499 (setq end (caar marks)))
500 ;; Skip past lines we want to leave visible.
501 (when (and beg end gnus-cited-lines-visible)
503 (forward-line (if (consp gnus-cited-lines-visible)
504 (car gnus-cited-lines-visible)
505 gnus-cited-lines-visible))
508 (setq beg (point-marker))
509 (when (consp gnus-cited-lines-visible)
511 (forward-line (- (cdr gnus-cited-lines-visible)))
514 (setq end (point-marker))))))
516 ;; We use markers for the end-points to facilitate later
517 ;; wrapping and mangling of text.
518 (setq beg (set-marker (make-marker) beg)
519 end (set-marker (make-marker) end))
520 (gnus-add-text-properties-when 'article-type nil beg end props)
522 (unless (save-excursion (search-backward "\n\n" nil t))
525 (setq start (point-marker))
527 (gnus-article-add-button
529 (progn (eval gnus-cited-closed-text-button-line-format-spec)
531 `gnus-article-toggle-cited-text
532 (list (cons beg end) start))
534 'article-type 'annotation)
535 (set-marker beg (point))))))))
537 (defun gnus-article-toggle-cited-text (args &optional arg)
538 "Toggle hiding the text in REGION.
539 ARG can be nil or a number. Positive means hide, negative
540 means show, nil means toggle."
541 (let* ((region (car args))
546 (text-property-any beg (1- end) 'article-type 'cite))
547 (inhibit-point-motion-hooks t)
551 (and (> arg 0) (not hidden))
552 (and (< arg 0) hidden))
554 (gnus-remove-text-properties-when
555 'article-type 'cite beg end
556 (cons 'article-type (cons 'cite
557 gnus-hidden-properties)))
558 (gnus-add-text-properties-when
559 'article-type nil beg end
560 (cons 'article-type (cons 'cite
561 gnus-hidden-properties))))
568 (gnus-article-add-button
572 gnus-cited-opened-text-button-line-format-spec
573 gnus-cited-closed-text-button-line-format-spec))
575 `gnus-article-toggle-cited-text
578 'article-type 'annotation)))))
580 (defun gnus-article-hide-citation-maybe (&optional arg force)
581 "Toggle hiding of cited text that has an attribution line.
582 If given a negative prefix, always show; if given a positive prefix,
584 This will do nothing unless at least `gnus-cite-hide-percentage'
585 percent and at least `gnus-cite-hide-absolute' lines of the body is
586 cited text with attributions. When called interactively, these two
587 variables are ignored.
588 See also the documentation for `gnus-article-highlight-citation'."
589 (interactive (append (gnus-article-hidden-arg) '(force)))
590 (unless (gnus-article-check-hidden-text 'cite arg)
592 (set-buffer gnus-article-buffer)
593 (gnus-cite-parse-maybe force)
595 (let ((start (point))
596 (atts gnus-cite-attribution-alist)
597 (buffer-read-only nil)
598 (inhibit-point-motion-hooks t)
601 (goto-char (point-max))
602 (gnus-article-search-signature)
603 (setq total (count-lines start (point)))
605 (setq hidden (+ hidden (length (cdr (assoc (cdar atts)
606 gnus-cite-prefix-alist))))
609 (and (> (* 100 hidden) (* gnus-cite-hide-percentage total))
610 (> hidden gnus-cite-hide-absolute)))
611 (setq atts gnus-cite-attribution-alist)
613 (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist))
616 (setq hidden (car total)
618 (goto-char (point-min))
619 (forward-line (1- hidden))
620 (unless (assq hidden gnus-cite-attribution-alist)
621 (gnus-add-text-properties
622 (point) (progn (forward-line 1) (point))
623 (nconc (list 'article-type 'cite)
624 gnus-hidden-properties))))))))))
626 (defun gnus-article-hide-citation-in-followups ()
627 "Hide cited text in non-root articles."
630 (set-buffer gnus-article-buffer)
631 (let ((article (cdr gnus-article-current)))
632 (unless (save-excursion
633 (set-buffer gnus-summary-buffer)
634 (gnus-article-displayed-root-p article))
635 (gnus-article-hide-citation)))))
637 ;;; Internal functions:
639 (defun gnus-cite-parse-maybe (&optional force no-overlay)
640 "Always parse the buffer."
642 ;;Reset parser information.
643 (setq gnus-cite-prefix-alist nil
644 gnus-cite-attribution-alist nil
645 gnus-cite-loose-prefix-alist nil
646 gnus-cite-loose-attribution-alist nil)
648 (gnus-cite-delete-overlays))
649 ;; Parse if not too large.
650 (if (and gnus-cite-parse-max-size
651 (> (buffer-size) gnus-cite-parse-max-size))
653 (setq gnus-cite-article (cons (car gnus-article-current)
654 (cdr gnus-article-current)))
655 (gnus-cite-parse-wrapper)))
657 (defun gnus-cite-delete-overlays ()
658 (dolist (overlay gnus-cite-overlay-list)
659 (when (or (not (gnus-overlay-end overlay))
660 (and (>= (gnus-overlay-end overlay) (point-min))
661 (<= (gnus-overlay-end overlay) (point-max))))
662 (setq gnus-cite-overlay-list (delete overlay gnus-cite-overlay-list))
663 (gnus-delete-overlay overlay))))
665 (defun gnus-cite-parse-wrapper ()
666 ;; Wrap chopped gnus-cite-parse.
668 (let ((inhibit-point-motion-hooks t))
670 (gnus-cite-parse-attributions))
674 (gnus-cite-connect-attributions))))
676 (defun gnus-cite-parse ()
677 ;; Parse and connect citation prefixes and attribution lines.
679 ;; Parse current buffer searching for citation prefixes.
680 (let ((line (1+ (count-lines (point-min) (point))))
683 (goto-char (point-max))
684 (gnus-article-search-signature)
686 alist entry start begin end numbers prefix)
687 ;; Get all potential prefixes in `alist'.
688 (while (< (point) max)
691 end (progn (beginning-of-line 2) (point))
694 ;; Ignore standard Supercite attribution prefix.
695 (when (looking-at gnus-supercite-regexp)
697 (setq end (1+ (match-end 1)))
698 (setq end (1+ begin))))
699 ;; Ignore very long prefixes.
700 (when (> end (+ (point) gnus-cite-max-prefix))
701 (setq end (+ (point) gnus-cite-max-prefix)))
702 (while (re-search-forward gnus-cite-prefix-regexp (1- end) t)
704 (setq end (match-end 0)
705 prefix (buffer-substring begin end))
706 (gnus-set-text-properties 0 (length prefix) nil prefix)
707 (setq entry (assoc prefix alist))
709 (setcdr entry (cons line (cdr entry)))
710 (push (list prefix line) alist))
713 (setq line (1+ line)))
714 ;; We got all the potential prefixes. Now create
715 ;; `gnus-cite-prefix-alist' containing the oldest prefix for each
716 ;; line that appears at least gnus-cite-minimum-match-count
717 ;; times. First sort them by length. Longer is older.
718 (setq alist (sort alist (lambda (a b)
719 (> (length (car a)) (length (car b))))))
721 (setq entry (car alist)
725 (cond ((null numbers)
726 ;; No lines with this prefix that wasn't also part of
729 ((< (length numbers) gnus-cite-minimum-match-count)
730 ;; Too few lines with this prefix. We keep it a bit
731 ;; longer in case it is an exact match for an attribution
732 ;; line, but we don't remove the line from other
734 (push entry gnus-cite-prefix-alist))
737 gnus-cite-prefix-alist)
738 ;; Remove articles from other prefixes.
742 (setq current (car loop)
745 (gnus-set-difference (cdr current) numbers)))))))))
747 (defun gnus-cite-parse-attributions ()
749 ;; Parse attributions
750 (while (re-search-forward gnus-cite-attribution-suffix (point-max) t)
751 (let* ((start (match-beginning 0))
753 (wrote (count-lines (point-min) end))
754 (prefix (gnus-cite-find-prefix wrote))
755 ;; Check previous line for an attribution leader.
757 (beginning-of-line 1)
758 (when (looking-at gnus-supercite-secondary-regexp)
759 (buffer-substring (match-beginning 1)
763 (and (re-search-backward gnus-cite-attribution-prefix
765 (beginning-of-line 0)
768 (not (re-search-forward gnus-cite-attribution-suffix
770 (count-lines (point-min) (1+ (point)))))))
774 ;; don't add duplicates
775 (let ((al (buffer-substring (save-excursion (beginning-of-line 0)
778 (if (not (assoc al al-alist))
780 (push (list wrote in prefix tag)
781 gnus-cite-loose-attribution-alist)
782 (push (cons al t) al-alist))))))))
784 (defun gnus-cite-connect-attributions ()
785 ;; Connect attributions to citations
787 ;; No citations have been connected to attribution lines yet.
788 (setq gnus-cite-loose-prefix-alist (append gnus-cite-prefix-alist nil))
790 ;; Parse current buffer searching for attribution lines.
791 ;; Find exact supercite citations.
792 (gnus-cite-match-attributions 'small nil
796 (regexp-quote prefix) "[ \t]*"
797 (regexp-quote tag) ">"))))
798 ;; Find loose supercite citations after attributions.
799 (gnus-cite-match-attributions 'small t
805 ;; Find loose supercite citations anywhere.
806 (gnus-cite-match-attributions 'small nil
812 ;; Find nested citations after attributions.
813 (gnus-cite-match-attributions 'small-if-unique t
815 (concat "\\`" (regexp-quote prefix) ".+")))
816 ;; Find nested citations anywhere.
817 (gnus-cite-match-attributions 'small nil
819 (concat "\\`" (regexp-quote prefix) ".+")))
820 ;; Remove loose prefixes with too few lines.
821 (let ((alist gnus-cite-loose-prefix-alist)
824 (setq entry (car alist)
826 (when (< (length (cdr entry)) gnus-cite-minimum-match-count)
827 (setq gnus-cite-prefix-alist
828 (delq entry gnus-cite-prefix-alist)
829 gnus-cite-loose-prefix-alist
830 (delq entry gnus-cite-loose-prefix-alist)))))
831 ;; Find flat attributions.
832 (gnus-cite-match-attributions 'first t nil)
833 ;; Find any attributions (are we getting desperate yet?).
834 (gnus-cite-match-attributions 'first nil nil))
836 (defun gnus-cite-match-attributions (sort after fun)
837 ;; Match all loose attributions and citations (SORT AFTER FUN) .
839 ;; If SORT is `small', the citation with the shortest prefix will be
840 ;; used, if it is `first' the first prefix will be used, if it is
841 ;; `small-if-unique' the shortest prefix will be used if the
842 ;; attribution line does not share its own prefix with other
843 ;; loose attribution lines, otherwise the first prefix will be used.
845 ;; If AFTER is non-nil, only citations after the attribution line
846 ;; will be considered.
848 ;; If FUN is non-nil, it will be called with the arguments (WROTE
849 ;; PREFIX TAG) and expected to return a regular expression. Only
850 ;; citations whose prefix matches the regular expression will be
853 ;; WROTE is the attribution line number.
854 ;; PREFIX is the attribution line prefix.
855 ;; TAG is the Supercite tag on the attribution line.
856 (let ((atts gnus-cite-loose-attribution-alist)
858 att wrote in prefix tag regexp limit smallest best size)
866 regexp (if fun (funcall fun prefix tag) "")
867 size (cond ((eq sort 'small) t)
868 ((eq sort 'first) nil)
869 (t (< (length (gnus-cite-find-loose prefix)) 2)))
870 limit (if after wrote -1)
873 (let ((cites gnus-cite-loose-prefix-alist)
874 cite candidate numbers first compare)
876 (setq cite (car cites)
880 first (apply 'min numbers)
881 compare (if size (length candidate) first))
884 (string-match regexp candidate)
890 (setq gnus-cite-loose-attribution-alist
891 (delq att gnus-cite-loose-attribution-alist))
892 (push (cons wrote (car best)) gnus-cite-attribution-alist)
894 (push (cons in (car best)) gnus-cite-attribution-alist))
895 (when (memq best gnus-cite-loose-prefix-alist)
896 (let ((loop gnus-cite-prefix-alist)
899 (setq gnus-cite-loose-prefix-alist
900 (delq best gnus-cite-loose-prefix-alist))
902 (setq current (car loop)
904 (if (eq current best)
906 (setcdr current (gnus-set-difference (cdr current) numbers))
907 (when (null (cdr current))
908 (setq gnus-cite-loose-prefix-alist
909 (delq current gnus-cite-loose-prefix-alist)
910 atts (delq current atts)))))))))))
912 (defun gnus-cite-find-loose (prefix)
913 ;; Return a list of loose attribution lines prefixed by PREFIX.
914 (let* ((atts gnus-cite-loose-attribution-alist)
920 (when (string-equal (gnus-cite-find-prefix line) prefix)
924 (defun gnus-cite-add-face (number prefix face)
925 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
927 (let ((inhibit-point-motion-hooks t)
929 (goto-char (point-min))
930 (when (zerop (forward-line (1- number)))
931 (forward-char (length prefix))
932 (skip-chars-forward " \t")
935 (skip-chars-backward " \t")
938 (push (setq overlay (gnus-make-overlay from to))
939 gnus-cite-overlay-list)
940 (gnus-overlay-put overlay 'face face))))))
942 (defun gnus-cite-toggle (prefix)
944 (set-buffer gnus-article-buffer)
945 (gnus-cite-parse-maybe nil t)
946 (let ((buffer-read-only nil)
947 (numbers (cdr (assoc prefix gnus-cite-prefix-alist)))
948 (inhibit-point-motion-hooks t)
951 (setq number (car numbers)
952 numbers (cdr numbers))
953 (goto-char (point-min))
954 (forward-line (1- number))
955 (cond ((get-text-property (point) 'invisible)
956 (remove-text-properties (point) (progn (forward-line 1) (point))
957 gnus-hidden-properties))
958 ((assq number gnus-cite-attribution-alist))
960 (gnus-add-text-properties
961 (point) (progn (forward-line 1) (point))
962 (nconc (list 'article-type 'cite)
963 gnus-hidden-properties))))))))
965 (defun gnus-cite-find-prefix (line)
966 ;; Return citation prefix for LINE.
967 (let ((alist gnus-cite-prefix-alist)
971 (setq entry (car alist)
973 (when (memq line (cdr entry))
974 (setq prefix (car entry))))
977 (defun gnus-cite-localize ()
978 "Make the citation variables local to the article buffer."
979 (let ((vars '(gnus-cite-article
980 gnus-cite-overlay-list gnus-cite-prefix-alist
981 gnus-cite-attribution-alist gnus-cite-loose-prefix-alist
982 gnus-cite-loose-attribution-alist)))
984 (make-local-variable (pop vars)))))
991 ;; coding: iso-8859-1
994 ;;; gnus-cite.el ends here