*** empty log message ***
[gnus] / lisp / nnkiboze.el
index 5493b1d..c7fb006 100644 (file)
@@ -1,4 +1,4 @@
-;;; nnkiboze.el --- select virtual news access for (ding) Gnus
+;;; nnkiboze.el --- select virtual news access for Gnus
 ;; Copyright (C) 1995 Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
   (expand-file-name (or gnus-article-save-directory "~/News/"))
   "nnkiboze will put its files in this directory.")
 
+(defvar nnkiboze-level 9
+  "*The maximum level to be searched for articles.")
+
+(defvar nnkiboze-remove-read-articles t
+  "*If non-nil, nnkiboze will remove read articles from the kiboze group.")
+
 \f
 
-(defconst nnkiboze-version "nnkiboze 0.0"
+(defconst nnkiboze-version "nnkiboze 1.0"
   "Version numbers of this version of nnkiboze.")
 
 (defvar nnkiboze-current-group nil)
@@ -50,9 +56,9 @@
 
 ;;; Interface functions.
 
-(defun nnkiboze-retrieve-headers (articles &optional group server)
+(defun nnkiboze-retrieve-headers (articles &optional group server fetch-old)
   (nnkiboze-possibly-change-newsgroups group)
-  (if (or gnus-nov-is-evil)
+  (if gnus-nov-is-evil
       nil
     (if (stringp (car articles))
        'headers
@@ -105,8 +111,8 @@ If the stream is opened, return T, otherwise return NIL."
       ;; does no harm I think. The only alternative is to offer no
       ;; article fetching by message-id at all.
       (nntp-request-article article newsgroup gnus-nntp-server buffer)
-    (let* ((header (gnus-get-header-by-number article))
-          (xref (header-xref header))
+    (let* ((header (gnus-summary-article-header article))
+          (xref (mail-header-xref header))
           igroup iarticle)
       (or xref (error "nnkiboze: No xref"))
       (or (string-match " \\([^ ]+\\):\\([0-9]+\\)" xref)
@@ -145,11 +151,13 @@ If the stream is opened, return T, otherwise return NIL."
 (defun nnkiboze-close-group (group &optional server)
   (nnkiboze-possibly-change-newsgroups group)
   ;; Remove NOV lines of articles that are marked as read.
-  (if (not (file-exists-p (nnkiboze-nov-file-name)))
+  (if (or (not (file-exists-p (nnkiboze-nov-file-name)))
+         (not nnkiboze-remove-read-articles))
       ()
     (save-excursion
       (let ((unreads gnus-newsgroup-unreads)
-           (unselected gnus-newsgroup-unselected))
+           (unselected gnus-newsgroup-unselected)
+            (version-control 'never))
        (set-buffer (get-buffer-create "*nnkiboze work*"))
        (buffer-disable-undo (current-buffer))
        (erase-buffer)
@@ -182,7 +190,18 @@ If the stream is opened, return T, otherwise return NIL."
 
 (defalias 'nnkiboze-request-post 'nntp-request-post)
 
-(defalias 'nnkiboze-request-post-buffer 'nntp-request-post-buffer)
+(defun nnkiboze-request-delete-group (group &optional force server)
+  (nnkiboze-possibly-change-newsgroups group)
+  (when force
+     (let ((files (list (nnkiboze-nov-file-name)
+                       (concat nnkiboze-directory group ".newsrc")
+                       (nnkiboze-score-file group))))
+       (while files
+        (and (file-exists-p (car files))
+             (file-writable-p (car files))
+             (delete-file (car files)))
+        (setq files (cdr files)))))
+  (setq nnkiboze-current-group nil))
 
 \f
 ;;; Internal functions.
@@ -204,9 +223,15 @@ Finds out what articles are to be part of the nnkiboze groups."
        (gnus-expert-user t))
     (gnus))
   (let* ((gnus-newsrc-alist (gnus-copy-sequence gnus-newsrc-alist))
-        (newsrc gnus-newsrc-alist))
+        (newsrc gnus-newsrc-alist)
+        gnus-newsrc-hashtb)
+    (gnus-make-hashtable-from-newsrc-alist)
+    ;; We have copied all the newsrc alist info over to local copies
+    ;; so that we can mess all we want with these lists.
     (while newsrc
       (if (string-match "nnkiboze" (car (car newsrc)))
+         ;; For each kiboze group, we call this function to generate
+         ;; it.  
          (nnkiboze-generate-group (car (car newsrc))))
       (setq newsrc (cdr newsrc)))))
 
@@ -222,15 +247,18 @@ Finds out what articles are to be part of the nnkiboze groups."
         (regexp (nth 1 (nth 4 info)))
         (gnus-expert-user t)
         (gnus-large-newsgroup nil)
+        (version-control 'never)
         (gnus-score-find-score-files-function 'nnkiboze-score-file)
         gnus-select-group-hook gnus-summary-prepare-hook 
         gnus-thread-sort-functions gnus-show-threads 
         gnus-visual
         method nnkiboze-newsrc nov-buffer gname newsrc active
-        ginfo lowest)
+        ginfo lowest glevel)
     (setq nnkiboze-current-score-group group)
     (or info (error "No such group: %s" group))
+    ;; Load the kiboze newsrc file for this group.
     (and (file-exists-p newsrc-file) (load newsrc-file))
+    ;; We also load the nov file for this group.
     (save-excursion
       (set-buffer (setq nov-buffer (find-file-noselect nov-file)))
       (buffer-disable-undo (current-buffer)))
@@ -238,50 +266,76 @@ Finds out what articles are to be part of the nnkiboze groups."
     ;; kiboze regexp.
     (mapatoms
      (lambda (group)
-       (if (and (string-match regexp (setq gname (symbol-name group))) ; Match
-               (not (assoc gname nnkiboze-newsrc)) ; It isn't registered
-               (numberp (car (symbol-value group))) ; It is active
-               (not (string-match "^nnkiboze:" gname))) ; Exclude kibozes
-          (setq nnkiboze-newsrc 
-                (cons (cons gname (1- (car (symbol-value group))))
-                      nnkiboze-newsrc))))
+       (and (string-match regexp (setq gname (symbol-name group))) ; Match
+           (not (assoc gname nnkiboze-newsrc)) ; It isn't registered
+           (numberp (car (symbol-value group))) ; It is active
+           (or (> nnkiboze-level 7)
+               (and (setq glevel (nth 1 (nth 2 (gnus-gethash
+                                                gname gnus-newsrc-hashtb))))
+                    (>= nnkiboze-level glevel)))
+           (not (string-match "^nnkiboze:" gname)) ; Exclude kibozes
+           (setq nnkiboze-newsrc 
+                 (cons (cons gname (1- (car (symbol-value group))))
+                       nnkiboze-newsrc))))
      gnus-active-hashtb)
+    ;; `newsrc' is set to the list of groups that possibly are
+    ;; component groups to this kiboze group.  This list has elements
+    ;; on the form `(GROUP . NUMBER)', where NUMBER is the highest
+    ;; number that has been kibozed in GROUP in this kiboze group.
     (setq newsrc nnkiboze-newsrc)
     (while newsrc
       (if (not (setq active (gnus-gethash 
                             (car (car newsrc)) gnus-active-hashtb)))
+         ;; This group isn't active after all, so we remove it from
+         ;; the list of component groups.
          (setq nnkiboze-newsrc (delq (car newsrc) nnkiboze-newsrc))
+       (setq lowest (cdr (car newsrc)))
+       ;; Ok, we have a valid component group, so we jump to it. 
        (switch-to-buffer gnus-group-buffer)
        (gnus-group-jump-to-group (car (car newsrc)))
-       (if (and (setq ginfo (nth 2 (gnus-gethash (gnus-group-group-name) 
-                                                 gnus-newsrc-hashtb)))
-                (nth 3 ginfo))
-           (setcar (nthcdr 3 ginfo) nil))
+       ;; We set all list of article marks to nil.  Since we operate
+       ;; on copies of the real lists, we can destroy anything we
+       ;; want here.
+       (and (setq ginfo (nth 2 (gnus-gethash (gnus-group-group-name)
+                                             gnus-newsrc-hashtb)))
+            (nth 3 ginfo)
+            (setcar (nthcdr 3 ginfo) nil))
+       ;; We set the list of read articles to be what we expect for
+       ;; this kiboze group -- either nil or `(1 . LOWEST)'. 
+       (and ginfo (setcar (nthcdr 2 ginfo)
+                          (and (not (= lowest 1)) (cons 1 lowest))))
        (if (not (and (or (not ginfo)
                          (> (length (gnus-list-of-unread-articles 
                                      (car ginfo))) 0))
                      (progn
                        (gnus-group-select-group nil)
                        (eq major-mode 'gnus-summary-mode))))
-           ()
-         (setq lowest (cdr (car newsrc)))
+           () ; No unread articles, or we couldn't enter this group.
+         ;; We are now in the group where we want to be.
          (setq method (gnus-find-method-for-group gnus-newsgroup-name))
          (and (eq method gnus-select-method) (setq method nil))
+         ;; We go through the list of scored articles.
          (while gnus-newsgroup-scored
            (if (> (car (car gnus-newsgroup-scored)) lowest)
+               ;; If it has a good score, then we enter this article
+               ;; into the kiboze group.
                (nnkiboze-enter-nov 
                 nov-buffer
-                (gnus-get-header-by-number (car (car gnus-newsgroup-scored)))
+                (gnus-summary-article-header 
+                 (car (car gnus-newsgroup-scored)))
                 (if method
                     (gnus-group-prefixed-name gnus-newsgroup-name method)
                   gnus-newsgroup-name)))
            (setq gnus-newsgroup-scored (cdr gnus-newsgroup-scored)))
-         (gnus-summary-quit)))
+         ;; That's it.  We exit this group.
+         (gnus-summary-exit-no-update)))
       (setcdr (car newsrc) (car active))
       (setq newsrc (cdr newsrc)))
+    ;; We save the nov file.
     (set-buffer nov-buffer)
     (save-buffer)
     (kill-buffer (current-buffer))
+    ;; We save the kiboze newsrc for this group.
     (set-buffer (get-buffer-create "*nnkiboze work*"))
     (buffer-disable-undo (current-buffer))
     (erase-buffer)
@@ -296,7 +350,7 @@ Finds out what articles are to be part of the nnkiboze groups."
   (save-excursion
     (set-buffer buffer)
     (goto-char (point-max))
-    (let ((xref (header-xref header))
+    (let ((xref (mail-header-xref header))
          (prefix (gnus-group-real-prefix group))
          (first t)
          article)
@@ -306,18 +360,18 @@ Finds out what articles are to be part of the nnkiboze groups."
            (forward-line 1))
        (setq article 1))
       (insert (int-to-string article) "\t"
-             (or (header-subject header) "") "\t"
-             (or (header-from header) "") "\t"
-             (or (header-date header) "") "\t"
-             (or (header-id header) "") "\t"
-             (or (header-references header) "") "\t"
-             (int-to-string (or (header-chars header) 0)) "\t"
-             (int-to-string (or (header-lines header) 0)) "\t")
+             (or (mail-header-subject header) "") "\t"
+             (or (mail-header-from header) "") "\t"
+             (or (mail-header-date header) "") "\t"
+             (or (mail-header-id header) "") "\t"
+             (or (mail-header-references header) "") "\t"
+             (int-to-string (or (mail-header-chars header) 0)) "\t"
+             (int-to-string (or (mail-header-lines header) 0)) "\t")
       (if (or (not xref) (equal "" xref))
-         (insert "Xref " (system-name) " " group ":" 
-                 (int-to-string (header-number header))
+         (insert "Xref: " (system-name) " " group ":" 
+                 (int-to-string (mail-header-number header))
                  "\t\n")
-       (insert (header-xref header) "\t\n")
+       (insert (mail-header-xref header) "\t\n")
        (search-backward "\t" nil t)
        (search-backward "\t" nil t)
        (while (re-search-forward 
@@ -330,7 +384,7 @@ Finds out what articles are to be part of the nnkiboze groups."
              (save-excursion
                (goto-char (match-beginning 0))
                (insert prefix group ":" 
-                       (int-to-string (header-number header)) " ")
+                       (int-to-string (mail-header-number header)) " ")
                (setq first nil)))
          (save-excursion
            (goto-char (match-beginning 0))