(gnus-cite-add-face): Add check for Emacs 21 or later.
[elisp/gnus.git-] / lisp / gnus-score.el
index 5fc3660..7baf55c 100644 (file)
@@ -1,5 +1,5 @@
 ;;; gnus-score.el --- scoring code for Gnus
-;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
+;; Copyright (C) 1995,96,97,98,99 Free Software Foundation, Inc.
 
 ;; Author: Per Abrahamsen <amanda@iesd.auc.dk>
 ;;     Lars Magne Ingebrigtsen <larsi@gnus.org>
@@ -387,7 +387,7 @@ If nil, the user will be asked for a duration."
 (defcustom gnus-score-thread-simplify nil
   "If non-nil, subjects will simplified as in threading."
   :group 'gnus-score-various
-  :type 'boolean) 
+  :type 'boolean)
 
 \f
 
@@ -437,21 +437,55 @@ of the last successful match.")
 
 (defconst gnus-header-index
   ;; Name to index alist.
-  '(("number" 1 gnus-score-integer)
-    ("subject" 8 gnus-score-string)
-    ("from" 9 gnus-score-string)
-    ("date" 10 gnus-score-date)
-    ("message-id" 11 gnus-score-string)
-    ("references" 12 gnus-score-string)
-    ("chars" 13 gnus-score-integer)
-    ("lines" 14 gnus-score-integer)
-    ("xref" 15 gnus-score-string)
-    ("extra" 16 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" 9 gnus-score-followup)
-    ("thread" 12 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.
 
@@ -556,7 +590,7 @@ used as score."
          (gnus-score-kill-help-buffer)
          (unless (setq entry (assq (downcase hchar) char-to-header))
            (if mimic (error "%c %c" prefix hchar)
-             (error "Illegal header type")))
+             (error "Invalid header type")))
 
          (when (/= (downcase hchar) hchar)
            ;; This was a majuscule, so we end reading and set the defaults.
@@ -589,7 +623,7 @@ used as score."
            (gnus-score-kill-help-buffer)
            (unless (setq type (nth 1 (assq (downcase tchar) legal-types)))
              (if mimic (error "%c %c" prefix hchar)
-               (error "Illegal match type"))))
+               (error "Invalid match type"))))
 
          (when (/= (downcase tchar) tchar)
            ;; It was a majuscule, so we end reading and use the default.
@@ -622,7 +656,7 @@ used as score."
              (error "You rang?"))
            (if mimic
                (error "%c %c %c %c" prefix hchar tchar pchar)
-             (error "Illegal match duration"))))
+             (error "Invalid match duration"))))
       ;; Always kill the score help buffer.
       (gnus-score-kill-help-buffer))
 
@@ -631,15 +665,15 @@ used as score."
     (setq extra
          (and gnus-extra-headers
               (equal (nth 1 entry) "extra")
-              (intern                                  ; need symbol
+              (intern                  ; need symbol
                (gnus-completing-read
                 (symbol-name (car gnus-extra-headers)) ; default response
-                "Score extra header:"                  ; prompt
-                (mapcar (lambda (x)                    ; completion list
+                "Score extra header:"  ; prompt
+                (mapcar (lambda (x)    ; completion list
                           (cons (symbol-name x) x))
                         gnus-extra-headers)
-                nil                                    ; no completion limit
-                t))))                                  ; require match
+                nil                    ; no completion limit
+                t))))                  ; require match
     ;; extra is now nil or a symbol.
 
     ;; We have all the data, so we enter this score.
@@ -672,7 +706,7 @@ used as score."
           current-score-file)
          (t
           (gnus-score-file-name "all"))))))
-    
+
     (gnus-summary-score-entry
      (nth 1 entry)                     ; Header
      match                             ; Match
@@ -682,7 +716,7 @@ used as score."
         nil
        temporary)
      (not (nth 3 entry))               ; Prompt
-     nil                               ; not silent 
+     nil                               ; not silent
      extra)                            ; non-standard overview.
 
     (when (eq symp 'a)
@@ -1029,7 +1063,7 @@ EXTRA is the possible non-standard header."
     (let ((buffer-read-only nil))
       ;; Set score.
       (gnus-summary-update-mark
-       (if (= n (or gnus-summary-default-score 0)) ? 
+       (if (= n (or gnus-summary-default-score 0)) ? ;Whitespace
         (if (< n (or gnus-summary-default-score 0))
             gnus-score-below-mark gnus-score-over-mark))
        'score))
@@ -1236,8 +1270,8 @@ EXTRA is the possible non-standard header."
        (setq gnus-score-alist nil)
       ;; Read file.
       (with-temp-buffer
-       (let ((coding-system-for-write 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))
@@ -1277,11 +1311,11 @@ EXTRA is the possible non-standard header."
         err
         (cond
          ((not (listp (car a)))
-          (format "Illegal score element %s in %s" (car a) file))
+          (format "Invalid score element %s in %s" (car a) file))
          ((stringp (caar a))
           (cond
            ((not (listp (setq sr (cdar a))))
-            (format "Illegal header match %s in %s" (nth 1 (car a)) file))
+            (format "Invalid header match %s in %s" (nth 1 (car a)) file))
            (t
             (setq type (caar a))
             (while (and sr (not err))
@@ -1292,7 +1326,7 @@ EXTRA is the possible non-standard header."
                 ((if (member (downcase type) '("lines" "chars"))
                      (not (numberp (car s)))
                    (not (stringp (car s))))
-                 (format "Illegal match %s in %s" (car s) file))
+                 (format "Invalid match %s in %s" (car s) file))
                 ((and (cadr s) (not (integerp (cadr s))))
                  (format "Non-integer score %s in %s" (cadr s) file))
                 ((and (caddr s) (not (integerp (caddr s))))
@@ -1370,8 +1404,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
@@ -1573,7 +1607,7 @@ EXTRA is the possible non-standard header."
               (match-func (if (or (eq type '>) (eq type '<) (eq type '<=)
                                   (eq type '>=) (eq type '=))
                               type
-                            (error "Illegal match type: %s" type)))
+                            (error "Invalid match type: %s" type)))
               (articles gnus-scores-articles))
          ;; Instead of doing all the clever stuff that
          ;; `gnus-score-string' does to minimize searches and stuff,
@@ -1633,7 +1667,7 @@ EXTRA is the possible non-standard header."
           ((eq type 'regexp)
            (setq match-func 'string-match
                  match (nth 0 kill)))
-          (t (error "Illegal match type: %s" type)))
+          (t (error "Invalid match type: %s" type)))
          ;; Instead of doing all the clever stuff that
          ;; `gnus-score-string' does to minimize searches and stuff,
          ;; I will assume that people generally will put so few
@@ -1731,7 +1765,7 @@ EXTRA is the possible non-standard header."
                                     (eq type 'string) (eq type 'String))
                                 'search-forward)
                                (t
-                                (error "Illegal match type: %s" type)))))
+                                (error "Invalid match type: %s" type)))))
                    (goto-char (point-min))
                    (when (funcall search-func match nil t)
                      ;; Found a match, update scores.
@@ -1817,7 +1851,7 @@ EXTRA is the possible non-standard header."
               (search-func
                (cond ((= dmt ?r) 're-search-forward)
                      ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward)
-                     (t (error "Illegal match type: %s" type))))
+                     (t (error "Invalid match type: %s" type))))
               arts art)
          (goto-char (point-min))
          (if (= dmt ?e)
@@ -1950,7 +1984,7 @@ EXTRA is the possible non-standard header."
               (mt (aref (symbol-name type) 0))
               (case-fold-search (not (memq mt '(?R ?S ?E ?F))))
               (dmt (downcase mt))
-                                       ; Assume user already simplified regexp and fuzzies
+              ;; Assume user already simplified regexp and fuzzies
               (match (if (and simplify (not (memq dmt '(?f ?r))))
                           (gnus-map-function
                            gnus-simplify-subject-functions
@@ -1960,11 +1994,12 @@ EXTRA is the possible non-standard header."
                (cond ((= dmt ?r) 're-search-forward)
                      ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward)
                      ((= dmt ?w) nil)
-                     (t (error "Illegal match type: %s" type)))))
+                     (t (error "Invalid match type: %s" type)))))
 
          ;; Evil hackery to make match usable in non-standard headers.
          (when extra
-           (setq match (concat "[ (](" extra " \\. \"[^)]*" match "[^(]*\")[ )]")
+           (setq match (concat "[ (](" extra " \\. \"[^)]*"
+                               match "[^(]*\")[ )]")
                  search-func 're-search-forward))      ; XXX danger?!?
 
          (cond
@@ -2299,7 +2334,7 @@ EXTRA is the possible non-standard header."
          (let ((ignored (append gnus-ignored-adaptive-words
                                 (if gnus-adaptive-word-no-group-words
                                     (message-tokenize-header
-                                     (gnus-group-real-name 
+                                     (gnus-group-real-name
                                       gnus-newsgroup-name)
                                      "."))
                                 gnus-default-ignored-adaptive-words)))
@@ -2341,11 +2376,10 @@ EXTRA is the possible non-standard header."
           1 "No score rules apply to the current article (default score %d)."
           gnus-summary-default-score)
        (set-buffer "*Score Trace*")
+       (setq truncate-lines t)
        (while trace
          (insert (format "%S  ->  %s\n" (cdar trace)
-                         (if (caar trace)
-                             (file-name-nondirectory (caar trace))
-                           "(non-file rule)")))
+                         (or (caar trace) "(non-file rule)")))
          (setq trace (cdr trace)))
        (goto-char (point-min))
        (gnus-configure-windows 'score-trace)))
@@ -2554,6 +2588,7 @@ GROUP using BNews sys file syntax."
         (klen (length kill-dir))
         (score-regexp (gnus-score-file-regexp))
         (trans (cdr (assq ?: nnheader-file-name-translation-alist)))
+        (group-trans (nnheader-translate-file-chars group t))
         ofiles not-match regexp)
     (save-excursion
       (set-buffer (gnus-get-buffer-create "*gnus score files*"))
@@ -2600,16 +2635,18 @@ GROUP using BNews sys file syntax."
          (if (looking-at "not.")
              (progn
                (setq not-match t)
-               (setq regexp (concat "^" (buffer-substring 5 (point-max)) "$")))
+               (setq regexp
+                     (concat "^" (buffer-substring 5 (point-max)) "$")))
            (setq regexp (concat "^" (buffer-substring 1 (point-max)) "$"))
            (setq not-match nil))
          ;; Finally - if this resulting regexp matches the group name,
          ;; we add this score file to the list of score files
          ;; applicable to this group.
          (when (or (and not-match
-                        (not (string-match regexp group)))
-                   (and (not not-match)
-                        (string-match regexp group)))
+                        (ignore-errors
+                          (not (string-match regexp group-trans))))
+                   (and (not not-match)
+                        (ignore-errors (string-match regexp group-trans))))
            (push (car sfiles) ofiles)))
        (setq sfiles (cdr sfiles)))
       (kill-buffer (current-buffer))
@@ -2903,7 +2940,7 @@ If ADAPT, return the home adaptive file instead."
                    n times)
              (while (natnump (decf n))
                (setq score (funcall gnus-decay-score-function score)))
-             (setcdr kill (cons score 
+             (setcdr kill (cons score
                                 (cdr (cdr kill)))))))))
     ;; Return whether this score file needs to be saved.  By Je-haysuss!
     updated))