Mercurial > emacs
annotate lisp/gnus/gnus-score.el @ 19878:a69ae37e6932
(quail-update-translation): Fix previous change.
(quail-simple-translation-keymap, quail-conversion-keymap):
Make the default binding with define-key.
Handle meta-prefix-char the way isearch does.
(quail-translation-keymap): Likewise.
(quail-execute-non-quail-command): Handle the key sequence as the
same way as universal-argument-other-key.
(quail-make-guidance-frame): Don't dedicate the guidance buffer window.
(quail-show-guidance-buf): Likewise.
(quail-hide-guidance-buf): Delete code to turn off window dedication.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 11 Sep 1997 23:15:08 +0000 |
parents | 6f6cf9184e93 |
children | 5f1ab3dd344d |
rev | line source |
---|---|
17493 | 1 ;;; gnus-score.el --- scoring code for Gnus |
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Per Abrahamsen <amanda@iesd.auc.dk> | |
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
6 ;; Keywords: news | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 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-sum) | |
33 (require 'gnus-range) | |
34 | |
35 (defcustom gnus-global-score-files nil | |
36 "List of global score files and directories. | |
37 Set this variable if you want to use people's score files. One entry | |
38 for each score file or each score file directory. Gnus will decide | |
39 by itself what score files are applicable to which group. | |
40 | |
41 Say you want to use the single score file | |
42 \"/ftp.gnus.org@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all | |
43 score files in the \"/ftp.some-where:/pub/score\" directory. | |
44 | |
45 (setq gnus-global-score-files | |
46 '(\"/ftp.gnus.org:/pub/larsi/ding/score/soc.motss.SCORE\" | |
47 \"/ftp.some-where:/pub/score\"))" | |
48 :group 'gnus-score-files | |
49 :type '(repeat file)) | |
50 | |
51 (defcustom gnus-score-file-single-match-alist nil | |
52 "Alist mapping regexps to lists of score files. | |
53 Each element of this alist should be of the form | |
54 (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... ) | |
55 | |
56 If the name of a group is matched by REGEXP, the corresponding scorefiles | |
57 will be used for that group. | |
58 The first match found is used, subsequent matching entries are ignored (to | |
59 use multiple matches, see gnus-score-file-multiple-match-alist). | |
60 | |
61 These score files are loaded in addition to any files returned by | |
62 gnus-score-find-score-files-function (which see)." | |
63 :group 'gnus-score-files | |
64 :type '(repeat (cons regexp (repeat file)))) | |
65 | |
66 (defcustom gnus-score-file-multiple-match-alist nil | |
67 "Alist mapping regexps to lists of score files. | |
68 Each element of this alist should be of the form | |
69 (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... ) | |
70 | |
71 If the name of a group is matched by REGEXP, the corresponding scorefiles | |
72 will be used for that group. | |
73 If multiple REGEXPs match a group, the score files corresponding to each | |
74 match will be used (for only one match to be used, see | |
75 gnus-score-file-single-match-alist). | |
76 | |
77 These score files are loaded in addition to any files returned by | |
78 gnus-score-find-score-files-function (which see)." | |
79 :group 'gnus-score-files | |
80 :type '(repeat (cons regexp (repeat file)))) | |
81 | |
82 (defcustom gnus-score-file-suffix "SCORE" | |
83 "Suffix of the score files." | |
84 :group 'gnus-score-files | |
85 :type 'string) | |
86 | |
87 (defcustom gnus-adaptive-file-suffix "ADAPT" | |
88 "Suffix of the adaptive score files." | |
89 :group 'gnus-score-files | |
90 :group 'gnus-score-adapt | |
91 :type 'string) | |
92 | |
93 (defcustom gnus-score-find-score-files-function 'gnus-score-find-bnews | |
94 "Function used to find score files. | |
95 The function will be called with the group name as the argument, and | |
96 should return a list of score files to apply to that group. The score | |
97 files do not actually have to exist. | |
98 | |
99 Predefined values are: | |
100 | |
101 gnus-score-find-single: Only apply the group's own score file. | |
102 gnus-score-find-hierarchical: Also apply score files from parent groups. | |
103 gnus-score-find-bnews: Apply score files whose names matches. | |
104 | |
105 See the documentation to these functions for more information. | |
106 | |
107 This variable can also be a list of functions to be called. Each | |
108 function should either return a list of score files, or a list of | |
109 score alists." | |
110 :group 'gnus-score-files | |
111 :type '(radio (function-item gnus-score-find-single) | |
112 (function-item gnus-score-find-hierarchical) | |
113 (function-item gnus-score-find-bnews) | |
114 (function :tag "Other"))) | |
115 | |
116 (defcustom gnus-score-interactive-default-score 1000 | |
117 "*Scoring commands will raise/lower the score with this number as the default." | |
118 :group 'gnus-score-default | |
119 :type 'integer) | |
120 | |
121 (defcustom gnus-score-expiry-days 7 | |
122 "*Number of days before unused score file entries are expired. | |
123 If this variable is nil, no score file entries will be expired." | |
124 :group 'gnus-score-expire | |
125 :type '(choice (const :tag "never" nil) | |
126 number)) | |
127 | |
128 (defcustom gnus-update-score-entry-dates t | |
129 "*In non-nil, update matching score entry dates. | |
130 If this variable is nil, then score entries that provide matches | |
131 will be expired along with non-matching score entries." | |
132 :group 'gnus-score-expire | |
133 :type 'boolean) | |
134 | |
135 (defcustom gnus-orphan-score nil | |
136 "*All orphans get this score added. Set in the score file." | |
137 :group 'gnus-score-default | |
138 :type 'integer) | |
139 | |
140 (defcustom gnus-decay-scores nil | |
141 "*If non-nil, decay non-permanent scores." | |
142 :group 'gnus-score-decay | |
143 :type 'boolean) | |
144 | |
145 (defcustom gnus-decay-score-function 'gnus-decay-score | |
146 "*Function called to decay a score. | |
147 It is called with one parameter -- the score to be decayed." | |
148 :group 'gnus-score-decay | |
149 :type '(radio (function-item gnus-decay-score) | |
150 (function :tag "Other"))) | |
151 | |
152 (defcustom gnus-score-decay-constant 3 | |
153 "*Decay all \"small\" scores with this amount." | |
154 :group 'gnus-score-decay | |
155 :type 'integer) | |
156 | |
157 (defcustom gnus-score-decay-scale .05 | |
158 "*Decay all \"big\" scores with this factor." | |
159 :group 'gnus-score-decay | |
160 :type 'number) | |
161 | |
162 (defcustom gnus-home-score-file nil | |
163 "Variable to control where interactive score entries are to go. | |
164 It can be: | |
165 | |
166 * A string | |
167 This file file will be used as the home score file. | |
168 | |
169 * A function | |
170 The result of this function will be used as the home score file. | |
171 The function will be passed the name of the group as its | |
172 parameter. | |
173 | |
174 * A list | |
175 The elements in this list can be: | |
176 | |
177 * `(regexp file-name ...)' | |
178 If the `regexp' matches the group name, the first `file-name' will | |
179 will be used as the home score file. (Multiple filenames are | |
180 allowed so that one may use gnus-score-file-single-match-alist to | |
181 set this variable.) | |
182 | |
183 * A function. | |
184 If the function returns non-nil, the result will be used | |
185 as the home score file. The function will be passed the | |
186 name of the group as its parameter. | |
187 | |
188 * A string. Use the string as the home score file. | |
189 | |
190 The list will be traversed from the beginning towards the end looking | |
191 for matches." | |
192 :group 'gnus-score-files | |
193 :type '(choice string | |
194 (repeat (choice string | |
195 (cons regexp (repeat file)) | |
196 function)) | |
197 function)) | |
198 | |
199 (defcustom gnus-home-adapt-file nil | |
200 "Variable to control where new adaptive score entries are to go. | |
201 This variable allows the same syntax as `gnus-home-score-file'." | |
202 :group 'gnus-score-adapt | |
203 :group 'gnus-score-files | |
204 :type '(choice string | |
205 (repeat (choice string | |
206 (cons regexp (repeat file)) | |
207 function)) | |
208 function)) | |
209 | |
210 (defcustom gnus-default-adaptive-score-alist | |
211 '((gnus-kill-file-mark) | |
212 (gnus-unread-mark) | |
213 (gnus-read-mark (from 3) (subject 30)) | |
214 (gnus-catchup-mark (subject -10)) | |
215 (gnus-killed-mark (from -1) (subject -20)) | |
216 (gnus-del-mark (from -2) (subject -15))) | |
217 "Alist of marks and scores." | |
218 :group 'gnus-score-adapt | |
219 :type '(repeat (cons (symbol :tag "Mark") | |
220 (repeat (list (choice :tag "Header" | |
221 (const from) | |
222 (const subject) | |
223 (symbol :tag "other")) | |
224 (integer :tag "Score")))))) | |
225 | |
226 (defcustom gnus-ignored-adaptive-words nil | |
227 "List of words to be ignored when doing adaptive word scoring." | |
228 :group 'gnus-score-adapt | |
229 :type '(repeat string)) | |
230 | |
231 (defcustom gnus-default-ignored-adaptive-words | |
232 '("a" "i" "the" "to" "of" "and" "in" "is" "it" "for" "that" "if" "you" | |
233 "this" "be" "on" "with" "not" "have" "are" "or" "as" "from" "can" | |
234 "but" "by" "at" "an" "will" "no" "all" "was" "do" "there" "my" "one" | |
235 "so" "we" "they" "what" "would" "any" "which" "about" "get" "your" | |
236 "use" "some" "me" "then" "name" "like" "out" "when" "up" "time" | |
237 "other" "more" "only" "just" "end" "also" "know" "how" "new" "should" | |
238 "been" "than" "them" "he" "who" "make" "may" "people" "these" "now" | |
239 "their" "here" "into" "first" "could" "way" "had" "see" "work" "well" | |
240 "were" "two" "very" "where" "while" "us" "because" "good" "same" | |
241 "even" "much" "most" "many" "such" "long" "his" "over" "last" "since" | |
242 "right" "before" "our" "without" "too" "those" "why" "must" "part" | |
243 "being" "current" "back" "still" "go" "point" "value" "each" "did" | |
244 "both" "true" "off" "say" "another" "state" "might" "under" "start" | |
245 "try" "re") | |
246 "Default list of words to be ignored when doing adaptive word scoring." | |
247 :group 'gnus-score-adapt | |
248 :type '(repeat string)) | |
249 | |
250 (defcustom gnus-default-adaptive-word-score-alist | |
251 `((,gnus-read-mark . 30) | |
252 (,gnus-catchup-mark . -10) | |
253 (,gnus-killed-mark . -20) | |
254 (,gnus-del-mark . -15)) | |
255 "Alist of marks and scores." | |
256 :group 'gnus-score-adapt | |
257 :type '(repeat (cons (character :tag "Mark") | |
258 (integer :tag "Score")))) | |
259 | |
260 (defcustom gnus-score-mimic-keymap nil | |
261 "*Have the score entry functions pretend that they are a keymap." | |
262 :group 'gnus-score-default | |
263 :type 'boolean) | |
264 | |
265 (defcustom gnus-score-exact-adapt-limit 10 | |
266 "*Number that says how long a match has to be before using substring matching. | |
267 When doing adaptive scoring, one normally uses fuzzy or substring | |
268 matching. However, if the header one matches is short, the possibility | |
269 for false positives is great, so if the length of the match is less | |
270 than this variable, exact matching will be used. | |
271 | |
272 If this variable is nil, exact matching will always be used." | |
273 :group 'gnus-score-adapt | |
274 :type '(choice (const nil) integer)) | |
275 | |
276 (defcustom gnus-score-uncacheable-files "ADAPT$" | |
277 "All score files that match this regexp will not be cached." | |
278 :group 'gnus-score-adapt | |
279 :group 'gnus-score-files | |
280 :type 'regexp) | |
281 | |
282 (defcustom gnus-score-default-header nil | |
283 "Default header when entering new scores. | |
284 | |
285 Should be one of the following symbols. | |
286 | |
287 a: from | |
288 s: subject | |
289 b: body | |
290 h: head | |
291 i: message-id | |
292 t: references | |
293 x: xref | |
294 l: lines | |
295 d: date | |
296 f: followup | |
297 | |
298 If nil, the user will be asked for a header." | |
299 :group 'gnus-score-default | |
300 :type '(choice (const :tag "from" a) | |
301 (const :tag "subject" s) | |
302 (const :tag "body" b) | |
303 (const :tag "head" h) | |
304 (const :tag "message-id" i) | |
305 (const :tag "references" t) | |
306 (const :tag "xref" x) | |
307 (const :tag "lines" l) | |
308 (const :tag "date" d) | |
309 (const :tag "followup" f))) | |
310 | |
311 (defcustom gnus-score-default-type nil | |
312 "Default match type when entering new scores. | |
313 | |
314 Should be one of the following symbols. | |
315 | |
316 s: substring | |
317 e: exact string | |
318 f: fuzzy string | |
319 r: regexp string | |
320 b: before date | |
321 a: at date | |
322 n: this date | |
323 <: less than number | |
324 >: greater than number | |
325 =: equal to number | |
326 | |
327 If nil, the user will be asked for a match type." | |
328 :group 'gnus-score-default | |
329 :type '(choice (const :tag "substring" s) | |
330 (const :tag "exact string" e) | |
331 (const :tag "fuzzy string" f) | |
332 (const :tag "regexp string" r) | |
333 (const :tag "before date" b) | |
334 (const :tag "at date" a) | |
335 (const :tag "this date" n) | |
336 (const :tag "less than number" <) | |
337 (const :tag "greater than number" >) | |
338 (const :tag "equal than number" =))) | |
339 | |
340 (defcustom gnus-score-default-fold nil | |
341 "Use case folding for new score file entries iff not nil." | |
342 :group 'gnus-score-default | |
343 :type 'boolean) | |
344 | |
345 (defcustom gnus-score-default-duration nil | |
346 "Default duration of effect when entering new scores. | |
347 | |
348 Should be one of the following symbols. | |
349 | |
350 t: temporary | |
351 p: permanent | |
352 i: immediate | |
353 | |
354 If nil, the user will be asked for a duration." | |
355 :group 'gnus-score-default | |
356 :type '(choice (const :tag "temporary" t) | |
357 (const :tag "permanent" p) | |
358 (const :tag "immediate" i) | |
359 (const :tag "ask" nil))) | |
360 | |
361 (defcustom gnus-score-after-write-file-function nil | |
362 "Function called with the name of the score file just written to disk." | |
363 :group 'gnus-score-files | |
364 :type 'function) | |
365 | |
366 | |
367 | |
368 ;; Internal variables. | |
369 | |
370 (defvar gnus-adaptive-word-syntax-table | |
371 (let ((table (copy-syntax-table (standard-syntax-table))) | |
372 (numbers '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))) | |
373 (while numbers | |
374 (modify-syntax-entry (pop numbers) " " table)) | |
375 (modify-syntax-entry ?' "w" table) | |
376 table) | |
377 "Syntax table used when doing adaptive word scoring.") | |
378 | |
379 (defvar gnus-scores-exclude-files nil) | |
380 (defvar gnus-internal-global-score-files nil) | |
381 (defvar gnus-score-file-list nil) | |
382 | |
383 (defvar gnus-short-name-score-file-cache nil) | |
384 | |
385 (defvar gnus-score-help-winconf nil) | |
386 (defvar gnus-adaptive-score-alist gnus-default-adaptive-score-alist) | |
387 (defvar gnus-adaptive-word-score-alist gnus-default-adaptive-word-score-alist) | |
388 (defvar gnus-score-trace nil) | |
389 (defvar gnus-score-edit-buffer nil) | |
390 | |
391 (defvar gnus-score-alist nil | |
392 "Alist containing score information. | |
393 The keys can be symbols or strings. The following symbols are defined. | |
394 | |
395 touched: If this alist has been modified. | |
396 mark: Automatically mark articles below this. | |
397 expunge: Automatically expunge articles below this. | |
398 files: List of other score files to load when loading this one. | |
399 eval: Sexp to be evaluated when the score file is loaded. | |
400 | |
401 String entries have the form (HEADER (MATCH TYPE SCORE DATE) ...) | |
402 where HEADER is the header being scored, MATCH is the string we are | |
403 looking for, TYPE is a flag indicating whether it should use regexp or | |
404 substring matching, SCORE is the score to add and DATE is the date | |
405 of the last successful match.") | |
406 | |
407 (defvar gnus-score-cache nil) | |
408 (defvar gnus-scores-articles nil) | |
409 (defvar gnus-score-index nil) | |
410 | |
411 | |
412 (defconst gnus-header-index | |
413 ;; Name to index alist. | |
414 '(("number" 0 gnus-score-integer) | |
415 ("subject" 1 gnus-score-string) | |
416 ("from" 2 gnus-score-string) | |
417 ("date" 3 gnus-score-date) | |
418 ("message-id" 4 gnus-score-string) | |
419 ("references" 5 gnus-score-string) | |
420 ("chars" 6 gnus-score-integer) | |
421 ("lines" 7 gnus-score-integer) | |
422 ("xref" 8 gnus-score-string) | |
423 ("head" -1 gnus-score-body) | |
424 ("body" -1 gnus-score-body) | |
425 ("all" -1 gnus-score-body) | |
426 ("followup" 2 gnus-score-followup) | |
427 ("thread" 5 gnus-score-thread))) | |
428 | |
429 ;;; Summary mode score maps. | |
430 | |
431 (gnus-define-keys (gnus-summary-score-map "V" gnus-summary-mode-map) | |
432 "s" gnus-summary-set-score | |
433 "a" gnus-summary-score-entry | |
434 "S" gnus-summary-current-score | |
435 "c" gnus-score-change-score-file | |
436 "C" gnus-score-customize | |
437 "m" gnus-score-set-mark-below | |
438 "x" gnus-score-set-expunge-below | |
439 "R" gnus-summary-rescore | |
440 "e" gnus-score-edit-current-scores | |
441 "f" gnus-score-edit-file | |
442 "F" gnus-score-flush-cache | |
443 "t" gnus-score-find-trace | |
444 "w" gnus-score-find-favourite-words) | |
445 | |
446 ;; Summary score file commands | |
447 | |
448 ;; Much modification of the kill (ahem, score) code and lots of the | |
449 ;; functions are written by Per Abrahamsen <amanda@iesd.auc.dk>. | |
450 | |
451 (defun gnus-summary-lower-score (&optional score) | |
452 "Make a score entry based on the current article. | |
453 The user will be prompted for header to score on, match type, | |
454 permanence, and the string to be used. The numerical prefix will be | |
455 used as score." | |
456 (interactive "P") | |
457 (gnus-summary-increase-score (- (gnus-score-default score)))) | |
458 | |
459 (defun gnus-score-kill-help-buffer () | |
460 (when (get-buffer "*Score Help*") | |
461 (kill-buffer "*Score Help*") | |
462 (when gnus-score-help-winconf | |
463 (set-window-configuration gnus-score-help-winconf)))) | |
464 | |
465 (defun gnus-summary-increase-score (&optional score) | |
466 "Make a score entry based on the current article. | |
467 The user will be prompted for header to score on, match type, | |
468 permanence, and the string to be used. The numerical prefix will be | |
469 used as score." | |
470 (interactive "P") | |
471 (gnus-set-global-variables) | |
472 (let* ((nscore (gnus-score-default score)) | |
473 (prefix (if (< nscore 0) ?L ?I)) | |
474 (increase (> nscore 0)) | |
475 (char-to-header | |
476 '((?a "from" nil nil string) | |
477 (?s "subject" nil nil string) | |
478 (?b "body" "" nil body-string) | |
479 (?h "head" "" nil body-string) | |
480 (?i "message-id" nil t string) | |
481 (?t "references" "message-id" nil string) | |
482 (?x "xref" nil nil string) | |
483 (?l "lines" nil nil number) | |
484 (?d "date" nil nil date) | |
485 (?f "followup" nil nil string) | |
486 (?T "thread" nil nil string))) | |
487 (char-to-type | |
488 '((?s s "substring" string) | |
489 (?e e "exact string" string) | |
490 (?f f "fuzzy string" string) | |
491 (?r r "regexp string" string) | |
492 (?z s "substring" body-string) | |
493 (?p r "regexp string" body-string) | |
494 (?b before "before date" date) | |
495 (?a at "at date" date) | |
496 (?n now "this date" date) | |
497 (?< < "less than number" number) | |
498 (?> > "greater than number" number) | |
499 (?= = "equal to number" number))) | |
500 (char-to-perm | |
501 (list (list ?t (current-time-string) "temporary") | |
502 '(?p perm "permanent") '(?i now "immediate"))) | |
503 (mimic gnus-score-mimic-keymap) | |
504 (hchar (and gnus-score-default-header | |
505 (aref (symbol-name gnus-score-default-header) 0))) | |
506 (tchar (and gnus-score-default-type | |
507 (aref (symbol-name gnus-score-default-type) 0))) | |
508 (pchar (and gnus-score-default-duration | |
509 (aref (symbol-name gnus-score-default-duration) 0))) | |
510 entry temporary type match) | |
511 | |
512 (unwind-protect | |
513 (progn | |
514 | |
515 ;; First we read the header to score. | |
516 (while (not hchar) | |
517 (if mimic | |
518 (progn | |
519 (sit-for 1) | |
520 (message "%c-" prefix)) | |
521 (message "%s header (%s?): " (if increase "Increase" "Lower") | |
522 (mapconcat (lambda (s) (char-to-string (car s))) | |
523 char-to-header ""))) | |
524 (setq hchar (read-char)) | |
525 (when (or (= hchar ??) (= hchar ?\C-h)) | |
526 (setq hchar nil) | |
527 (gnus-score-insert-help "Match on header" char-to-header 1))) | |
528 | |
529 (gnus-score-kill-help-buffer) | |
530 (unless (setq entry (assq (downcase hchar) char-to-header)) | |
531 (if mimic (error "%c %c" prefix hchar) (error ""))) | |
532 | |
533 (when (/= (downcase hchar) hchar) | |
534 ;; This was a majuscule, so we end reading and set the defaults. | |
535 (if mimic (message "%c %c" prefix hchar) (message "")) | |
536 (setq tchar (or tchar ?s) | |
537 pchar (or pchar ?t))) | |
538 | |
539 ;; We continue reading - the type. | |
540 (while (not tchar) | |
541 (if mimic | |
542 (progn | |
543 (sit-for 1) (message "%c %c-" prefix hchar)) | |
544 (message "%s header '%s' with match type (%s?): " | |
545 (if increase "Increase" "Lower") | |
546 (nth 1 entry) | |
547 (mapconcat (lambda (s) | |
548 (if (eq (nth 4 entry) | |
549 (nth 3 s)) | |
550 (char-to-string (car s)) | |
551 "")) | |
552 char-to-type ""))) | |
553 (setq tchar (read-char)) | |
554 (when (or (= tchar ??) (= tchar ?\C-h)) | |
555 (setq tchar nil) | |
556 (gnus-score-insert-help | |
557 "Match type" | |
558 (delq nil | |
559 (mapcar (lambda (s) | |
560 (if (eq (nth 4 entry) | |
561 (nth 3 s)) | |
562 s nil)) | |
563 char-to-type)) | |
564 2))) | |
565 | |
566 (gnus-score-kill-help-buffer) | |
567 (unless (setq type (nth 1 (assq (downcase tchar) char-to-type))) | |
568 (if mimic (error "%c %c" prefix hchar) (error ""))) | |
569 | |
570 (when (/= (downcase tchar) tchar) | |
571 ;; It was a majuscule, so we end reading and use the default. | |
572 (if mimic (message "%c %c %c" prefix hchar tchar) | |
573 (message "")) | |
574 (setq pchar (or pchar ?p))) | |
575 | |
576 ;; We continue reading. | |
577 (while (not pchar) | |
578 (if mimic | |
579 (progn | |
580 (sit-for 1) (message "%c %c %c-" prefix hchar tchar)) | |
581 (message "%s permanence (%s?): " (if increase "Increase" "Lower") | |
582 (mapconcat (lambda (s) (char-to-string (car s))) | |
583 char-to-perm ""))) | |
584 (setq pchar (read-char)) | |
585 (when (or (= pchar ??) (= pchar ?\C-h)) | |
586 (setq pchar nil) | |
587 (gnus-score-insert-help "Match permanence" char-to-perm 2))) | |
588 | |
589 (gnus-score-kill-help-buffer) | |
590 (if mimic (message "%c %c %c" prefix hchar tchar pchar) | |
591 (message "")) | |
592 (unless (setq temporary (cadr (assq pchar char-to-perm))) | |
593 ;; Deal with der(r)ided superannuated paradigms. | |
594 (when (and (eq (1+ prefix) 77) | |
595 (eq (+ hchar 12) 109) | |
596 (eq tchar 114) | |
597 (eq (- pchar 4) 111)) | |
598 (error "You rang?")) | |
599 (if mimic | |
600 (error "%c %c %c %c" prefix hchar tchar pchar) | |
601 (error "")))) | |
602 ;; Always kill the score help buffer. | |
603 (gnus-score-kill-help-buffer)) | |
604 | |
605 ;; We have all the data, so we enter this score. | |
606 (setq match (if (string= (nth 2 entry) "") "" | |
607 (gnus-summary-header (or (nth 2 entry) (nth 1 entry))))) | |
608 | |
609 ;; Modify the match, perhaps. | |
610 (cond | |
611 ((equal (nth 1 entry) "xref") | |
612 (when (string-match "^Xref: *" match) | |
613 (setq match (substring match (match-end 0)))) | |
614 (when (string-match "^[^:]* +" match) | |
615 (setq match (substring match (match-end 0)))))) | |
616 | |
617 (when (memq type '(r R regexp Regexp)) | |
618 (setq match (regexp-quote match))) | |
619 | |
620 (gnus-summary-score-entry | |
621 (nth 1 entry) ; Header | |
622 match ; Match | |
623 type ; Type | |
624 (if (eq score 's) nil score) ; Score | |
625 (if (eq temporary 'perm) ; Temp | |
626 nil | |
627 temporary) | |
628 (not (nth 3 entry))) ; Prompt | |
629 )) | |
630 | |
631 (defun gnus-score-insert-help (string alist idx) | |
632 (setq gnus-score-help-winconf (current-window-configuration)) | |
633 (save-excursion | |
634 (set-buffer (get-buffer-create "*Score Help*")) | |
635 (buffer-disable-undo (current-buffer)) | |
636 (delete-windows-on (current-buffer)) | |
637 (erase-buffer) | |
638 (insert string ":\n\n") | |
639 (let ((max -1) | |
640 (list alist) | |
641 (i 0) | |
642 n width pad format) | |
643 ;; find the longest string to display | |
644 (while list | |
645 (setq n (length (nth idx (car list)))) | |
646 (unless (> max n) | |
647 (setq max n)) | |
648 (setq list (cdr list))) | |
649 (setq max (+ max 4)) ; %c, `:', SPACE, a SPACE at end | |
650 (setq n (/ (1- (window-width)) max)) ; items per line | |
651 (setq width (/ (1- (window-width)) n)) ; width of each item | |
652 ;; insert `n' items, each in a field of width `width' | |
653 (while alist | |
654 (if (< i n) | |
655 () | |
656 (setq i 0) | |
657 (delete-char -1) ; the `\n' takes a char | |
658 (insert "\n")) | |
659 (setq pad (- width 3)) | |
660 (setq format (concat "%c: %-" (int-to-string pad) "s")) | |
661 (insert (format format (caar alist) (nth idx (car alist)))) | |
662 (setq alist (cdr alist)) | |
663 (setq i (1+ i)))) | |
664 ;; display ourselves in a small window at the bottom | |
665 (gnus-appt-select-lowest-window) | |
666 (split-window) | |
667 (pop-to-buffer "*Score Help*") | |
668 (let ((window-min-height 1)) | |
669 (shrink-window-if-larger-than-buffer)) | |
670 (select-window (get-buffer-window gnus-summary-buffer)))) | |
671 | |
672 (defun gnus-summary-header (header &optional no-err) | |
673 ;; Return HEADER for current articles, or error. | |
674 (let ((article (gnus-summary-article-number)) | |
675 headers) | |
676 (if article | |
677 (if (and (setq headers (gnus-summary-article-header article)) | |
678 (vectorp headers)) | |
679 (aref headers (nth 1 (assoc header gnus-header-index))) | |
680 (if no-err | |
681 nil | |
682 (error "Pseudo-articles can't be scored"))) | |
683 (if no-err | |
684 (error "No article on current line") | |
685 nil)))) | |
686 | |
687 (defun gnus-newsgroup-score-alist () | |
688 (or | |
689 (let ((param-file (gnus-group-find-parameter | |
690 gnus-newsgroup-name 'score-file))) | |
691 (when param-file | |
692 (gnus-score-load param-file))) | |
693 (gnus-score-load | |
694 (gnus-score-file-name gnus-newsgroup-name))) | |
695 gnus-score-alist) | |
696 | |
697 (defsubst gnus-score-get (symbol &optional alist) | |
698 ;; Get SYMBOL's definition in ALIST. | |
699 (cdr (assoc symbol | |
700 (or alist | |
701 gnus-score-alist | |
702 (gnus-newsgroup-score-alist))))) | |
703 | |
704 (defun gnus-summary-score-entry (header match type score date | |
705 &optional prompt silent) | |
706 "Enter score file entry. | |
707 HEADER is the header being scored. | |
708 MATCH is the string we are looking for. | |
709 TYPE is the match type: substring, regexp, exact, fuzzy. | |
710 SCORE is the score to add. | |
711 DATE is the expire date, or nil for no expire, or 'now for immediate expire. | |
712 If optional argument `PROMPT' is non-nil, allow user to edit match. | |
713 If optional argument `SILENT' is nil, show effect of score entry." | |
714 (interactive | |
715 (list (completing-read "Header: " | |
716 gnus-header-index | |
717 (lambda (x) (fboundp (nth 2 x))) | |
718 t) | |
719 (read-string "Match: ") | |
720 (if (y-or-n-p "Use regexp match? ") 'r 's) | |
721 (and current-prefix-arg | |
722 (prefix-numeric-value current-prefix-arg)) | |
723 (cond ((not (y-or-n-p "Add to score file? ")) | |
724 'now) | |
725 ((y-or-n-p "Expire kill? ") | |
726 (current-time-string)) | |
727 (t nil)))) | |
728 ;; Regexp is the default type. | |
729 (when (eq type t) | |
730 (setq type 'r)) | |
731 ;; Simplify matches... | |
732 (cond ((or (eq type 'r) (eq type 's) (eq type nil)) | |
733 (setq match (if match (gnus-simplify-subject-re match) ""))) | |
734 ((eq type 'f) | |
735 (setq match (gnus-simplify-subject-fuzzy match)))) | |
736 (let ((score (gnus-score-default score)) | |
737 (header (format "%s" (downcase header))) | |
738 new) | |
739 (when prompt | |
740 (setq match (read-string | |
741 (format "Match %s on %s, %s: " | |
742 (cond ((eq date 'now) | |
743 "now") | |
744 ((stringp date) | |
745 "temp") | |
746 (t "permanent")) | |
747 header | |
748 (if (< score 0) "lower" "raise")) | |
749 (if (numberp match) | |
750 (int-to-string match) | |
751 match)))) | |
752 | |
753 ;; Get rid of string props. | |
754 (setq match (format "%s" match)) | |
755 | |
756 ;; If this is an integer comparison, we transform from string to int. | |
757 (when (eq (nth 2 (assoc header gnus-header-index)) 'gnus-score-integer) | |
758 (setq match (string-to-int match))) | |
759 | |
760 (unless (eq date 'now) | |
761 ;; Add the score entry to the score file. | |
762 (when (= score gnus-score-interactive-default-score) | |
763 (setq score nil)) | |
764 (let ((old (gnus-score-get header)) | |
765 elem) | |
766 (setq new | |
767 (cond | |
768 (type | |
769 (list match score | |
770 (and date (if (numberp date) date | |
771 (gnus-day-number date))) | |
772 type)) | |
773 (date (list match score (gnus-day-number date))) | |
774 (score (list match score)) | |
775 (t (list match)))) | |
776 ;; We see whether we can collapse some score entries. | |
777 ;; This isn't quite correct, because there may be more elements | |
778 ;; later on with the same key that have matching elems... Hm. | |
779 (if (and old | |
780 (setq elem (assoc match old)) | |
781 (eq (nth 3 elem) (nth 3 new)) | |
782 (or (and (numberp (nth 2 elem)) (numberp (nth 2 new))) | |
783 (and (not (nth 2 elem)) (not (nth 2 new))))) | |
784 ;; Yup, we just add this new score to the old elem. | |
785 (setcar (cdr elem) (+ (or (nth 1 elem) | |
786 gnus-score-interactive-default-score) | |
787 (or (nth 1 new) | |
788 gnus-score-interactive-default-score))) | |
789 ;; Nope, we have to add a new elem. | |
790 (gnus-score-set header (if old (cons new old) (list new)))) | |
791 (gnus-score-set 'touched '(t)))) | |
792 | |
793 ;; Score the current buffer. | |
794 (unless silent | |
795 (if (and (>= (nth 1 (assoc header gnus-header-index)) 0) | |
796 (eq (nth 2 (assoc header gnus-header-index)) | |
797 'gnus-score-string)) | |
798 (gnus-summary-score-effect header match type score) | |
799 (gnus-summary-rescore))) | |
800 | |
801 ;; Return the new scoring rule. | |
802 new)) | |
803 | |
804 (defun gnus-summary-score-effect (header match type score) | |
805 "Simulate the effect of a score file entry. | |
806 HEADER is the header being scored. | |
807 MATCH is the string we are looking for. | |
808 TYPE is the score type. | |
809 SCORE is the score to add." | |
810 (interactive (list (completing-read "Header: " | |
811 gnus-header-index | |
812 (lambda (x) (fboundp (nth 2 x))) | |
813 t) | |
814 (read-string "Match: ") | |
815 (y-or-n-p "Use regexp match? ") | |
816 (prefix-numeric-value current-prefix-arg))) | |
817 (save-excursion | |
818 (unless (and (stringp match) (> (length match) 0)) | |
819 (error "No match")) | |
820 (goto-char (point-min)) | |
821 (let ((regexp (cond ((eq type 'f) | |
822 (gnus-simplify-subject-fuzzy match)) | |
823 ((eq type 'r) | |
824 match) | |
825 ((eq type 'e) | |
826 (concat "\\`" (regexp-quote match) "\\'")) | |
827 (t | |
828 (regexp-quote match))))) | |
829 (while (not (eobp)) | |
830 (let ((content (gnus-summary-header header 'noerr)) | |
831 (case-fold-search t)) | |
832 (and content | |
833 (when (if (eq type 'f) | |
834 (string-equal (gnus-simplify-subject-fuzzy content) | |
835 regexp) | |
836 (string-match regexp content)) | |
837 (gnus-summary-raise-score score)))) | |
838 (beginning-of-line 2)))) | |
839 (gnus-set-mode-line 'summary)) | |
840 | |
841 (defun gnus-summary-score-crossposting (score date) | |
842 ;; Enter score file entry for current crossposting. | |
843 ;; SCORE is the score to add. | |
844 ;; DATE is the expire date. | |
845 (let ((xref (gnus-summary-header "xref")) | |
846 (start 0) | |
847 group) | |
848 (unless xref | |
849 (error "This article is not crossposted")) | |
850 (while (string-match " \\([^ \t]+\\):" xref start) | |
851 (setq start (match-end 0)) | |
852 (when (not (string= | |
853 (setq group | |
854 (substring xref (match-beginning 1) (match-end 1))) | |
855 gnus-newsgroup-name)) | |
856 (gnus-summary-score-entry | |
857 "xref" (concat " " group ":") nil score date t))))) | |
858 | |
859 | |
860 ;;; | |
861 ;;; Gnus Score Files | |
862 ;;; | |
863 | |
864 ;; All score code written by Per Abrahamsen <abraham@iesd.auc.dk>. | |
865 | |
866 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>. | |
867 (defun gnus-score-set-mark-below (score) | |
868 "Automatically mark articles with score below SCORE as read." | |
869 (interactive | |
870 (list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg)) | |
871 (string-to-int (read-string "Mark below: "))))) | |
872 (setq score (or score gnus-summary-default-score 0)) | |
873 (gnus-score-set 'mark (list score)) | |
874 (gnus-score-set 'touched '(t)) | |
875 (setq gnus-summary-mark-below score) | |
876 (gnus-score-update-lines)) | |
877 | |
878 (defun gnus-score-update-lines () | |
879 "Update all lines in the summary buffer." | |
880 (save-excursion | |
881 (goto-char (point-min)) | |
882 (while (not (eobp)) | |
883 (gnus-summary-update-line) | |
884 (forward-line 1)))) | |
885 | |
886 (defun gnus-score-update-all-lines () | |
887 "Update all lines in the summary buffer, even the hidden ones." | |
888 (save-excursion | |
889 (goto-char (point-min)) | |
890 (let (hidden) | |
891 (while (not (eobp)) | |
892 (when (gnus-summary-show-thread) | |
893 (push (point) hidden)) | |
894 (gnus-summary-update-line) | |
895 (forward-line 1)) | |
896 ;; Re-hide the hidden threads. | |
897 (while hidden | |
898 (goto-char (pop hidden)) | |
899 (gnus-summary-hide-thread))))) | |
900 | |
901 (defun gnus-score-set-expunge-below (score) | |
902 "Automatically expunge articles with score below SCORE." | |
903 (interactive | |
904 (list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg)) | |
905 (string-to-int (read-string "Set expunge below: "))))) | |
906 (setq score (or score gnus-summary-default-score 0)) | |
907 (gnus-score-set 'expunge (list score)) | |
908 (gnus-score-set 'touched '(t))) | |
909 | |
910 (defun gnus-score-followup-article (&optional score) | |
911 "Add SCORE to all followups to the article in the current buffer." | |
912 (interactive "P") | |
913 (setq score (gnus-score-default score)) | |
914 (when (gnus-buffer-live-p gnus-summary-buffer) | |
915 (save-excursion | |
916 (save-restriction | |
917 (message-narrow-to-headers) | |
918 (let ((id (mail-fetch-field "message-id"))) | |
919 (when id | |
920 (set-buffer gnus-summary-buffer) | |
921 (gnus-summary-score-entry | |
922 "references" (concat id "[ \t]*$") 'r | |
923 score (current-time-string) nil t))))))) | |
924 | |
925 (defun gnus-score-followup-thread (&optional score) | |
926 "Add SCORE to all later articles in the thread the current buffer is part of." | |
927 (interactive "P") | |
928 (setq score (gnus-score-default score)) | |
929 (when (gnus-buffer-live-p gnus-summary-buffer) | |
930 (save-excursion | |
931 (save-restriction | |
932 (goto-char (point-min)) | |
933 (let ((id (mail-fetch-field "message-id"))) | |
934 (when id | |
935 (set-buffer gnus-summary-buffer) | |
936 (gnus-summary-score-entry | |
937 "references" id 's | |
938 score (current-time-string)))))))) | |
939 | |
940 (defun gnus-score-set (symbol value &optional alist) | |
941 ;; Set SYMBOL to VALUE in ALIST. | |
942 (let* ((alist | |
943 (or alist | |
944 gnus-score-alist | |
945 (gnus-newsgroup-score-alist))) | |
946 (entry (assoc symbol alist))) | |
947 (cond ((gnus-score-get 'read-only alist) | |
948 ;; This is a read-only score file, so we do nothing. | |
949 ) | |
950 (entry | |
951 (setcdr entry value)) | |
952 ((null alist) | |
953 (error "Empty alist")) | |
954 (t | |
955 (setcdr alist | |
956 (cons (cons symbol value) (cdr alist))))))) | |
957 | |
958 (defun gnus-summary-raise-score (n) | |
959 "Raise the score of the current article by N." | |
960 (interactive "p") | |
961 (gnus-set-global-variables) | |
962 (gnus-summary-set-score (+ (gnus-summary-article-score) | |
963 (or n gnus-score-interactive-default-score )))) | |
964 | |
965 (defun gnus-summary-set-score (n) | |
966 "Set the score of the current article to N." | |
967 (interactive "p") | |
968 (gnus-set-global-variables) | |
969 (save-excursion | |
970 (gnus-summary-show-thread) | |
971 (let ((buffer-read-only nil)) | |
972 ;; Set score. | |
973 (gnus-summary-update-mark | |
974 (if (= n (or gnus-summary-default-score 0)) ? | |
975 (if (< n (or gnus-summary-default-score 0)) | |
976 gnus-score-below-mark gnus-score-over-mark)) | |
977 'score)) | |
978 (let* ((article (gnus-summary-article-number)) | |
979 (score (assq article gnus-newsgroup-scored))) | |
980 (if score (setcdr score n) | |
981 (push (cons article n) gnus-newsgroup-scored))) | |
982 (gnus-summary-update-line))) | |
983 | |
984 (defun gnus-summary-current-score () | |
985 "Return the score of the current article." | |
986 (interactive) | |
987 (gnus-set-global-variables) | |
988 (gnus-message 1 "%s" (gnus-summary-article-score))) | |
989 | |
990 (defun gnus-score-change-score-file (file) | |
991 "Change current score alist." | |
992 (interactive | |
993 (list (read-file-name "Change to score file: " gnus-kill-files-directory))) | |
994 (gnus-score-load-file file) | |
995 (gnus-set-mode-line 'summary)) | |
996 | |
997 (defvar gnus-score-edit-exit-function) | |
998 (defun gnus-score-edit-current-scores (file) | |
999 "Edit the current score alist." | |
1000 (interactive (list gnus-current-score-file)) | |
1001 (gnus-set-global-variables) | |
1002 (let ((winconf (current-window-configuration))) | |
1003 (when (buffer-name gnus-summary-buffer) | |
1004 (gnus-score-save)) | |
1005 (gnus-make-directory (file-name-directory file)) | |
1006 (setq gnus-score-edit-buffer (find-file-noselect file)) | |
1007 (gnus-configure-windows 'edit-score) | |
1008 (gnus-score-mode) | |
1009 (setq gnus-score-edit-exit-function 'gnus-score-edit-done) | |
1010 (make-local-variable 'gnus-prev-winconf) | |
1011 (setq gnus-prev-winconf winconf)) | |
1012 (gnus-message | |
1013 4 (substitute-command-keys | |
1014 "\\<gnus-score-mode-map>\\[gnus-score-edit-exit] to save edits"))) | |
1015 | |
1016 (defun gnus-score-edit-file (file) | |
1017 "Edit a score file." | |
1018 (interactive | |
1019 (list (read-file-name "Edit score file: " gnus-kill-files-directory))) | |
1020 (gnus-make-directory (file-name-directory file)) | |
1021 (when (buffer-name gnus-summary-buffer) | |
1022 (gnus-score-save)) | |
1023 (let ((winconf (current-window-configuration))) | |
1024 (setq gnus-score-edit-buffer (find-file-noselect file)) | |
1025 (gnus-configure-windows 'edit-score) | |
1026 (gnus-score-mode) | |
1027 (setq gnus-score-edit-exit-function 'gnus-score-edit-done) | |
1028 (make-local-variable 'gnus-prev-winconf) | |
1029 (setq gnus-prev-winconf winconf)) | |
1030 (gnus-message | |
1031 4 (substitute-command-keys | |
1032 "\\<gnus-score-mode-map>\\[gnus-score-edit-exit] to save edits"))) | |
1033 | |
1034 (defun gnus-score-load-file (file) | |
1035 ;; Load score file FILE. Returns a list a retrieved score-alists. | |
1036 (let* ((file (expand-file-name | |
1037 (or (and (string-match | |
1038 (concat "^" (expand-file-name | |
1039 gnus-kill-files-directory)) | |
1040 (expand-file-name file)) | |
1041 file) | |
1042 (concat (file-name-as-directory gnus-kill-files-directory) | |
1043 file)))) | |
1044 (cached (assoc file gnus-score-cache)) | |
1045 (global (member file gnus-internal-global-score-files)) | |
1046 lists alist) | |
1047 (if cached | |
1048 ;; The score file was already loaded. | |
1049 (setq alist (cdr cached)) | |
1050 ;; We load the score file. | |
1051 (setq gnus-score-alist nil) | |
1052 (setq alist (gnus-score-load-score-alist file)) | |
1053 ;; We add '(touched) to the alist to signify that it hasn't been | |
1054 ;; touched (yet). | |
1055 (unless (assq 'touched alist) | |
1056 (push (list 'touched nil) alist)) | |
1057 ;; If it is a global score file, we make it read-only. | |
1058 (and global | |
1059 (not (assq 'read-only alist)) | |
1060 (push (list 'read-only t) alist)) | |
1061 (push (cons file alist) gnus-score-cache)) | |
1062 (let ((a alist) | |
1063 found) | |
1064 (while a | |
1065 ;; Downcase all header names. | |
1066 (when (stringp (caar a)) | |
1067 (setcar (car a) (downcase (caar a))) | |
1068 (setq found t)) | |
1069 (pop a)) | |
1070 ;; If there are actual scores in the alist, we add it to the | |
1071 ;; return value of this function. | |
1072 (when found | |
1073 (setq lists (list alist)))) | |
1074 ;; Treat the other possible atoms in the score alist. | |
1075 (let ((mark (car (gnus-score-get 'mark alist))) | |
1076 (expunge (car (gnus-score-get 'expunge alist))) | |
1077 (mark-and-expunge (car (gnus-score-get 'mark-and-expunge alist))) | |
1078 (files (gnus-score-get 'files alist)) | |
1079 (exclude-files (gnus-score-get 'exclude-files alist)) | |
1080 (orphan (car (gnus-score-get 'orphan alist))) | |
1081 (adapt (gnus-score-get 'adapt alist)) | |
1082 (thread-mark-and-expunge | |
1083 (car (gnus-score-get 'thread-mark-and-expunge alist))) | |
1084 (adapt-file (car (gnus-score-get 'adapt-file alist))) | |
1085 (local (gnus-score-get 'local alist)) | |
1086 (decay (car (gnus-score-get 'decay alist))) | |
1087 (eval (car (gnus-score-get 'eval alist)))) | |
1088 ;; Perform possible decays. | |
1089 (when (and gnus-decay-scores | |
1090 (gnus-decay-scores | |
1091 alist (or decay (gnus-time-to-day (current-time))))) | |
1092 (gnus-score-set 'touched '(t) alist) | |
1093 (gnus-score-set 'decay (list (gnus-time-to-day (current-time))))) | |
1094 ;; We do not respect eval and files atoms from global score | |
1095 ;; files. | |
1096 (and files (not global) | |
1097 (setq lists (apply 'append lists | |
1098 (mapcar (lambda (file) | |
1099 (gnus-score-load-file file)) | |
1100 (if adapt-file (cons adapt-file files) | |
1101 files))))) | |
1102 (and eval (not global) (eval eval)) | |
1103 ;; We then expand any exclude-file directives. | |
1104 (setq gnus-scores-exclude-files | |
1105 (nconc | |
1106 (mapcar | |
1107 (lambda (sfile) | |
1108 (expand-file-name sfile (file-name-directory file))) | |
1109 exclude-files) | |
1110 gnus-scores-exclude-files)) | |
1111 (if (not local) | |
1112 () | |
1113 (save-excursion | |
1114 (set-buffer gnus-summary-buffer) | |
1115 (while local | |
1116 (and (consp (car local)) | |
1117 (symbolp (caar local)) | |
1118 (progn | |
1119 (make-local-variable (caar local)) | |
1120 (set (caar local) (nth 1 (car local))))) | |
1121 (setq local (cdr local))))) | |
1122 (when orphan | |
1123 (setq gnus-orphan-score orphan)) | |
1124 (setq gnus-adaptive-score-alist | |
1125 (cond ((equal adapt '(t)) | |
1126 (setq gnus-newsgroup-adaptive t) | |
1127 gnus-default-adaptive-score-alist) | |
1128 ((equal adapt '(ignore)) | |
1129 (setq gnus-newsgroup-adaptive nil)) | |
1130 ((consp adapt) | |
1131 (setq gnus-newsgroup-adaptive t) | |
1132 adapt) | |
1133 (t | |
1134 ;;(setq gnus-newsgroup-adaptive gnus-use-adaptive-scoring) | |
1135 gnus-default-adaptive-score-alist))) | |
1136 (setq gnus-thread-expunge-below | |
1137 (or thread-mark-and-expunge gnus-thread-expunge-below)) | |
1138 (setq gnus-summary-mark-below | |
1139 (or mark mark-and-expunge gnus-summary-mark-below)) | |
1140 (setq gnus-summary-expunge-below | |
1141 (or expunge mark-and-expunge gnus-summary-expunge-below)) | |
1142 (setq gnus-newsgroup-adaptive-score-file | |
1143 (or adapt-file gnus-newsgroup-adaptive-score-file))) | |
1144 (setq gnus-current-score-file file) | |
1145 (setq gnus-score-alist alist) | |
1146 lists)) | |
1147 | |
1148 (defun gnus-score-load (file) | |
1149 ;; Load score FILE. | |
1150 (let ((cache (assoc file gnus-score-cache))) | |
1151 (if cache | |
1152 (setq gnus-score-alist (cdr cache)) | |
1153 (setq gnus-score-alist nil) | |
1154 (gnus-score-load-score-alist file) | |
1155 (unless gnus-score-alist | |
1156 (setq gnus-score-alist (copy-alist '((touched nil))))) | |
1157 (push (cons file gnus-score-alist) gnus-score-cache)))) | |
1158 | |
1159 (defun gnus-score-remove-from-cache (file) | |
1160 (setq gnus-score-cache | |
1161 (delq (assoc file gnus-score-cache) gnus-score-cache))) | |
1162 | |
1163 (defun gnus-score-load-score-alist (file) | |
1164 "Read score FILE." | |
1165 (let (alist) | |
1166 (if (not (file-readable-p file)) | |
1167 ;; Couldn't read file. | |
1168 (setq gnus-score-alist nil) | |
1169 ;; Read file. | |
1170 (save-excursion | |
1171 (gnus-set-work-buffer) | |
1172 (insert-file-contents file) | |
1173 (goto-char (point-min)) | |
1174 ;; Only do the loading if the score file isn't empty. | |
1175 (when (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t)) | |
1176 (setq alist | |
1177 (condition-case () | |
1178 (read (current-buffer)) | |
1179 (error | |
1180 (gnus-error 3.2 "Problem with score file %s" file)))))) | |
1181 (if (eq (car alist) 'setq) | |
1182 ;; This is an old-style score file. | |
1183 (setq gnus-score-alist (gnus-score-transform-old-to-new alist)) | |
1184 (setq gnus-score-alist alist)) | |
1185 ;; Check the syntax of the score file. | |
1186 (setq gnus-score-alist | |
1187 (gnus-score-check-syntax gnus-score-alist file))))) | |
1188 | |
1189 (defun gnus-score-check-syntax (alist file) | |
1190 "Check the syntax of the score ALIST." | |
1191 (cond | |
1192 ((null alist) | |
1193 nil) | |
1194 ((not (consp alist)) | |
1195 (gnus-message 1 "Score file is not a list: %s" file) | |
1196 (ding) | |
1197 nil) | |
1198 (t | |
1199 (let ((a alist) | |
1200 sr err s type) | |
1201 (while (and a (not err)) | |
1202 (setq | |
1203 err | |
1204 (cond | |
1205 ((not (listp (car a))) | |
1206 (format "Illegal score element %s in %s" (car a) file)) | |
1207 ((stringp (caar a)) | |
1208 (cond | |
1209 ((not (listp (setq sr (cdar a)))) | |
1210 (format "Illegal header match %s in %s" (nth 1 (car a)) file)) | |
1211 (t | |
1212 (setq type (caar a)) | |
1213 (while (and sr (not err)) | |
1214 (setq s (pop sr)) | |
1215 (setq | |
1216 err | |
1217 (cond | |
1218 ((if (member (downcase type) '("lines" "chars")) | |
1219 (not (numberp (car s))) | |
1220 (not (stringp (car s)))) | |
1221 (format "Illegal match %s in %s" (car s) file)) | |
1222 ((and (cadr s) (not (integerp (cadr s)))) | |
1223 (format "Non-integer score %s in %s" (cadr s) file)) | |
1224 ((and (caddr s) (not (integerp (caddr s)))) | |
1225 (format "Non-integer date %s in %s" (caddr s) file)) | |
1226 ((and (cadddr s) (not (symbolp (cadddr s)))) | |
1227 (format "Non-symbol match type %s in %s" (cadddr s) file))))) | |
1228 err))))) | |
1229 (setq a (cdr a))) | |
1230 (if err | |
1231 (progn | |
1232 (ding) | |
1233 (gnus-message 3 err) | |
1234 (sit-for 2) | |
1235 nil) | |
1236 alist))))) | |
1237 | |
1238 (defun gnus-score-transform-old-to-new (alist) | |
1239 (let* ((alist (nth 2 alist)) | |
1240 out entry) | |
1241 (when (eq (car alist) 'quote) | |
1242 (setq alist (nth 1 alist))) | |
1243 (while alist | |
1244 (setq entry (car alist)) | |
1245 (if (stringp (car entry)) | |
1246 (let ((scor (cdr entry))) | |
1247 (push entry out) | |
1248 (while scor | |
1249 (setcar scor | |
1250 (list (caar scor) (nth 2 (car scor)) | |
1251 (and (nth 3 (car scor)) | |
1252 (gnus-day-number (nth 3 (car scor)))) | |
1253 (if (nth 1 (car scor)) 'r 's))) | |
1254 (setq scor (cdr scor)))) | |
1255 (push (if (not (listp (cdr entry))) | |
1256 (list (car entry) (cdr entry)) | |
1257 entry) | |
1258 out)) | |
1259 (setq alist (cdr alist))) | |
1260 (cons (list 'touched t) (nreverse out)))) | |
1261 | |
1262 (defun gnus-score-save () | |
1263 ;; Save all score information. | |
1264 (let ((cache gnus-score-cache) | |
1265 entry score file) | |
1266 (save-excursion | |
1267 (setq gnus-score-alist nil) | |
1268 (nnheader-set-temp-buffer " *Gnus Scores*") | |
1269 (while cache | |
1270 (current-buffer) | |
1271 (setq entry (pop cache) | |
1272 file (car entry) | |
1273 score (cdr entry)) | |
1274 (if (or (not (equal (gnus-score-get 'touched score) '(t))) | |
1275 (gnus-score-get 'read-only score) | |
1276 (and (file-exists-p file) | |
1277 (not (file-writable-p file)))) | |
1278 () | |
1279 (setq score (setcdr entry (delq (assq 'touched score) score))) | |
1280 (erase-buffer) | |
1281 (let (emacs-lisp-mode-hook) | |
1282 (if (string-match | |
1283 (concat (regexp-quote gnus-adaptive-file-suffix) | |
1284 "$") | |
1285 file) | |
1286 ;; This is an adaptive score file, so we do not run | |
1287 ;; it through `pp'. These files can get huge, and | |
1288 ;; are not meant to be edited by human hands. | |
1289 (gnus-prin1 score) | |
1290 ;; This is a normal score file, so we print it very | |
1291 ;; prettily. | |
1292 (pp score (current-buffer)))) | |
1293 (gnus-make-directory (file-name-directory file)) | |
1294 ;; If the score file is empty, we delete it. | |
1295 (if (zerop (buffer-size)) | |
1296 (delete-file file) | |
1297 ;; There are scores, so we write the file. | |
1298 (when (file-writable-p file) | |
1299 (gnus-write-buffer file) | |
1300 (when gnus-score-after-write-file-function | |
1301 (funcall gnus-score-after-write-file-function file))))) | |
1302 (and gnus-score-uncacheable-files | |
1303 (string-match gnus-score-uncacheable-files file) | |
1304 (gnus-score-remove-from-cache file))) | |
1305 (kill-buffer (current-buffer))))) | |
1306 | |
1307 (defun gnus-score-load-files (score-files) | |
1308 "Load all score files in SCORE-FILES." | |
1309 ;; Load the score files. | |
1310 (let (scores) | |
1311 (while score-files | |
1312 (if (stringp (car score-files)) | |
1313 ;; It is a string, which means that it's a score file name, | |
1314 ;; so we load the score file and add the score alist to | |
1315 ;; the list of alists. | |
1316 (setq scores (nconc (gnus-score-load-file (car score-files)) scores)) | |
1317 ;; It is an alist, so we just add it to the list directly. | |
1318 (setq scores (nconc (car score-files) scores))) | |
1319 (setq score-files (cdr score-files))) | |
1320 ;; Prune the score files that are to be excluded, if any. | |
1321 (when gnus-scores-exclude-files | |
1322 (let ((s scores) | |
1323 c) | |
1324 (while s | |
1325 (and (setq c (rassq (car s) gnus-score-cache)) | |
1326 (member (car c) gnus-scores-exclude-files) | |
1327 (setq scores (delq (car s) scores))) | |
1328 (setq s (cdr s))))) | |
1329 scores)) | |
1330 | |
1331 (defun gnus-score-headers (score-files &optional trace) | |
1332 ;; Score `gnus-newsgroup-headers'. | |
1333 (let (scores news) | |
1334 ;; PLM: probably this is not the best place to clear orphan-score | |
1335 (setq gnus-orphan-score nil | |
1336 gnus-scores-articles nil | |
1337 gnus-scores-exclude-files nil | |
1338 scores (gnus-score-load-files score-files)) | |
1339 (setq news scores) | |
1340 ;; Do the scoring. | |
1341 (while news | |
1342 (setq scores news | |
1343 news nil) | |
1344 (when (and gnus-summary-default-score | |
1345 scores) | |
1346 (let* ((entries gnus-header-index) | |
1347 (now (gnus-day-number (current-time-string))) | |
1348 (expire (and gnus-score-expiry-days | |
1349 (- now gnus-score-expiry-days))) | |
1350 (headers gnus-newsgroup-headers) | |
1351 (current-score-file gnus-current-score-file) | |
1352 entry header new) | |
1353 (gnus-message 5 "Scoring...") | |
1354 ;; Create articles, an alist of the form `(HEADER . SCORE)'. | |
1355 (while (setq header (pop headers)) | |
1356 ;; WARNING: The assq makes the function O(N*S) while it could | |
1357 ;; be written as O(N+S), where N is (length gnus-newsgroup-headers) | |
1358 ;; and S is (length gnus-newsgroup-scored). | |
1359 (unless (assq (mail-header-number header) gnus-newsgroup-scored) | |
1360 (setq gnus-scores-articles ;Total of 2 * N cons-cells used. | |
1361 (cons (cons header (or gnus-summary-default-score 0)) | |
1362 gnus-scores-articles)))) | |
1363 | |
1364 (save-excursion | |
1365 (set-buffer (get-buffer-create "*Headers*")) | |
1366 (buffer-disable-undo (current-buffer)) | |
1367 | |
1368 ;; Set the global variant of this variable. | |
1369 (setq gnus-current-score-file current-score-file) | |
1370 ;; score orphans | |
1371 (when gnus-orphan-score | |
1372 (setq gnus-score-index | |
1373 (nth 1 (assoc "references" gnus-header-index))) | |
1374 (gnus-score-orphans gnus-orphan-score)) | |
1375 ;; Run each header through the score process. | |
1376 (while entries | |
1377 (setq entry (pop entries) | |
1378 header (nth 0 entry) | |
1379 gnus-score-index (nth 1 (assoc header gnus-header-index))) | |
1380 (when (< 0 (apply 'max (mapcar | |
1381 (lambda (score) | |
1382 (length (gnus-score-get header score))) | |
1383 scores))) | |
1384 ;; Call the scoring function for this type of "header". | |
1385 (when (setq new (funcall (nth 2 entry) scores header | |
1386 now expire trace)) | |
1387 (push new news)))) | |
1388 ;; Remove the buffer. | |
1389 (kill-buffer (current-buffer))) | |
1390 | |
1391 ;; Add articles to `gnus-newsgroup-scored'. | |
1392 (while gnus-scores-articles | |
1393 (when (or (/= gnus-summary-default-score | |
1394 (cdar gnus-scores-articles)) | |
1395 gnus-save-score) | |
1396 (push (cons (mail-header-number (caar gnus-scores-articles)) | |
1397 (cdar gnus-scores-articles)) | |
1398 gnus-newsgroup-scored)) | |
1399 (setq gnus-scores-articles (cdr gnus-scores-articles))) | |
1400 | |
1401 (let (score) | |
1402 (while (setq score (pop scores)) | |
1403 (while score | |
1404 (when (listp (caar score)) | |
1405 (gnus-score-advanced (car score) trace)) | |
1406 (pop score)))) | |
1407 | |
1408 (gnus-message 5 "Scoring...done")))))) | |
1409 | |
1410 | |
1411 (defun gnus-get-new-thread-ids (articles) | |
1412 (let ((index (nth 1 (assoc "message-id" gnus-header-index))) | |
1413 (refind gnus-score-index) | |
1414 id-list art this tref) | |
1415 (while articles | |
1416 (setq art (car articles) | |
1417 this (aref (car art) index) | |
1418 tref (aref (car art) refind) | |
1419 articles (cdr articles)) | |
1420 (when (string-equal tref "") ;no references line | |
1421 (push this id-list))) | |
1422 id-list)) | |
1423 | |
1424 ;; Orphan functions written by plm@atcmp.nl (Peter Mutsaers). | |
1425 (defun gnus-score-orphans (score) | |
1426 (let ((new-thread-ids (gnus-get-new-thread-ids gnus-scores-articles)) | |
1427 alike articles art arts this last this-id) | |
1428 | |
1429 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<) | |
1430 articles gnus-scores-articles) | |
1431 | |
1432 ;;more or less the same as in gnus-score-string | |
1433 (erase-buffer) | |
1434 (while articles | |
1435 (setq art (car articles) | |
1436 this (aref (car art) gnus-score-index) | |
1437 articles (cdr articles)) | |
1438 ;;completely skip if this is empty (not a child, so not an orphan) | |
1439 (when (not (string= this "")) | |
1440 (if (equal last this) | |
1441 ;; O(N*H) cons-cells used here, where H is the number of | |
1442 ;; headers. | |
1443 (push art alike) | |
1444 (when last | |
1445 ;; Insert the line, with a text property on the | |
1446 ;; terminating newline referring to the articles with | |
1447 ;; this line. | |
1448 (insert last ?\n) | |
1449 (put-text-property (1- (point)) (point) 'articles alike)) | |
1450 (setq alike (list art) | |
1451 last this)))) | |
1452 (when last ; Bwadr, duplicate code. | |
1453 (insert last ?\n) | |
1454 (put-text-property (1- (point)) (point) 'articles alike)) | |
1455 | |
1456 ;; PLM: now delete those lines that contain an entry from new-thread-ids | |
1457 (while new-thread-ids | |
1458 (setq this-id (car new-thread-ids) | |
1459 new-thread-ids (cdr new-thread-ids)) | |
1460 (goto-char (point-min)) | |
1461 (while (search-forward this-id nil t) | |
1462 ;; found a match. remove this line | |
1463 (beginning-of-line) | |
1464 (kill-line 1))) | |
1465 | |
1466 ;; now for each line: update its articles with score by moving to | |
1467 ;; every end-of-line in the buffer and read the articles property | |
1468 (goto-char (point-min)) | |
1469 (while (eq 0 (progn | |
1470 (end-of-line) | |
1471 (setq arts (get-text-property (point) 'articles)) | |
1472 (while arts | |
1473 (setq art (car arts) | |
1474 arts (cdr arts)) | |
1475 (setcdr art (+ score (cdr art)))) | |
1476 (forward-line)))))) | |
1477 | |
1478 | |
1479 (defun gnus-score-integer (scores header now expire &optional trace) | |
1480 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index))) | |
1481 entries alist) | |
1482 | |
1483 ;; Find matches. | |
1484 (while scores | |
1485 (setq alist (car scores) | |
1486 scores (cdr scores) | |
1487 entries (assoc header alist)) | |
1488 (while (cdr entries) ;First entry is the header index. | |
1489 (let* ((rest (cdr entries)) | |
1490 (kill (car rest)) | |
1491 (match (nth 0 kill)) | |
1492 (type (or (nth 3 kill) '>)) | |
1493 (score (or (nth 1 kill) gnus-score-interactive-default-score)) | |
1494 (date (nth 2 kill)) | |
1495 (found nil) | |
1496 (match-func (if (or (eq type '>) (eq type '<) (eq type '<=) | |
1497 (eq type '>=) (eq type '=)) | |
1498 type | |
1499 (error "Illegal match type: %s" type))) | |
1500 (articles gnus-scores-articles)) | |
1501 ;; Instead of doing all the clever stuff that | |
1502 ;; `gnus-score-string' does to minimize searches and stuff, | |
1503 ;; I will assume that people generally will put so few | |
1504 ;; matches on numbers that any cleverness will take more | |
1505 ;; time than one would gain. | |
1506 (while articles | |
1507 (when (funcall match-func | |
1508 (or (aref (caar articles) gnus-score-index) 0) | |
1509 match) | |
1510 (when trace | |
1511 (push (cons (car-safe (rassq alist gnus-score-cache)) kill) | |
1512 gnus-score-trace)) | |
1513 (setq found t) | |
1514 (setcdr (car articles) (+ score (cdar articles)))) | |
1515 (setq articles (cdr articles))) | |
1516 ;; Update expire date | |
1517 (cond ((null date)) ;Permanent entry. | |
1518 ((and found gnus-update-score-entry-dates) ;Match, update date. | |
1519 (gnus-score-set 'touched '(t) alist) | |
1520 (setcar (nthcdr 2 kill) now)) | |
1521 ((and expire (< date expire)) ;Old entry, remove. | |
1522 (gnus-score-set 'touched '(t) alist) | |
1523 (setcdr entries (cdr rest)) | |
1524 (setq rest entries))) | |
1525 (setq entries rest))))) | |
1526 nil) | |
1527 | |
1528 (defun gnus-score-date (scores header now expire &optional trace) | |
1529 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index))) | |
1530 entries alist match match-func article) | |
1531 | |
1532 ;; Find matches. | |
1533 (while scores | |
1534 (setq alist (car scores) | |
1535 scores (cdr scores) | |
1536 entries (assoc header alist)) | |
1537 (while (cdr entries) ;First entry is the header index. | |
1538 (let* ((rest (cdr entries)) | |
1539 (kill (car rest)) | |
1540 (type (or (nth 3 kill) 'before)) | |
1541 (score (or (nth 1 kill) gnus-score-interactive-default-score)) | |
1542 (date (nth 2 kill)) | |
1543 (found nil) | |
1544 (articles gnus-scores-articles) | |
1545 l) | |
1546 (cond | |
1547 ((eq type 'after) | |
1548 (setq match-func 'string< | |
1549 match (gnus-date-iso8601 (nth 0 kill)))) | |
1550 ((eq type 'before) | |
1551 (setq match-func 'gnus-string> | |
1552 match (gnus-date-iso8601 (nth 0 kill)))) | |
1553 ((eq type 'at) | |
1554 (setq match-func 'string= | |
1555 match (gnus-date-iso8601 (nth 0 kill)))) | |
1556 ((eq type 'regexp) | |
1557 (setq match-func 'string-match | |
1558 match (nth 0 kill))) | |
1559 (t (error "Illegal match type: %s" type))) | |
1560 ;; Instead of doing all the clever stuff that | |
1561 ;; `gnus-score-string' does to minimize searches and stuff, | |
1562 ;; I will assume that people generally will put so few | |
1563 ;; matches on numbers that any cleverness will take more | |
1564 ;; time than one would gain. | |
1565 (while (setq article (pop articles)) | |
1566 (when (and | |
1567 (setq l (aref (car article) gnus-score-index)) | |
1568 (funcall match-func match (gnus-date-iso8601 l))) | |
1569 (when trace | |
1570 (push (cons (car-safe (rassq alist gnus-score-cache)) kill) | |
1571 gnus-score-trace)) | |
1572 (setq found t) | |
1573 (setcdr article (+ score (cdr article))))) | |
1574 ;; Update expire date | |
1575 (cond ((null date)) ;Permanent entry. | |
1576 ((and found gnus-update-score-entry-dates) ;Match, update date. | |
1577 (gnus-score-set 'touched '(t) alist) | |
1578 (setcar (nthcdr 2 kill) now)) | |
1579 ((and expire (< date expire)) ;Old entry, remove. | |
1580 (gnus-score-set 'touched '(t) alist) | |
1581 (setcdr entries (cdr rest)) | |
1582 (setq rest entries))) | |
1583 (setq entries rest))))) | |
1584 nil) | |
1585 | |
1586 (defun gnus-score-body (scores header now expire &optional trace) | |
1587 (save-excursion | |
1588 (setq gnus-scores-articles | |
1589 (sort gnus-scores-articles | |
1590 (lambda (a1 a2) | |
1591 (< (mail-header-number (car a1)) | |
1592 (mail-header-number (car a2)))))) | |
1593 (set-buffer nntp-server-buffer) | |
1594 (save-restriction | |
1595 (let* ((buffer-read-only nil) | |
1596 (articles gnus-scores-articles) | |
1597 (all-scores scores) | |
1598 (request-func (cond ((string= "head" header) | |
1599 'gnus-request-head) | |
1600 ((string= "body" header) | |
1601 'gnus-request-body) | |
1602 (t 'gnus-request-article))) | |
1603 entries alist ofunc article last) | |
1604 (when articles | |
1605 (setq last (mail-header-number (caar (last articles)))) | |
1606 ;; Not all backends support partial fetching. In that case, | |
1607 ;; we just fetch the entire article. | |
1608 (unless (gnus-check-backend-function | |
1609 (and (string-match "^gnus-" (symbol-name request-func)) | |
1610 (intern (substring (symbol-name request-func) | |
1611 (match-end 0)))) | |
1612 gnus-newsgroup-name) | |
1613 (setq ofunc request-func) | |
1614 (setq request-func 'gnus-request-article)) | |
1615 (while articles | |
1616 (setq article (mail-header-number (caar articles))) | |
1617 (gnus-message 7 "Scoring on article %s of %s..." article last) | |
1618 (when (funcall request-func article gnus-newsgroup-name) | |
1619 (widen) | |
1620 (goto-char (point-min)) | |
1621 ;; If just parts of the article is to be searched, but the | |
1622 ;; backend didn't support partial fetching, we just narrow | |
1623 ;; to the relevant parts. | |
1624 (when ofunc | |
1625 (if (eq ofunc 'gnus-request-head) | |
1626 (narrow-to-region | |
1627 (point) | |
1628 (or (search-forward "\n\n" nil t) (point-max))) | |
1629 (narrow-to-region | |
1630 (or (search-forward "\n\n" nil t) (point)) | |
1631 (point-max)))) | |
1632 (setq scores all-scores) | |
1633 ;; Find matches. | |
1634 (while scores | |
1635 (setq alist (pop scores) | |
1636 entries (assoc header alist)) | |
1637 (while (cdr entries) ;First entry is the header index. | |
1638 (let* ((rest (cdr entries)) | |
1639 (kill (car rest)) | |
1640 (match (nth 0 kill)) | |
1641 (type (or (nth 3 kill) 's)) | |
1642 (score (or (nth 1 kill) | |
1643 gnus-score-interactive-default-score)) | |
1644 (date (nth 2 kill)) | |
1645 (found nil) | |
1646 (case-fold-search | |
1647 (not (or (eq type 'R) (eq type 'S) | |
1648 (eq type 'Regexp) (eq type 'String)))) | |
1649 (search-func | |
1650 (cond ((or (eq type 'r) (eq type 'R) | |
1651 (eq type 'regexp) (eq type 'Regexp)) | |
1652 're-search-forward) | |
1653 ((or (eq type 's) (eq type 'S) | |
1654 (eq type 'string) (eq type 'String)) | |
1655 'search-forward) | |
1656 (t | |
1657 (error "Illegal match type: %s" type))))) | |
1658 (goto-char (point-min)) | |
1659 (when (funcall search-func match nil t) | |
1660 ;; Found a match, update scores. | |
1661 (setcdr (car articles) (+ score (cdar articles))) | |
1662 (setq found t) | |
1663 (when trace | |
1664 (push | |
1665 (cons (car-safe (rassq alist gnus-score-cache)) kill) | |
1666 gnus-score-trace))) | |
1667 ;; Update expire date | |
1668 (unless trace | |
1669 (cond | |
1670 ((null date)) ;Permanent entry. | |
1671 ((and found gnus-update-score-entry-dates) | |
1672 ;; Match, update date. | |
1673 (gnus-score-set 'touched '(t) alist) | |
1674 (setcar (nthcdr 2 kill) now)) | |
1675 ((and expire (< date expire)) ;Old entry, remove. | |
1676 (gnus-score-set 'touched '(t) alist) | |
1677 (setcdr entries (cdr rest)) | |
1678 (setq rest entries)))) | |
1679 (setq entries rest))))) | |
1680 (setq articles (cdr articles))))))) | |
1681 nil) | |
1682 | |
1683 (defun gnus-score-thread (scores header now expire &optional trace) | |
1684 (gnus-score-followup scores header now expire trace t)) | |
1685 | |
1686 (defun gnus-score-followup (scores header now expire &optional trace thread) | |
1687 ;; Insert the unique article headers in the buffer. | |
1688 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index))) | |
1689 (current-score-file gnus-current-score-file) | |
1690 (all-scores scores) | |
1691 ;; gnus-score-index is used as a free variable. | |
1692 alike last this art entries alist articles | |
1693 new news) | |
1694 | |
1695 ;; Change score file to the adaptive score file. All entries that | |
1696 ;; this function makes will be put into this file. | |
1697 (save-excursion | |
1698 (set-buffer gnus-summary-buffer) | |
1699 (gnus-score-load-file | |
1700 (or gnus-newsgroup-adaptive-score-file | |
1701 (gnus-score-file-name | |
1702 gnus-newsgroup-name gnus-adaptive-file-suffix)))) | |
1703 | |
1704 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<) | |
1705 articles gnus-scores-articles) | |
1706 | |
1707 (erase-buffer) | |
1708 (while articles | |
1709 (setq art (car articles) | |
1710 this (aref (car art) gnus-score-index) | |
1711 articles (cdr articles)) | |
1712 (if (equal last this) | |
1713 (push art alike) | |
1714 (when last | |
1715 (insert last ?\n) | |
1716 (put-text-property (1- (point)) (point) 'articles alike)) | |
1717 (setq alike (list art) | |
1718 last this))) | |
1719 (when last ; Bwadr, duplicate code. | |
1720 (insert last ?\n) | |
1721 (put-text-property (1- (point)) (point) 'articles alike)) | |
1722 | |
1723 ;; Find matches. | |
1724 (while scores | |
1725 (setq alist (car scores) | |
1726 scores (cdr scores) | |
1727 entries (assoc header alist)) | |
1728 (while (cdr entries) ;First entry is the header index. | |
1729 (let* ((rest (cdr entries)) | |
1730 (kill (car rest)) | |
1731 (match (nth 0 kill)) | |
1732 (type (or (nth 3 kill) 's)) | |
1733 (score (or (nth 1 kill) gnus-score-interactive-default-score)) | |
1734 (date (nth 2 kill)) | |
1735 (found nil) | |
1736 (mt (aref (symbol-name type) 0)) | |
1737 (case-fold-search | |
1738 (not (or (= mt ?R) (= mt ?S) (= mt ?E) (= mt ?F)))) | |
1739 (dmt (downcase mt)) | |
1740 (search-func | |
1741 (cond ((= dmt ?r) 're-search-forward) | |
1742 ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward) | |
1743 (t (error "Illegal match type: %s" type)))) | |
1744 arts art) | |
1745 (goto-char (point-min)) | |
1746 (if (= dmt ?e) | |
1747 (while (funcall search-func match nil t) | |
1748 (and (= (progn (beginning-of-line) (point)) | |
1749 (match-beginning 0)) | |
1750 (= (progn (end-of-line) (point)) | |
1751 (match-end 0)) | |
1752 (progn | |
1753 (setq found (setq arts (get-text-property | |
1754 (point) 'articles))) | |
1755 ;; Found a match, update scores. | |
1756 (while arts | |
1757 (setq art (car arts) | |
1758 arts (cdr arts)) | |
1759 (gnus-score-add-followups | |
1760 (car art) score all-scores thread)))) | |
1761 (end-of-line)) | |
1762 (while (funcall search-func match nil t) | |
1763 (end-of-line) | |
1764 (setq found (setq arts (get-text-property (point) 'articles))) | |
1765 ;; Found a match, update scores. | |
1766 (while (setq art (pop arts)) | |
1767 (when (setq new (gnus-score-add-followups | |
1768 (car art) score all-scores thread)) | |
1769 (push new news))))) | |
1770 ;; Update expire date | |
1771 (cond ((null date)) ;Permanent entry. | |
1772 ((and found gnus-update-score-entry-dates) ;Match, update date. | |
1773 (gnus-score-set 'touched '(t) alist) | |
1774 (setcar (nthcdr 2 kill) now)) | |
1775 ((and expire (< date expire)) ;Old entry, remove. | |
1776 (gnus-score-set 'touched '(t) alist) | |
1777 (setcdr entries (cdr rest)) | |
1778 (setq rest entries))) | |
1779 (setq entries rest)))) | |
1780 ;; We change the score file back to the previous one. | |
1781 (save-excursion | |
1782 (set-buffer gnus-summary-buffer) | |
1783 (gnus-score-load-file current-score-file)) | |
1784 (list (cons "references" news)))) | |
1785 | |
1786 (defun gnus-score-add-followups (header score scores &optional thread) | |
1787 "Add a score entry to the adapt file." | |
1788 (save-excursion | |
1789 (set-buffer gnus-summary-buffer) | |
1790 (let* ((id (mail-header-id header)) | |
1791 (scores (car scores)) | |
1792 entry dont) | |
1793 ;; Don't enter a score if there already is one. | |
1794 (while (setq entry (pop scores)) | |
1795 (and (equal "references" (car entry)) | |
1796 (or (null (nth 3 (cadr entry))) | |
1797 (eq 's (nth 3 (cadr entry)))) | |
1798 (assoc id entry) | |
1799 (setq dont t))) | |
1800 (unless dont | |
1801 (gnus-summary-score-entry | |
1802 (if thread "thread" "references") | |
1803 id 's score (current-time-string) nil t))))) | |
1804 | |
1805 (defun gnus-score-string (score-list header now expire &optional trace) | |
1806 ;; Score ARTICLES according to HEADER in SCORE-LIST. | |
1807 ;; Update matching entries to NOW and remove unmatched entries older | |
1808 ;; than EXPIRE. | |
1809 | |
1810 ;; Insert the unique article headers in the buffer. | |
1811 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index))) | |
1812 ;; gnus-score-index is used as a free variable. | |
1813 alike last this art entries alist articles | |
1814 fuzzies arts words kill) | |
1815 | |
1816 ;; Sorting the articles costs os O(N*log N) but will allow us to | |
1817 ;; only match with each unique header. Thus the actual matching | |
1818 ;; will be O(M*U) where M is the number of strings to match with, | |
1819 ;; and U is the number of unique headers. It is assumed (but | |
1820 ;; untested) this will be a net win because of the large constant | |
1821 ;; factor involved with string matching. | |
1822 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<) | |
1823 articles gnus-scores-articles) | |
1824 | |
1825 (erase-buffer) | |
1826 (while (setq art (pop articles)) | |
1827 (setq this (aref (car art) gnus-score-index)) | |
1828 (if (equal last this) | |
1829 ;; O(N*H) cons-cells used here, where H is the number of | |
1830 ;; headers. | |
1831 (push art alike) | |
1832 (when last | |
1833 ;; Insert the line, with a text property on the | |
1834 ;; terminating newline referring to the articles with | |
1835 ;; this line. | |
1836 (insert last ?\n) | |
1837 (put-text-property (1- (point)) (point) 'articles alike)) | |
1838 (setq alike (list art) | |
1839 last this))) | |
1840 (when last ; Bwadr, duplicate code. | |
1841 (insert last ?\n) | |
1842 (put-text-property (1- (point)) (point) 'articles alike)) | |
1843 | |
1844 ;; Go through all the score alists and pick out the entries | |
1845 ;; for this header. | |
1846 (while score-list | |
1847 (setq alist (pop score-list) | |
1848 ;; There's only one instance of this header for | |
1849 ;; each score alist. | |
1850 entries (assoc header alist)) | |
1851 (while (cdr entries) ;First entry is the header index. | |
1852 (let* ((kill (cadr entries)) | |
1853 (match (nth 0 kill)) | |
1854 (type (or (nth 3 kill) 's)) | |
1855 (score (or (nth 1 kill) gnus-score-interactive-default-score)) | |
1856 (date (nth 2 kill)) | |
1857 (found nil) | |
1858 (mt (aref (symbol-name type) 0)) | |
1859 (case-fold-search (not (memq mt '(?R ?S ?E ?F)))) | |
1860 (dmt (downcase mt)) | |
1861 (search-func | |
1862 (cond ((= dmt ?r) 're-search-forward) | |
1863 ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward) | |
1864 ((= dmt ?w) nil) | |
1865 (t (error "Illegal match type: %s" type))))) | |
1866 (cond | |
1867 ;; Fuzzy matches. We save these for later. | |
1868 ((= dmt ?f) | |
1869 (push (cons entries alist) fuzzies)) | |
1870 ;; Word matches. Save these for even later. | |
1871 ((= dmt ?w) | |
1872 (push (cons entries alist) words)) | |
1873 ;; Exact matches. | |
1874 ((= dmt ?e) | |
1875 ;; Do exact matching. | |
1876 (goto-char (point-min)) | |
1877 (while (and (not (eobp)) | |
1878 (funcall search-func match nil t)) | |
1879 ;; Is it really exact? | |
1880 (and (eolp) | |
1881 (= (gnus-point-at-bol) (match-beginning 0)) | |
1882 ;; Yup. | |
1883 (progn | |
1884 (setq found (setq arts (get-text-property | |
1885 (point) 'articles))) | |
1886 ;; Found a match, update scores. | |
1887 (if trace | |
1888 (while (setq art (pop arts)) | |
1889 (setcdr art (+ score (cdr art))) | |
1890 (push | |
1891 (cons | |
1892 (car-safe (rassq alist gnus-score-cache)) | |
1893 kill) | |
1894 gnus-score-trace)) | |
1895 (while (setq art (pop arts)) | |
1896 (setcdr art (+ score (cdr art))))))) | |
1897 (forward-line 1))) | |
1898 ;; Regexp and substring matching. | |
1899 (t | |
1900 (goto-char (point-min)) | |
1901 (when (string= match "") | |
1902 (setq match "\n")) | |
1903 (while (and (not (eobp)) | |
1904 (funcall search-func match nil t)) | |
1905 (goto-char (match-beginning 0)) | |
1906 (end-of-line) | |
1907 (setq found (setq arts (get-text-property (point) 'articles))) | |
1908 ;; Found a match, update scores. | |
1909 (if trace | |
1910 (while (setq art (pop arts)) | |
1911 (setcdr art (+ score (cdr art))) | |
1912 (push (cons (car-safe (rassq alist gnus-score-cache)) kill) | |
1913 gnus-score-trace)) | |
1914 (while (setq art (pop arts)) | |
1915 (setcdr art (+ score (cdr art))))) | |
1916 (forward-line 1)))) | |
1917 ;; Update expiry date | |
1918 (if trace | |
1919 (setq entries (cdr entries)) | |
1920 (cond | |
1921 ;; Permanent entry. | |
1922 ((null date) | |
1923 (setq entries (cdr entries))) | |
1924 ;; We have a match, so we update the date. | |
1925 ((and found gnus-update-score-entry-dates) | |
1926 (gnus-score-set 'touched '(t) alist) | |
1927 (setcar (nthcdr 2 kill) now) | |
1928 (setq entries (cdr entries))) | |
1929 ;; This entry has expired, so we remove it. | |
1930 ((and expire (< date expire)) | |
1931 (gnus-score-set 'touched '(t) alist) | |
1932 (setcdr entries (cddr entries))) | |
1933 ;; No match; go to next entry. | |
1934 (t | |
1935 (setq entries (cdr entries)))))))) | |
1936 | |
1937 ;; Find fuzzy matches. | |
1938 (when fuzzies | |
1939 ;; Simplify the entire buffer for easy matching. | |
1940 (gnus-simplify-buffer-fuzzy) | |
1941 (while (setq kill (cadaar fuzzies)) | |
1942 (let* ((match (nth 0 kill)) | |
1943 (type (nth 3 kill)) | |
1944 (score (or (nth 1 kill) gnus-score-interactive-default-score)) | |
1945 (date (nth 2 kill)) | |
1946 (mt (aref (symbol-name type) 0)) | |
1947 (case-fold-search (not (= mt ?F))) | |
1948 found) | |
1949 (goto-char (point-min)) | |
1950 (while (and (not (eobp)) | |
1951 (search-forward match nil t)) | |
1952 (when (and (= (gnus-point-at-bol) (match-beginning 0)) | |
1953 (eolp)) | |
1954 (setq found (setq arts (get-text-property (point) 'articles))) | |
1955 (if trace | |
1956 (while (setq art (pop arts)) | |
1957 (setcdr art (+ score (cdr art))) | |
1958 (push (cons | |
1959 (car-safe (rassq (cdar fuzzies) gnus-score-cache)) | |
1960 kill) | |
1961 gnus-score-trace)) | |
1962 ;; Found a match, update scores. | |
1963 (while (setq art (pop arts)) | |
1964 (setcdr art (+ score (cdr art)))))) | |
1965 (forward-line 1)) | |
1966 ;; Update expiry date | |
1967 (cond | |
1968 ;; Permanent. | |
1969 ((null date) | |
1970 ) | |
1971 ;; Match, update date. | |
1972 ((and found gnus-update-score-entry-dates) | |
1973 (gnus-score-set 'touched '(t) (cdar fuzzies)) | |
1974 (setcar (nthcdr 2 kill) now)) | |
1975 ;; Old entry, remove. | |
1976 ((and expire (< date expire)) | |
1977 (gnus-score-set 'touched '(t) (cdar fuzzies)) | |
1978 (setcdr (caar fuzzies) (cddaar fuzzies)))) | |
1979 (setq fuzzies (cdr fuzzies))))) | |
1980 | |
1981 (when words | |
1982 ;; Enter all words into the hashtb. | |
1983 (let ((hashtb (gnus-make-hashtable | |
1984 (* 10 (count-lines (point-min) (point-max)))))) | |
1985 (gnus-enter-score-words-into-hashtb hashtb) | |
1986 (while (setq kill (cadaar words)) | |
1987 (let* ((score (or (nth 1 kill) gnus-score-interactive-default-score)) | |
1988 (date (nth 2 kill)) | |
1989 found) | |
1990 (when (setq arts (intern-soft (nth 0 kill) hashtb)) | |
1991 (setq arts (symbol-value arts)) | |
1992 (setq found t) | |
1993 (if trace | |
1994 (while (setq art (pop arts)) | |
1995 (setcdr art (+ score (cdr art))) | |
1996 (push (cons | |
1997 (car-safe (rassq (cdar words) gnus-score-cache)) | |
1998 kill) | |
1999 gnus-score-trace)) | |
2000 ;; Found a match, update scores. | |
2001 (while (setq art (pop arts)) | |
2002 (setcdr art (+ score (cdr art)))))) | |
2003 ;; Update expiry date | |
2004 (cond | |
2005 ;; Permanent. | |
2006 ((null date) | |
2007 ) | |
2008 ;; Match, update date. | |
2009 ((and found gnus-update-score-entry-dates) | |
2010 (gnus-score-set 'touched '(t) (cdar words)) | |
2011 (setcar (nthcdr 2 kill) now)) | |
2012 ;; Old entry, remove. | |
2013 ((and expire (< date expire)) | |
2014 (gnus-score-set 'touched '(t) (cdar words)) | |
2015 (setcdr (caar words) (cddaar words)))) | |
2016 (setq words (cdr words)))))) | |
2017 nil)) | |
2018 | |
2019 (defun gnus-enter-score-words-into-hashtb (hashtb) | |
2020 ;; Find all the words in the buffer and enter them into | |
2021 ;; the hashtable. | |
2022 (let ((syntab (syntax-table)) | |
2023 word val) | |
2024 (goto-char (point-min)) | |
2025 (unwind-protect | |
2026 (progn | |
2027 (set-syntax-table gnus-adaptive-word-syntax-table) | |
2028 (while (re-search-forward "\\b\\w+\\b" nil t) | |
2029 (setq val | |
2030 (gnus-gethash | |
2031 (setq word (downcase (buffer-substring | |
2032 (match-beginning 0) (match-end 0)))) | |
2033 hashtb)) | |
2034 (gnus-sethash | |
2035 word | |
2036 (append (get-text-property (gnus-point-at-eol) 'articles) val) | |
2037 hashtb))) | |
2038 (set-syntax-table syntab)) | |
2039 ;; Make all the ignorable words ignored. | |
2040 (let ((ignored (append gnus-ignored-adaptive-words | |
2041 gnus-default-ignored-adaptive-words))) | |
2042 (while ignored | |
2043 (gnus-sethash (pop ignored) nil hashtb))))) | |
2044 | |
2045 (defun gnus-score-string< (a1 a2) | |
2046 ;; Compare headers in articles A2 and A2. | |
2047 ;; The header index used is the free variable `gnus-score-index'. | |
2048 (string-lessp (aref (car a1) gnus-score-index) | |
2049 (aref (car a2) gnus-score-index))) | |
2050 | |
2051 (defun gnus-current-score-file-nondirectory (&optional score-file) | |
2052 (let ((score-file (or score-file gnus-current-score-file))) | |
2053 (if score-file | |
2054 (gnus-short-group-name (file-name-nondirectory score-file)) | |
2055 "none"))) | |
2056 | |
2057 (defun gnus-score-adaptive () | |
2058 "Create adaptive score rules for this newsgroup." | |
2059 (when gnus-newsgroup-adaptive | |
2060 ;; We change the score file to the adaptive score file. | |
2061 (save-excursion | |
2062 (set-buffer gnus-summary-buffer) | |
2063 (gnus-score-load-file | |
2064 (or gnus-newsgroup-adaptive-score-file | |
2065 (gnus-score-file-name | |
2066 gnus-newsgroup-name gnus-adaptive-file-suffix)))) | |
2067 ;; Perform ordinary line scoring. | |
2068 (when (or (not (listp gnus-newsgroup-adaptive)) | |
2069 (memq 'line gnus-newsgroup-adaptive)) | |
2070 (save-excursion | |
2071 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist)) | |
2072 (alist malist) | |
2073 (date (current-time-string)) | |
2074 (data gnus-newsgroup-data) | |
2075 elem headers match) | |
2076 ;; First we transform the adaptive rule alist into something | |
2077 ;; that's faster to process. | |
2078 (while malist | |
2079 (setq elem (car malist)) | |
2080 (when (symbolp (car elem)) | |
2081 (setcar elem (symbol-value (car elem)))) | |
2082 (setq elem (cdr elem)) | |
2083 (while elem | |
2084 (setcdr (car elem) | |
2085 (cons (if (eq (caar elem) 'followup) | |
2086 "references" | |
2087 (symbol-name (caar elem))) | |
2088 (cdar elem))) | |
2089 (setcar (car elem) | |
2090 `(lambda (h) | |
2091 (,(intern | |
2092 (concat "mail-header-" | |
2093 (if (eq (caar elem) 'followup) | |
2094 "message-id" | |
2095 (downcase (symbol-name (caar elem)))))) | |
2096 h))) | |
2097 (setq elem (cdr elem))) | |
2098 (setq malist (cdr malist))) | |
2099 ;; Then we score away. | |
2100 (while data | |
2101 (setq elem (cdr (assq (gnus-data-mark (car data)) alist))) | |
2102 (if (or (not elem) | |
2103 (gnus-data-pseudo-p (car data))) | |
2104 () | |
2105 (when (setq headers (gnus-data-header (car data))) | |
2106 (while elem | |
2107 (setq match (funcall (caar elem) headers)) | |
2108 (gnus-summary-score-entry | |
2109 (nth 1 (car elem)) match | |
2110 (cond | |
2111 ((numberp match) | |
2112 '=) | |
2113 ((equal (nth 1 (car elem)) "date") | |
2114 'a) | |
2115 (t | |
2116 ;; Whether we use substring or exact matches is | |
2117 ;; controlled here. | |
2118 (if (or (not gnus-score-exact-adapt-limit) | |
2119 (< (length match) gnus-score-exact-adapt-limit)) | |
2120 'e | |
2121 (if (equal (nth 1 (car elem)) "subject") | |
2122 'f 's)))) | |
2123 (nth 2 (car elem)) date nil t) | |
2124 (setq elem (cdr elem))))) | |
2125 (setq data (cdr data)))))) | |
2126 | |
2127 ;; Perform adaptive word scoring. | |
2128 (when (and (listp gnus-newsgroup-adaptive) | |
2129 (memq 'word gnus-newsgroup-adaptive)) | |
2130 (nnheader-temp-write nil | |
2131 (let* ((hashtb (gnus-make-hashtable 1000)) | |
2132 (date (gnus-day-number (current-time-string))) | |
2133 (data gnus-newsgroup-data) | |
2134 (syntab (syntax-table)) | |
2135 word d score val) | |
2136 (unwind-protect | |
2137 (progn | |
2138 (set-syntax-table gnus-adaptive-word-syntax-table) | |
2139 ;; Go through all articles. | |
2140 (while (setq d (pop data)) | |
2141 (when (and | |
2142 (not (gnus-data-pseudo-p d)) | |
2143 (setq score | |
2144 (cdr (assq | |
2145 (gnus-data-mark d) | |
2146 gnus-adaptive-word-score-alist)))) | |
2147 ;; This article has a mark that should lead to | |
2148 ;; adaptive word rules, so we insert the subject | |
2149 ;; and find all words in that string. | |
2150 (insert (mail-header-subject (gnus-data-header d))) | |
2151 (downcase-region (point-min) (point-max)) | |
2152 (goto-char (point-min)) | |
2153 (while (re-search-forward "\\b\\w+\\b" nil t) | |
2154 ;; Put the word and score into the hashtb. | |
2155 (setq val (gnus-gethash (setq word (match-string 0)) | |
2156 hashtb)) | |
2157 (gnus-sethash word (+ (or val 0) score) hashtb)) | |
2158 (erase-buffer)))) | |
2159 (set-syntax-table syntab)) | |
2160 ;; Make all the ignorable words ignored. | |
2161 (let ((ignored (append gnus-ignored-adaptive-words | |
2162 gnus-default-ignored-adaptive-words))) | |
2163 (while ignored | |
2164 (gnus-sethash (pop ignored) nil hashtb))) | |
2165 ;; Now we have all the words and scores, so we | |
2166 ;; add these rules to the ADAPT file. | |
2167 (set-buffer gnus-summary-buffer) | |
2168 (mapatoms | |
2169 (lambda (word) | |
2170 (when (symbol-value word) | |
2171 (gnus-summary-score-entry | |
2172 "subject" (symbol-name word) 'w (symbol-value word) | |
2173 date nil t))) | |
2174 hashtb)))))) | |
2175 | |
2176 (defun gnus-score-edit-done () | |
2177 (let ((bufnam (buffer-file-name (current-buffer))) | |
2178 (winconf gnus-prev-winconf)) | |
2179 (when winconf | |
2180 (set-window-configuration winconf)) | |
2181 (gnus-score-remove-from-cache bufnam) | |
2182 (gnus-score-load-file bufnam))) | |
2183 | |
2184 (defun gnus-score-find-trace () | |
2185 "Find all score rules that applies to the current article." | |
2186 (interactive) | |
2187 (let ((old-scored gnus-newsgroup-scored)) | |
2188 (let ((gnus-newsgroup-headers | |
2189 (list (gnus-summary-article-header))) | |
2190 (gnus-newsgroup-scored nil) | |
2191 trace) | |
2192 (save-excursion | |
2193 (nnheader-set-temp-buffer "*Score Trace*")) | |
2194 (setq gnus-score-trace nil) | |
2195 (gnus-possibly-score-headers 'trace) | |
2196 (if (not (setq trace gnus-score-trace)) | |
2197 (gnus-error | |
2198 1 "No score rules apply to the current article (default score %d)." | |
2199 gnus-summary-default-score) | |
2200 (set-buffer "*Score Trace*") | |
2201 (gnus-add-current-to-buffer-list) | |
2202 (while trace | |
2203 (insert (format "%S -> %s\n" (cdar trace) | |
2204 (file-name-nondirectory (caar trace)))) | |
2205 (setq trace (cdr trace))) | |
2206 (goto-char (point-min)) | |
2207 (gnus-configure-windows 'score-trace))) | |
2208 (set-buffer gnus-summary-buffer) | |
2209 (setq gnus-newsgroup-scored old-scored))) | |
2210 | |
2211 (defun gnus-score-find-favourite-words () | |
2212 "List words used in scoring." | |
2213 (interactive) | |
2214 (let ((alists (gnus-score-load-files (gnus-all-score-files))) | |
2215 alist rule rules kill) | |
2216 ;; Go through all the score alists for this group | |
2217 ;; and find all `w' rules. | |
2218 (while (setq alist (pop alists)) | |
2219 (while (setq rule (pop alist)) | |
2220 (when (and (stringp (car rule)) | |
2221 (equal "subject" (downcase (pop rule)))) | |
2222 (while (setq kill (pop rule)) | |
2223 (when (memq (nth 3 kill) '(w W word Word)) | |
2224 (push (cons (or (nth 1 kill) | |
2225 gnus-score-interactive-default-score) | |
2226 (car kill)) | |
2227 rules)))))) | |
2228 (setq rules (sort rules (lambda (r1 r2) | |
2229 (string-lessp (cdr r1) (cdr r2))))) | |
2230 ;; Add up words that have appeared several times. | |
2231 (let ((r rules)) | |
2232 (while (cdr r) | |
2233 (if (equal (cdar r) (cdadr r)) | |
2234 (progn | |
2235 (setcar (car r) (+ (caar r) (caadr r))) | |
2236 (setcdr r (cddr r))) | |
2237 (pop r)))) | |
2238 ;; Insert the words. | |
2239 (nnheader-set-temp-buffer "*Score Words*") | |
2240 (if (not (setq rules (sort rules (lambda (r1 r2) (> (car r1) (car r2)))))) | |
2241 (gnus-error 3 "No word score rules") | |
2242 (while rules | |
2243 (insert (format "%-5d: %s\n" (caar rules) (cdar rules))) | |
2244 (pop rules)) | |
2245 (gnus-add-current-to-buffer-list) | |
2246 (goto-char (point-min)) | |
2247 (gnus-configure-windows 'score-words)))) | |
2248 | |
2249 (defun gnus-summary-rescore () | |
2250 "Redo the entire scoring process in the current summary." | |
2251 (interactive) | |
2252 (gnus-score-save) | |
2253 (setq gnus-score-cache nil) | |
2254 (setq gnus-newsgroup-scored nil) | |
2255 (gnus-possibly-score-headers) | |
2256 (gnus-score-update-all-lines)) | |
2257 | |
2258 (defun gnus-score-flush-cache () | |
2259 "Flush the cache of score files." | |
2260 (interactive) | |
2261 (gnus-score-save) | |
2262 (setq gnus-score-cache nil | |
2263 gnus-score-alist nil | |
2264 gnus-short-name-score-file-cache nil) | |
2265 (gnus-message 6 "The score cache is now flushed")) | |
2266 | |
2267 (gnus-add-shutdown 'gnus-score-close 'gnus) | |
2268 | |
2269 (defvar gnus-score-file-alist-cache nil) | |
2270 | |
2271 (defun gnus-score-close () | |
2272 "Clear all internal score variables." | |
2273 (setq gnus-score-cache nil | |
2274 gnus-internal-global-score-files nil | |
2275 gnus-score-file-list nil | |
2276 gnus-score-file-alist-cache nil)) | |
2277 | |
2278 ;; Summary score marking commands. | |
2279 | |
2280 (defun gnus-summary-raise-same-subject-and-select (score) | |
2281 "Raise articles which has the same subject with SCORE and select the next." | |
2282 (interactive "p") | |
2283 (let ((subject (gnus-summary-article-subject))) | |
2284 (gnus-summary-raise-score score) | |
2285 (while (gnus-summary-find-subject subject) | |
2286 (gnus-summary-raise-score score)) | |
2287 (gnus-summary-next-article t))) | |
2288 | |
2289 (defun gnus-summary-raise-same-subject (score) | |
2290 "Raise articles which has the same subject with SCORE." | |
2291 (interactive "p") | |
2292 (let ((subject (gnus-summary-article-subject))) | |
2293 (gnus-summary-raise-score score) | |
2294 (while (gnus-summary-find-subject subject) | |
2295 (gnus-summary-raise-score score)) | |
2296 (gnus-summary-next-subject 1 t))) | |
2297 | |
2298 (defun gnus-score-default (level) | |
2299 (if level (prefix-numeric-value level) | |
2300 gnus-score-interactive-default-score)) | |
2301 | |
2302 (defun gnus-summary-raise-thread (&optional score) | |
2303 "Raise the score of the articles in the current thread with SCORE." | |
2304 (interactive "P") | |
2305 (setq score (gnus-score-default score)) | |
2306 (let (e) | |
2307 (save-excursion | |
2308 (let ((articles (gnus-summary-articles-in-thread))) | |
2309 (while articles | |
2310 (gnus-summary-goto-subject (car articles)) | |
2311 (gnus-summary-raise-score score) | |
2312 (setq articles (cdr articles)))) | |
2313 (setq e (point))) | |
2314 (let ((gnus-summary-check-current t)) | |
2315 (unless (zerop (gnus-summary-next-subject 1 t)) | |
2316 (goto-char e)))) | |
2317 (gnus-summary-recenter) | |
2318 (gnus-summary-position-point) | |
2319 (gnus-set-mode-line 'summary)) | |
2320 | |
2321 (defun gnus-summary-lower-same-subject-and-select (score) | |
2322 "Raise articles which has the same subject with SCORE and select the next." | |
2323 (interactive "p") | |
2324 (gnus-summary-raise-same-subject-and-select (- score))) | |
2325 | |
2326 (defun gnus-summary-lower-same-subject (score) | |
2327 "Raise articles which has the same subject with SCORE." | |
2328 (interactive "p") | |
2329 (gnus-summary-raise-same-subject (- score))) | |
2330 | |
2331 (defun gnus-summary-lower-thread (&optional score) | |
2332 "Lower score of articles in the current thread with SCORE." | |
2333 (interactive "P") | |
2334 (gnus-summary-raise-thread (- (1- (gnus-score-default score))))) | |
2335 | |
2336 ;;; Finding score files. | |
2337 | |
2338 (defun gnus-score-score-files (group) | |
2339 "Return a list of all possible score files." | |
2340 ;; Search and set any global score files. | |
2341 (when gnus-global-score-files | |
2342 (unless gnus-internal-global-score-files | |
2343 (gnus-score-search-global-directories gnus-global-score-files))) | |
2344 ;; Fix the kill-file dir variable. | |
2345 (setq gnus-kill-files-directory | |
2346 (file-name-as-directory gnus-kill-files-directory)) | |
2347 ;; If we can't read it, there are no score files. | |
2348 (if (not (file-exists-p (expand-file-name gnus-kill-files-directory))) | |
2349 (setq gnus-score-file-list nil) | |
2350 (if (not (gnus-use-long-file-name 'not-score)) | |
2351 ;; We do not use long file names, so we have to do some | |
2352 ;; directory traversing. | |
2353 (setq gnus-score-file-list | |
2354 (cons nil | |
2355 (or gnus-short-name-score-file-cache | |
2356 (prog2 | |
2357 (gnus-message 6 "Finding all score files...") | |
2358 (setq gnus-short-name-score-file-cache | |
2359 (gnus-score-score-files-1 | |
2360 gnus-kill-files-directory)) | |
2361 (gnus-message 6 "Finding all score files...done"))))) | |
2362 ;; We want long file names. | |
2363 (when (or (not gnus-score-file-list) | |
2364 (not (car gnus-score-file-list)) | |
2365 (gnus-file-newer-than gnus-kill-files-directory | |
2366 (car gnus-score-file-list))) | |
2367 (setq gnus-score-file-list | |
2368 (cons (nth 5 (file-attributes gnus-kill-files-directory)) | |
2369 (nreverse | |
2370 (directory-files | |
2371 gnus-kill-files-directory t | |
2372 (gnus-score-file-regexp))))))) | |
2373 (cdr gnus-score-file-list))) | |
2374 | |
2375 (defun gnus-score-score-files-1 (dir) | |
2376 "Return all possible score files under DIR." | |
2377 (let ((files (list (expand-file-name dir))) | |
2378 (regexp (gnus-score-file-regexp)) | |
2379 (case-fold-search nil) | |
2380 seen out file) | |
2381 (while (setq file (pop files)) | |
2382 (cond | |
2383 ;; Ignore "." and "..". | |
2384 ((member (file-name-nondirectory file) '("." "..")) | |
2385 nil) | |
2386 ;; Add subtrees of directory to also be searched. | |
2387 ((and (file-directory-p file) | |
2388 (not (member (file-truename file) seen))) | |
2389 (push (file-truename file) seen) | |
2390 (setq files (nconc (directory-files file t nil t) files))) | |
2391 ;; Add files to the list of score files. | |
2392 ((string-match regexp file) | |
2393 (push file out)))) | |
2394 (or out | |
2395 ;; Return a dummy value. | |
2396 (list "~/News/this.file.does.not.exist.SCORE")))) | |
2397 | |
2398 (defun gnus-score-file-regexp () | |
2399 "Return a regexp that match all score files." | |
2400 (concat "\\(" (regexp-quote gnus-score-file-suffix ) | |
2401 "\\|" (regexp-quote gnus-adaptive-file-suffix) "\\)\\'")) | |
2402 | |
2403 (defun gnus-score-find-bnews (group) | |
2404 "Return a list of score files for GROUP. | |
2405 The score files are those files in the ~/News/ directory which matches | |
2406 GROUP using BNews sys file syntax." | |
2407 (let* ((sfiles (append (gnus-score-score-files group) | |
2408 gnus-internal-global-score-files)) | |
2409 (kill-dir (file-name-as-directory | |
2410 (expand-file-name gnus-kill-files-directory))) | |
2411 (klen (length kill-dir)) | |
2412 (score-regexp (gnus-score-file-regexp)) | |
2413 (trans (cdr (assq ?: nnheader-file-name-translation-alist))) | |
2414 ofiles not-match regexp) | |
2415 (save-excursion | |
2416 (set-buffer (get-buffer-create "*gnus score files*")) | |
2417 (buffer-disable-undo (current-buffer)) | |
2418 ;; Go through all score file names and create regexp with them | |
2419 ;; as the source. | |
2420 (while sfiles | |
2421 (erase-buffer) | |
2422 (insert (car sfiles)) | |
2423 (goto-char (point-min)) | |
2424 ;; First remove the suffix itself. | |
2425 (when (re-search-forward (concat "." score-regexp) nil t) | |
2426 (replace-match "" t t) | |
2427 (goto-char (point-min)) | |
2428 (if (looking-at (regexp-quote kill-dir)) | |
2429 ;; If the file name was just "SCORE", `klen' is one character | |
2430 ;; too much. | |
2431 (delete-char (min (1- (point-max)) klen)) | |
2432 (goto-char (point-max)) | |
2433 (search-backward "/") | |
2434 (delete-region (1+ (point)) (point-min))) | |
2435 ;; If short file names were used, we have to translate slashes. | |
2436 (goto-char (point-min)) | |
2437 (let ((regexp (concat | |
2438 "[/:" (if trans (char-to-string trans) "") "]"))) | |
2439 (while (re-search-forward regexp nil t) | |
2440 (replace-match "." t t))) | |
2441 ;; Kludge to get rid of "nntp+" problems. | |
2442 (goto-char (point-min)) | |
2443 (when (looking-at "nn[a-z]+\\+") | |
2444 (search-forward "+") | |
2445 (forward-char -1) | |
2446 (insert "\\") | |
2447 (forward-char 1)) | |
2448 ;; Kludge to deal with "++". | |
2449 (while (search-forward "+" nil t) | |
2450 (replace-match "\\+" t t)) | |
2451 ;; Translate "all" to ".*". | |
2452 (goto-char (point-min)) | |
2453 (while (search-forward "all" nil t) | |
2454 (replace-match ".*" t t)) | |
2455 (goto-char (point-min)) | |
2456 ;; Deal with "not."s. | |
2457 (if (looking-at "not.") | |
2458 (progn | |
2459 (setq not-match t) | |
2460 (setq regexp (concat "^" (buffer-substring 5 (point-max))))) | |
2461 (setq regexp (concat "^" (buffer-substring 1 (point-max)))) | |
2462 (setq not-match nil)) | |
2463 ;; Finally - if this resulting regexp matches the group name, | |
2464 ;; we add this score file to the list of score files | |
2465 ;; applicable to this group. | |
2466 (when (or (and not-match | |
2467 (not (string-match regexp group))) | |
2468 (and (not not-match) | |
2469 (string-match regexp group))) | |
2470 (push (car sfiles) ofiles))) | |
2471 (setq sfiles (cdr sfiles))) | |
2472 (kill-buffer (current-buffer)) | |
2473 ;; Slight kludge here - the last score file returned should be | |
2474 ;; the local score file, whether it exists or not. This is so | |
2475 ;; that any score commands the user enters will go to the right | |
2476 ;; file, and not end up in some global score file. | |
2477 (let ((localscore (gnus-score-file-name group))) | |
2478 (setq ofiles (cons localscore (delete localscore ofiles)))) | |
2479 (gnus-sort-score-files (nreverse ofiles))))) | |
2480 | |
2481 (defun gnus-score-find-single (group) | |
2482 "Return list containing the score file for GROUP." | |
2483 (list (or gnus-newsgroup-adaptive-score-file | |
2484 (gnus-score-file-name group gnus-adaptive-file-suffix)) | |
2485 (gnus-score-file-name group))) | |
2486 | |
2487 (defun gnus-score-find-hierarchical (group) | |
2488 "Return list of score files for GROUP. | |
2489 This includes the score file for the group and all its parents." | |
2490 (let* ((prefix (gnus-group-real-prefix group)) | |
2491 (all (list nil)) | |
2492 (group (gnus-group-real-name group)) | |
2493 (start 0)) | |
2494 (while (string-match "\\." group (1+ start)) | |
2495 (setq start (match-beginning 0)) | |
2496 (push (substring group 0 start) all)) | |
2497 (push group all) | |
2498 (setq all | |
2499 (nconc | |
2500 (mapcar (lambda (group) | |
2501 (gnus-score-file-name group gnus-adaptive-file-suffix)) | |
2502 (setq all (nreverse all))) | |
2503 (mapcar 'gnus-score-file-name all))) | |
2504 (if (equal prefix "") | |
2505 all | |
2506 (mapcar | |
2507 (lambda (file) | |
2508 (nnheader-translate-file-chars | |
2509 (concat (file-name-directory file) prefix | |
2510 (file-name-nondirectory file)))) | |
2511 all)))) | |
2512 | |
2513 (defun gnus-score-file-rank (file) | |
2514 "Return a number that says how specific score FILE is. | |
2515 Destroys the current buffer." | |
2516 (if (member file gnus-internal-global-score-files) | |
2517 0 | |
2518 (when (string-match | |
2519 (concat "^" (regexp-quote | |
2520 (expand-file-name | |
2521 (file-name-as-directory gnus-kill-files-directory)))) | |
2522 file) | |
2523 (setq file (substring file (match-end 0)))) | |
2524 (insert file) | |
2525 (goto-char (point-min)) | |
2526 (let ((beg (point)) | |
2527 elems) | |
2528 (while (re-search-forward "[./]" nil t) | |
2529 (push (buffer-substring beg (1- (point))) | |
2530 elems)) | |
2531 (erase-buffer) | |
2532 (setq elems (delete "all" elems)) | |
2533 (length elems)))) | |
2534 | |
2535 (defun gnus-sort-score-files (files) | |
2536 "Sort FILES so that the most general files come first." | |
2537 (nnheader-temp-write nil | |
2538 (let ((alist | |
2539 (mapcar | |
2540 (lambda (file) | |
2541 (cons (inline (gnus-score-file-rank file)) file)) | |
2542 files))) | |
2543 (mapcar | |
2544 (lambda (f) (cdr f)) | |
2545 (sort alist (lambda (f1 f2) (< (car f1) (car f2)))))))) | |
2546 | |
2547 (defun gnus-score-find-alist (group) | |
2548 "Return list of score files for GROUP. | |
2549 The list is determined from the variable gnus-score-file-alist." | |
2550 (let ((alist gnus-score-file-multiple-match-alist) | |
2551 score-files) | |
2552 ;; if this group has been seen before, return the cached entry | |
2553 (if (setq score-files (assoc group gnus-score-file-alist-cache)) | |
2554 (cdr score-files) ;ensures caching groups with no matches | |
2555 ;; handle the multiple match alist | |
2556 (while alist | |
2557 (when (string-match (caar alist) group) | |
2558 (setq score-files | |
2559 (nconc score-files (copy-sequence (cdar alist))))) | |
2560 (setq alist (cdr alist))) | |
2561 (setq alist gnus-score-file-single-match-alist) | |
2562 ;; handle the single match alist | |
2563 (while alist | |
2564 (when (string-match (caar alist) group) | |
2565 ;; progn used just in case ("regexp") has no files | |
2566 ;; and score-files is still nil. -sj | |
2567 ;; this can be construed as a "stop searching here" feature :> | |
2568 ;; and used to simplify regexps in the single-alist | |
2569 (setq score-files | |
2570 (nconc score-files (copy-sequence (cdar alist)))) | |
2571 (setq alist nil)) | |
2572 (setq alist (cdr alist))) | |
2573 ;; cache the score files | |
2574 (push (cons group score-files) gnus-score-file-alist-cache) | |
2575 score-files))) | |
2576 | |
2577 (defun gnus-all-score-files (&optional group) | |
2578 "Return a list of all score files for the current group." | |
2579 (let ((funcs gnus-score-find-score-files-function) | |
2580 (group (or group gnus-newsgroup-name)) | |
2581 score-files) | |
2582 ;; Make sure funcs is a list. | |
2583 (and funcs | |
2584 (not (listp funcs)) | |
2585 (setq funcs (list funcs))) | |
2586 ;; Get the initial score files for this group. | |
2587 (when funcs | |
2588 (setq score-files (nreverse (gnus-score-find-alist group)))) | |
2589 ;; Add any home adapt files. | |
2590 (let ((home (gnus-home-score-file group t))) | |
2591 (when home | |
2592 (push home score-files) | |
2593 (setq gnus-newsgroup-adaptive-score-file home))) | |
2594 ;; Check whether there is a `adapt-file' group parameter. | |
2595 (let ((param-file (gnus-group-find-parameter group 'adapt-file))) | |
2596 (when param-file | |
2597 (push param-file score-files) | |
2598 (setq gnus-newsgroup-adaptive-score-file param-file))) | |
2599 ;; Go through all the functions for finding score files (or actual | |
2600 ;; scores) and add them to a list. | |
2601 (while funcs | |
2602 (when (gnus-functionp (car funcs)) | |
2603 (setq score-files | |
2604 (nconc score-files (nreverse (funcall (car funcs) group))))) | |
2605 (setq funcs (cdr funcs))) | |
2606 ;; Add any home score files. | |
2607 (let ((home (gnus-home-score-file group))) | |
2608 (when home | |
2609 (push home score-files))) | |
2610 ;; Check whether there is a `score-file' group parameter. | |
2611 (let ((param-file (gnus-group-find-parameter group 'score-file))) | |
2612 (when param-file | |
2613 (push param-file score-files))) | |
2614 ;; Expand all files names. | |
2615 (let ((files score-files)) | |
2616 (while files | |
2617 (when (stringp (car files)) | |
2618 (setcar files (expand-file-name | |
2619 (car files) gnus-kill-files-directory))) | |
2620 (pop files))) | |
2621 (setq score-files (nreverse score-files)) | |
2622 ;; Remove any duplicate score files. | |
2623 (while (and score-files | |
2624 (member (car score-files) (cdr score-files))) | |
2625 (pop score-files)) | |
2626 (let ((files score-files)) | |
2627 (while (cdr files) | |
2628 (if (member (cadr files) (cddr files)) | |
2629 (setcdr files (cddr files)) | |
2630 (pop files)))) | |
2631 ;; Do the scoring if there are any score files for this group. | |
2632 score-files)) | |
2633 | |
2634 (defun gnus-possibly-score-headers (&optional trace) | |
2635 "Do scoring if scoring is required." | |
2636 (let ((score-files (gnus-all-score-files))) | |
2637 (when score-files | |
2638 (gnus-score-headers score-files trace)))) | |
2639 | |
2640 (defun gnus-score-file-name (newsgroup &optional suffix) | |
2641 "Return the name of a score file for NEWSGROUP." | |
2642 (let ((suffix (or suffix gnus-score-file-suffix))) | |
2643 (nnheader-translate-file-chars | |
2644 (cond | |
2645 ((or (null newsgroup) | |
2646 (string-equal newsgroup "")) | |
2647 ;; The global score file is placed at top of the directory. | |
2648 (expand-file-name | |
2649 suffix gnus-kill-files-directory)) | |
2650 ((gnus-use-long-file-name 'not-score) | |
2651 ;; Append ".SCORE" to newsgroup name. | |
2652 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup) | |
2653 "." suffix) | |
2654 gnus-kill-files-directory)) | |
2655 (t | |
2656 ;; Place "SCORE" under the hierarchical directory. | |
2657 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) | |
2658 "/" suffix) | |
2659 gnus-kill-files-directory)))))) | |
2660 | |
2661 (defun gnus-score-search-global-directories (files) | |
2662 "Scan all global score directories for score files." | |
2663 ;; Set the variable `gnus-internal-global-score-files' to all | |
2664 ;; available global score files. | |
2665 (interactive (list gnus-global-score-files)) | |
2666 (let (out) | |
2667 (while files | |
2668 (if (string-match "/$" (car files)) | |
2669 (setq out (nconc (directory-files | |
2670 (car files) t | |
2671 (concat (gnus-score-file-regexp) "$")))) | |
2672 (push (car files) out)) | |
2673 (setq files (cdr files))) | |
2674 (setq gnus-internal-global-score-files out))) | |
2675 | |
2676 (defun gnus-score-default-fold-toggle () | |
2677 "Toggle folding for new score file entries." | |
2678 (interactive) | |
2679 (setq gnus-score-default-fold (not gnus-score-default-fold)) | |
2680 (if gnus-score-default-fold | |
2681 (gnus-message 1 "New score file entries will be case insensitive.") | |
2682 (gnus-message 1 "New score file entries will be case sensitive."))) | |
2683 | |
2684 ;;; Home score file. | |
2685 | |
2686 (defun gnus-home-score-file (group &optional adapt) | |
2687 "Return the home score file for GROUP. | |
2688 If ADAPT, return the home adaptive file instead." | |
2689 (let ((list (if adapt gnus-home-adapt-file gnus-home-score-file)) | |
2690 elem found) | |
2691 ;; Make sure we have a list. | |
2692 (unless (listp list) | |
2693 (setq list (list list))) | |
2694 ;; Go through the list and look for matches. | |
2695 (while (and (not found) | |
2696 (setq elem (pop list))) | |
2697 (setq found | |
2698 (cond | |
2699 ;; Simple string. | |
2700 ((stringp elem) | |
2701 elem) | |
2702 ;; Function. | |
2703 ((gnus-functionp elem) | |
2704 (funcall elem group)) | |
2705 ;; Regexp-file cons | |
2706 ((consp elem) | |
2707 (when (string-match (car elem) group) | |
2708 (cadr elem)))))) | |
2709 (when found | |
2710 (nnheader-concat gnus-kill-files-directory found)))) | |
2711 | |
2712 (defun gnus-hierarchial-home-score-file (group) | |
2713 "Return the score file of the top-level hierarchy of GROUP." | |
2714 (if (string-match "^[^.]+\\." group) | |
2715 (concat (match-string 0 group) gnus-score-file-suffix) | |
2716 ;; Group name without any dots. | |
2717 (concat group (if (gnus-use-long-file-name 'not-score) "." "/") | |
2718 gnus-score-file-suffix))) | |
2719 | |
2720 (defun gnus-hierarchial-home-adapt-file (group) | |
2721 "Return the adapt file of the top-level hierarchy of GROUP." | |
2722 (if (string-match "^[^.]+\\." group) | |
2723 (concat (match-string 0 group) gnus-adaptive-file-suffix) | |
2724 ;; Group name without any dots. | |
2725 (concat group (if (gnus-use-long-file-name 'not-score) "." "/") | |
2726 gnus-adaptive-file-suffix))) | |
2727 | |
2728 ;;; | |
2729 ;;; Score decays | |
2730 ;;; | |
2731 | |
2732 (defun gnus-decay-score (score) | |
2733 "Decay SCORE." | |
2734 (floor | |
2735 (- score | |
2736 (* (if (< score 0) 1 -1) | |
2737 (min score | |
2738 (max gnus-score-decay-constant | |
2739 (* (abs score) | |
2740 gnus-score-decay-scale))))))) | |
2741 | |
2742 (defun gnus-decay-scores (alist day) | |
2743 "Decay non-permanent scores in ALIST." | |
2744 (let ((times (- (gnus-time-to-day (current-time)) day)) | |
2745 kill entry updated score n) | |
2746 (unless (zerop times) ;Done decays today already? | |
2747 (while (setq entry (pop alist)) | |
2748 (when (stringp (car entry)) | |
2749 (setq entry (cdr entry)) | |
2750 (while (setq kill (pop entry)) | |
2751 (when (nth 2 kill) | |
2752 (setq updated t) | |
2753 (setq score (or (car kill) gnus-score-interactive-default-score) | |
2754 n times) | |
2755 (while (natnump (decf n)) | |
2756 (setq score (funcall gnus-decay-score-function score))) | |
2757 (setcar kill score)))))) | |
2758 ;; Return whether this score file needs to be saved. By Je-haysuss! | |
2759 updated)) | |
2760 | |
2761 (provide 'gnus-score) | |
2762 | |
2763 ;;; gnus-score.el ends here |