Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / gnus-score.el
index fe7db38..b99a41d 100644 (file)
@@ -1,5 +1,5 @@
 ;;; gnus-score.el --- scoring code for Gnus
-;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001
+;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
 ;;        Free Software Foundation, Inc.
 
 ;; Author: Per Abrahamsen <amanda@iesd.auc.dk>
@@ -28,6 +28,7 @@
 ;;; Code:
 
 (eval-when-compile (require 'cl))
+(eval-when-compile (require 'gnus-clfns))
 
 (require 'gnus)
 (require 'gnus-sum)
@@ -448,21 +449,55 @@ of the last successful match.")
 
 (defconst gnus-header-index
   ;; Name to index alist.
-  '(("number" 0 gnus-score-integer)
-    ("subject" 1 gnus-score-string)
-    ("from" 2 gnus-score-string)
-    ("date" 3 gnus-score-date)
-    ("message-id" 4 gnus-score-string)
-    ("references" 5 gnus-score-string)
-    ("chars" 6 gnus-score-integer)
-    ("lines" 7 gnus-score-integer)
-    ("xref" 8 gnus-score-string)
-    ("extra" 9 gnus-score-string)
+  `(("number"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'location)
+     gnus-score-integer)
+    ("subject"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'subject)
+     gnus-score-string)
+    ("from"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'from)
+     gnus-score-string)
+    ("date"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'date)
+     gnus-score-date)
+    ("message-id"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'id)
+     gnus-score-string)
+    ("references"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'references)
+     gnus-score-string)
+    ("chars"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'chars)
+     gnus-score-integer)
+    ("lines"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'lines)
+     gnus-score-integer)
+    ("xref"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'xref)
+     gnus-score-string)
+;;    ("extra" 16 gnus-score-string)
+    ("extra" -1 gnus-score-body)
     ("head" -1 gnus-score-body)
     ("body" -1 gnus-score-body)
     ("all" -1 gnus-score-body)
-    ("followup" 2 gnus-score-followup)
-    ("thread" 5 gnus-score-thread)))
+    ("followup"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'from)
+     gnus-score-followup)
+    ("thread"
+     ,(luna-class-slot-index (luna-find-class 'mime-gnus-entity)
+                            'references)
+     gnus-score-thread)))
 
 ;;; Summary mode score maps.
 
@@ -643,7 +678,7 @@ used as score."
          (and gnus-extra-headers
               (equal (nth 1 entry) "extra")
               (intern                  ; need symbol
-               (gnus-completing-read
+               (gnus-completing-read-with-default
                 (symbol-name (car gnus-extra-headers)) ; default response
                 "Score extra header:"  ; prompt
                 (mapcar (lambda (x)    ; completion list
@@ -735,10 +770,13 @@ used as score."
        (insert (format format (caar alist) (nth idx (car alist))))
        (setq alist (cdr alist))
        (setq i (1+ i))))
+    (goto-char (point-min))
     ;; display ourselves in a small window at the bottom
     (gnus-appt-select-lowest-window)
-    (split-window)
-    (pop-to-buffer "*Score Help*")
+    (if (< (/ (window-height) 2) window-min-height)
+       (switch-to-buffer "*Score Help*")
+      (split-window)
+      (pop-to-buffer "*Score Help*"))
     (let ((window-min-height 1))
       (shrink-window-if-larger-than-buffer))
     (select-window (gnus-get-buffer-window gnus-summary-buffer t))))
@@ -1208,7 +1246,6 @@ EXTRA is the possible non-standard header."
                   (setq gnus-newsgroup-adaptive t)
                   adapt)
                  (t
-                  ;;(setq gnus-newsgroup-adaptive gnus-use-adaptive-scoring)
                   gnus-default-adaptive-score-alist)))
       (setq gnus-thread-expunge-below
            (or thread-mark-and-expunge gnus-thread-expunge-below))
@@ -1245,8 +1282,8 @@ EXTRA is the possible non-standard header."
        (setq gnus-score-alist nil)
       ;; Read file.
       (with-temp-buffer
-       (let ((coding-system-for-read score-mode-coding-system))
-         (insert-file-contents file))
+       (insert-file-contents-as-coding-system
+        score-mode-coding-system file)
        (goto-char (point-min))
        ;; Only do the loading if the score file isn't empty.
        (when (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t))
@@ -1379,8 +1416,8 @@ EXTRA is the possible non-standard header."
              (delete-file file)
            ;; There are scores, so we write the file.
            (when (file-writable-p file)
-             (let ((coding-system-for-write score-mode-coding-system))
-               (gnus-write-buffer file))
+             (gnus-write-buffer-as-coding-system
+              score-mode-coding-system file)
              (when gnus-score-after-write-file-function
                (funcall gnus-score-after-write-file-function file)))))
        (and gnus-score-uncacheable-files
@@ -1663,7 +1700,7 @@ score in `gnus-newsgroup-scored' by SCORE."
               entries alist ofunc article last)
          (when articles
            (setq last (mail-header-number (caar (last articles))))
-         ;; Not all backends support partial fetching.  In that case,
+           ;; Not all backends support partial fetching.  In that case,
            ;; we just fetch the entire article.
            (unless (gnus-check-backend-function
                     (and (string-match "^gnus-" (symbol-name request-func))
@@ -1678,8 +1715,8 @@ score in `gnus-newsgroup-scored' by SCORE."
              (widen)
              (when (funcall request-func article gnus-newsgroup-name)
                (goto-char (point-min))
-           ;; If just parts of the article is to be searched, but the
-           ;; backend didn't support partial fetching, we just narrow
+               ;; If just parts of the article is to be searched, but the
+               ;; backend didn't support partial fetching, we just narrow
                ;; to the relevant parts.
                (when ofunc
                  (if (eq ofunc 'gnus-request-head)
@@ -1834,7 +1871,7 @@ score in `gnus-newsgroup-scored' by SCORE."
            ;; Update expire date
            (cond ((null date))         ;Permanent entry.
                  ((and found gnus-update-score-entry-dates)
-                                       ;Match, update date.
+                  ;Match, update date.
                   (gnus-score-set 'touched '(t) alist)
                   (setcar (nthcdr 2 kill) now))
                  ((and expire (< date expire)) ;Old entry, remove.