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))
29 (require 'message) ; for message-cite-prefix-regexp
33 (defgroup gnus-cite nil
36 :link '(custom-manual "(gnus)Article Highlighting")
39 (defcustom gnus-cite-reply-regexp
40 "^\\(Subject: Re\\|In-Reply-To\\|References\\):"
41 "*If headers match this regexp it is reasonable to believe that
42 article has citations."
46 (defcustom gnus-cite-always-check nil
47 "Check article always for citations. Set it t to check all articles."
49 :type '(choice (const :tag "no" nil)
50 (const :tag "yes" t)))
52 (defcustom gnus-cited-opened-text-button-line-format "%(%{[-]%}%)\n"
53 "Format of opened cited text buttons."
57 (defcustom gnus-cited-closed-text-button-line-format "%(%{[+]%}%)\n"
58 "Format of closed cited text buttons."
62 (defcustom gnus-cited-lines-visible nil
63 "The number of lines of hidden cited text to remain visible.
64 Or a pair (cons) of numbers which are the number of lines at the top
65 and bottom of the text, respectively, to remain visible."
67 :type '(choice (const :tag "none" nil)
69 (cons :tag "Top and Bottom" integer integer)))
71 (defcustom gnus-cite-parse-max-size 25000
72 "Maximum article size (in bytes) where parsing citations is allowed.
73 Set it to nil to parse all articles."
75 :type '(choice (const :tag "all" nil)
78 (defcustom gnus-cite-max-prefix 20
79 "Maximum possible length for a citation prefix."
83 (defcustom gnus-supercite-regexp
84 (concat "^\\(" message-cite-prefix-regexp "\\)? *"
85 ">>>>> +\"\\([^\"\n]+\\)\" +==")
86 "*Regexp matching normal Supercite attribution lines.
87 The first grouping must match prefixes added by other packages."
91 (defcustom gnus-supercite-secondary-regexp "^.*\"\\([^\"\n]+\\)\" +=="
92 "Regexp matching mangled Supercite attribution lines.
93 The first regexp group should match the Supercite attribution."
97 (defcustom gnus-cite-minimum-match-count 2
98 "Minimum number of identical prefixes before we believe it's a citation."
102 (defcustom gnus-cite-attribution-prefix
103 "In article\\|in <\\|On \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\),\\|-----Original Message-----"
104 "*Regexp matching the beginning of an attribution line."
108 (defcustom gnus-cite-attribution-suffix
109 "\\(\\(wrote\\|writes\\|said\\|says\\|>\\)\\(:\\|\\.\\.\\.\\)\\|-----Original Message-----\\)[ \t]*$"
110 "*Regexp matching the end of an attribution line.
111 The text matching the first grouping will be used as a button."
115 (defface gnus-cite-attribution-face '((t
117 "Face used for attribution lines.")
119 (defcustom gnus-cite-attribution-face 'gnus-cite-attribution-face
120 "Face used for attribution lines.
121 It is merged with the face for the cited text belonging to the attribution."
125 (defface gnus-cite-face-1 '((((class color)
127 (:foreground "light blue"))
130 (:foreground "MidnightBlue"))
135 (defface gnus-cite-face-2 '((((class color)
137 (:foreground "light cyan"))
140 (:foreground "firebrick"))
145 (defface gnus-cite-face-3 '((((class color)
147 (:foreground "light yellow"))
150 (:foreground "dark green"))
155 (defface gnus-cite-face-4 '((((class color)
157 (:foreground "light pink"))
160 (:foreground "OrangeRed"))
165 (defface gnus-cite-face-5 '((((class color)
167 (:foreground "pale green"))
170 (:foreground "dark khaki"))
175 (defface gnus-cite-face-6 '((((class color)
177 (:foreground "beige"))
180 (:foreground "dark violet"))
185 (defface gnus-cite-face-7 '((((class color)
187 (:foreground "orange"))
190 (:foreground "SteelBlue4"))
195 (defface gnus-cite-face-8 '((((class color)
197 (:foreground "magenta"))
200 (:foreground "magenta"))
205 (defface gnus-cite-face-9 '((((class color)
207 (:foreground "violet"))
210 (:foreground "violet"))
215 (defface gnus-cite-face-10 '((((class color)
217 (:foreground "medium purple"))
220 (:foreground "medium purple"))
225 (defface gnus-cite-face-11 '((((class color)
227 (:foreground "turquoise"))
230 (:foreground "turquoise"))
235 (defcustom gnus-cite-face-list
236 '(gnus-cite-face-1 gnus-cite-face-2 gnus-cite-face-3 gnus-cite-face-4
237 gnus-cite-face-5 gnus-cite-face-6 gnus-cite-face-7 gnus-cite-face-8
238 gnus-cite-face-9 gnus-cite-face-10 gnus-cite-face-11)
239 "*List of faces used for highlighting citations.
241 When there are citations from multiple articles in the same message,
242 Gnus will try to give each citation from each article its own face.
243 This should make it easier to see who wrote what."
245 :type '(repeat face))
247 (defcustom gnus-cite-hide-percentage 50
248 "Only hide excess citation if above this percentage of the body."
252 (defcustom gnus-cite-hide-absolute 10
253 "Only hide excess citation if above this number of lines in the body."
257 ;;; Internal Variables:
259 (defvar gnus-cite-article nil)
260 (defvar gnus-cite-overlay-list nil)
262 (defvar gnus-cite-prefix-alist nil)
263 ;; Alist of citation prefixes.
264 ;; The cdr is a list of lines with that prefix.
266 (defvar gnus-cite-attribution-alist nil)
267 ;; Alist of attribution lines.
268 ;; The car is a line number.
269 ;; The cdr is the prefix for the citation started by that line.
271 (defvar gnus-cite-loose-prefix-alist nil)
272 ;; Alist of citation prefixes that have no matching attribution.
273 ;; The cdr is a list of lines with that prefix.
275 (defvar gnus-cite-loose-attribution-alist nil)
276 ;; Alist of attribution lines that have no matching citation.
277 ;; Each member has the form (WROTE IN PREFIX TAG), where
278 ;; WROTE: is the attribution line number
279 ;; IN: is the line number of the previous line if part of the same attribution,
280 ;; PREFIX: Is the citation prefix of the attribution line(s), and
281 ;; TAG: Is a Supercite tag, if any.
283 (defvar gnus-cited-opened-text-button-line-format-alist
284 `((?b (marker-position beg) ?d)
285 (?e (marker-position end) ?d)
286 (?n (count-lines beg end) ?d)
287 (?l (- end beg) ?d)))
288 (defvar gnus-cited-opened-text-button-line-format-spec nil)
289 (defvar gnus-cited-closed-text-button-line-format-alist
290 gnus-cited-opened-text-button-line-format-alist)
291 (defvar gnus-cited-closed-text-button-line-format-spec nil)
296 (defun gnus-article-highlight-citation (&optional force)
297 "Highlight cited text.
298 Each citation in the article will be highlighted with a different face.
299 The faces are taken from `gnus-cite-face-list'.
300 Attribution lines are highlighted with the same face as the
301 corresponding citation merged with `gnus-cite-attribution-face'.
303 Text is considered cited if at least `gnus-cite-minimum-match-count'
304 lines matches `message-cite-prefix-regexp' with the same prefix.
306 Lines matching `gnus-cite-attribution-suffix' and perhaps
307 `gnus-cite-attribution-prefix' are considered attribution lines."
308 (interactive (list 'force))
310 (set-buffer gnus-article-buffer)
311 (gnus-cite-parse-maybe force)
312 (let ((buffer-read-only nil)
313 (alist gnus-cite-prefix-alist)
314 (faces gnus-cite-face-list)
315 (inhibit-point-motion-hooks t)
316 face entry prefix skip numbers number face-alist)
317 ;; Loop through citation prefixes.
319 (setq entry (car alist)
324 faces (or (cdr faces) gnus-cite-face-list)
325 face-alist (cons (cons prefix face) face-alist))
327 (setq number (car numbers)
328 numbers (cdr numbers))
329 (and (not (assq number gnus-cite-attribution-alist))
330 (not (assq number gnus-cite-loose-attribution-alist))
331 (gnus-cite-add-face number prefix face))))
332 ;; Loop through attribution lines.
333 (setq alist gnus-cite-attribution-alist)
335 (setq entry (car alist)
339 skip (gnus-cite-find-prefix number)
340 face (cdr (assoc prefix face-alist)))
341 ;; Add attribution button.
342 (goto-char (point-min))
343 (forward-line (1- number))
344 (when (re-search-forward gnus-cite-attribution-suffix
345 (save-excursion (end-of-line 1) (point))
347 (gnus-article-add-button (match-beginning 1) (match-end 1)
348 'gnus-cite-toggle prefix))
349 ;; Highlight attribution line.
350 (gnus-cite-add-face number skip face)
351 (gnus-cite-add-face number skip gnus-cite-attribution-face))
352 ;; Loop through attribution lines.
353 (setq alist gnus-cite-loose-attribution-alist)
355 (setq entry (car alist)
358 skip (gnus-cite-find-prefix number))
359 (gnus-cite-add-face number skip gnus-cite-attribution-face)))))
361 (defun gnus-dissect-cited-text ()
362 "Dissect the article buffer looking for cited text."
364 (set-buffer gnus-article-buffer)
365 (gnus-cite-parse-maybe nil t)
366 (let ((alist gnus-cite-prefix-alist)
367 prefix numbers number marks m)
368 ;; Loop through citation prefixes.
370 (setq numbers (pop alist)
371 prefix (pop numbers))
373 (setq number (pop numbers))
374 (goto-char (point-min))
375 (forward-line number)
376 (push (cons (point-marker) "") marks)
378 (= (1- number) (car numbers)))
379 (setq number (pop numbers)))
380 (goto-char (point-min))
381 (forward-line (1- number))
382 (push (cons (point-marker) prefix) marks)))
383 ;; Skip to the beginning of the body.
385 (push (cons (point-marker) "") marks)
386 ;; Find the end of the body.
387 (goto-char (point-max))
388 (gnus-article-search-signature)
389 (push (cons (point-marker) "") marks)
391 (setq marks (sort marks 'car-less-than-car))
392 (let ((omarks marks))
395 (if (= (caar omarks) (caadr omarks))
397 (unless (equal (cdar omarks) "")
398 (push (car omarks) marks))
399 (unless (equal (cdadr omarks) "")
400 (push (cadr omarks) marks))
401 (unless (and (equal (cdar omarks) "")
402 (equal (cdadr omarks) "")
404 (setq omarks (cdr omarks))))
405 (push (car omarks) marks))
406 (setq omarks (cdr omarks)))
408 (push (car omarks) marks))
409 (setq marks (setq m (nreverse marks)))
411 (if (and (equal (cdadr m) "")
412 (equal (cdar m) (cdaddr m))
413 (goto-char (caadr m))
415 (= (point) (caaddr m)))
420 (defun gnus-article-fill-cited-article (&optional force width)
421 "Do word wrapping in the current article.
422 If WIDTH (the numerical prefix), use that text width when filling."
423 (interactive (list t current-prefix-arg))
425 (set-buffer gnus-article-buffer)
426 (let ((buffer-read-only nil)
427 (inhibit-point-motion-hooks t)
428 (marks (gnus-dissect-cited-text))
429 (adaptive-fill-mode nil)
431 (fill-column (if width (prefix-numeric-value width) fill-column)))
434 (narrow-to-region (caar marks) (caadr marks))
435 (let ((adaptive-fill-regexp
436 (concat "^" (regexp-quote (cdar marks)) " *"))
437 (fill-prefix (cdar marks)))
438 (fill-region (point-min) (point-max)))
439 (set-marker (caar marks) nil)
440 (setq marks (cdr marks)))
442 (set-marker (caar marks) nil))
443 ;; All this information is now incorrect.
444 (setq gnus-cite-prefix-alist nil
445 gnus-cite-attribution-alist nil
446 gnus-cite-loose-prefix-alist nil
447 gnus-cite-loose-attribution-alist nil
448 gnus-cite-article nil)))))
450 (defun gnus-article-hide-citation (&optional arg force)
451 "Toggle hiding of all cited text except attribution lines.
452 See the documentation for `gnus-article-highlight-citation'.
453 If given a negative prefix, always show; if given a positive prefix,
455 (interactive (append (gnus-article-hidden-arg) (list 'force)))
456 (gnus-set-format 'cited-opened-text-button t)
457 (gnus-set-format 'cited-closed-text-button t)
459 (set-buffer gnus-article-buffer)
460 (let ((buffer-read-only nil)
462 (inhibit-point-motion-hooks t)
463 (props (nconc (list 'article-type 'cite)
464 gnus-hidden-properties))
468 (text-property-any point (point-max)
470 'gnus-article-toggle-cited-text))
473 (gnus-article-toggle-cited-text
474 (get-text-property point 'gnus-data) arg)
476 (setq point (point)))
478 (setq marks (gnus-dissect-cited-text))
482 (while (and marks (string= (cdar marks) ""))
483 (setq marks (cdr marks)))
485 (setq beg (caar marks)))
486 (while (and marks (not (string= (cdar marks) "")))
487 (setq marks (cdr marks)))
489 (setq end (caar marks)))
490 ;; Skip past lines we want to leave visible.
491 (when (and beg end gnus-cited-lines-visible)
493 (forward-line (if (consp gnus-cited-lines-visible)
494 (car gnus-cited-lines-visible)
495 gnus-cited-lines-visible))
498 (setq beg (point-marker))
499 (when (consp gnus-cited-lines-visible)
501 (forward-line (- (cdr gnus-cited-lines-visible)))
504 (setq end (point-marker))))))
506 ;; We use markers for the end-points to facilitate later
507 ;; wrapping and mangling of text.
508 (setq beg (set-marker (make-marker) beg)
509 end (set-marker (make-marker) end))
510 (gnus-add-text-properties-when 'article-type nil beg end props)
512 (unless (save-excursion (search-backward "\n\n" nil t))
515 (setq start (point-marker))
517 (gnus-article-add-button
519 (progn (eval gnus-cited-closed-text-button-line-format-spec)
521 `gnus-article-toggle-cited-text
522 (list (cons beg end) start))
524 'article-type 'annotation)
525 (set-marker beg (point))))))))
527 (defun gnus-article-toggle-cited-text (args &optional arg)
528 "Toggle hiding the text in REGION.
529 ARG can be nil or a number. Positive means hide, negative
530 means show, nil means toggle."
531 (let* ((region (car args))
536 (text-property-any beg (1- end) 'article-type 'cite))
537 (inhibit-point-motion-hooks t)
541 (and (> arg 0) (not hidden))
542 (and (< arg 0) hidden))
544 (gnus-remove-text-properties-when
545 'article-type 'cite beg end
546 (cons 'article-type (cons 'cite
547 gnus-hidden-properties)))
548 (gnus-add-text-properties-when
549 'article-type nil beg end
550 (cons 'article-type (cons 'cite
551 gnus-hidden-properties))))
558 (gnus-article-add-button
562 gnus-cited-opened-text-button-line-format-spec
563 gnus-cited-closed-text-button-line-format-spec))
565 `gnus-article-toggle-cited-text
568 'article-type 'annotation)))))
570 (defun gnus-article-hide-citation-maybe (&optional arg force)
571 "Toggle hiding of cited text that has an attribution line.
572 If given a negative prefix, always show; if given a positive prefix,
574 This will do nothing unless at least `gnus-cite-hide-percentage'
575 percent and at least `gnus-cite-hide-absolute' lines of the body is
576 cited text with attributions. When called interactively, these two
577 variables are ignored.
578 See also the documentation for `gnus-article-highlight-citation'."
579 (interactive (append (gnus-article-hidden-arg) '(force)))
580 (unless (gnus-article-check-hidden-text 'cite arg)
582 (set-buffer gnus-article-buffer)
583 (gnus-cite-parse-maybe force)
585 (let ((start (point))
586 (atts gnus-cite-attribution-alist)
587 (buffer-read-only nil)
588 (inhibit-point-motion-hooks t)
591 (goto-char (point-max))
592 (gnus-article-search-signature)
593 (setq total (count-lines start (point)))
595 (setq hidden (+ hidden (length (cdr (assoc (cdar atts)
596 gnus-cite-prefix-alist))))
599 (and (> (* 100 hidden) (* gnus-cite-hide-percentage total))
600 (> hidden gnus-cite-hide-absolute)))
601 (setq atts gnus-cite-attribution-alist)
603 (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist))
606 (setq hidden (car total)
608 (goto-char (point-min))
609 (forward-line (1- hidden))
610 (unless (assq hidden gnus-cite-attribution-alist)
611 (gnus-add-text-properties
612 (point) (progn (forward-line 1) (point))
613 (nconc (list 'article-type 'cite)
614 gnus-hidden-properties))))))))))
616 (defun gnus-article-hide-citation-in-followups ()
617 "Hide cited text in non-root articles."
620 (set-buffer gnus-article-buffer)
621 (let ((article (cdr gnus-article-current)))
622 (unless (save-excursion
623 (set-buffer gnus-summary-buffer)
624 (gnus-article-displayed-root-p article))
625 (gnus-article-hide-citation)))))
627 ;;; Internal functions:
629 (defun gnus-cite-parse-maybe (&optional force no-overlay)
630 "Always parse the buffer."
632 ;;Reset parser information.
633 (setq gnus-cite-prefix-alist nil
634 gnus-cite-attribution-alist nil
635 gnus-cite-loose-prefix-alist nil
636 gnus-cite-loose-attribution-alist nil)
638 (gnus-cite-delete-overlays))
639 ;; Parse if not too large.
640 (if (and gnus-cite-parse-max-size
641 (> (buffer-size) gnus-cite-parse-max-size))
643 (setq gnus-cite-article (cons (car gnus-article-current)
644 (cdr gnus-article-current)))
645 (gnus-cite-parse-wrapper)))
647 (defun gnus-cite-delete-overlays ()
648 (dolist (overlay gnus-cite-overlay-list)
649 (when (or (not (gnus-overlay-end overlay))
650 (and (>= (gnus-overlay-end overlay) (point-min))
651 (<= (gnus-overlay-end overlay) (point-max))))
652 (setq gnus-cite-overlay-list (delete overlay gnus-cite-overlay-list))
653 (gnus-delete-overlay overlay))))
655 (defun gnus-cite-parse-wrapper ()
656 ;; Wrap chopped gnus-cite-parse.
658 (let ((inhibit-point-motion-hooks t))
660 (gnus-cite-parse-attributions))
664 (gnus-cite-connect-attributions))))
666 (defun gnus-cite-parse ()
667 ;; Parse and connect citation prefixes and attribution lines.
669 ;; Parse current buffer searching for citation prefixes.
670 (let ((line (1+ (count-lines (point-min) (point))))
673 (goto-char (point-max))
674 (gnus-article-search-signature)
676 (prefix-regexp (concat "^\\(" message-cite-prefix-regexp "\\)"))
677 alist entry start begin end numbers prefix guess-limit)
678 ;; Get all potential prefixes in `alist'.
679 (while (< (point) max)
682 guess-limit (progn (skip-chars-forward "^> \t\r\n") (point))
683 end (progn (beginning-of-line 2) (point))
686 ;; Ignore standard Supercite attribution prefix.
687 (when (and (< guess-limit (+ begin gnus-cite-max-prefix))
688 (looking-at gnus-supercite-regexp))
690 (setq end (1+ (match-end 1)))
691 (setq end (1+ begin))))
692 ;; Ignore very long prefixes.
693 (when (> end (+ begin gnus-cite-max-prefix))
694 (setq end (+ begin gnus-cite-max-prefix)))
695 (while (re-search-forward prefix-regexp (1- end) t)
697 (setq end (match-end 0)
698 prefix (buffer-substring begin end))
699 (gnus-set-text-properties 0 (length prefix) nil prefix)
700 (setq entry (assoc prefix alist))
702 (setcdr entry (cons line (cdr entry)))
703 (push (list prefix line) alist))
706 (setq line (1+ line)))
707 ;; We got all the potential prefixes. Now create
708 ;; `gnus-cite-prefix-alist' containing the oldest prefix for each
709 ;; line that appears at least gnus-cite-minimum-match-count
710 ;; times. First sort them by length. Longer is older.
711 (setq alist (sort alist (lambda (a b)
712 (> (length (car a)) (length (car b))))))
714 (setq entry (car alist)
718 (cond ((null numbers)
719 ;; No lines with this prefix that wasn't also part of
722 ((< (length numbers) gnus-cite-minimum-match-count)
723 ;; Too few lines with this prefix. We keep it a bit
724 ;; longer in case it is an exact match for an attribution
725 ;; line, but we don't remove the line from other
727 (push entry gnus-cite-prefix-alist))
730 gnus-cite-prefix-alist)
731 ;; Remove articles from other prefixes.
735 (setq current (car loop)
738 (gnus-set-difference (cdr current) numbers)))))))))
740 (defun gnus-cite-parse-attributions ()
742 ;; Parse attributions
743 (while (re-search-forward gnus-cite-attribution-suffix (point-max) t)
744 (let* ((start (match-beginning 0))
746 (wrote (count-lines (point-min) end))
747 (prefix (gnus-cite-find-prefix wrote))
748 ;; Check previous line for an attribution leader.
750 (beginning-of-line 1)
751 (when (looking-at gnus-supercite-secondary-regexp)
752 (buffer-substring (match-beginning 1)
756 (and (re-search-backward gnus-cite-attribution-prefix
758 (beginning-of-line 0)
761 (not (re-search-forward gnus-cite-attribution-suffix
763 (count-lines (point-min) (1+ (point)))))))
767 ;; don't add duplicates
768 (let ((al (buffer-substring (save-excursion (beginning-of-line 0)
771 (if (not (assoc al al-alist))
773 (push (list wrote in prefix tag)
774 gnus-cite-loose-attribution-alist)
775 (push (cons al t) al-alist))))))))
777 (defun gnus-cite-connect-attributions ()
778 ;; Connect attributions to citations
780 ;; No citations have been connected to attribution lines yet.
781 (setq gnus-cite-loose-prefix-alist (append gnus-cite-prefix-alist nil))
783 ;; Parse current buffer searching for attribution lines.
784 ;; Find exact supercite citations.
785 (gnus-cite-match-attributions 'small nil
789 (regexp-quote prefix) "[ \t]*"
790 (regexp-quote tag) ">"))))
791 ;; Find loose supercite citations after attributions.
792 (gnus-cite-match-attributions 'small t
798 ;; Find loose supercite citations anywhere.
799 (gnus-cite-match-attributions 'small nil
805 ;; Find nested citations after attributions.
806 (gnus-cite-match-attributions 'small-if-unique t
808 (concat "\\`" (regexp-quote prefix) ".+")))
809 ;; Find nested citations anywhere.
810 (gnus-cite-match-attributions 'small nil
812 (concat "\\`" (regexp-quote prefix) ".+")))
813 ;; Remove loose prefixes with too few lines.
814 (let ((alist gnus-cite-loose-prefix-alist)
817 (setq entry (car alist)
819 (when (< (length (cdr entry)) gnus-cite-minimum-match-count)
820 (setq gnus-cite-prefix-alist
821 (delq entry gnus-cite-prefix-alist)
822 gnus-cite-loose-prefix-alist
823 (delq entry gnus-cite-loose-prefix-alist)))))
824 ;; Find flat attributions.
825 (gnus-cite-match-attributions 'first t nil)
826 ;; Find any attributions (are we getting desperate yet?).
827 (gnus-cite-match-attributions 'first nil nil))
829 (defun gnus-cite-match-attributions (sort after fun)
830 ;; Match all loose attributions and citations (SORT AFTER FUN) .
832 ;; If SORT is `small', the citation with the shortest prefix will be
833 ;; used, if it is `first' the first prefix will be used, if it is
834 ;; `small-if-unique' the shortest prefix will be used if the
835 ;; attribution line does not share its own prefix with other
836 ;; loose attribution lines, otherwise the first prefix will be used.
838 ;; If AFTER is non-nil, only citations after the attribution line
839 ;; will be considered.
841 ;; If FUN is non-nil, it will be called with the arguments (WROTE
842 ;; PREFIX TAG) and expected to return a regular expression. Only
843 ;; citations whose prefix matches the regular expression will be
846 ;; WROTE is the attribution line number.
847 ;; PREFIX is the attribution line prefix.
848 ;; TAG is the Supercite tag on the attribution line.
849 (let ((atts gnus-cite-loose-attribution-alist)
851 att wrote in prefix tag regexp limit smallest best size)
859 regexp (if fun (funcall fun prefix tag) "")
860 size (cond ((eq sort 'small) t)
861 ((eq sort 'first) nil)
862 (t (< (length (gnus-cite-find-loose prefix)) 2)))
863 limit (if after wrote -1)
866 (let ((cites gnus-cite-loose-prefix-alist)
867 cite candidate numbers first compare)
869 (setq cite (car cites)
873 first (apply 'min numbers)
874 compare (if size (length candidate) first))
877 (string-match regexp candidate)
883 (setq gnus-cite-loose-attribution-alist
884 (delq att gnus-cite-loose-attribution-alist))
885 (push (cons wrote (car best)) gnus-cite-attribution-alist)
887 (push (cons in (car best)) gnus-cite-attribution-alist))
888 (when (memq best gnus-cite-loose-prefix-alist)
889 (let ((loop gnus-cite-prefix-alist)
892 (setq gnus-cite-loose-prefix-alist
893 (delq best gnus-cite-loose-prefix-alist))
895 (setq current (car loop)
897 (if (eq current best)
899 (setcdr current (gnus-set-difference (cdr current) numbers))
900 (when (null (cdr current))
901 (setq gnus-cite-loose-prefix-alist
902 (delq current gnus-cite-loose-prefix-alist)
903 atts (delq current atts)))))))))))
905 (defun gnus-cite-find-loose (prefix)
906 ;; Return a list of loose attribution lines prefixed by PREFIX.
907 (let* ((atts gnus-cite-loose-attribution-alist)
913 (when (string-equal (gnus-cite-find-prefix line) prefix)
917 (defun gnus-cite-add-face (number prefix face)
918 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
920 (let ((inhibit-point-motion-hooks t)
922 (goto-char (point-min))
923 (when (zerop (forward-line (1- number)))
924 (forward-char (length prefix))
925 (skip-chars-forward " \t")
928 (skip-chars-backward " \t")
931 (push (setq overlay (gnus-make-overlay from to))
932 gnus-cite-overlay-list)
933 (gnus-overlay-put overlay 'face face))))))
935 (defun gnus-cite-toggle (prefix)
937 (set-buffer gnus-article-buffer)
938 (gnus-cite-parse-maybe nil t)
939 (let ((buffer-read-only nil)
940 (numbers (cdr (assoc prefix gnus-cite-prefix-alist)))
941 (inhibit-point-motion-hooks t)
944 (setq number (car numbers)
945 numbers (cdr numbers))
946 (goto-char (point-min))
947 (forward-line (1- number))
948 (cond ((get-text-property (point) 'invisible)
949 (remove-text-properties (point) (progn (forward-line 1) (point))
950 gnus-hidden-properties))
951 ((assq number gnus-cite-attribution-alist))
953 (gnus-add-text-properties
954 (point) (progn (forward-line 1) (point))
955 (nconc (list 'article-type 'cite)
956 gnus-hidden-properties))))))))
958 (defun gnus-cite-find-prefix (line)
959 ;; Return citation prefix for LINE.
960 (let ((alist gnus-cite-prefix-alist)
964 (setq entry (car alist)
966 (when (memq line (cdr entry))
967 (setq prefix (car entry))))
970 (defun gnus-cite-localize ()
971 "Make the citation variables local to the article buffer."
972 (let ((vars '(gnus-cite-article
973 gnus-cite-overlay-list gnus-cite-prefix-alist
974 gnus-cite-attribution-alist gnus-cite-loose-prefix-alist
975 gnus-cite-loose-attribution-alist)))
977 (make-local-variable (pop vars)))))
984 ;; coding: iso-8859-1
987 ;;; gnus-cite.el ends here