;;; gnus-score.el --- scoring code for Gnus
-;; Copyright (C) 1995,96 Free Software Foundation, Inc.
+;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
;; Author: Per Abrahamsen <amanda@iesd.auc.dk>
;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
"Simulate the effect of a score file entry.
HEADER is the header being scored.
MATCH is the string we are looking for.
-TYPE is a flag indicating if it is a regexp or substring.
+TYPE is the score type.
SCORE is the score to add."
(interactive (list (completing-read "Header: "
gnus-header-index
(defun gnus-score-edit-current-scores (file)
"Edit the current score alist."
(interactive (list gnus-current-score-file))
+ (gnus-set-global-variables)
(let ((winconf (current-window-configuration)))
(when (buffer-name gnus-summary-buffer)
(gnus-score-save))
(cond
;; Fuzzy matches. We save these for later.
((= dmt ?f)
- (push entries fuzzies))
+ (push (cons entries alist) fuzzies))
;; Word matches. Save these for even later.
((= dmt ?w)
- (push entries words))
+ (push (cons entries alist) words))
;; Exact matches.
((= dmt ?e)
;; Do exact matching.
(when fuzzies
;; Simplify the entire buffer for easy matching.
(gnus-simplify-buffer-fuzzy)
- (while (setq kill (cadar fuzzies))
+ (while (setq kill (cadaar fuzzies))
(let* ((match (nth 0 kill))
(type (nth 3 kill))
(score (or (nth 1 kill) gnus-score-interactive-default-score))
(while (setq art (pop arts))
(setcdr art (+ score (cdr art)))
(push (cons
- (car-safe (rassq alist gnus-score-cache)) kill)
+ (car-safe (rassq (cdar fuzzies) gnus-score-cache))
+ kill)
gnus-score-trace))
;; Found a match, update scores.
(while (setq art (pop arts))
)
;; Match, update date.
((and found gnus-update-score-entry-dates)
- (gnus-score-set 'touched '(t) alist)
+ (gnus-score-set 'touched '(t) (cdar fuzzies))
(setcar (nthcdr 2 kill) now))
;; Old entry, remove.
((and expire (< date expire))
- (gnus-score-set 'touched '(t) alist)
- (setcdr (car fuzzies) (cddar fuzzies))))
+ (gnus-score-set 'touched '(t) (cdar fuzzies))
+ (setcdr (caar fuzzies) (cddaar fuzzies))))
(setq fuzzies (cdr fuzzies)))))
(when words
(let ((hashtb (gnus-make-hashtable
(* 10 (count-lines (point-min) (point-max))))))
(gnus-enter-score-words-into-hashtb hashtb)
- (while (setq kill (cadar words))
+ (while (setq kill (cadaar words))
(let* ((score (or (nth 1 kill) gnus-score-interactive-default-score))
(date (nth 2 kill))
found)
(if trace
(while (setq art (pop arts))
(setcdr art (+ score (cdr art)))
- (push (cons (car-safe (rassq alist gnus-score-cache)) kill)
+ (push (cons
+ (car-safe (rassq (cdar words) gnus-score-cache))
+ kill)
gnus-score-trace))
;; Found a match, update scores.
(while (setq art (pop arts))
)
;; Match, update date.
((and found gnus-update-score-entry-dates)
- (gnus-score-set 'touched '(t) alist)
+ (gnus-score-set 'touched '(t) (cdar words))
(setcar (nthcdr 2 kill) now))
;; Old entry, remove.
((and expire (< date expire))
- (gnus-score-set 'touched '(t) alist)
- (setcdr (car words) (cddar words))))
+ (gnus-score-set 'touched '(t) (cdar words))
+ (setcdr (caar words) (cddaar words))))
(setq words (cdr words))))))
nil))
(insert (format "%-5d: %s\n" (caar rules) (cdar rules)))
(pop rules))
(gnus-add-current-to-buffer-list)
- (gnus-configure-windows 'score-words)
- (goto-char (point-min)))))
+ (goto-char (point-min))
+ (gnus-configure-windows 'score-words))))
(defun gnus-summary-rescore ()
"Redo the entire scoring process in the current summary."
(defun gnus-score-score-files-1 (dir)
"Return all possible score files under DIR."
- (let ((files (directory-files (expand-file-name dir) t nil t))
+ (let ((files (list (expand-file-name dir)))
(regexp (gnus-score-file-regexp))
(case-fold-search nil)
- out file)
+ seen out file)
(while (setq file (pop files))
(cond
;; Ignore "." and "..".
((member (file-name-nondirectory file) '("." ".."))
nil)
- ;; Recurse down directories.
- ((file-directory-p file)
- (setq out (nconc (gnus-score-score-files-1 file) out)))
+ ;; Add subtrees of directory to also be searched.
+ ((and (file-directory-p file)
+ (not (member (file-truename file) seen)))
+ (push (file-truename file) seen)
+ (setq files (nconc (directory-files file t nil t) files)))
;; Add files to the list of score files.
((string-match regexp file)
(push file out))))
;; Kludge to get rid of "nntp+" problems.
(goto-char (point-min))
(when (looking-at "nn[a-z]+\\+")
- (progn
- (search-forward "+")
- (forward-char -1)
- (insert "\\")))
+ (search-forward "+")
+ (forward-char -1)
+ (insert "\\")
+ (forward-char 1))
;; Kludge to deal with "++".
- (goto-char (point-min))
- (while (search-forward "++" nil t)
- (replace-match "\\+\\+" t t))
+ (while (search-forward "+" nil t)
+ (replace-match "\\+" t t))
;; Translate "all" to ".*".
(goto-char (point-min))
(while (search-forward "all" nil t)
(defun gnus-score-find-hierarchical (group)
"Return list of score files for GROUP.
This includes the score file for the group and all its parents."
- (let ((all (copy-sequence '(nil)))
- (start 0))
+ (let* ((prefix (gnus-group-real-prefix group))
+ (all (list nil))
+ (group (gnus-group-real-name group))
+ (start 0))
(while (string-match "\\." group (1+ start))
(setq start (match-beginning 0))
(push (substring group 0 start) all))
(push group all)
- (nconc
- (mapcar (lambda (newsgroup)
- (gnus-score-file-name newsgroup gnus-adaptive-file-suffix))
- (setq all (nreverse all)))
- (mapcar 'gnus-score-file-name all))))
+ (setq all
+ (nconc
+ (mapcar (lambda (group)
+ (gnus-score-file-name group gnus-adaptive-file-suffix))
+ (setq all (nreverse all)))
+ (mapcar 'gnus-score-file-name all)))
+ (if (equal prefix "")
+ all
+ (mapcar
+ (lambda (file)
+ (concat (file-name-directory file) prefix
+ (file-name-nondirectory file)))
+ all))))
(defun gnus-score-file-rank (file)
"Return a number that says how specific score FILE is.
(push (cons group score-files) gnus-score-file-alist-cache)
score-files)))
-(defun gnus-all-score-files ()
+(defun gnus-all-score-files (&optional group)
"Return a list of all score files for the current group."
(let ((funcs gnus-score-find-score-files-function)
- (group gnus-newsgroup-name)
+ (group (or group gnus-newsgroup-name))
score-files)
;; Make sure funcs is a list.
(and funcs
(setq funcs (list funcs)))
;; Get the initial score files for this group.
(when funcs
- (setq score-files (gnus-score-find-alist group)))
+ (setq score-files (nreverse (gnus-score-find-alist group))))
;; Add any home adapt files.
(let ((home (gnus-home-score-file group t)))
(when home
(while funcs
(when (gnus-functionp (car funcs))
(setq score-files
- (nconc score-files (funcall (car funcs) group))))
+ (nconc score-files (nreverse (funcall (car funcs) group)))))
(setq funcs (cdr funcs)))
;; Add any home score files.
(let ((home (gnus-home-score-file group)))
(let ((files score-files))
(while files
(when (stringp (car files))
- (setcar files (expand-file-name (car files))))
+ (setcar files (expand-file-name (car files)
+ gnus-kill-files-directory)))
(pop files)))
+ (setq score-files (nreverse score-files))
;; Remove any duplicate score files.
(while (and score-files
(member (car score-files) (cdr score-files)))