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