Fix up some byte-compiler warnings.
[bpt/emacs.git] / lisp / gnus / gnus-cite.el
CommitLineData
23f87bed 1;;; gnus-cite.el --- parse citations in articles for Gnus
eec82323 2
e84b4b86 3;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
114f9c96 4;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
16409b0b
GM
5
6;; Author: Per Abhiddenware
7
8;; This file is part of GNU Emacs.
9
5e809f55 10;; GNU Emacs is free software: you can redistribute it and/or modify
eec82323 11;; it under the terms of the GNU General Public License as published by
5e809f55
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
eec82323
LMI
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
5e809f55 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
22
23;;; Commentary:
24
25;;; Code:
26
5ab7173c 27(eval-when-compile (require 'cl))
01c52d31
MB
28(eval-when-compile
29 (when (featurep 'xemacs)
30 (require 'easy-mmode))) ; for `define-minor-mode'
5ab7173c 31
eec82323 32(require 'gnus)
eec82323 33(require 'gnus-range)
23f87bed
MB
34(require 'gnus-art)
35(require 'message) ; for message-cite-prefix-regexp
eec82323
LMI
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
6748645f
LMI
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."
eec82323
LMI
52 :group 'gnus-cite
53 :type 'string)
54
55(defcustom gnus-cited-lines-visible nil
16409b0b
GM
56 "The number of lines of hidden cited text to remain visible.
57Or a pair (cons) of numbers which are the number of lines at the top
58and bottom of the text, respectively, to remain visible."
eec82323
LMI
59 :group 'gnus-cite
60 :type '(choice (const :tag "none" nil)
16409b0b
GM
61 integer
62 (cons :tag "Top and Bottom" integer integer)))
eec82323
LMI
63
64(defcustom gnus-cite-parse-max-size 25000
65 "Maximum article size (in bytes) where parsing citations is allowed.
66Set it to nil to parse all articles."
67 :group 'gnus-cite
68 :type '(choice (const :tag "all" nil)
69 integer))
70
eec82323
LMI
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
23f87bed 77 (concat "^\\(" message-cite-prefix-regexp "\\)? *"
eec82323 78 ">>>>> +\"\\([^\"\n]+\\)\" +==")
6748645f 79 "*Regexp matching normal Supercite attribution lines.
eec82323
LMI
80The 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.
86The 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
23f87bed
MB
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
6748645f 112(defcustom gnus-cite-attribution-prefix
23f87bed 113 "In article\\|in <\\|On \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\),\\|----- ?Original Message ?-----"
6748645f 114 "*Regexp matching the beginning of an attribution line."
eec82323
LMI
115 :group 'gnus-cite
116 :type 'regexp)
117
118(defcustom gnus-cite-attribution-suffix
23f87bed 119 "\\(\\(wrote\\|writes\\|said\\|says\\|>\\)\\(:\\|\\.\\.\\.\\)\\|----- ?Original Message ?-----\\)[ \t]*$"
6748645f 120 "*Regexp matching the end of an attribution line.
eec82323
LMI
121The text matching the first grouping will be used as a button."
122 :group 'gnus-cite
123 :type 'regexp)
124
23f87bed
MB
125(defcustom gnus-cite-unsightly-citation-regexp
126 "^-----Original Message-----\nFrom: \\(.+\n\\)+\n"
127 "Regexp matching Microsoft-type rest-of-message citations."
bf247b6e 128 :version "22.1"
23f87bed
MB
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.
134Those lines may have been quoted by MTAs in order not to mix up with
135the envelope From line."
bf247b6e 136 :version "22.1"
23f87bed
MB
137 :group 'gnus-cite
138 :type 'boolean)
139
0f49874b 140(defface gnus-cite-attribution '((t (:italic t)))
d0859c9a
MB
141 "Face used for attribution lines."
142 :group 'gnus-cite)
0f49874b
MB
143;; backward-compatibility alias
144(put 'gnus-cite-attribution-face 'face-alias 'gnus-cite-attribution)
3d493bef 145(put 'gnus-cite-attribution-face 'obsolete-face "22.1")
eec82323 146
0f49874b 147(defcustom gnus-cite-attribution-face 'gnus-cite-attribution
eec82323
LMI
148 "Face used for attribution lines.
149It is merged with the face for the cited text belonging to the attribution."
bf247b6e 150 :version "22.1"
eec82323
LMI
151 :group 'gnus-cite
152 :type 'face)
153
0f49874b
MB
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)))
d0859c9a
MB
162 "Citation face."
163 :group 'gnus-cite)
0f49874b
MB
164;; backward-compatibility alias
165(put 'gnus-cite-face-1 'face-alias 'gnus-cite-1)
3d493bef 166(put 'gnus-cite-face-1 'obsolete-face "22.1")
0f49874b
MB
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)))
d0859c9a
MB
176 "Citation face."
177 :group 'gnus-cite)
0f49874b
MB
178;; backward-compatibility alias
179(put 'gnus-cite-face-2 'face-alias 'gnus-cite-2)
3d493bef 180(put 'gnus-cite-face-2 'obsolete-face "22.1")
0f49874b
MB
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)))
d0859c9a
MB
190 "Citation face."
191 :group 'gnus-cite)
0f49874b
MB
192;; backward-compatibility alias
193(put 'gnus-cite-face-3 'face-alias 'gnus-cite-3)
3d493bef 194(put 'gnus-cite-face-3 'obsolete-face "22.1")
0f49874b
MB
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)))
d0859c9a
MB
204 "Citation face."
205 :group 'gnus-cite)
0f49874b
MB
206;; backward-compatibility alias
207(put 'gnus-cite-face-4 'face-alias 'gnus-cite-4)
3d493bef 208(put 'gnus-cite-face-4 'obsolete-face "22.1")
0f49874b
MB
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)))
d0859c9a
MB
218 "Citation face."
219 :group 'gnus-cite)
0f49874b
MB
220;; backward-compatibility alias
221(put 'gnus-cite-face-5 'face-alias 'gnus-cite-5)
3d493bef 222(put 'gnus-cite-face-5 'obsolete-face "22.1")
0f49874b
MB
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)))
d0859c9a
MB
232 "Citation face."
233 :group 'gnus-cite)
0f49874b
MB
234;; backward-compatibility alias
235(put 'gnus-cite-face-6 'face-alias 'gnus-cite-6)
3d493bef 236(put 'gnus-cite-face-6 'obsolete-face "22.1")
0f49874b
MB
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)))
d0859c9a
MB
246 "Citation face."
247 :group 'gnus-cite)
0f49874b
MB
248;; backward-compatibility alias
249(put 'gnus-cite-face-7 'face-alias 'gnus-cite-7)
3d493bef 250(put 'gnus-cite-face-7 'obsolete-face "22.1")
0f49874b
MB
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)))
d0859c9a
MB
260 "Citation face."
261 :group 'gnus-cite)
0f49874b
MB
262;; backward-compatibility alias
263(put 'gnus-cite-face-8 'face-alias 'gnus-cite-8)
3d493bef 264(put 'gnus-cite-face-8 'obsolete-face "22.1")
0f49874b
MB
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)))
d0859c9a
MB
274 "Citation face."
275 :group 'gnus-cite)
0f49874b
MB
276;; backward-compatibility alias
277(put 'gnus-cite-face-9 'face-alias 'gnus-cite-9)
3d493bef 278(put 'gnus-cite-face-9 'obsolete-face "22.1")
0f49874b
MB
279
280(defface gnus-cite-10 '((((class color)
281 (background dark))
01c52d31 282 (:foreground "plum1"))
0f49874b
MB
283 (((class color)
284 (background light))
285 (:foreground "medium purple"))
286 (t
287 (:italic t)))
d0859c9a
MB
288 "Citation face."
289 :group 'gnus-cite)
0f49874b
MB
290;; backward-compatibility alias
291(put 'gnus-cite-face-10 'face-alias 'gnus-cite-10)
3d493bef 292(put 'gnus-cite-face-10 'obsolete-face "22.1")
0f49874b
MB
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)))
d0859c9a
MB
302 "Citation face."
303 :group 'gnus-cite)
0f49874b
MB
304;; backward-compatibility alias
305(put 'gnus-cite-face-11 'face-alias 'gnus-cite-11)
3d493bef 306(put 'gnus-cite-face-11 'obsolete-face "22.1")
eec82323
LMI
307
308(defcustom gnus-cite-face-list
0f49874b 309 '(gnus-cite-1 gnus-cite-2 gnus-cite-3 gnus-cite-4 gnus-cite-5 gnus-cite-6
01c52d31 310 gnus-cite-7 gnus-cite-8 gnus-cite-9 gnus-cite-10 gnus-cite-11)
6748645f 311 "*List of faces used for highlighting citations.
eec82323
LMI
312
313When there are citations from multiple articles in the same message,
314Gnus will try to give each citation from each article its own face.
315This should make it easier to see who wrote what."
316 :group 'gnus-cite
01c52d31
MB
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)))))))))))
eec82323
LMI
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
eb1666e2
MB
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
23f87bed
MB
348;; This has to go here because its default value depends on
349;; gnus-cite-face-list.
0f49874b 350(defcustom gnus-article-boring-faces (cons 'gnus-signature gnus-cite-face-list)
23f87bed
MB
351 "List of faces that are not worth reading.
352If an article has more pages below the one you are looking at, but
353nothing on those pages is a word of at least three letters that is not
354in a boring face, then the pages will be skipped."
355 :type '(repeat face)
356 :group 'gnus-article-hiding)
357
eec82323
LMI
358;;; Internal Variables:
359
360(defvar gnus-cite-article nil)
6748645f 361(defvar gnus-cite-overlay-list nil)
eec82323
LMI
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
6748645f 384(defvar gnus-cited-opened-text-button-line-format-alist
eec82323
LMI
385 `((?b (marker-position beg) ?d)
386 (?e (marker-position end) ?d)
6748645f 387 (?n (count-lines beg end) ?d)
eec82323 388 (?l (- end beg) ?d)))
6748645f
LMI
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
eec82323
LMI
394
395;;; Commands:
396
01c52d31 397(defun gnus-article-highlight-citation (&optional force same-buffer)
eec82323
LMI
398 "Highlight cited text.
399Each citation in the article will be highlighted with a different face.
400The faces are taken from `gnus-cite-face-list'.
401Attribution lines are highlighted with the same face as the
0f49874b 402corresponding citation merged with the face `gnus-cite-attribution'.
eec82323
LMI
403
404Text is considered cited if at least `gnus-cite-minimum-match-count'
23f87bed 405lines matches `message-cite-prefix-regexp' with the same prefix.
eec82323
LMI
406
407Lines matching `gnus-cite-attribution-suffix' and perhaps
408`gnus-cite-attribution-prefix' are considered attribution lines."
409 (interactive (list 'force))
765abcce 410 (with-current-buffer (if same-buffer (current-buffer) gnus-article-buffer)
eec82323
LMI
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.
16409b0b
GM
442 (goto-char (point-min))
443 (forward-line (1- number))
eec82323 444 (when (re-search-forward gnus-cite-attribution-suffix
01c52d31 445 (point-at-eol)
eec82323
LMI
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."
765abcce 463 (with-current-buffer gnus-article-buffer
16409b0b 464 (gnus-cite-parse-maybe nil t)
eec82323
LMI
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.
16409b0b 483 (article-goto-body)
eec82323
LMI
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.
6748645f 490 (setq marks (sort marks 'car-less-than-car))
eec82323
LMI
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-article (&optional force width)
520 "Do word wrapping in the current article.
521If WIDTH (the numerical prefix), use that text width when filling."
522 (interactive (list t current-prefix-arg))
765abcce 523 (with-current-buffer gnus-article-buffer
eec82323
LMI
524 (let ((buffer-read-only nil)
525 (inhibit-point-motion-hooks t)
526 (marks (gnus-dissect-cited-text))
527 (adaptive-fill-mode nil)
528 (filladapt-mode nil)
529 (fill-column (if width (prefix-numeric-value width) fill-column)))
530 (save-restriction
531 (while (cdr marks)
eec82323
LMI
532 (narrow-to-region (caar marks) (caadr marks))
533 (let ((adaptive-fill-regexp
534 (concat "^" (regexp-quote (cdar marks)) " *"))
23f87bed
MB
535 (fill-prefix
536 (if (string= (cdar marks) "") ""
537 (concat (cdar marks) " ")))
538 use-hard-newlines)
eec82323
LMI
539 (fill-region (point-min) (point-max)))
540 (set-marker (caar marks) nil)
541 (setq marks (cdr marks)))
542 (when marks
543 (set-marker (caar marks) nil))
544 ;; All this information is now incorrect.
545 (setq gnus-cite-prefix-alist nil
546 gnus-cite-attribution-alist nil
547 gnus-cite-loose-prefix-alist nil
a8151ef7
LMI
548 gnus-cite-loose-attribution-alist nil
549 gnus-cite-article nil)))))
eec82323 550
2cdd366f
KY
551(defun gnus-article-natural-long-line-p ()
552 "Return true if the current line is long, and it's natural text."
553 (save-excursion
554 (beginning-of-line)
555 (and
556 ;; The line is long.
557 (> (- (line-end-position) (line-beginning-position))
558 (frame-width))
559 ;; It doesn't start with spaces.
560 (not (looking-at " "))
561 ;; Not cited text.
562 (let ((line-number (1+ (count-lines (point-min) (point))))
563 citep)
564 (dolist (elem gnus-cite-prefix-alist)
565 (when (member line-number (cdr elem))
566 (setq citep t)))
567 (not citep)))))
568
eec82323
LMI
569(defun gnus-article-hide-citation (&optional arg force)
570 "Toggle hiding of all cited text except attribution lines.
571See the documentation for `gnus-article-highlight-citation'.
572If given a negative prefix, always show; if given a positive prefix,
573always hide."
574 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6748645f
LMI
575 (gnus-set-format 'cited-opened-text-button t)
576 (gnus-set-format 'cited-closed-text-button t)
765abcce
SM
577 (with-current-buffer gnus-article-buffer
578 (let ((buffer-read-only nil)
579 marks
580 (inhibit-point-motion-hooks t)
581 (props (nconc (list 'article-type 'cite)
582 gnus-hidden-properties))
583 (point (point-min))
584 found beg end start)
585 (while (setq point
586 (text-property-any point (point-max)
587 'gnus-callback
588 'gnus-article-toggle-cited-text))
589 (setq found t)
590 (goto-char point)
591 (gnus-article-toggle-cited-text
592 (get-text-property point 'gnus-data) arg)
593 (forward-line 1)
594 (setq point (point)))
595 (unless found
596 (setq marks (gnus-dissect-cited-text))
597 (while marks
598 (setq beg nil
599 end nil)
600 (while (and marks (string= (cdar marks) ""))
601 (setq marks (cdr marks)))
602 (when marks
603 (setq beg (caar marks)))
604 (while (and marks (not (string= (cdar marks) "")))
605 (setq marks (cdr marks)))
606 (when marks
eec82323 607 (setq end (caar marks)))
765abcce
SM
608 ;; Skip past lines we want to leave visible.
609 (when (and beg end gnus-cited-lines-visible)
610 (goto-char beg)
611 (forward-line (if (consp gnus-cited-lines-visible)
612 (car gnus-cited-lines-visible)
613 gnus-cited-lines-visible))
614 (if (>= (point) end)
615 (setq beg nil)
616 (setq beg (point-marker))
617 (when (consp gnus-cited-lines-visible)
618 (goto-char end)
619 (forward-line (- (cdr gnus-cited-lines-visible)))
620 (if (<= (point) beg)
621 (setq beg nil)
16409b0b 622 (setq end (point-marker))))))
765abcce
SM
623 (when (and beg end)
624 (gnus-add-wash-type 'cite)
625 ;; We use markers for the end-points to facilitate later
626 ;; wrapping and mangling of text.
627 (setq beg (set-marker (make-marker) beg)
628 end (set-marker (make-marker) end))
629 (gnus-add-text-properties-when 'article-type nil beg end props)
630 (goto-char beg)
631 (when (and gnus-cite-blank-line-after-header
632 (not (save-excursion (search-backward "\n\n" nil t))))
633 (insert "\n"))
634 (put-text-property
635 (setq start (point-marker))
636 (progn
eec82323
LMI
637 (gnus-article-add-button
638 (point)
6748645f
LMI
639 (progn (eval gnus-cited-closed-text-button-line-format-spec)
640 (point))
641 `gnus-article-toggle-cited-text
642 (list (cons beg end) start))
eec82323 643 (point))
765abcce
SM
644 'article-type 'annotation)
645 (set-marker beg (point))))))))
eec82323 646
520aa572
SZ
647(defun gnus-article-toggle-cited-text (args &optional arg)
648 "Toggle hiding the text in REGION.
649ARG can be nil or a number. Positive means hide, negative
650means show, nil means toggle."
6748645f 651 (let* ((region (car args))
16409b0b
GM
652 (beg (car region))
653 (end (cdr region))
6748645f
LMI
654 (start (cadr args))
655 (hidden
520aa572 656 (text-property-any beg (1- end) 'article-type 'cite))
6748645f
LMI
657 (inhibit-point-motion-hooks t)
658 buffer-read-only)
520aa572
SZ
659 (when (or (null arg)
660 (zerop arg)
661 (and (> arg 0) (not hidden))
662 (and (< arg 0) hidden))
663 (if hidden
23f87bed
MB
664 (progn
665 ;; Can't remove 'cite from g-a-wash-types here because
666 ;; multiple citations may be hidden -jas
667 (gnus-remove-text-properties-when
668 'article-type 'cite beg end
669 (cons 'article-type (cons 'cite
670 gnus-hidden-properties))))
671 (gnus-add-wash-type 'cite)
520aa572 672 (gnus-add-text-properties-when
a1506d29 673 'article-type nil beg end
520aa572
SZ
674 (cons 'article-type (cons 'cite
675 gnus-hidden-properties))))
23f87bed
MB
676 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
677 (gnus-set-mode-line 'article))
520aa572
SZ
678 (save-excursion
679 (goto-char start)
680 (gnus-delete-line)
681 (put-text-property
682 (point)
683 (progn
684 (gnus-article-add-button
685 (point)
686 (progn (eval
687 (if hidden
688 gnus-cited-opened-text-button-line-format-spec
689 gnus-cited-closed-text-button-line-format-spec))
690 (point))
691 `gnus-article-toggle-cited-text
692 args)
693 (point))
694 'article-type 'annotation)))))
eec82323
LMI
695
696(defun gnus-article-hide-citation-maybe (&optional arg force)
697 "Toggle hiding of cited text that has an attribution line.
698If given a negative prefix, always show; if given a positive prefix,
699always hide.
700This will do nothing unless at least `gnus-cite-hide-percentage'
701percent and at least `gnus-cite-hide-absolute' lines of the body is
702cited text with attributions. When called interactively, these two
703variables are ignored.
704See also the documentation for `gnus-article-highlight-citation'."
6748645f 705 (interactive (append (gnus-article-hidden-arg) '(force)))
23f87bed
MB
706 (with-current-buffer gnus-article-buffer
707 (gnus-delete-wash-type 'cite)
708 (unless (gnus-article-check-hidden-text 'cite arg)
709 (save-excursion
710 (gnus-cite-parse-maybe force)
711 (article-goto-body)
712 (let ((start (point))
713 (atts gnus-cite-attribution-alist)
714 (buffer-read-only nil)
715 (inhibit-point-motion-hooks t)
716 (hidden 0)
717 total)
718 (goto-char (point-max))
719 (gnus-article-search-signature)
720 (setq total (count-lines start (point)))
eec82323 721 (while atts
23f87bed
MB
722 (setq hidden (+ hidden (length (cdr (assoc (cdar atts)
723 gnus-cite-prefix-alist))))
724 atts (cdr atts)))
725 (when (or force
726 (and (> (* 100 hidden) (* gnus-cite-hide-percentage total))
727 (> hidden gnus-cite-hide-absolute)))
728 (gnus-add-wash-type 'cite)
729 (setq atts gnus-cite-attribution-alist)
730 (while atts
731 (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist))
732 atts (cdr atts))
733 (while total
734 (setq hidden (car total)
735 total (cdr total))
736 (goto-char (point-min))
737 (forward-line (1- hidden))
738 (unless (assq hidden gnus-cite-attribution-alist)
739 (gnus-add-text-properties
740 (point) (progn (forward-line 1) (point))
741 (nconc (list 'article-type 'cite)
742 gnus-hidden-properties)))))))))
743 (gnus-set-mode-line 'article)))
eec82323
LMI
744
745(defun gnus-article-hide-citation-in-followups ()
746 "Hide cited text in non-root articles."
747 (interactive)
765abcce 748 (with-current-buffer gnus-article-buffer
eec82323 749 (let ((article (cdr gnus-article-current)))
765abcce 750 (unless (with-current-buffer gnus-summary-buffer
eec82323
LMI
751 (gnus-article-displayed-root-p article))
752 (gnus-article-hide-citation)))))
753
754;;; Internal functions:
755
16409b0b
GM
756(defun gnus-cite-parse-maybe (&optional force no-overlay)
757 "Always parse the buffer."
758 (gnus-cite-localize)
759 ;;Reset parser information.
760 (setq gnus-cite-prefix-alist nil
761 gnus-cite-attribution-alist nil
762 gnus-cite-loose-prefix-alist nil
763 gnus-cite-loose-attribution-alist nil)
764 (unless no-overlay
765 (gnus-cite-delete-overlays))
766 ;; Parse if not too large.
767 (if (and gnus-cite-parse-max-size
768 (> (buffer-size) gnus-cite-parse-max-size))
eec82323 769 ()
16409b0b
GM
770 (setq gnus-cite-article (cons (car gnus-article-current)
771 (cdr gnus-article-current)))
772 (gnus-cite-parse-wrapper)))
773
774(defun gnus-cite-delete-overlays ()
775 (dolist (overlay gnus-cite-overlay-list)
23f87bed
MB
776 (ignore-errors
777 (when (or (not (gnus-overlay-end overlay))
778 (and (>= (gnus-overlay-end overlay) (point-min))
779 (<= (gnus-overlay-end overlay) (point-max))))
780 (setq gnus-cite-overlay-list (delete overlay gnus-cite-overlay-list))
781 (ignore-errors
782 (gnus-delete-overlay overlay))))))
eec82323
LMI
783
784(defun gnus-cite-parse-wrapper ()
16409b0b
GM
785 ;; Wrap chopped gnus-cite-parse.
786 (article-goto-body)
787 (let ((inhibit-point-motion-hooks t))
788 (save-excursion
789 (gnus-cite-parse-attributions))
790 (save-excursion
791 (gnus-cite-parse))
792 (save-excursion
793 (gnus-cite-connect-attributions))))
eec82323
LMI
794
795(defun gnus-cite-parse ()
796 ;; Parse and connect citation prefixes and attribution lines.
797
798 ;; Parse current buffer searching for citation prefixes.
799 (let ((line (1+ (count-lines (point-min) (point))))
800 (case-fold-search t)
801 (max (save-excursion
802 (goto-char (point-max))
803 (gnus-article-search-signature)
804 (point)))
23f87bed
MB
805 (prefix-regexp (concat "^\\(" message-cite-prefix-regexp "\\)"))
806 alist entry start begin end numbers prefix guess-limit)
eec82323
LMI
807 ;; Get all potential prefixes in `alist'.
808 (while (< (point) max)
809 ;; Each line.
810 (setq begin (point)
23f87bed 811 guess-limit (progn (skip-chars-forward "^> \t\r\n") (point))
01c52d31 812 end (point-at-bol 2)
eec82323
LMI
813 start end)
814 (goto-char begin)
815 ;; Ignore standard Supercite attribution prefix.
23f87bed
MB
816 (when (and (< guess-limit (+ begin gnus-cite-max-prefix))
817 (looking-at gnus-supercite-regexp))
eec82323
LMI
818 (if (match-end 1)
819 (setq end (1+ (match-end 1)))
820 (setq end (1+ begin))))
821 ;; Ignore very long prefixes.
23f87bed
MB
822 (when (> end (+ begin gnus-cite-max-prefix))
823 (setq end (+ begin gnus-cite-max-prefix)))
824 ;; Ignore quoted envelope From_.
825 (when (and gnus-cite-ignore-quoted-from
826 (prog2
827 (setq case-fold-search nil)
828 (looking-at ">From ")
829 (setq case-fold-search t)))
830 (setq end (1+ begin)))
831 (while (re-search-forward prefix-regexp (1- end) t)
eec82323
LMI
832 ;; Each prefix.
833 (setq end (match-end 0)
834 prefix (buffer-substring begin end))
01c52d31 835 (set-text-properties 0 (length prefix) nil prefix)
eec82323
LMI
836 (setq entry (assoc prefix alist))
837 (if entry
838 (setcdr entry (cons line (cdr entry)))
839 (push (list prefix line) alist))
840 (goto-char begin))
841 (goto-char start)
842 (setq line (1+ line)))
23f87bed
MB
843 ;; Horrible special case for some Microsoft mailers.
844 (goto-char (point-min))
01c52d31
MB
845 (setq start t begin nil entry nil)
846 (while start
847 ;; Assume this search ends up at the beginning of a line.
848 (if (re-search-forward gnus-cite-unsightly-citation-regexp max t)
849 (progn
850 (when (number-or-marker-p start)
851 (setq begin (count-lines (point-min) start)
852 end (count-lines (point-min) (match-beginning 0))))
853 (setq start (match-end 0)))
854 (when (number-or-marker-p start)
855 (setq begin (count-lines (point-min) start)
856 end (count-lines (point-min) max)))
857 (setq start nil))
858 (when begin
859 (while (< begin end)
860 ;; Need to do 1+ because we're in the bol.
861 (push (setq begin (1+ begin)) entry))))
862 (when entry
23f87bed 863 (push (cons "" entry) alist))
eec82323
LMI
864 ;; We got all the potential prefixes. Now create
865 ;; `gnus-cite-prefix-alist' containing the oldest prefix for each
23f87bed 866 ;; line that appears at least `gnus-cite-minimum-match-count'
eec82323
LMI
867 ;; times. First sort them by length. Longer is older.
868 (setq alist (sort alist (lambda (a b)
869 (> (length (car a)) (length (car b))))))
870 (while alist
871 (setq entry (car alist)
872 prefix (car entry)
873 numbers (cdr entry)
874 alist (cdr alist))
875 (cond ((null numbers)
876 ;; No lines with this prefix that wasn't also part of
877 ;; a longer prefix.
878 )
879 ((< (length numbers) gnus-cite-minimum-match-count)
880 ;; Too few lines with this prefix. We keep it a bit
881 ;; longer in case it is an exact match for an attribution
882 ;; line, but we don't remove the line from other
883 ;; prefixes.
884 (push entry gnus-cite-prefix-alist))
885 (t
886 (push entry
887 gnus-cite-prefix-alist)
888 ;; Remove articles from other prefixes.
889 (let ((loop alist)
890 current)
891 (while loop
892 (setq current (car loop)
893 loop (cdr loop))
894 (setcdr current
895 (gnus-set-difference (cdr current) numbers)))))))))
896
897(defun gnus-cite-parse-attributions ()
898 (let (al-alist)
899 ;; Parse attributions
900 (while (re-search-forward gnus-cite-attribution-suffix (point-max) t)
901 (let* ((start (match-beginning 0))
902 (end (match-end 0))
903 (wrote (count-lines (point-min) end))
904 (prefix (gnus-cite-find-prefix wrote))
905 ;; Check previous line for an attribution leader.
906 (tag (progn
907 (beginning-of-line 1)
908 (when (looking-at gnus-supercite-secondary-regexp)
909 (buffer-substring (match-beginning 1)
910 (match-end 1)))))
911 (in (progn
912 (goto-char start)
913 (and (re-search-backward gnus-cite-attribution-prefix
914 (save-excursion
915 (beginning-of-line 0)
916 (point))
917 t)
918 (not (re-search-forward gnus-cite-attribution-suffix
919 start t))
920 (count-lines (point-min) (1+ (point)))))))
921 (when (eq wrote in)
922 (setq in nil))
923 (goto-char end)
924 ;; don't add duplicates
925 (let ((al (buffer-substring (save-excursion (beginning-of-line 0)
926 (1+ (point)))
927 end)))
01c52d31
MB
928 (when (not (assoc al al-alist))
929 (push (list wrote in prefix tag)
930 gnus-cite-loose-attribution-alist)
931 (push (cons al t) al-alist)))))))
eec82323
LMI
932
933(defun gnus-cite-connect-attributions ()
934 ;; Connect attributions to citations
935
936 ;; No citations have been connected to attribution lines yet.
937 (setq gnus-cite-loose-prefix-alist (append gnus-cite-prefix-alist nil))
938
939 ;; Parse current buffer searching for attribution lines.
940 ;; Find exact supercite citations.
941 (gnus-cite-match-attributions 'small nil
942 (lambda (prefix tag)
943 (when tag
944 (concat "\\`"
945 (regexp-quote prefix) "[ \t]*"
946 (regexp-quote tag) ">"))))
947 ;; Find loose supercite citations after attributions.
948 (gnus-cite-match-attributions 'small t
949 (lambda (prefix tag)
950 (when tag
951 (concat "\\<"
952 (regexp-quote tag)
953 "\\>"))))
954 ;; Find loose supercite citations anywhere.
955 (gnus-cite-match-attributions 'small nil
956 (lambda (prefix tag)
957 (when tag
958 (concat "\\<"
959 (regexp-quote tag)
960 "\\>"))))
961 ;; Find nested citations after attributions.
962 (gnus-cite-match-attributions 'small-if-unique t
963 (lambda (prefix tag)
964 (concat "\\`" (regexp-quote prefix) ".+")))
965 ;; Find nested citations anywhere.
966 (gnus-cite-match-attributions 'small nil
967 (lambda (prefix tag)
968 (concat "\\`" (regexp-quote prefix) ".+")))
969 ;; Remove loose prefixes with too few lines.
970 (let ((alist gnus-cite-loose-prefix-alist)
971 entry)
972 (while alist
973 (setq entry (car alist)
974 alist (cdr alist))
975 (when (< (length (cdr entry)) gnus-cite-minimum-match-count)
976 (setq gnus-cite-prefix-alist
977 (delq entry gnus-cite-prefix-alist)
978 gnus-cite-loose-prefix-alist
979 (delq entry gnus-cite-loose-prefix-alist)))))
980 ;; Find flat attributions.
981 (gnus-cite-match-attributions 'first t nil)
982 ;; Find any attributions (are we getting desperate yet?).
983 (gnus-cite-match-attributions 'first nil nil))
984
985(defun gnus-cite-match-attributions (sort after fun)
986 ;; Match all loose attributions and citations (SORT AFTER FUN) .
987 ;;
988 ;; If SORT is `small', the citation with the shortest prefix will be
989 ;; used, if it is `first' the first prefix will be used, if it is
990 ;; `small-if-unique' the shortest prefix will be used if the
991 ;; attribution line does not share its own prefix with other
992 ;; loose attribution lines, otherwise the first prefix will be used.
993 ;;
994 ;; If AFTER is non-nil, only citations after the attribution line
995 ;; will be considered.
996 ;;
997 ;; If FUN is non-nil, it will be called with the arguments (WROTE
998 ;; PREFIX TAG) and expected to return a regular expression. Only
999 ;; citations whose prefix matches the regular expression will be
1000 ;; considered.
1001 ;;
1002 ;; WROTE is the attribution line number.
1003 ;; PREFIX is the attribution line prefix.
1004 ;; TAG is the Supercite tag on the attribution line.
1005 (let ((atts gnus-cite-loose-attribution-alist)
1006 (case-fold-search t)
1007 att wrote in prefix tag regexp limit smallest best size)
1008 (while atts
1009 (setq att (car atts)
1010 atts (cdr atts)
1011 wrote (nth 0 att)
1012 in (nth 1 att)
1013 prefix (nth 2 att)
1014 tag (nth 3 att)
1015 regexp (if fun (funcall fun prefix tag) "")
1016 size (cond ((eq sort 'small) t)
1017 ((eq sort 'first) nil)
1018 (t (< (length (gnus-cite-find-loose prefix)) 2)))
1019 limit (if after wrote -1)
1020 smallest 1000000
1021 best nil)
1022 (let ((cites gnus-cite-loose-prefix-alist)
1023 cite candidate numbers first compare)
1024 (while cites
1025 (setq cite (car cites)
1026 cites (cdr cites)
1027 candidate (car cite)
1028 numbers (cdr cite)
1029 first (apply 'min numbers)
1030 compare (if size (length candidate) first))
1031 (and (> first limit)
1032 regexp
1033 (string-match regexp candidate)
1034 (< compare smallest)
1035 (setq best cite
1036 smallest compare))))
1037 (if (null best)
1038 ()
1039 (setq gnus-cite-loose-attribution-alist
1040 (delq att gnus-cite-loose-attribution-alist))
1041 (push (cons wrote (car best)) gnus-cite-attribution-alist)
1042 (when in
1043 (push (cons in (car best)) gnus-cite-attribution-alist))
1044 (when (memq best gnus-cite-loose-prefix-alist)
1045 (let ((loop gnus-cite-prefix-alist)
1046 (numbers (cdr best))
1047 current)
1048 (setq gnus-cite-loose-prefix-alist
1049 (delq best gnus-cite-loose-prefix-alist))
1050 (while loop
1051 (setq current (car loop)
1052 loop (cdr loop))
1053 (if (eq current best)
1054 ()
1055 (setcdr current (gnus-set-difference (cdr current) numbers))
1056 (when (null (cdr current))
1057 (setq gnus-cite-loose-prefix-alist
1058 (delq current gnus-cite-loose-prefix-alist)
1059 atts (delq current atts)))))))))))
1060
1061(defun gnus-cite-find-loose (prefix)
1062 ;; Return a list of loose attribution lines prefixed by PREFIX.
1063 (let* ((atts gnus-cite-loose-attribution-alist)
1064 att line lines)
1065 (while atts
1066 (setq att (car atts)
1067 line (car att)
1068 atts (cdr atts))
1069 (when (string-equal (gnus-cite-find-prefix line) prefix)
1070 (push line lines)))
1071 lines))
1072
1073(defun gnus-cite-add-face (number prefix face)
1074 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
1075 (when face
1076 (let ((inhibit-point-motion-hooks t)
6748645f 1077 from to overlay)
16409b0b
GM
1078 (goto-char (point-min))
1079 (when (zerop (forward-line (1- number)))
eec82323
LMI
1080 (forward-char (length prefix))
1081 (skip-chars-forward " \t")
1082 (setq from (point))
1083 (end-of-line 1)
1084 (skip-chars-backward " \t")
1085 (setq to (point))
1086 (when (< from to)
6748645f
LMI
1087 (push (setq overlay (gnus-make-overlay from to))
1088 gnus-cite-overlay-list)
c1b1a4f3 1089 (gnus-overlay-put overlay 'evaporate t)
6748645f 1090 (gnus-overlay-put overlay 'face face))))))
eec82323
LMI
1091
1092(defun gnus-cite-toggle (prefix)
765abcce 1093 (with-current-buffer gnus-article-buffer
16409b0b 1094 (gnus-cite-parse-maybe nil t)
eec82323
LMI
1095 (let ((buffer-read-only nil)
1096 (numbers (cdr (assoc prefix gnus-cite-prefix-alist)))
1097 (inhibit-point-motion-hooks t)
1098 number)
1099 (while numbers
1100 (setq number (car numbers)
1101 numbers (cdr numbers))
16409b0b
GM
1102 (goto-char (point-min))
1103 (forward-line (1- number))
eec82323 1104 (cond ((get-text-property (point) 'invisible)
23f87bed
MB
1105 ;; Can't remove 'cite from g-a-wash-types here because
1106 ;; multiple citations may be hidden -jas
eec82323
LMI
1107 (remove-text-properties (point) (progn (forward-line 1) (point))
1108 gnus-hidden-properties))
1109 ((assq number gnus-cite-attribution-alist))
1110 (t
23f87bed 1111 (gnus-add-wash-type 'cite)
eec82323
LMI
1112 (gnus-add-text-properties
1113 (point) (progn (forward-line 1) (point))
1114 (nconc (list 'article-type 'cite)
23f87bed
MB
1115 gnus-hidden-properties))))
1116 (let ((gnus-article-mime-handle-alist-1
1117 gnus-article-mime-handle-alist))
1118 (gnus-set-mode-line 'article))))))
eec82323
LMI
1119
1120(defun gnus-cite-find-prefix (line)
1121 ;; Return citation prefix for LINE.
1122 (let ((alist gnus-cite-prefix-alist)
1123 (prefix "")
1124 entry)
1125 (while alist
1126 (setq entry (car alist)
1127 alist (cdr alist))
1128 (when (memq line (cdr entry))
1129 (setq prefix (car entry))))
1130 prefix))
1131
6748645f
LMI
1132(defun gnus-cite-localize ()
1133 "Make the citation variables local to the article buffer."
1134 (let ((vars '(gnus-cite-article
1135 gnus-cite-overlay-list gnus-cite-prefix-alist
1136 gnus-cite-attribution-alist gnus-cite-loose-prefix-alist
1137 gnus-cite-loose-attribution-alist)))
1138 (while vars
1139 (make-local-variable (pop vars)))))
eec82323 1140
23f87bed
MB
1141(defun gnus-cited-line-p ()
1142 "Say whether the current line is a cited line."
1143 (save-excursion
1144 (beginning-of-line)
1145 (let ((found nil))
1146 (dolist (prefix (mapcar 'car gnus-cite-prefix-alist))
1147 (when (string= (buffer-substring (point) (+ (length prefix) (point)))
1148 prefix)
1149 (setq found t)))
1150 found)))
1151
01c52d31
MB
1152
1153;; Highlighting of different citation levels in message-mode.
1154;; - message-cite-prefix will be overridden if this is enabled.
1155
1156(defvar gnus-message-max-citation-depth
1157 (length gnus-cite-face-list)
1158 "Maximum supported level of citation.")
1159
1160(defvar gnus-message-cite-prefix-regexp
1161 (concat "^\\(?:" message-cite-prefix-regexp "\\)"))
1162
1163(defun gnus-message-search-citation-line (limit)
1164 "Search for a cited line and set match data accordingly.
1165Returns nil if there is no such line before LIMIT, t otherwise."
1166 (when (re-search-forward gnus-message-cite-prefix-regexp limit t)
1167 (let ((cdepth (min (length (apply 'concat
1168 (split-string
1169 (match-string-no-properties 0)
1170 "[ \t [:alnum:]]+")))
1171 gnus-message-max-citation-depth))
1172 (mlist (make-list (* (1+ gnus-message-max-citation-depth) 2) nil))
1173 (start (point-at-bol))
1174 (end (point-at-eol)))
1175 (setcar mlist start)
1176 (setcar (cdr mlist) end)
1177 (setcar (nthcdr (* cdepth 2) mlist) start)
1178 (setcar (nthcdr (1+ (* cdepth 2)) mlist) end)
1179 (set-match-data mlist))
1180 t))
1181
1182(defvar gnus-message-citation-keywords
1183 ;; eval-when-compile ;; This breaks in XEmacs
1184 `((gnus-message-search-citation-line
1185 ,@(let ((list nil)
1186 (count 1))
1187 ;; (require 'gnus-cite)
1188 (dolist (face gnus-cite-face-list (nreverse list))
1189 (push (list count (list 'quote face) 'prepend t) list)
1190 (setq count (1+ count)))))) ;;
1191 "Keywords for highlighting different levels of message citations.")
1192
9efa445f
DN
1193(defvar font-lock-defaults-computed)
1194(defvar font-lock-keywords)
1195(defvar font-lock-set-defaults)
01c52d31
MB
1196
1197(eval-and-compile
1198 (unless (featurep 'xemacs)
1199 (autoload 'font-lock-set-defaults "font-lock")))
1200
1201(define-minor-mode gnus-message-citation-mode
1202 "Toggle `gnus-message-citation-mode' in current buffer.
1203This buffer local minor mode provides additional font-lock support for
1204nested citations.
1205With prefix ARG, turn `gnus-message-citation-mode' on if and only if ARG
1206is positive.
1207Automatically turn `font-lock-mode' on when `gnus-message-citation-mode'
1208is turned on."
1209 nil ;; init-value
1210 "" ;; lighter
1211 nil ;; keymap
1212 (when (eq major-mode 'message-mode)
1213 (let ((defaults (car (if (featurep 'xemacs)
1214 (get 'message-mode 'font-lock-defaults)
1215 font-lock-defaults)))
1216 default keywords)
1217 (while defaults
1218 (setq default (if (consp defaults)
1219 (pop defaults)
1220 (prog1
1221 defaults
1222 (setq defaults nil))))
1223 (if gnus-message-citation-mode
1224 ;; `gnus-message-citation-keywords' should be the last
1225 ;; elements of the keywords because the others are unlikely
1226 ;; to have the OVERRIDE flags -- XEmacs applies a keyword
1227 ;; having no OVERRIDE flag to matched text even if it has
1228 ;; already other faces, while Emacs doesn't.
1229 (set (make-local-variable default)
1230 (append (default-value default)
1231 gnus-message-citation-keywords))
1232 (kill-local-variable default))))
1233 ;; Force `font-lock-set-defaults' to update `font-lock-keywords'.
1234 (if (featurep 'xemacs)
1235 (progn
1236 (require 'font-lock)
1237 (setq font-lock-defaults-computed nil
1238 font-lock-keywords nil))
1239 (setq font-lock-set-defaults nil))
1240 (font-lock-set-defaults)
1241 (cond ((symbol-value 'font-lock-mode)
1242 (font-lock-fontify-buffer))
1243 (gnus-message-citation-mode
1244 (font-lock-mode 1)))))
1245
1246(defun turn-on-gnus-message-citation-mode ()
1247 "Turn on `gnus-message-citation-mode'."
1248 (gnus-message-citation-mode 1))
1249(defun turn-off-gnus-message-citation-mode ()
1250 "Turn off `gnus-message-citation-mode'."
1251 (gnus-message-citation-mode -1))
1252
eec82323
LMI
1253(gnus-ems-redefine)
1254
1255(provide 'gnus-cite)
1256
16409b0b
GM
1257;; Local Variables:
1258;; coding: iso-8859-1
1259;; End:
1260
cbee283d 1261;; arch-tag: 1997b044-6067-471e-8c8f-dc903093098a
eec82323 1262;;; gnus-cite.el ends here