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