*** empty log message ***
[gnus] / lisp / gnus-kill.el
index ac76cd2..3f674d2 100644 (file)
@@ -26,8 +26,9 @@
 
 ;;; Code:
 
-(require 'gnus)
-(eval-when-compile (require 'cl))
+(require 'gnus-load)
+(require 'gnus-art)
+(require 'gnus-range)
 
 (defvar gnus-kill-file-mode-hook nil
   "*A hook for Gnus kill file mode.")
 
 (defvar gnus-winconf-kill-file nil)
 
+(defvar gnus-kill-killed t
+  "*If non-nil, Gnus will apply kill files to already killed articles.
+If it is nil, Gnus will never apply kill files to articles that have
+already been through the scoring process, which might very well save lots
+of time.")
+
 \f
 
 (defmacro gnus-raise (field expression level)
@@ -93,12 +100,12 @@ well-known.  For this reason, Gnus provides a general function which
 does this easily for non-Lisp programmers.
 
   The `gnus-kill' function executes commands available in Summary Mode
-by their key sequences. `gnus-kill' should be called with FIELD,
+by their key sequences.  `gnus-kill' should be called with FIELD,
 REGEXP and optional COMMAND and ALL.  FIELD is a string representing
 the header field or an empty string.  If FIELD is an empty string, the
 entire article body is searched for.  REGEXP is a string which is
-compared with FIELD value. COMMAND is a string representing a valid
-key sequence in Summary mode or Lisp expression. COMMAND defaults to
+compared with FIELD value.  COMMAND is a string representing a valid
+key sequence in Summary mode or Lisp expression.  COMMAND defaults to
 '(gnus-summary-mark-as-read nil \"X\").  Make sure that COMMAND is
 executed in the Summary buffer.  If the second optional argument ALL
 is non-nil, the COMMAND is applied to articles which are already
@@ -336,7 +343,7 @@ If NEWSGROUP is nil, return the global kill file instead."
          ;; Ignores global KILL.
          (if (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name))
              (gnus-message 3 "Note: Ignoring %s.KILL; preferring .SCORE"
-                            gnus-newsgroup-name))
+                          gnus-newsgroup-name))
          0)
         ((or (file-exists-p (gnus-newsgroup-kill-file nil))
              (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
@@ -355,7 +362,7 @@ Returns the number of articles marked as read."
     (setq gnus-newsgroup-kill-headers nil)
     ;; If there are any previously scored articles, we remove these
     ;; from the `gnus-newsgroup-headers' list that the score functions
-    ;; will see. This is probably pretty wasteful when it comes to
+    ;; will see.  This is probably pretty wasteful when it comes to
     ;; conses, but is, I think, faster than having to assq in every
     ;; single score function.
     (let ((files kill-files))
@@ -493,7 +500,7 @@ COMMAND must be a lisp expression or a string representing a key sequence."
     (save-excursion
       (save-window-excursion
        ;; Selected window must be summary buffer to execute keyboard
-       ;; macros correctly. See command_loop_1.
+       ;; macros correctly.  See command_loop_1.
        (switch-to-buffer gnus-summary-buffer 'norecord)
        (goto-char (point-min))         ;From the beginning.
        (let ((kill-list regexp)
@@ -525,7 +532,7 @@ COMMAND must be a lisp expression or a string representing a key sequence."
                                (if prev
                                    (setcdr prev (cdr kill-list))
                                  (setq regexp (cdr regexp))))
-                         ;; Successful kill. Set the date to today.
+                         ;; Successful kill.  Set the date to today.
                          (setcdr kill date)))
                    ;; It's a permanent kill.
                    (gnus-execute field kill command nil (not all)))
@@ -545,7 +552,7 @@ COMMAND must be a lisp expression or a string representing a key sequence."
          (not (consp (cdr (nth 2 object))))
          (and (eq 'quote (car (nth 2 object)))
               (not (consp (cdadr (nth 2 object))))))
-      (concat "\n" (prin1-to-string object))
+      (concat "\n" (gnus-prin1-to-string object))
     (save-excursion
       (set-buffer (get-buffer-create "*Gnus PP*"))
       (buffer-disable-undo (current-buffer))
@@ -555,7 +562,7 @@ COMMAND must be a lisp expression or a string representing a key sequence."
            (first t))
        (while klist
          (insert (if first (progn (setq first nil) "")  "\n    ")
-                 (prin1-to-string (car klist)))
+                 (gnus-prin1-to-string (car klist)))
          (setq klist (cdr klist))))
       (insert ")")
       (and (nth 3 object)
@@ -563,7 +570,7 @@ COMMAND must be a lisp expression or a string representing a key sequence."
                   (if (and (consp (nth 3 object))
                            (not (eq 'quote (car (nth 3 object))))) 
                       "'" "")
-                  (prin1-to-string (nth 3 object))))
+                  (gnus-prin1-to-string (nth 3 object))))
       (and (nth 4 object)
           (insert "\n  t"))
       (insert ")")
@@ -584,9 +591,9 @@ COMMAND must be a lisp expression or a string representing a key sequence."
                     (setq value (funcall function header))
                     ;; Number (Lines:) or symbol must be converted to string.
                     (or (stringp value)
-                        (setq value (prin1-to-string value)))
+                        (setq value (gnus-prin1-to-string value)))
                     (setq did-kill (string-match regexp value)))
-                  (cond ((stringp form)        ;Keyboard macro.
+                  (cond ((stringp form) ;Keyboard macro.
                          (execute-kbd-macro form))
                         ((gnus-functionp form)
                          (funcall form))
@@ -641,7 +648,7 @@ marked as read or ticked are ignored."
              ;; Find later articles.
              (setq article 
                    (gnus-summary-search-forward 
-                    (not ignore-marked) nil backward)))
+                    ignore-marked nil backward)))
        (and (or (null gnus-newsgroup-kill-headers)
                 (memq article gnus-newsgroup-kill-headers))
             (vectorp (setq header (gnus-summary-article-header article)))
@@ -650,6 +657,47 @@ marked as read or ticked are ignored."
       ;; Return the number of killed articles.
       killed-no)))
 
+;;;###autoload
+(defalias 'gnus-batch-kill 'gnus-batch-score)
+;;;###autoload
+(defun gnus-batch-score ()
+  "Run batched scoring.
+Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ...
+Newsgroups is a list of strings in Bnews format.  If you want to score
+the comp hierarchy, you'd say \"comp.all\".  If you would not like to
+score the alt hierarchy, you'd say \"!alt.all\"."
+  (interactive)
+  (let* ((gnus-newsrc-options-n    
+         (gnus-newsrc-parse-options
+          (concat "options -n "
+                  (mapconcat 'identity command-line-args-left " "))))
+        (gnus-expert-user t)
+        (nnmail-spool-file nil)
+        (gnus-use-dribble-file nil)
+        group newsrc entry
+        ;; Disable verbose message.
+        gnus-novice-user gnus-large-newsgroup
+        gnus-options-subscribe gnus-auto-subscribed-groups
+        gnus-options-not-subscribe)
+    ;; Eat all arguments.
+    (setq command-line-args-left nil)
+    (gnus)
+    ;; Apply kills to specified newsgroups in command line arguments.
+    (setq newsrc (cdr gnus-newsrc-alist))
+    (while (setq group (car (pop newsrc)))
+      (setq entry (gnus-gethash group gnus-newsrc-hashtb))
+      (when (and (<= (nth 1 (car newsrc)) gnus-level-subscribed)
+                (and (car entry)
+                     (or (eq (car entry) t)
+                         (not (zerop (car entry)))))
+                (eq (gnus-matches-options-n group) 'subscribe))
+       (gnus-summary-read-group group nil t nil t)
+       (when (eq (current-buffer) (get-buffer gnus-summary-buffer))
+         (gnus-summary-exit))))
+    ;; Exit Emacs.
+    (switch-to-buffer gnus-group-buffer)
+    (gnus-group-save-newsrc)))
+
 (provide 'gnus-kill)
 
 ;;; gnus-kill.el ends here