afc78c33eff36ef99e308d8042c53b5d695fd838
[gnus] / lisp / gnus-cite.el
1 ;;; gnus-cite.el --- parse citations in articles for Gnus
2
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;;   2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5
6 ;; Author: Per Abhiddenware
7
8 ;; This file is part of GNU Emacs.
9
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 3 of the License, or
13 ;; (at your option) any later version.
14
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.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile (require 'cl))
28 (eval-when-compile
29   (when (featurep 'xemacs)
30     (require 'easy-mmode))) ; for `define-minor-mode'
31
32 (require 'gnus)
33 (require 'gnus-range)
34 (require 'gnus-art)
35 (require 'message)      ; for message-cite-prefix-regexp
36
37 ;;; Customization:
38
39 (defgroup gnus-cite nil
40   "Citation."
41   :prefix "gnus-cite-"
42   :link '(custom-manual "(gnus)Article Highlighting")
43   :group 'gnus-article)
44
45 (defcustom gnus-cited-opened-text-button-line-format "%(%{[-]%}%)\n"
46   "Format of opened cited text buttons."
47   :group 'gnus-cite
48   :type 'string)
49
50 (defcustom gnus-cited-closed-text-button-line-format "%(%{[+]%}%)\n"
51   "Format of closed cited text buttons."
52   :group 'gnus-cite
53   :type 'string)
54
55 (defcustom gnus-cited-lines-visible nil
56   "The number of lines of hidden cited text to remain visible.
57 Or a pair (cons) of numbers which are the number of lines at the top
58 and bottom of the text, respectively, to remain visible."
59   :group 'gnus-cite
60   :type '(choice (const :tag "none" nil)
61                  integer
62                  (cons :tag "Top and Bottom" integer integer)))
63
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."
67   :group 'gnus-cite
68   :type '(choice (const :tag "all" nil)
69                  integer))
70
71 (defcustom gnus-cite-max-prefix 20
72   "Maximum possible length for a citation prefix."
73   :group 'gnus-cite
74   :type 'integer)
75
76 (defcustom gnus-supercite-regexp
77   (concat "^\\(" message-cite-prefix-regexp "\\)? *"
78           ">>>>> +\"\\([^\"\n]+\\)\" +==")
79   "*Regexp matching normal Supercite attribution lines.
80 The first grouping must match prefixes added by other packages."
81   :group 'gnus-cite
82   :type 'regexp)
83
84 (defcustom gnus-supercite-secondary-regexp "^.*\"\\([^\"\n]+\\)\" +=="
85   "Regexp matching mangled Supercite attribution lines.
86 The first regexp group should match the Supercite attribution."
87   :group 'gnus-cite
88   :type 'regexp)
89
90 (defcustom gnus-cite-minimum-match-count 2
91   "Minimum number of identical prefixes before we believe it's a citation."
92   :group 'gnus-cite
93   :type 'integer)
94
95 ;; Some Microsoft products put in a citation that extends to the
96 ;; remainder of the message:
97 ;;
98 ;;     -----Original Message-----
99 ;;     From: ...
100 ;;     To: ...
101 ;;     Sent: ...   [date, in non-RFC-2822 format]
102 ;;     Subject: ...
103 ;;
104 ;;     Cited message, with no prefixes
105 ;;
106 ;; The four headers are always the same.  But note they are prone to
107 ;; folding without additional indentation.
108 ;;
109 ;; Others use "----- Original Message -----" instead, and properly quote
110 ;; the body using "> ".  This style is handled without special cases.
111
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."
115   :group 'gnus-cite
116   :type 'regexp)
117
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."
122   :group 'gnus-cite
123   :type 'regexp)
124
125 (defcustom gnus-cite-unsightly-citation-regexp
126   "^-----Original Message-----\nFrom: \\(.+\n\\)+\n"
127   "Regexp matching Microsoft-type rest-of-message citations."
128   :version "22.1"
129   :group 'gnus-cite
130   :type 'regexp)
131
132 (defcustom gnus-cite-ignore-quoted-from t
133   "Non-nil means don't regard lines beginning with \">From \" as cited text.
134 Those lines may have been quoted by MTAs in order not to mix up with
135 the envelope From line."
136   :version "22.1"
137   :group 'gnus-cite
138   :type 'boolean)
139
140 (defface gnus-cite-attribution '((t (:italic t)))
141   "Face used for attribution lines."
142   :group 'gnus-cite)
143 ;; backward-compatibility alias
144 (put 'gnus-cite-attribution-face 'face-alias 'gnus-cite-attribution)
145 (put 'gnus-cite-attribution-face 'obsolete-face "22.1")
146
147 (defcustom gnus-cite-attribution-face 'gnus-cite-attribution
148   "Face used for attribution lines.
149 It is merged with the face for the cited text belonging to the attribution."
150   :version "22.1"
151   :group 'gnus-cite
152   :type 'face)
153
154 (defface gnus-cite-1 '((((class color)
155                          (background dark))
156                         (:foreground "light blue"))
157                        (((class color)
158                          (background light))
159                         (:foreground "MidnightBlue"))
160                        (t
161                         (:italic t)))
162   "Citation face."
163   :group 'gnus-cite)
164 ;; backward-compatibility alias
165 (put 'gnus-cite-face-1 'face-alias 'gnus-cite-1)
166 (put 'gnus-cite-face-1 'obsolete-face "22.1")
167
168 (defface gnus-cite-2 '((((class color)
169                          (background dark))
170                         (:foreground "light cyan"))
171                        (((class color)
172                          (background light))
173                         (:foreground "firebrick"))
174                        (t
175                         (:italic t)))
176   "Citation face."
177   :group 'gnus-cite)
178 ;; backward-compatibility alias
179 (put 'gnus-cite-face-2 'face-alias 'gnus-cite-2)
180 (put 'gnus-cite-face-2 'obsolete-face "22.1")
181
182 (defface gnus-cite-3 '((((class color)
183                          (background dark))
184                         (:foreground "light yellow"))
185                        (((class color)
186                          (background light))
187                         (:foreground "dark green"))
188                        (t
189                         (:italic t)))
190   "Citation face."
191   :group 'gnus-cite)
192 ;; backward-compatibility alias
193 (put 'gnus-cite-face-3 'face-alias 'gnus-cite-3)
194 (put 'gnus-cite-face-3 'obsolete-face "22.1")
195
196 (defface gnus-cite-4 '((((class color)
197                          (background dark))
198                         (:foreground "light pink"))
199                        (((class color)
200                          (background light))
201                         (:foreground "OrangeRed"))
202                        (t
203                         (:italic t)))
204   "Citation face."
205   :group 'gnus-cite)
206 ;; backward-compatibility alias
207 (put 'gnus-cite-face-4 'face-alias 'gnus-cite-4)
208 (put 'gnus-cite-face-4 'obsolete-face "22.1")
209
210 (defface gnus-cite-5 '((((class color)
211                          (background dark))
212                         (:foreground "pale green"))
213                        (((class color)
214                          (background light))
215                         (:foreground "dark khaki"))
216                        (t
217                         (:italic t)))
218   "Citation face."
219   :group 'gnus-cite)
220 ;; backward-compatibility alias
221 (put 'gnus-cite-face-5 'face-alias 'gnus-cite-5)
222 (put 'gnus-cite-face-5 'obsolete-face "22.1")
223
224 (defface gnus-cite-6 '((((class color)
225                          (background dark))
226                         (:foreground "beige"))
227                        (((class color)
228                          (background light))
229                         (:foreground "dark violet"))
230                        (t
231                         (:italic t)))
232   "Citation face."
233   :group 'gnus-cite)
234 ;; backward-compatibility alias
235 (put 'gnus-cite-face-6 'face-alias 'gnus-cite-6)
236 (put 'gnus-cite-face-6 'obsolete-face "22.1")
237
238 (defface gnus-cite-7 '((((class color)
239                          (background dark))
240                         (:foreground "orange"))
241                        (((class color)
242                          (background light))
243                         (:foreground "SteelBlue4"))
244                        (t
245                         (:italic t)))
246   "Citation face."
247   :group 'gnus-cite)
248 ;; backward-compatibility alias
249 (put 'gnus-cite-face-7 'face-alias 'gnus-cite-7)
250 (put 'gnus-cite-face-7 'obsolete-face "22.1")
251
252 (defface gnus-cite-8 '((((class color)
253                          (background dark))
254                         (:foreground "magenta"))
255                        (((class color)
256                          (background light))
257                         (:foreground "magenta"))
258                        (t
259                         (:italic t)))
260   "Citation face."
261   :group 'gnus-cite)
262 ;; backward-compatibility alias
263 (put 'gnus-cite-face-8 'face-alias 'gnus-cite-8)
264 (put 'gnus-cite-face-8 'obsolete-face "22.1")
265
266 (defface gnus-cite-9 '((((class color)
267                          (background dark))
268                         (:foreground "violet"))
269                        (((class color)
270                          (background light))
271                         (:foreground "violet"))
272                        (t
273                         (:italic t)))
274   "Citation face."
275   :group 'gnus-cite)
276 ;; backward-compatibility alias
277 (put 'gnus-cite-face-9 'face-alias 'gnus-cite-9)
278 (put 'gnus-cite-face-9 'obsolete-face "22.1")
279
280 (defface gnus-cite-10 '((((class color)
281                           (background dark))
282                          (:foreground "plum1"))
283                         (((class color)
284                           (background light))
285                          (:foreground "medium purple"))
286                         (t
287                          (:italic t)))
288   "Citation face."
289   :group 'gnus-cite)
290 ;; backward-compatibility alias
291 (put 'gnus-cite-face-10 'face-alias 'gnus-cite-10)
292 (put 'gnus-cite-face-10 'obsolete-face "22.1")
293
294 (defface gnus-cite-11 '((((class color)
295                           (background dark))
296                          (:foreground "turquoise"))
297                         (((class color)
298                           (background light))
299                          (:foreground "turquoise"))
300                         (t
301                          (:italic t)))
302   "Citation face."
303   :group 'gnus-cite)
304 ;; backward-compatibility alias
305 (put 'gnus-cite-face-11 'face-alias 'gnus-cite-11)
306 (put 'gnus-cite-face-11 'obsolete-face "22.1")
307
308 (defcustom gnus-cite-face-list
309   '(gnus-cite-1 gnus-cite-2 gnus-cite-3 gnus-cite-4 gnus-cite-5 gnus-cite-6
310                 gnus-cite-7 gnus-cite-8 gnus-cite-9 gnus-cite-10 gnus-cite-11)
311   "*List of faces used for highlighting citations.
312
313 When there are citations from multiple articles in the same message,
314 Gnus will try to give each citation from each article its own face.
315 This should make it easier to see who wrote what."
316   :group 'gnus-cite
317   :type '(repeat face)
318   :set (lambda (symbol value)
319          (prog1
320              (custom-set-default symbol value)
321            (if (boundp 'gnus-message-max-citation-depth)
322                (setq gnus-message-max-citation-depth (length value)))
323            (if (boundp 'gnus-message-citation-keywords)
324                (setq gnus-message-citation-keywords
325                      `((gnus-message-search-citation-line
326                         ,@(let ((list nil)
327                                 (count 1))
328                             (dolist (face value (nreverse list))
329                               (push (list count (list 'quote face) 'prepend t)
330                                     list)
331                               (setq count (1+ count)))))))))))
332
333 (defcustom gnus-cite-hide-percentage 50
334   "Only hide excess citation if above this percentage of the body."
335   :group 'gnus-cite
336   :type 'number)
337
338 (defcustom gnus-cite-hide-absolute 10
339   "Only hide excess citation if above this number of lines in the body."
340   :group 'gnus-cite
341   :type 'integer)
342
343 (defcustom gnus-cite-blank-line-after-header t
344   "If non-nil, put a blank line between the citation header and the button."
345   :group 'gnus-cite
346   :type 'boolean)
347
348 ;; This has to go here because its default value depends on
349 ;; gnus-cite-face-list.
350 (defcustom gnus-article-boring-faces (cons 'gnus-signature gnus-cite-face-list)
351   "List of faces that are not worth reading.
352 If an article has more pages below the one you are looking at, but
353 nothing on those pages is a word of at least three letters that is not
354 in a boring face, then the pages will be skipped."
355   :type '(repeat face)
356   :group 'gnus-article-hiding)
357
358 ;;; Internal Variables:
359
360 (defvar gnus-cite-article nil)
361 (defvar gnus-cite-overlay-list nil)
362
363 (defvar gnus-cite-prefix-alist nil)
364 ;; Alist of citation prefixes.
365 ;; The cdr is a list of lines with that prefix.
366
367 (defvar gnus-cite-attribution-alist nil)
368 ;; Alist of attribution lines.
369 ;; The car is a line number.
370 ;; The cdr is the prefix for the citation started by that line.
371
372 (defvar gnus-cite-loose-prefix-alist nil)
373 ;; Alist of citation prefixes that have no matching attribution.
374 ;; The cdr is a list of lines with that prefix.
375
376 (defvar gnus-cite-loose-attribution-alist nil)
377 ;; Alist of attribution lines that have no matching citation.
378 ;; Each member has the form (WROTE IN PREFIX TAG), where
379 ;; WROTE: is the attribution line number
380 ;; IN: is the line number of the previous line if part of the same attribution,
381 ;; PREFIX: Is the citation prefix of the attribution line(s), and
382 ;; TAG: Is a Supercite tag, if any.
383
384 (defvar gnus-cited-opened-text-button-line-format-alist
385   `((?b (marker-position beg) ?d)
386     (?e (marker-position end) ?d)
387     (?n (count-lines beg end) ?d)
388     (?l (- end beg) ?d)))
389 (defvar gnus-cited-opened-text-button-line-format-spec nil)
390 (defvar gnus-cited-closed-text-button-line-format-alist
391   gnus-cited-opened-text-button-line-format-alist)
392 (defvar gnus-cited-closed-text-button-line-format-spec nil)
393
394
395 ;;; Commands:
396
397 (defun gnus-article-highlight-citation (&optional force same-buffer)
398   "Highlight cited text.
399 Each citation in the article will be highlighted with a different face.
400 The faces are taken from `gnus-cite-face-list'.
401 Attribution lines are highlighted with the same face as the
402 corresponding citation merged with the face `gnus-cite-attribution'.
403
404 Text is considered cited if at least `gnus-cite-minimum-match-count'
405 lines matches `message-cite-prefix-regexp' with the same prefix.
406
407 Lines matching `gnus-cite-attribution-suffix' and perhaps
408 `gnus-cite-attribution-prefix' are considered attribution lines."
409   (interactive (list 'force))
410   (with-current-buffer (if same-buffer (current-buffer) gnus-article-buffer)
411     (gnus-cite-parse-maybe force)
412     (let ((buffer-read-only nil)
413           (alist gnus-cite-prefix-alist)
414           (faces gnus-cite-face-list)
415           (inhibit-point-motion-hooks t)
416           face entry prefix skip numbers number face-alist)
417       ;; Loop through citation prefixes.
418       (while alist
419         (setq entry (car alist)
420               alist (cdr alist)
421               prefix (car entry)
422               numbers (cdr entry)
423               face (car faces)
424               faces (or (cdr faces) gnus-cite-face-list)
425               face-alist (cons (cons prefix face) face-alist))
426         (while numbers
427           (setq number (car numbers)
428                 numbers (cdr numbers))
429           (and (not (assq number gnus-cite-attribution-alist))
430                (not (assq number gnus-cite-loose-attribution-alist))
431                (gnus-cite-add-face number prefix face))))
432       ;; Loop through attribution lines.
433       (setq alist gnus-cite-attribution-alist)
434       (while alist
435         (setq entry (car alist)
436               alist (cdr alist)
437               number (car entry)
438               prefix (cdr entry)
439               skip (gnus-cite-find-prefix number)
440               face (cdr (assoc prefix face-alist)))
441         ;; Add attribution button.
442         (goto-char (point-min))
443         (forward-line (1- number))
444         (when (re-search-forward gnus-cite-attribution-suffix
445                                  (point-at-eol)
446                                  t)
447           (gnus-article-add-button (match-beginning 1) (match-end 1)
448                                    'gnus-cite-toggle prefix))
449         ;; Highlight attribution line.
450         (gnus-cite-add-face number skip face)
451         (gnus-cite-add-face number skip gnus-cite-attribution-face))
452       ;; Loop through attribution lines.
453       (setq alist gnus-cite-loose-attribution-alist)
454       (while alist
455         (setq entry (car alist)
456               alist (cdr alist)
457               number (car entry)
458               skip (gnus-cite-find-prefix number))
459         (gnus-cite-add-face number skip gnus-cite-attribution-face)))))
460
461 (defun gnus-dissect-cited-text ()
462   "Dissect the article buffer looking for cited text."
463   (with-current-buffer gnus-article-buffer
464     (gnus-cite-parse-maybe nil t)
465     (let ((alist gnus-cite-prefix-alist)
466           prefix numbers number marks m)
467       ;; Loop through citation prefixes.
468       (while alist
469         (setq numbers (pop alist)
470               prefix (pop numbers))
471         (while numbers
472           (setq number (pop numbers))
473           (goto-char (point-min))
474           (forward-line number)
475           (push (cons (point-marker) "") marks)
476           (while (and numbers
477                       (= (1- number) (car numbers)))
478             (setq number (pop numbers)))
479           (goto-char (point-min))
480           (forward-line (1- number))
481           (push (cons (point-marker) prefix) marks)))
482       ;; Skip to the beginning of the body.
483       (article-goto-body)
484       (push (cons (point-marker) "") marks)
485       ;; Find the end of the body.
486       (goto-char (point-max))
487       (gnus-article-search-signature)
488       (push (cons (point-marker) "") marks)
489       ;; Sort the marks.
490       (setq marks (sort marks 'car-less-than-car))
491       (let ((omarks marks))
492         (setq marks nil)
493         (while (cdr omarks)
494           (if (= (caar omarks) (caadr omarks))
495               (progn
496                 (unless (equal (cdar omarks) "")
497                   (push (car omarks) marks))
498                 (unless (equal (cdadr omarks) "")
499                   (push (cadr omarks) marks))
500                 (unless (and (equal (cdar omarks) "")
501                              (equal (cdadr omarks) "")
502                              (not (cddr omarks)))
503                   (setq omarks (cdr omarks))))
504             (push (car omarks) marks))
505           (setq omarks (cdr omarks)))
506         (when (car omarks)
507           (push (car omarks) marks))
508         (setq marks (setq m (nreverse marks)))
509         (while (cddr m)
510           (if (and (equal (cdadr m) "")
511                    (equal (cdar m) (cdaddr m))
512                    (goto-char (caadr m))
513                    (forward-line 1)
514                    (= (point) (caaddr m)))
515               (setcdr m (cdddr m))
516             (setq m (cdr m))))
517         marks))))
518
519 (defun gnus-article-fill-cited-long-lines ()
520   (gnus-article-fill-cited-article nil t))
521
522 (defun gnus-article-fill-cited-article (&optional width long-lines)
523   "Do word wrapping in the current article.
524 If WIDTH (the numerical prefix), use that text width when
525 filling.  If LONG-LINES, only fill sections that have lines
526 longer than the frame width."
527   (interactive "P")
528   (with-current-buffer gnus-article-buffer
529     (let ((buffer-read-only nil)
530           (inhibit-point-motion-hooks t)
531           (marks (gnus-dissect-cited-text))
532           (adaptive-fill-mode nil)
533           (filladapt-mode nil)
534           (fill-column (if width (prefix-numeric-value width) fill-column)))
535       (save-restriction
536         (while (cdr marks)
537           (narrow-to-region (caar marks) (caadr marks))
538           (let ((adaptive-fill-regexp
539                  (concat "^" (regexp-quote (cdar marks)) " *"))
540                 (fill-prefix
541                  (if (string= (cdar marks) "") ""
542                    (concat (cdar marks) " ")))
543                 (do-fill (not long-lines))
544                 use-hard-newlines)
545             (goto-char (point-min))
546             (unless do-fill
547               (while (not (eobp))
548                 (end-of-line)
549                 (when (> (current-column) (frame-width))
550                   (setq do-fill t))
551                 (forward-line 1)))
552             (when do-fill
553               (fill-region (point-min) (point-max))))
554           (set-marker (caar marks) nil)
555           (setq marks (cdr marks)))
556         (when marks
557           (set-marker (caar marks) nil))
558         ;; All this information is now incorrect.
559         (setq gnus-cite-prefix-alist nil
560               gnus-cite-attribution-alist nil
561               gnus-cite-loose-prefix-alist nil
562               gnus-cite-loose-attribution-alist nil
563               gnus-cite-article nil)))))
564
565 (defun gnus-article-natural-long-line-p ()
566   "Return true if the current line is long, and it's natural text."
567   (save-excursion
568     (beginning-of-line)
569     (and
570      ;; The line is long.
571      (> (- (line-end-position) (line-beginning-position))
572         (frame-width))
573      ;; It doesn't start with spaces.
574      (not (looking-at "    "))
575      ;; Not cited text.
576      (let ((line-number (1+ (count-lines (point-min) (point))))
577            citep)
578        (dolist (elem gnus-cite-prefix-alist)
579          (when (member line-number (cdr elem))
580            (setq citep t)))
581        (not citep)))))
582
583 (defun gnus-article-hide-citation (&optional arg force)
584   "Toggle hiding of all cited text except attribution lines.
585 See the documentation for `gnus-article-highlight-citation'.
586 If given a negative prefix, always show; if given a positive prefix,
587 always hide."
588   (interactive (append (gnus-article-hidden-arg) (list 'force)))
589   (gnus-set-format 'cited-opened-text-button t)
590   (gnus-set-format 'cited-closed-text-button t)
591   (with-current-buffer gnus-article-buffer
592     (let ((buffer-read-only nil)
593           marks
594           (inhibit-point-motion-hooks t)
595           (props (nconc (list 'article-type 'cite)
596                         gnus-hidden-properties))
597           (point (point-min))
598           found beg end start)
599       (while (setq point
600                    (text-property-any point (point-max)
601                                       'gnus-callback
602                                       'gnus-article-toggle-cited-text))
603         (setq found t)
604         (goto-char point)
605         (gnus-article-toggle-cited-text
606          (get-text-property point 'gnus-data) arg)
607         (forward-line 1)
608         (setq point (point)))
609       (unless found
610         (setq marks (gnus-dissect-cited-text))
611         (while marks
612           (setq beg nil
613                 end nil)
614           (while (and marks (string= (cdar marks) ""))
615             (setq marks (cdr marks)))
616           (when marks
617             (setq beg (caar marks)))
618           (while (and marks (not (string= (cdar marks) "")))
619             (setq marks (cdr marks)))
620           (when marks
621             (setq end (caar marks)))
622           ;; Skip past lines we want to leave visible.
623           (when (and beg end gnus-cited-lines-visible)
624             (goto-char beg)
625             (forward-line (if (consp gnus-cited-lines-visible)
626                               (car gnus-cited-lines-visible)
627                             gnus-cited-lines-visible))
628             (if (>= (point) end)
629                 (setq beg nil)
630               (setq beg (point-marker))
631               (when (consp gnus-cited-lines-visible)
632                 (goto-char end)
633                 (forward-line (- (cdr gnus-cited-lines-visible)))
634                 (if (<= (point) beg)
635                     (setq beg nil)
636                   (setq end (point-marker))))))
637           (when (and beg end)
638             (gnus-add-wash-type 'cite)
639             ;; We use markers for the end-points to facilitate later
640             ;; wrapping and mangling of text.
641             (setq beg (set-marker (make-marker) beg)
642                   end (set-marker (make-marker) end))
643             (gnus-add-text-properties-when 'article-type nil beg end props)
644             (goto-char beg)
645             (when (and gnus-cite-blank-line-after-header
646                        (not (save-excursion (search-backward "\n\n" nil t))))
647               (insert "\n"))
648             (put-text-property
649              (setq start (point-marker))
650              (progn
651                (gnus-article-add-button
652                 (point)
653                 (progn (eval gnus-cited-closed-text-button-line-format-spec)
654                        (point))
655                 `gnus-article-toggle-cited-text
656                 (list (cons beg end) start))
657                (point))
658              'article-type 'annotation)
659             (set-marker beg (point))))))))
660
661 (defun gnus-article-toggle-cited-text (args &optional arg)
662   "Toggle hiding the text in REGION.
663 ARG can be nil or a number.  Positive means hide, negative
664 means show, nil means toggle."
665   (let* ((region (car args))
666          (beg (car region))
667          (end (cdr region))
668          (start (cadr args))
669          (hidden
670           (text-property-any beg (1- end) 'article-type 'cite))
671          (inhibit-point-motion-hooks t)
672          buffer-read-only)
673     (when (or (null arg)
674               (zerop arg)
675               (and (> arg 0) (not hidden))
676               (and (< arg 0) hidden))
677       (if hidden
678           (progn
679             ;; Can't remove 'cite from g-a-wash-types here because
680             ;; multiple citations may be hidden -jas
681             (gnus-remove-text-properties-when
682              'article-type 'cite beg end
683              (cons 'article-type (cons 'cite
684                                        gnus-hidden-properties))))
685         (gnus-add-wash-type 'cite)
686         (gnus-add-text-properties-when
687          'article-type nil beg end
688          (cons 'article-type (cons 'cite
689                                    gnus-hidden-properties))))
690       (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
691         (gnus-set-mode-line 'article))
692       (save-excursion
693         (goto-char start)
694         (gnus-delete-line)
695         (put-text-property
696          (point)
697          (progn
698            (gnus-article-add-button
699             (point)
700             (progn (eval
701                     (if hidden
702                         gnus-cited-opened-text-button-line-format-spec
703                       gnus-cited-closed-text-button-line-format-spec))
704                    (point))
705             `gnus-article-toggle-cited-text
706             args)
707            (point))
708          'article-type 'annotation)))))
709
710 (defun gnus-article-hide-citation-maybe (&optional arg force)
711   "Toggle hiding of cited text that has an attribution line.
712 If given a negative prefix, always show; if given a positive prefix,
713 always hide.
714 This will do nothing unless at least `gnus-cite-hide-percentage'
715 percent and at least `gnus-cite-hide-absolute' lines of the body is
716 cited text with attributions.  When called interactively, these two
717 variables are ignored.
718 See also the documentation for `gnus-article-highlight-citation'."
719   (interactive (append (gnus-article-hidden-arg) '(force)))
720   (with-current-buffer gnus-article-buffer
721     (gnus-delete-wash-type 'cite)
722     (unless (gnus-article-check-hidden-text 'cite arg)
723       (save-excursion
724         (gnus-cite-parse-maybe force)
725         (article-goto-body)
726         (let ((start (point))
727               (atts gnus-cite-attribution-alist)
728               (buffer-read-only nil)
729               (inhibit-point-motion-hooks t)
730               (hidden 0)
731               total)
732           (goto-char (point-max))
733           (gnus-article-search-signature)
734           (setq total (count-lines start (point)))
735           (while atts
736             (setq hidden (+ hidden (length (cdr (assoc (cdar atts)
737                                                        gnus-cite-prefix-alist))))
738                   atts (cdr atts)))
739           (when (or force
740                     (and (> (* 100 hidden) (* gnus-cite-hide-percentage total))
741                          (> hidden gnus-cite-hide-absolute)))
742             (gnus-add-wash-type 'cite)
743             (setq atts gnus-cite-attribution-alist)
744             (while atts
745               (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist))
746                     atts (cdr atts))
747               (while total
748                 (setq hidden (car total)
749                       total (cdr total))
750                 (goto-char (point-min))
751                 (forward-line (1- hidden))
752                 (unless (assq hidden gnus-cite-attribution-alist)
753                   (gnus-add-text-properties
754                    (point) (progn (forward-line 1) (point))
755                    (nconc (list 'article-type 'cite)
756                           gnus-hidden-properties)))))))))
757     (gnus-set-mode-line 'article)))
758
759 (defun gnus-article-hide-citation-in-followups ()
760   "Hide cited text in non-root articles."
761   (interactive)
762   (with-current-buffer gnus-article-buffer
763     (let ((article (cdr gnus-article-current)))
764       (unless (with-current-buffer gnus-summary-buffer
765                 (gnus-article-displayed-root-p article))
766         (gnus-article-hide-citation)))))
767
768 ;;; Internal functions:
769
770 (defun gnus-cite-parse-maybe (&optional force no-overlay)
771   "Always parse the buffer."
772   (gnus-cite-localize)
773   ;;Reset parser information.
774   (setq gnus-cite-prefix-alist nil
775         gnus-cite-attribution-alist nil
776         gnus-cite-loose-prefix-alist nil
777         gnus-cite-loose-attribution-alist nil)
778   (unless no-overlay
779     (gnus-cite-delete-overlays))
780   ;; Parse if not too large.
781   (if (and gnus-cite-parse-max-size
782            (> (buffer-size) gnus-cite-parse-max-size))
783       ()
784     (setq gnus-cite-article (cons (car gnus-article-current)
785                                   (cdr gnus-article-current)))
786     (gnus-cite-parse-wrapper)))
787
788 (defun gnus-cite-delete-overlays ()
789   (dolist (overlay gnus-cite-overlay-list)
790     (ignore-errors
791       (when (or (not (gnus-overlay-end overlay))
792                 (and (>= (gnus-overlay-end overlay) (point-min))
793                      (<= (gnus-overlay-end overlay) (point-max))))
794         (setq gnus-cite-overlay-list (delete overlay gnus-cite-overlay-list))
795         (ignore-errors
796           (gnus-delete-overlay overlay))))))
797
798 (defun gnus-cite-parse-wrapper ()
799   ;; Wrap chopped gnus-cite-parse.
800   (article-goto-body)
801   (let ((inhibit-point-motion-hooks t))
802     (save-excursion
803       (gnus-cite-parse-attributions))
804     (save-excursion
805       (gnus-cite-parse))
806     (save-excursion
807       (gnus-cite-connect-attributions))))
808
809 (defun gnus-cite-parse ()
810   ;; Parse and connect citation prefixes and attribution lines.
811
812   ;; Parse current buffer searching for citation prefixes.
813   (let ((line (1+ (count-lines (point-min) (point))))
814         (case-fold-search t)
815         (max (save-excursion
816                (goto-char (point-max))
817                (gnus-article-search-signature)
818                (point)))
819         (prefix-regexp (concat "^\\(" message-cite-prefix-regexp "\\)"))
820         alist entry start begin end numbers prefix guess-limit)
821     ;; Get all potential prefixes in `alist'.
822     (while (< (point) max)
823       ;; Each line.
824       (setq begin (point)
825             guess-limit (progn (skip-chars-forward "^> \t\r\n") (point))
826             end (point-at-bol 2)
827             start end)
828       (goto-char begin)
829       ;; Ignore standard Supercite attribution prefix.
830       (when (and (< guess-limit (+ begin gnus-cite-max-prefix))
831                  (looking-at gnus-supercite-regexp))
832         (if (match-end 1)
833             (setq end (1+ (match-end 1)))
834           (setq end (1+ begin))))
835       ;; Ignore very long prefixes.
836       (when (> end (+ begin gnus-cite-max-prefix))
837         (setq end (+ begin gnus-cite-max-prefix)))
838       ;; Ignore quoted envelope From_.
839       (when (and gnus-cite-ignore-quoted-from
840                  (prog2
841                      (setq case-fold-search nil)
842                      (looking-at ">From ")
843                    (setq case-fold-search t)))
844         (setq end (1+ begin)))
845       (while (re-search-forward prefix-regexp (1- end) t)
846         ;; Each prefix.
847         (setq end (match-end 0)
848               prefix (buffer-substring begin end))
849         (set-text-properties 0 (length prefix) nil prefix)
850         (setq entry (assoc prefix alist))
851         (if entry
852             (setcdr entry (cons line (cdr entry)))
853           (push (list prefix line) alist))
854         (goto-char begin))
855       (goto-char start)
856       (setq line (1+ line)))
857     ;; Horrible special case for some Microsoft mailers.
858     (goto-char (point-min))
859     (setq start t begin nil entry nil)
860     (while start
861       ;; Assume this search ends up at the beginning of a line.
862       (if (re-search-forward gnus-cite-unsightly-citation-regexp max t)
863           (progn
864             (when (number-or-marker-p start)
865               (setq begin (count-lines (point-min) start)
866                     end (count-lines (point-min) (match-beginning 0))))
867             (setq start (match-end 0)))
868         (when (number-or-marker-p start)
869           (setq begin (count-lines (point-min) start)
870                 end (count-lines (point-min) max)))
871         (setq start nil))
872       (when begin
873         (while (< begin end)
874           ;; Need to do 1+ because we're in the bol.
875           (push (setq begin (1+ begin)) entry))))
876     (when entry
877       (push (cons "" entry) alist))
878     ;; We got all the potential prefixes.  Now create
879     ;; `gnus-cite-prefix-alist' containing the oldest prefix for each
880     ;; line that appears at least `gnus-cite-minimum-match-count'
881     ;; times.  First sort them by length.  Longer is older.
882     (setq alist (sort alist (lambda (a b)
883                               (> (length (car a)) (length (car b))))))
884     (while alist
885       (setq entry (car alist)
886             prefix (car entry)
887             numbers (cdr entry)
888             alist (cdr alist))
889       (cond ((null numbers)
890              ;; No lines with this prefix that wasn't also part of
891              ;; a longer prefix.
892              )
893             ((< (length numbers) gnus-cite-minimum-match-count)
894              ;; Too few lines with this prefix.  We keep it a bit
895              ;; longer in case it is an exact match for an attribution
896              ;; line, but we don't remove the line from other
897              ;; prefixes.
898              (push entry gnus-cite-prefix-alist))
899             (t
900              (push entry
901                    gnus-cite-prefix-alist)
902              ;; Remove articles from other prefixes.
903              (let ((loop alist)
904                    current)
905                (while loop
906                  (setq current (car loop)
907                        loop (cdr loop))
908                  (setcdr current
909                          (gnus-set-difference (cdr current) numbers)))))))))
910
911 (defun gnus-cite-parse-attributions ()
912   (let (al-alist)
913     ;; Parse attributions
914     (while (re-search-forward gnus-cite-attribution-suffix (point-max) t)
915       (let* ((start (match-beginning 0))
916              (end (match-end 0))
917              (wrote (count-lines (point-min) end))
918              (prefix (gnus-cite-find-prefix wrote))
919              ;; Check previous line for an attribution leader.
920              (tag (progn
921                     (beginning-of-line 1)
922                     (when (looking-at gnus-supercite-secondary-regexp)
923                       (buffer-substring (match-beginning 1)
924                                         (match-end 1)))))
925              (in (progn
926                    (goto-char start)
927                    (and (re-search-backward gnus-cite-attribution-prefix
928                                             (save-excursion
929                                               (beginning-of-line 0)
930                                               (point))
931                                             t)
932                         (not (re-search-forward gnus-cite-attribution-suffix
933                                                 start t))
934                         (count-lines (point-min) (1+ (point)))))))
935         (when (eq wrote in)
936           (setq in nil))
937         (goto-char end)
938         ;; don't add duplicates
939         (let ((al (buffer-substring (save-excursion (beginning-of-line 0)
940                                                     (1+ (point)))
941                                     end)))
942           (when (not (assoc al al-alist))
943             (push (list wrote in prefix tag)
944                   gnus-cite-loose-attribution-alist)
945             (push (cons al t) al-alist)))))))
946
947 (defun gnus-cite-connect-attributions ()
948   ;; Connect attributions to citations
949
950   ;; No citations have been connected to attribution lines yet.
951   (setq gnus-cite-loose-prefix-alist (append gnus-cite-prefix-alist nil))
952
953   ;; Parse current buffer searching for attribution lines.
954   ;; Find exact supercite citations.
955   (gnus-cite-match-attributions 'small nil
956                                 (lambda (prefix tag)
957                                   (when tag
958                                     (concat "\\`"
959                                             (regexp-quote prefix) "[ \t]*"
960                                             (regexp-quote tag) ">"))))
961   ;; Find loose supercite citations after attributions.
962   (gnus-cite-match-attributions 'small t
963                                 (lambda (prefix tag)
964                                   (when tag
965                                     (concat "\\<"
966                                             (regexp-quote tag)
967                                             "\\>"))))
968   ;; Find loose supercite citations anywhere.
969   (gnus-cite-match-attributions 'small nil
970                                 (lambda (prefix tag)
971                                   (when tag
972                                     (concat "\\<"
973                                             (regexp-quote tag)
974                                             "\\>"))))
975   ;; Find nested citations after attributions.
976   (gnus-cite-match-attributions 'small-if-unique t
977                                 (lambda (prefix tag)
978                                   (concat "\\`" (regexp-quote prefix) ".+")))
979   ;; Find nested citations anywhere.
980   (gnus-cite-match-attributions 'small nil
981                                 (lambda (prefix tag)
982                                   (concat "\\`" (regexp-quote prefix) ".+")))
983   ;; Remove loose prefixes with too few lines.
984   (let ((alist gnus-cite-loose-prefix-alist)
985         entry)
986     (while alist
987       (setq entry (car alist)
988             alist (cdr alist))
989       (when (< (length (cdr entry)) gnus-cite-minimum-match-count)
990         (setq gnus-cite-prefix-alist
991               (delq entry gnus-cite-prefix-alist)
992               gnus-cite-loose-prefix-alist
993               (delq entry gnus-cite-loose-prefix-alist)))))
994   ;; Find flat attributions.
995   (gnus-cite-match-attributions 'first t nil)
996   ;; Find any attributions (are we getting desperate yet?).
997   (gnus-cite-match-attributions 'first nil nil))
998
999 (defun gnus-cite-match-attributions (sort after fun)
1000   ;; Match all loose attributions and citations (SORT AFTER FUN) .
1001   ;;
1002   ;; If SORT is `small', the citation with the shortest prefix will be
1003   ;; used, if it is `first' the first prefix will be used, if it is
1004   ;; `small-if-unique' the shortest prefix will be used if the
1005   ;; attribution line does not share its own prefix with other
1006   ;; loose attribution lines, otherwise the first prefix will be used.
1007   ;;
1008   ;; If AFTER is non-nil, only citations after the attribution line
1009   ;; will be considered.
1010   ;;
1011   ;; If FUN is non-nil, it will be called with the arguments (WROTE
1012   ;; PREFIX TAG) and expected to return a regular expression.  Only
1013   ;; citations whose prefix matches the regular expression will be
1014   ;; considered.
1015   ;;
1016   ;; WROTE is the attribution line number.
1017   ;; PREFIX is the attribution line prefix.
1018   ;; TAG is the Supercite tag on the attribution line.
1019   (let ((atts gnus-cite-loose-attribution-alist)
1020         (case-fold-search t)
1021         att wrote in prefix tag regexp limit smallest best size)
1022     (while atts
1023       (setq att (car atts)
1024             atts (cdr atts)
1025             wrote (nth 0 att)
1026             in (nth 1 att)
1027             prefix (nth 2 att)
1028             tag (nth 3 att)
1029             regexp (if fun (funcall fun prefix tag) "")
1030             size (cond ((eq sort 'small) t)
1031                        ((eq sort 'first) nil)
1032                        (t (< (length (gnus-cite-find-loose prefix)) 2)))
1033             limit (if after wrote -1)
1034             smallest 1000000
1035             best nil)
1036       (let ((cites gnus-cite-loose-prefix-alist)
1037             cite candidate numbers first compare)
1038         (while cites
1039           (setq cite (car cites)
1040                 cites (cdr cites)
1041                 candidate (car cite)
1042                 numbers (cdr cite)
1043                 first (apply 'min numbers)
1044                 compare (if size (length candidate) first))
1045           (and (> first limit)
1046                regexp
1047                (string-match regexp candidate)
1048                (< compare smallest)
1049                (setq best cite
1050                      smallest compare))))
1051       (if (null best)
1052           ()
1053         (setq gnus-cite-loose-attribution-alist
1054               (delq att gnus-cite-loose-attribution-alist))
1055         (push (cons wrote (car best)) gnus-cite-attribution-alist)
1056         (when in
1057           (push (cons in (car best)) gnus-cite-attribution-alist))
1058         (when (memq best gnus-cite-loose-prefix-alist)
1059           (let ((loop gnus-cite-prefix-alist)
1060                 (numbers (cdr best))
1061                 current)
1062             (setq gnus-cite-loose-prefix-alist
1063                   (delq best gnus-cite-loose-prefix-alist))
1064             (while loop
1065               (setq current (car loop)
1066                     loop (cdr loop))
1067               (if (eq current best)
1068                   ()
1069                 (setcdr current (gnus-set-difference (cdr current) numbers))
1070                 (when (null (cdr current))
1071                   (setq gnus-cite-loose-prefix-alist
1072                         (delq current gnus-cite-loose-prefix-alist)
1073                         atts (delq current atts)))))))))))
1074
1075 (defun gnus-cite-find-loose (prefix)
1076   ;; Return a list of loose attribution lines prefixed by PREFIX.
1077   (let* ((atts gnus-cite-loose-attribution-alist)
1078          att line lines)
1079     (while atts
1080       (setq att (car atts)
1081             line (car att)
1082             atts (cdr atts))
1083       (when (string-equal (gnus-cite-find-prefix line) prefix)
1084         (push line lines)))
1085     lines))
1086
1087 (defun gnus-cite-add-face (number prefix face)
1088   ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
1089   (when face
1090     (let ((inhibit-point-motion-hooks t)
1091           from to overlay)
1092       (goto-char (point-min))
1093       (when (zerop (forward-line (1- number)))
1094         (forward-char (length prefix))
1095         (skip-chars-forward " \t")
1096         (setq from (point))
1097         (end-of-line 1)
1098         (skip-chars-backward " \t")
1099         (setq to (point))
1100         (when (< from to)
1101           (push (setq overlay (gnus-make-overlay from to))
1102                 gnus-cite-overlay-list)
1103           (gnus-overlay-put overlay 'evaporate t)
1104           (gnus-overlay-put overlay 'face face))))))
1105
1106 (defun gnus-cite-toggle (prefix)
1107   (with-current-buffer gnus-article-buffer
1108     (gnus-cite-parse-maybe nil t)
1109     (let ((buffer-read-only nil)
1110           (numbers (cdr (assoc prefix gnus-cite-prefix-alist)))
1111           (inhibit-point-motion-hooks t)
1112           number)
1113       (while numbers
1114         (setq number (car numbers)
1115               numbers (cdr numbers))
1116         (goto-char (point-min))
1117         (forward-line (1- number))
1118         (cond ((get-text-property (point) 'invisible)
1119                ;; Can't remove 'cite from g-a-wash-types here because
1120                ;; multiple citations may be hidden -jas
1121                (remove-text-properties (point) (progn (forward-line 1) (point))
1122                                        gnus-hidden-properties))
1123               ((assq number gnus-cite-attribution-alist))
1124               (t
1125                (gnus-add-wash-type 'cite)
1126                (gnus-add-text-properties
1127                 (point) (progn (forward-line 1) (point))
1128                 (nconc (list 'article-type 'cite)
1129                        gnus-hidden-properties))))
1130         (let ((gnus-article-mime-handle-alist-1
1131                gnus-article-mime-handle-alist))
1132           (gnus-set-mode-line 'article))))))
1133
1134 (defun gnus-cite-find-prefix (line)
1135   ;; Return citation prefix for LINE.
1136   (let ((alist gnus-cite-prefix-alist)
1137         (prefix "")
1138         entry)
1139     (while alist
1140       (setq entry (car alist)
1141             alist (cdr alist))
1142       (when (memq line (cdr entry))
1143         (setq prefix (car entry))))
1144     prefix))
1145
1146 (defun gnus-cite-localize ()
1147   "Make the citation variables local to the article buffer."
1148   (let ((vars '(gnus-cite-article
1149                 gnus-cite-overlay-list gnus-cite-prefix-alist
1150                 gnus-cite-attribution-alist gnus-cite-loose-prefix-alist
1151                 gnus-cite-loose-attribution-alist)))
1152     (while vars
1153       (make-local-variable (pop vars)))))
1154
1155 (defun gnus-cited-line-p ()
1156   "Say whether the current line is a cited line."
1157   (save-excursion
1158     (beginning-of-line)
1159     (let ((found nil))
1160       (dolist (prefix (mapcar 'car gnus-cite-prefix-alist))
1161         (when (string= (buffer-substring (point) (+ (length prefix) (point)))
1162                        prefix)
1163           (setq found t)))
1164       found)))
1165
1166
1167 ;; Highlighting of different citation levels in message-mode.
1168 ;; - message-cite-prefix will be overridden if this is enabled.
1169
1170 (defvar gnus-message-max-citation-depth
1171   (length gnus-cite-face-list)
1172   "Maximum supported level of citation.")
1173
1174 (defvar gnus-message-cite-prefix-regexp
1175   (concat "^\\(?:" message-cite-prefix-regexp "\\)"))
1176
1177 (defun gnus-message-search-citation-line (limit)
1178   "Search for a cited line and set match data accordingly.
1179 Returns nil if there is no such line before LIMIT, t otherwise."
1180   (when (re-search-forward gnus-message-cite-prefix-regexp limit t)
1181     (let ((cdepth (min (length (apply 'concat
1182                                       (split-string
1183                                        (match-string-no-properties 0)
1184                                        "[ \t [:alnum:]]+")))
1185                        gnus-message-max-citation-depth))
1186           (mlist (make-list (* (1+ gnus-message-max-citation-depth) 2) nil))
1187           (start (point-at-bol))
1188           (end (point-at-eol)))
1189       (setcar mlist start)
1190       (setcar (cdr mlist) end)
1191       (setcar (nthcdr (* cdepth 2) mlist) start)
1192       (setcar (nthcdr (1+ (* cdepth 2)) mlist) end)
1193       (set-match-data mlist))
1194     t))
1195
1196 (defvar gnus-message-citation-keywords
1197   ;; eval-when-compile ;; This breaks in XEmacs
1198   `((gnus-message-search-citation-line
1199      ,@(let ((list nil)
1200              (count 1))
1201          ;; (require 'gnus-cite)
1202          (dolist (face gnus-cite-face-list (nreverse list))
1203            (push (list count (list 'quote face) 'prepend t) list)
1204            (setq count (1+ count)))))) ;;
1205   "Keywords for highlighting different levels of message citations.")
1206
1207 (defvar font-lock-defaults-computed)
1208 (defvar font-lock-keywords)
1209 (defvar font-lock-set-defaults)
1210
1211 (eval-and-compile
1212   (unless (featurep 'xemacs)
1213     (autoload 'font-lock-set-defaults "font-lock")))
1214
1215 (define-minor-mode gnus-message-citation-mode
1216   "Toggle `gnus-message-citation-mode' in current buffer.
1217 This buffer local minor mode provides additional font-lock support for
1218 nested citations.
1219 With prefix ARG, turn `gnus-message-citation-mode' on if and only if ARG
1220 is positive.
1221 Automatically turn `font-lock-mode' on when `gnus-message-citation-mode'
1222 is turned on."
1223   nil ;; init-value
1224   "" ;; lighter
1225   nil ;; keymap
1226   (when (eq major-mode 'message-mode)
1227     (let ((defaults (car (if (featurep 'xemacs)
1228                              (get 'message-mode 'font-lock-defaults)
1229                            font-lock-defaults)))
1230           default keywords)
1231       (while defaults
1232         (setq default (if (consp defaults)
1233                           (pop defaults)
1234                         (prog1
1235                             defaults
1236                           (setq defaults nil))))
1237         (if gnus-message-citation-mode
1238             ;; `gnus-message-citation-keywords' should be the last
1239             ;; elements of the keywords because the others are unlikely
1240             ;; to have the OVERRIDE flags -- XEmacs applies a keyword
1241             ;; having no OVERRIDE flag to matched text even if it has
1242             ;; already other faces, while Emacs doesn't.
1243             (set (make-local-variable default)
1244                  (append (default-value default)
1245                          gnus-message-citation-keywords))
1246           (kill-local-variable default))))
1247     ;; Force `font-lock-set-defaults' to update `font-lock-keywords'.
1248     (if (featurep 'xemacs)
1249         (progn
1250           (require 'font-lock)
1251           (setq font-lock-defaults-computed nil
1252                 font-lock-keywords nil))
1253       (setq font-lock-set-defaults nil))
1254     (font-lock-set-defaults)
1255     (cond ((symbol-value 'font-lock-mode)
1256            (font-lock-fontify-buffer))
1257           (gnus-message-citation-mode
1258            (font-lock-mode 1)))))
1259
1260 (defun turn-on-gnus-message-citation-mode ()
1261   "Turn on `gnus-message-citation-mode'."
1262   (gnus-message-citation-mode 1))
1263 (defun turn-off-gnus-message-citation-mode ()
1264   "Turn off `gnus-message-citation-mode'."
1265   (gnus-message-citation-mode -1))
1266
1267 (gnus-ems-redefine)
1268
1269 (provide 'gnus-cite)
1270
1271 ;; Local Variables:
1272 ;; coding: iso-8859-1
1273 ;; End:
1274
1275 ;;; gnus-cite.el ends here