Mercurial > emacs
annotate lisp/gnus/gnus-cite.el @ 33817:c0bef67fde0c
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Thu, 23 Nov 2000 16:13:21 +0000 |
parents | 1666541ea9be |
children | 4b9a7a10deaa |
rev | line source |
---|---|
33374 | 1 ;;; gnus-cite.el --- parse citations in articles for Gnus -*- coding: iso-latin-1 -*- |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
2 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
17493 | 5 |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
6 ;; Author: Per Abhiddenware |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
7 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
9 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
17493 | 11 ;; it under the terms of the GNU General Public License as published by |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; 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; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;;; Code: | |
28 | |
19521
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
30 |
17493 | 31 (require 'gnus) |
32 (require 'gnus-art) | |
33 (require 'gnus-range) | |
34 | |
35 ;;; Customization: | |
36 | |
37 (defgroup gnus-cite nil | |
38 "Citation." | |
39 :prefix "gnus-cite-" | |
40 :link '(custom-manual "(gnus)Article Highlighting") | |
41 :group 'gnus-article) | |
42 | |
43 (defcustom gnus-cite-reply-regexp | |
44 "^\\(Subject: Re\\|In-Reply-To\\|References\\):" | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
45 "*If headers match this regexp it is reasonable to believe that |
17493 | 46 article has citations." |
47 :group 'gnus-cite | |
48 :type 'string) | |
49 | |
50 (defcustom gnus-cite-always-check nil | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
51 "Check article always for citations. Set it t to check all articles." |
17493 | 52 :group 'gnus-cite |
53 :type '(choice (const :tag "no" nil) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
54 (const :tag "yes" t))) |
17493 | 55 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
56 (defcustom gnus-cited-opened-text-button-line-format "%(%{[-]%}%)\n" |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
57 "Format of opened cited text buttons." |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
58 :group 'gnus-cite |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
59 :type 'string) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
60 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
61 (defcustom gnus-cited-closed-text-button-line-format "%(%{[+]%}%)\n" |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
62 "Format of closed cited text buttons." |
17493 | 63 :group 'gnus-cite |
64 :type 'string) | |
65 | |
66 (defcustom gnus-cited-lines-visible nil | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
67 "The number of lines of hidden cited text to remain visible. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
68 Or a pair (cons) of numbers which are the number of lines at the top |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
69 and bottom of the text, respectively, to remain visible." |
17493 | 70 :group 'gnus-cite |
71 :type '(choice (const :tag "none" nil) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
72 integer |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
73 (cons :tag "Top and Bottom" integer integer))) |
17493 | 74 |
75 (defcustom gnus-cite-parse-max-size 25000 | |
76 "Maximum article size (in bytes) where parsing citations is allowed. | |
77 Set it to nil to parse all articles." | |
78 :group 'gnus-cite | |
79 :type '(choice (const :tag "all" nil) | |
80 integer)) | |
81 | |
82 (defcustom gnus-cite-prefix-regexp | |
33374 | 83 ;; The Latin-1 angle quote looks pretty dubious. -- fx |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
84 "^[]>»|:}+ ]*[]>»|:}+]\\(.*>»\\)?\\|^.*>" |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
85 "*Regexp matching the longest possible citation prefix on a line." |
17493 | 86 :group 'gnus-cite |
87 :type 'regexp) | |
88 | |
89 (defcustom gnus-cite-max-prefix 20 | |
90 "Maximum possible length for a citation prefix." | |
91 :group 'gnus-cite | |
92 :type 'integer) | |
93 | |
94 (defcustom gnus-supercite-regexp | |
95 (concat "^\\(" gnus-cite-prefix-regexp "\\)? *" | |
96 ">>>>> +\"\\([^\"\n]+\\)\" +==") | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
97 "*Regexp matching normal Supercite attribution lines. |
17493 | 98 The first grouping must match prefixes added by other packages." |
99 :group 'gnus-cite | |
100 :type 'regexp) | |
101 | |
102 (defcustom gnus-supercite-secondary-regexp "^.*\"\\([^\"\n]+\\)\" +==" | |
103 "Regexp matching mangled Supercite attribution lines. | |
104 The first regexp group should match the Supercite attribution." | |
105 :group 'gnus-cite | |
106 :type 'regexp) | |
107 | |
108 (defcustom gnus-cite-minimum-match-count 2 | |
109 "Minimum number of identical prefixes before we believe it's a citation." | |
110 :group 'gnus-cite | |
111 :type 'integer) | |
112 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
113 (defcustom gnus-cite-attribution-prefix |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
114 "In article\\|in <\\|On \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\),\\|-----Original Message-----" |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
115 "*Regexp matching the beginning of an attribution line." |
17493 | 116 :group 'gnus-cite |
117 :type 'regexp) | |
118 | |
119 (defcustom gnus-cite-attribution-suffix | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
120 "\\(\\(wrote\\|writes\\|said\\|says\\|>\\)\\(:\\|\\.\\.\\.\\)\\|-----Original Message-----\\)[ \t]*$" |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
121 "*Regexp matching the end of an attribution line. |
17493 | 122 The text matching the first grouping will be used as a button." |
123 :group 'gnus-cite | |
124 :type 'regexp) | |
125 | |
126 (defface gnus-cite-attribution-face '((t | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
127 (:italic t))) |
17493 | 128 "Face used for attribution lines.") |
129 | |
130 (defcustom gnus-cite-attribution-face 'gnus-cite-attribution-face | |
131 "Face used for attribution lines. | |
132 It is merged with the face for the cited text belonging to the attribution." | |
133 :group 'gnus-cite | |
134 :type 'face) | |
135 | |
136 (defface gnus-cite-face-1 '((((class color) | |
137 (background dark)) | |
138 (:foreground "light blue")) | |
139 (((class color) | |
140 (background light)) | |
141 (:foreground "MidnightBlue")) | |
142 (t | |
143 (:italic t))) | |
144 "Citation face.") | |
145 | |
146 (defface gnus-cite-face-2 '((((class color) | |
147 (background dark)) | |
148 (:foreground "light cyan")) | |
149 (((class color) | |
150 (background light)) | |
151 (:foreground "firebrick")) | |
152 (t | |
153 (:italic t))) | |
154 "Citation face.") | |
155 | |
156 (defface gnus-cite-face-3 '((((class color) | |
157 (background dark)) | |
158 (:foreground "light yellow")) | |
159 (((class color) | |
160 (background light)) | |
161 (:foreground "dark green")) | |
162 (t | |
163 (:italic t))) | |
164 "Citation face.") | |
165 | |
166 (defface gnus-cite-face-4 '((((class color) | |
167 (background dark)) | |
168 (:foreground "light pink")) | |
169 (((class color) | |
170 (background light)) | |
171 (:foreground "OrangeRed")) | |
172 (t | |
173 (:italic t))) | |
174 "Citation face.") | |
175 | |
176 (defface gnus-cite-face-5 '((((class color) | |
177 (background dark)) | |
178 (:foreground "pale green")) | |
179 (((class color) | |
180 (background light)) | |
181 (:foreground "dark khaki")) | |
182 (t | |
183 (:italic t))) | |
184 "Citation face.") | |
185 | |
186 (defface gnus-cite-face-6 '((((class color) | |
187 (background dark)) | |
188 (:foreground "beige")) | |
189 (((class color) | |
190 (background light)) | |
191 (:foreground "dark violet")) | |
192 (t | |
193 (:italic t))) | |
194 "Citation face.") | |
195 | |
196 (defface gnus-cite-face-7 '((((class color) | |
197 (background dark)) | |
198 (:foreground "orange")) | |
199 (((class color) | |
200 (background light)) | |
201 (:foreground "SteelBlue4")) | |
202 (t | |
203 (:italic t))) | |
204 "Citation face.") | |
205 | |
206 (defface gnus-cite-face-8 '((((class color) | |
207 (background dark)) | |
208 (:foreground "magenta")) | |
209 (((class color) | |
210 (background light)) | |
211 (:foreground "magenta")) | |
212 (t | |
213 (:italic t))) | |
214 "Citation face.") | |
215 | |
216 (defface gnus-cite-face-9 '((((class color) | |
217 (background dark)) | |
218 (:foreground "violet")) | |
219 (((class color) | |
220 (background light)) | |
221 (:foreground "violet")) | |
222 (t | |
223 (:italic t))) | |
224 "Citation face.") | |
225 | |
226 (defface gnus-cite-face-10 '((((class color) | |
227 (background dark)) | |
228 (:foreground "medium purple")) | |
229 (((class color) | |
230 (background light)) | |
231 (:foreground "medium purple")) | |
232 (t | |
233 (:italic t))) | |
234 "Citation face.") | |
235 | |
236 (defface gnus-cite-face-11 '((((class color) | |
237 (background dark)) | |
238 (:foreground "turquoise")) | |
239 (((class color) | |
240 (background light)) | |
241 (:foreground "turquoise")) | |
242 (t | |
243 (:italic t))) | |
244 "Citation face.") | |
245 | |
246 (defcustom gnus-cite-face-list | |
247 '(gnus-cite-face-1 gnus-cite-face-2 gnus-cite-face-3 gnus-cite-face-4 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
248 gnus-cite-face-5 gnus-cite-face-6 gnus-cite-face-7 gnus-cite-face-8 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
249 gnus-cite-face-9 gnus-cite-face-10 gnus-cite-face-11) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
250 "*List of faces used for highlighting citations. |
17493 | 251 |
252 When there are citations from multiple articles in the same message, | |
253 Gnus will try to give each citation from each article its own face. | |
254 This should make it easier to see who wrote what." | |
255 :group 'gnus-cite | |
256 :type '(repeat face)) | |
257 | |
258 (defcustom gnus-cite-hide-percentage 50 | |
259 "Only hide excess citation if above this percentage of the body." | |
260 :group 'gnus-cite | |
261 :type 'number) | |
262 | |
263 (defcustom gnus-cite-hide-absolute 10 | |
264 "Only hide excess citation if above this number of lines in the body." | |
265 :group 'gnus-cite | |
266 :type 'integer) | |
267 | |
268 ;;; Internal Variables: | |
269 | |
270 (defvar gnus-cite-article nil) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
271 (defvar gnus-cite-overlay-list nil) |
17493 | 272 |
273 (defvar gnus-cite-prefix-alist nil) | |
274 ;; Alist of citation prefixes. | |
275 ;; The cdr is a list of lines with that prefix. | |
276 | |
277 (defvar gnus-cite-attribution-alist nil) | |
278 ;; Alist of attribution lines. | |
279 ;; The car is a line number. | |
280 ;; The cdr is the prefix for the citation started by that line. | |
281 | |
282 (defvar gnus-cite-loose-prefix-alist nil) | |
283 ;; Alist of citation prefixes that have no matching attribution. | |
284 ;; The cdr is a list of lines with that prefix. | |
285 | |
286 (defvar gnus-cite-loose-attribution-alist nil) | |
287 ;; Alist of attribution lines that have no matching citation. | |
288 ;; Each member has the form (WROTE IN PREFIX TAG), where | |
289 ;; WROTE: is the attribution line number | |
290 ;; IN: is the line number of the previous line if part of the same attribution, | |
291 ;; PREFIX: Is the citation prefix of the attribution line(s), and | |
292 ;; TAG: Is a Supercite tag, if any. | |
293 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
294 (defvar gnus-cited-opened-text-button-line-format-alist |
17493 | 295 `((?b (marker-position beg) ?d) |
296 (?e (marker-position end) ?d) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
297 (?n (count-lines beg end) ?d) |
17493 | 298 (?l (- end beg) ?d))) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
299 (defvar gnus-cited-opened-text-button-line-format-spec nil) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
300 (defvar gnus-cited-closed-text-button-line-format-alist |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
301 gnus-cited-opened-text-button-line-format-alist) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
302 (defvar gnus-cited-closed-text-button-line-format-spec nil) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
303 |
17493 | 304 |
305 ;;; Commands: | |
306 | |
307 (defun gnus-article-highlight-citation (&optional force) | |
308 "Highlight cited text. | |
309 Each citation in the article will be highlighted with a different face. | |
310 The faces are taken from `gnus-cite-face-list'. | |
311 Attribution lines are highlighted with the same face as the | |
312 corresponding citation merged with `gnus-cite-attribution-face'. | |
313 | |
314 Text is considered cited if at least `gnus-cite-minimum-match-count' | |
315 lines matches `gnus-cite-prefix-regexp' with the same prefix. | |
316 | |
317 Lines matching `gnus-cite-attribution-suffix' and perhaps | |
318 `gnus-cite-attribution-prefix' are considered attribution lines." | |
319 (interactive (list 'force)) | |
320 (save-excursion | |
321 (set-buffer gnus-article-buffer) | |
322 (gnus-cite-parse-maybe force) | |
323 (let ((buffer-read-only nil) | |
324 (alist gnus-cite-prefix-alist) | |
325 (faces gnus-cite-face-list) | |
326 (inhibit-point-motion-hooks t) | |
327 face entry prefix skip numbers number face-alist) | |
328 ;; Loop through citation prefixes. | |
329 (while alist | |
330 (setq entry (car alist) | |
331 alist (cdr alist) | |
332 prefix (car entry) | |
333 numbers (cdr entry) | |
334 face (car faces) | |
335 faces (or (cdr faces) gnus-cite-face-list) | |
336 face-alist (cons (cons prefix face) face-alist)) | |
337 (while numbers | |
338 (setq number (car numbers) | |
339 numbers (cdr numbers)) | |
340 (and (not (assq number gnus-cite-attribution-alist)) | |
341 (not (assq number gnus-cite-loose-attribution-alist)) | |
342 (gnus-cite-add-face number prefix face)))) | |
343 ;; Loop through attribution lines. | |
344 (setq alist gnus-cite-attribution-alist) | |
345 (while alist | |
346 (setq entry (car alist) | |
347 alist (cdr alist) | |
348 number (car entry) | |
349 prefix (cdr entry) | |
350 skip (gnus-cite-find-prefix number) | |
351 face (cdr (assoc prefix face-alist))) | |
352 ;; Add attribution button. | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
353 (goto-char (point-min)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
354 (forward-line (1- number)) |
17493 | 355 (when (re-search-forward gnus-cite-attribution-suffix |
356 (save-excursion (end-of-line 1) (point)) | |
357 t) | |
358 (gnus-article-add-button (match-beginning 1) (match-end 1) | |
359 'gnus-cite-toggle prefix)) | |
360 ;; Highlight attribution line. | |
361 (gnus-cite-add-face number skip face) | |
362 (gnus-cite-add-face number skip gnus-cite-attribution-face)) | |
363 ;; Loop through attribution lines. | |
364 (setq alist gnus-cite-loose-attribution-alist) | |
365 (while alist | |
366 (setq entry (car alist) | |
367 alist (cdr alist) | |
368 number (car entry) | |
369 skip (gnus-cite-find-prefix number)) | |
370 (gnus-cite-add-face number skip gnus-cite-attribution-face))))) | |
371 | |
372 (defun gnus-dissect-cited-text () | |
373 "Dissect the article buffer looking for cited text." | |
374 (save-excursion | |
375 (set-buffer gnus-article-buffer) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
376 (gnus-cite-parse-maybe nil t) |
17493 | 377 (let ((alist gnus-cite-prefix-alist) |
378 prefix numbers number marks m) | |
379 ;; Loop through citation prefixes. | |
380 (while alist | |
381 (setq numbers (pop alist) | |
382 prefix (pop numbers)) | |
383 (while numbers | |
384 (setq number (pop numbers)) | |
385 (goto-char (point-min)) | |
386 (forward-line number) | |
387 (push (cons (point-marker) "") marks) | |
388 (while (and numbers | |
389 (= (1- number) (car numbers))) | |
390 (setq number (pop numbers))) | |
391 (goto-char (point-min)) | |
392 (forward-line (1- number)) | |
393 (push (cons (point-marker) prefix) marks))) | |
394 ;; Skip to the beginning of the body. | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
395 (article-goto-body) |
17493 | 396 (push (cons (point-marker) "") marks) |
397 ;; Find the end of the body. | |
398 (goto-char (point-max)) | |
399 (gnus-article-search-signature) | |
400 (push (cons (point-marker) "") marks) | |
401 ;; Sort the marks. | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
402 (setq marks (sort marks 'car-less-than-car)) |
17493 | 403 (let ((omarks marks)) |
404 (setq marks nil) | |
405 (while (cdr omarks) | |
406 (if (= (caar omarks) (caadr omarks)) | |
407 (progn | |
408 (unless (equal (cdar omarks) "") | |
409 (push (car omarks) marks)) | |
410 (unless (equal (cdadr omarks) "") | |
411 (push (cadr omarks) marks)) | |
412 (unless (and (equal (cdar omarks) "") | |
413 (equal (cdadr omarks) "") | |
414 (not (cddr omarks))) | |
415 (setq omarks (cdr omarks)))) | |
416 (push (car omarks) marks)) | |
417 (setq omarks (cdr omarks))) | |
418 (when (car omarks) | |
419 (push (car omarks) marks)) | |
420 (setq marks (setq m (nreverse marks))) | |
421 (while (cddr m) | |
422 (if (and (equal (cdadr m) "") | |
423 (equal (cdar m) (cdaddr m)) | |
424 (goto-char (caadr m)) | |
425 (forward-line 1) | |
426 (= (point) (caaddr m))) | |
427 (setcdr m (cdddr m)) | |
428 (setq m (cdr m)))) | |
429 marks)))) | |
430 | |
431 (defun gnus-article-fill-cited-article (&optional force width) | |
432 "Do word wrapping in the current article. | |
433 If WIDTH (the numerical prefix), use that text width when filling." | |
434 (interactive (list t current-prefix-arg)) | |
435 (save-excursion | |
436 (set-buffer gnus-article-buffer) | |
437 (let ((buffer-read-only nil) | |
438 (inhibit-point-motion-hooks t) | |
439 (marks (gnus-dissect-cited-text)) | |
440 (adaptive-fill-mode nil) | |
441 (filladapt-mode nil) | |
442 (fill-column (if width (prefix-numeric-value width) fill-column))) | |
443 (save-restriction | |
444 (while (cdr marks) | |
445 (narrow-to-region (caar marks) (caadr marks)) | |
446 (let ((adaptive-fill-regexp | |
447 (concat "^" (regexp-quote (cdar marks)) " *")) | |
448 (fill-prefix (cdar marks))) | |
449 (fill-region (point-min) (point-max))) | |
450 (set-marker (caar marks) nil) | |
451 (setq marks (cdr marks))) | |
452 (when marks | |
453 (set-marker (caar marks) nil)) | |
454 ;; All this information is now incorrect. | |
455 (setq gnus-cite-prefix-alist nil | |
456 gnus-cite-attribution-alist nil | |
457 gnus-cite-loose-prefix-alist nil | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
458 gnus-cite-loose-attribution-alist nil |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
459 gnus-cite-article nil))))) |
17493 | 460 |
461 (defun gnus-article-hide-citation (&optional arg force) | |
462 "Toggle hiding of all cited text except attribution lines. | |
463 See the documentation for `gnus-article-highlight-citation'. | |
464 If given a negative prefix, always show; if given a positive prefix, | |
465 always hide." | |
466 (interactive (append (gnus-article-hidden-arg) (list 'force))) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
467 (gnus-set-format 'cited-opened-text-button t) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
468 (gnus-set-format 'cited-closed-text-button t) |
17493 | 469 (save-excursion |
470 (set-buffer gnus-article-buffer) | |
471 (cond | |
472 ((gnus-article-check-hidden-text 'cite arg) | |
473 t) | |
474 ((gnus-article-text-type-exists-p 'cite) | |
475 (let ((buffer-read-only nil)) | |
476 (gnus-article-hide-text-of-type 'cite))) | |
477 (t | |
478 (let ((buffer-read-only nil) | |
479 (marks (gnus-dissect-cited-text)) | |
480 (inhibit-point-motion-hooks t) | |
481 (props (nconc (list 'article-type 'cite) | |
482 gnus-hidden-properties)) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
483 beg end start) |
17493 | 484 (while marks |
485 (setq beg nil | |
486 end nil) | |
487 (while (and marks (string= (cdar marks) "")) | |
488 (setq marks (cdr marks))) | |
489 (when marks | |
490 (setq beg (caar marks))) | |
491 (while (and marks (not (string= (cdar marks) ""))) | |
492 (setq marks (cdr marks))) | |
493 (when marks | |
494 (setq end (caar marks))) | |
495 ;; Skip past lines we want to leave visible. | |
496 (when (and beg end gnus-cited-lines-visible) | |
497 (goto-char beg) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
498 (forward-line (if (consp gnus-cited-lines-visible) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
499 (car gnus-cited-lines-visible) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
500 gnus-cited-lines-visible)) |
17493 | 501 (if (>= (point) end) |
502 (setq beg nil) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
503 (setq beg (point-marker)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
504 (when (consp gnus-cited-lines-visible) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
505 (goto-char end) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
506 (forward-line (- (cdr gnus-cited-lines-visible))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
507 (if (<= (point) beg) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
508 (setq beg nil) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
509 (setq end (point-marker)))))) |
17493 | 510 (when (and beg end) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
511 ;; We use markers for the end-points to facilitate later |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
512 ;; wrapping and mangling of text. |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
513 (setq beg (set-marker (make-marker) beg) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
514 end (set-marker (make-marker) end)) |
17493 | 515 (gnus-add-text-properties beg end props) |
516 (goto-char beg) | |
517 (unless (save-excursion (search-backward "\n\n" nil t)) | |
518 (insert "\n")) | |
519 (put-text-property | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
520 (setq start (point-marker)) |
17493 | 521 (progn |
522 (gnus-article-add-button | |
523 (point) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
524 (progn (eval gnus-cited-closed-text-button-line-format-spec) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
525 (point)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
526 `gnus-article-toggle-cited-text |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
527 (list (cons beg end) start)) |
17493 | 528 (point)) |
529 'article-type 'annotation) | |
530 (set-marker beg (point))))))))) | |
531 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
532 (defun gnus-article-toggle-cited-text (args) |
17493 | 533 "Toggle hiding the text in REGION." |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
534 (let* ((region (car args)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
535 (beg (car region)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
536 (end (cdr region)) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
537 (start (cadr args)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
538 (hidden |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
539 (text-property-any |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
540 beg (1- end) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
541 (car gnus-hidden-properties) (cadr gnus-hidden-properties))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
542 (inhibit-point-motion-hooks t) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
543 buffer-read-only) |
17493 | 544 (funcall |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
545 (if hidden |
17493 | 546 'remove-text-properties 'gnus-add-text-properties) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
547 beg end gnus-hidden-properties) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
548 (save-excursion |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
549 (goto-char start) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
550 (gnus-delete-line) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
551 (put-text-property |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
552 (point) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
553 (progn |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
554 (gnus-article-add-button |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
555 (point) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
556 (progn (eval |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
557 (if hidden |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
558 gnus-cited-opened-text-button-line-format-spec |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
559 gnus-cited-closed-text-button-line-format-spec)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
560 (point)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
561 `gnus-article-toggle-cited-text |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
562 args) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
563 (point)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
564 'article-type 'annotation)))) |
17493 | 565 |
566 (defun gnus-article-hide-citation-maybe (&optional arg force) | |
567 "Toggle hiding of cited text that has an attribution line. | |
568 If given a negative prefix, always show; if given a positive prefix, | |
569 always hide. | |
570 This will do nothing unless at least `gnus-cite-hide-percentage' | |
571 percent and at least `gnus-cite-hide-absolute' lines of the body is | |
572 cited text with attributions. When called interactively, these two | |
573 variables are ignored. | |
574 See also the documentation for `gnus-article-highlight-citation'." | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
575 (interactive (append (gnus-article-hidden-arg) '(force))) |
17493 | 576 (unless (gnus-article-check-hidden-text 'cite arg) |
577 (save-excursion | |
578 (set-buffer gnus-article-buffer) | |
579 (gnus-cite-parse-maybe force) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
580 (article-goto-body) |
17493 | 581 (let ((start (point)) |
582 (atts gnus-cite-attribution-alist) | |
583 (buffer-read-only nil) | |
584 (inhibit-point-motion-hooks t) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
585 (hidden 0) |
17493 | 586 total) |
587 (goto-char (point-max)) | |
588 (gnus-article-search-signature) | |
589 (setq total (count-lines start (point))) | |
590 (while atts | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
591 (setq hidden (+ hidden (length (cdr (assoc (cdar atts) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
592 gnus-cite-prefix-alist)))) |
17493 | 593 atts (cdr atts))) |
594 (when (or force | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
595 (and (> (* 100 hidden) (* gnus-cite-hide-percentage total)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
596 (> hidden gnus-cite-hide-absolute))) |
17493 | 597 (setq atts gnus-cite-attribution-alist) |
598 (while atts | |
599 (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist)) | |
600 atts (cdr atts)) | |
601 (while total | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
602 (setq hidden (car total) |
17493 | 603 total (cdr total)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
604 (goto-char (point-min)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
605 (forward-line (1- hidden)) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
606 (unless (assq hidden gnus-cite-attribution-alist) |
17493 | 607 (gnus-add-text-properties |
608 (point) (progn (forward-line 1) (point)) | |
609 (nconc (list 'article-type 'cite) | |
610 gnus-hidden-properties)))))))))) | |
611 | |
612 (defun gnus-article-hide-citation-in-followups () | |
613 "Hide cited text in non-root articles." | |
614 (interactive) | |
615 (save-excursion | |
616 (set-buffer gnus-article-buffer) | |
617 (let ((article (cdr gnus-article-current))) | |
618 (unless (save-excursion | |
619 (set-buffer gnus-summary-buffer) | |
620 (gnus-article-displayed-root-p article)) | |
621 (gnus-article-hide-citation))))) | |
622 | |
623 ;;; Internal functions: | |
624 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
625 (defun gnus-cite-parse-maybe (&optional force no-overlay) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
626 "Always parse the buffer." |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
627 (gnus-cite-localize) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
628 ;;Reset parser information. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
629 (setq gnus-cite-prefix-alist nil |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
630 gnus-cite-attribution-alist nil |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
631 gnus-cite-loose-prefix-alist nil |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
632 gnus-cite-loose-attribution-alist nil) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
633 (unless no-overlay |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
634 (gnus-cite-delete-overlays)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
635 ;; Parse if not too large. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
636 (if (and gnus-cite-parse-max-size |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
637 (> (buffer-size) gnus-cite-parse-max-size)) |
17493 | 638 () |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
639 (setq gnus-cite-article (cons (car gnus-article-current) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
640 (cdr gnus-article-current))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
641 (gnus-cite-parse-wrapper))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
642 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
643 (defun gnus-cite-delete-overlays () |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
644 (dolist (overlay gnus-cite-overlay-list) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
645 (when (or (not (gnus-overlay-end overlay)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
646 (and (>= (gnus-overlay-end overlay) (point-min)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
647 (<= (gnus-overlay-end overlay) (point-max)))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
648 (setq gnus-cite-overlay-list (delete overlay gnus-cite-overlay-list)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
649 (gnus-delete-overlay overlay)))) |
17493 | 650 |
651 (defun gnus-cite-parse-wrapper () | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
652 ;; Wrap chopped gnus-cite-parse. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
653 (article-goto-body) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
654 (let ((inhibit-point-motion-hooks t)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
655 (save-excursion |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
656 (gnus-cite-parse-attributions)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
657 (save-excursion |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
658 (gnus-cite-parse)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
659 (save-excursion |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
660 (gnus-cite-connect-attributions)))) |
17493 | 661 |
662 (defun gnus-cite-parse () | |
663 ;; Parse and connect citation prefixes and attribution lines. | |
664 | |
665 ;; Parse current buffer searching for citation prefixes. | |
666 (let ((line (1+ (count-lines (point-min) (point)))) | |
667 (case-fold-search t) | |
668 (max (save-excursion | |
669 (goto-char (point-max)) | |
670 (gnus-article-search-signature) | |
671 (point))) | |
672 alist entry start begin end numbers prefix) | |
673 ;; Get all potential prefixes in `alist'. | |
674 (while (< (point) max) | |
675 ;; Each line. | |
676 (setq begin (point) | |
677 end (progn (beginning-of-line 2) (point)) | |
678 start end) | |
679 (goto-char begin) | |
680 ;; Ignore standard Supercite attribution prefix. | |
681 (when (looking-at gnus-supercite-regexp) | |
682 (if (match-end 1) | |
683 (setq end (1+ (match-end 1))) | |
684 (setq end (1+ begin)))) | |
685 ;; Ignore very long prefixes. | |
686 (when (> end (+ (point) gnus-cite-max-prefix)) | |
687 (setq end (+ (point) gnus-cite-max-prefix))) | |
688 (while (re-search-forward gnus-cite-prefix-regexp (1- end) t) | |
689 ;; Each prefix. | |
690 (setq end (match-end 0) | |
691 prefix (buffer-substring begin end)) | |
692 (gnus-set-text-properties 0 (length prefix) nil prefix) | |
693 (setq entry (assoc prefix alist)) | |
694 (if entry | |
695 (setcdr entry (cons line (cdr entry))) | |
696 (push (list prefix line) alist)) | |
697 (goto-char begin)) | |
698 (goto-char start) | |
699 (setq line (1+ line))) | |
700 ;; We got all the potential prefixes. Now create | |
701 ;; `gnus-cite-prefix-alist' containing the oldest prefix for each | |
702 ;; line that appears at least gnus-cite-minimum-match-count | |
703 ;; times. First sort them by length. Longer is older. | |
704 (setq alist (sort alist (lambda (a b) | |
705 (> (length (car a)) (length (car b)))))) | |
706 (while alist | |
707 (setq entry (car alist) | |
708 prefix (car entry) | |
709 numbers (cdr entry) | |
710 alist (cdr alist)) | |
711 (cond ((null numbers) | |
712 ;; No lines with this prefix that wasn't also part of | |
713 ;; a longer prefix. | |
714 ) | |
715 ((< (length numbers) gnus-cite-minimum-match-count) | |
716 ;; Too few lines with this prefix. We keep it a bit | |
717 ;; longer in case it is an exact match for an attribution | |
718 ;; line, but we don't remove the line from other | |
719 ;; prefixes. | |
720 (push entry gnus-cite-prefix-alist)) | |
721 (t | |
722 (push entry | |
723 gnus-cite-prefix-alist) | |
724 ;; Remove articles from other prefixes. | |
725 (let ((loop alist) | |
726 current) | |
727 (while loop | |
728 (setq current (car loop) | |
729 loop (cdr loop)) | |
730 (setcdr current | |
731 (gnus-set-difference (cdr current) numbers))))))))) | |
732 | |
733 (defun gnus-cite-parse-attributions () | |
734 (let (al-alist) | |
735 ;; Parse attributions | |
736 (while (re-search-forward gnus-cite-attribution-suffix (point-max) t) | |
737 (let* ((start (match-beginning 0)) | |
738 (end (match-end 0)) | |
739 (wrote (count-lines (point-min) end)) | |
740 (prefix (gnus-cite-find-prefix wrote)) | |
741 ;; Check previous line for an attribution leader. | |
742 (tag (progn | |
743 (beginning-of-line 1) | |
744 (when (looking-at gnus-supercite-secondary-regexp) | |
745 (buffer-substring (match-beginning 1) | |
746 (match-end 1))))) | |
747 (in (progn | |
748 (goto-char start) | |
749 (and (re-search-backward gnus-cite-attribution-prefix | |
750 (save-excursion | |
751 (beginning-of-line 0) | |
752 (point)) | |
753 t) | |
754 (not (re-search-forward gnus-cite-attribution-suffix | |
755 start t)) | |
756 (count-lines (point-min) (1+ (point))))))) | |
757 (when (eq wrote in) | |
758 (setq in nil)) | |
759 (goto-char end) | |
760 ;; don't add duplicates | |
761 (let ((al (buffer-substring (save-excursion (beginning-of-line 0) | |
762 (1+ (point))) | |
763 end))) | |
764 (if (not (assoc al al-alist)) | |
765 (progn | |
766 (push (list wrote in prefix tag) | |
767 gnus-cite-loose-attribution-alist) | |
768 (push (cons al t) al-alist)))))))) | |
769 | |
770 (defun gnus-cite-connect-attributions () | |
771 ;; Connect attributions to citations | |
772 | |
773 ;; No citations have been connected to attribution lines yet. | |
774 (setq gnus-cite-loose-prefix-alist (append gnus-cite-prefix-alist nil)) | |
775 | |
776 ;; Parse current buffer searching for attribution lines. | |
777 ;; Find exact supercite citations. | |
778 (gnus-cite-match-attributions 'small nil | |
779 (lambda (prefix tag) | |
780 (when tag | |
781 (concat "\\`" | |
782 (regexp-quote prefix) "[ \t]*" | |
783 (regexp-quote tag) ">")))) | |
784 ;; Find loose supercite citations after attributions. | |
785 (gnus-cite-match-attributions 'small t | |
786 (lambda (prefix tag) | |
787 (when tag | |
788 (concat "\\<" | |
789 (regexp-quote tag) | |
790 "\\>")))) | |
791 ;; Find loose supercite citations anywhere. | |
792 (gnus-cite-match-attributions 'small nil | |
793 (lambda (prefix tag) | |
794 (when tag | |
795 (concat "\\<" | |
796 (regexp-quote tag) | |
797 "\\>")))) | |
798 ;; Find nested citations after attributions. | |
799 (gnus-cite-match-attributions 'small-if-unique t | |
800 (lambda (prefix tag) | |
801 (concat "\\`" (regexp-quote prefix) ".+"))) | |
802 ;; Find nested citations anywhere. | |
803 (gnus-cite-match-attributions 'small nil | |
804 (lambda (prefix tag) | |
805 (concat "\\`" (regexp-quote prefix) ".+"))) | |
806 ;; Remove loose prefixes with too few lines. | |
807 (let ((alist gnus-cite-loose-prefix-alist) | |
808 entry) | |
809 (while alist | |
810 (setq entry (car alist) | |
811 alist (cdr alist)) | |
812 (when (< (length (cdr entry)) gnus-cite-minimum-match-count) | |
813 (setq gnus-cite-prefix-alist | |
814 (delq entry gnus-cite-prefix-alist) | |
815 gnus-cite-loose-prefix-alist | |
816 (delq entry gnus-cite-loose-prefix-alist))))) | |
817 ;; Find flat attributions. | |
818 (gnus-cite-match-attributions 'first t nil) | |
819 ;; Find any attributions (are we getting desperate yet?). | |
820 (gnus-cite-match-attributions 'first nil nil)) | |
821 | |
822 (defun gnus-cite-match-attributions (sort after fun) | |
823 ;; Match all loose attributions and citations (SORT AFTER FUN) . | |
824 ;; | |
825 ;; If SORT is `small', the citation with the shortest prefix will be | |
826 ;; used, if it is `first' the first prefix will be used, if it is | |
827 ;; `small-if-unique' the shortest prefix will be used if the | |
828 ;; attribution line does not share its own prefix with other | |
829 ;; loose attribution lines, otherwise the first prefix will be used. | |
830 ;; | |
831 ;; If AFTER is non-nil, only citations after the attribution line | |
832 ;; will be considered. | |
833 ;; | |
834 ;; If FUN is non-nil, it will be called with the arguments (WROTE | |
835 ;; PREFIX TAG) and expected to return a regular expression. Only | |
836 ;; citations whose prefix matches the regular expression will be | |
837 ;; considered. | |
838 ;; | |
839 ;; WROTE is the attribution line number. | |
840 ;; PREFIX is the attribution line prefix. | |
841 ;; TAG is the Supercite tag on the attribution line. | |
842 (let ((atts gnus-cite-loose-attribution-alist) | |
843 (case-fold-search t) | |
844 att wrote in prefix tag regexp limit smallest best size) | |
845 (while atts | |
846 (setq att (car atts) | |
847 atts (cdr atts) | |
848 wrote (nth 0 att) | |
849 in (nth 1 att) | |
850 prefix (nth 2 att) | |
851 tag (nth 3 att) | |
852 regexp (if fun (funcall fun prefix tag) "") | |
853 size (cond ((eq sort 'small) t) | |
854 ((eq sort 'first) nil) | |
855 (t (< (length (gnus-cite-find-loose prefix)) 2))) | |
856 limit (if after wrote -1) | |
857 smallest 1000000 | |
858 best nil) | |
859 (let ((cites gnus-cite-loose-prefix-alist) | |
860 cite candidate numbers first compare) | |
861 (while cites | |
862 (setq cite (car cites) | |
863 cites (cdr cites) | |
864 candidate (car cite) | |
865 numbers (cdr cite) | |
866 first (apply 'min numbers) | |
867 compare (if size (length candidate) first)) | |
868 (and (> first limit) | |
869 regexp | |
870 (string-match regexp candidate) | |
871 (< compare smallest) | |
872 (setq best cite | |
873 smallest compare)))) | |
874 (if (null best) | |
875 () | |
876 (setq gnus-cite-loose-attribution-alist | |
877 (delq att gnus-cite-loose-attribution-alist)) | |
878 (push (cons wrote (car best)) gnus-cite-attribution-alist) | |
879 (when in | |
880 (push (cons in (car best)) gnus-cite-attribution-alist)) | |
881 (when (memq best gnus-cite-loose-prefix-alist) | |
882 (let ((loop gnus-cite-prefix-alist) | |
883 (numbers (cdr best)) | |
884 current) | |
885 (setq gnus-cite-loose-prefix-alist | |
886 (delq best gnus-cite-loose-prefix-alist)) | |
887 (while loop | |
888 (setq current (car loop) | |
889 loop (cdr loop)) | |
890 (if (eq current best) | |
891 () | |
892 (setcdr current (gnus-set-difference (cdr current) numbers)) | |
893 (when (null (cdr current)) | |
894 (setq gnus-cite-loose-prefix-alist | |
895 (delq current gnus-cite-loose-prefix-alist) | |
896 atts (delq current atts))))))))))) | |
897 | |
898 (defun gnus-cite-find-loose (prefix) | |
899 ;; Return a list of loose attribution lines prefixed by PREFIX. | |
900 (let* ((atts gnus-cite-loose-attribution-alist) | |
901 att line lines) | |
902 (while atts | |
903 (setq att (car atts) | |
904 line (car att) | |
905 atts (cdr atts)) | |
906 (when (string-equal (gnus-cite-find-prefix line) prefix) | |
907 (push line lines))) | |
908 lines)) | |
909 | |
910 (defun gnus-cite-add-face (number prefix face) | |
911 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line. | |
912 (when face | |
913 (let ((inhibit-point-motion-hooks t) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
914 from to overlay) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
915 (goto-char (point-min)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
916 (when (zerop (forward-line (1- number))) |
17493 | 917 (forward-char (length prefix)) |
918 (skip-chars-forward " \t") | |
919 (setq from (point)) | |
920 (end-of-line 1) | |
921 (skip-chars-backward " \t") | |
922 (setq to (point)) | |
923 (when (< from to) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
924 (push (setq overlay (gnus-make-overlay from to)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
925 gnus-cite-overlay-list) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
926 (gnus-overlay-put overlay 'face face)))))) |
17493 | 927 |
928 (defun gnus-cite-toggle (prefix) | |
929 (save-excursion | |
930 (set-buffer gnus-article-buffer) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
931 (gnus-cite-parse-maybe nil t) |
17493 | 932 (let ((buffer-read-only nil) |
933 (numbers (cdr (assoc prefix gnus-cite-prefix-alist))) | |
934 (inhibit-point-motion-hooks t) | |
935 number) | |
936 (while numbers | |
937 (setq number (car numbers) | |
938 numbers (cdr numbers)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
939 (goto-char (point-min)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
940 (forward-line (1- number)) |
17493 | 941 (cond ((get-text-property (point) 'invisible) |
942 (remove-text-properties (point) (progn (forward-line 1) (point)) | |
943 gnus-hidden-properties)) | |
944 ((assq number gnus-cite-attribution-alist)) | |
945 (t | |
946 (gnus-add-text-properties | |
947 (point) (progn (forward-line 1) (point)) | |
948 (nconc (list 'article-type 'cite) | |
949 gnus-hidden-properties)))))))) | |
950 | |
951 (defun gnus-cite-find-prefix (line) | |
952 ;; Return citation prefix for LINE. | |
953 (let ((alist gnus-cite-prefix-alist) | |
954 (prefix "") | |
955 entry) | |
956 (while alist | |
957 (setq entry (car alist) | |
958 alist (cdr alist)) | |
959 (when (memq line (cdr entry)) | |
960 (setq prefix (car entry)))) | |
961 prefix)) | |
962 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
963 (defun gnus-cite-localize () |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
964 "Make the citation variables local to the article buffer." |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
965 (let ((vars '(gnus-cite-article |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
966 gnus-cite-overlay-list gnus-cite-prefix-alist |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
967 gnus-cite-attribution-alist gnus-cite-loose-prefix-alist |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
968 gnus-cite-loose-attribution-alist))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
969 (while vars |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
970 (make-local-variable (pop vars))))) |
17493 | 971 |
972 (gnus-ems-redefine) | |
973 | |
974 (provide 'gnus-cite) | |
975 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
976 ;; Local Variables: |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
977 ;; coding: iso-8859-1 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
978 ;; End: |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
979 |
17493 | 980 ;;; gnus-cite.el ends here |