*** empty log message ***
[gnus] / lisp / gnus-score.el
index f4f439a..3630426 100644 (file)
@@ -1,5 +1,5 @@
 ;;; 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>
@@ -799,7 +799,7 @@ If optional argument `SILENT' is nil, show effect of score entry."
   "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
@@ -991,6 +991,7 @@ SCORE is the score to add."
 (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))
@@ -1858,10 +1859,10 @@ SCORE is the score to add."
          (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.
@@ -1930,7 +1931,7 @@ SCORE is the score to add."
     (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))
@@ -1948,7 +1949,8 @@ SCORE is the score to add."
                  (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))
@@ -1961,12 +1963,12 @@ SCORE is the score to add."
            )
           ;; 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
@@ -1974,7 +1976,7 @@ SCORE is the score to add."
       (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)
@@ -1984,7 +1986,9 @@ SCORE is the score to add."
              (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))
@@ -1996,12 +2000,12 @@ SCORE is the score to add."
              )
             ;; 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))
 
@@ -2227,8 +2231,8 @@ SCORE is the score to add."
        (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."
@@ -2358,18 +2362,20 @@ SCORE is the score to add."
 
 (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))))
@@ -2423,14 +2429,13 @@ GROUP using BNews sys file syntax."
          ;; 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)
@@ -2470,17 +2475,27 @@ GROUP using BNews sys file syntax."
 (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.
@@ -2544,10 +2559,10 @@ The list is determined from the variable gnus-score-file-alist."
       (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
@@ -2555,7 +2570,7 @@ The list is determined from the variable gnus-score-file-alist."
         (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
@@ -2571,7 +2586,7 @@ The list is determined from the variable gnus-score-file-alist."
     (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)))
@@ -2585,8 +2600,10 @@ The list is determined from the variable gnus-score-file-alist."
     (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)))