* gnus-agent.el (gnus-agent-braid-nov): Find the first article to
[gnus] / lisp / gnus-agent.el
index 7d8afef..325d306 100644 (file)
@@ -128,6 +128,18 @@ If this is `ask' the hook will query the user."
                 (const :tag "Ask" ask))
   :group 'gnus-agent)
 
+(defcustom gnus-agent-mark-unread-after-downloaded t
+  "Indicate whether to mark articles unread after downloaded."
+  :version "21.1"
+  :type 'boolean
+  :group 'gnus-agent)
+
+(defcustom gnus-agent-download-marks '(download)
+  "Marks for downloading."
+  :version "21.1"
+  :type '(repeat (symbol :tag "Mark"))
+  :group 'gnus-agent)
+
 ;;; Internal variables
 
 (defvar gnus-agent-history-buffers nil)
@@ -313,7 +325,7 @@ If this is `ask' the hook will query the user."
        ["Mark as downloadable" gnus-agent-mark-article t]
        ["Unmark as downloadable" gnus-agent-unmark-article t]
        ["Toggle mark" gnus-agent-toggle-mark t]
-       ["Fetch downloadable" gnus-aget-summary-fetch-group t]
+       ["Fetch downloadable" gnus-agent-summary-fetch-group t]
        ["Catchup undownloaded" gnus-agent-catchup t]))))
 
 (defvar gnus-agent-server-mode-map (make-sparse-keymap))
@@ -671,7 +683,8 @@ the actual number of articles toggled is returned."
          (push article gnus-newsgroup-undownloaded))
       (setq gnus-newsgroup-undownloaded
            (delq article gnus-newsgroup-undownloaded))
-      (push article gnus-newsgroup-downloadable))
+      (setq gnus-newsgroup-downloadable
+           (gnus-add-to-sorted-list gnus-newsgroup-downloadable article)))
     (gnus-summary-update-mark
      (if unmark gnus-undownloaded-mark gnus-downloadable-mark)
      'unread)))
@@ -732,7 +745,8 @@ the actual number of articles toggled is returned."
            (dolist (article articles)
              (setq gnus-newsgroup-downloadable
                    (delq article gnus-newsgroup-downloadable))
-             (gnus-summary-mark-article article gnus-unread-mark))))
+             (if gnus-agent-mark-unread-after-downloaded
+                 (gnus-summary-mark-article article gnus-unread-mark)))))
       (when (and (not state)
                 gnus-plugged)
        (gnus-agent-toggle-plugged nil)))))
@@ -1033,9 +1047,9 @@ the actual number of articles toggled is returned."
     (setq articles (sort (gnus-uncompress-sequence articles) '<))
     ;; Remove known articles.
     (when (gnus-agent-load-alist group)
-      (setq articles (gnus-sorted-intersection
+      (setq articles (gnus-list-range-intersection 
                      articles
-                     (gnus-uncompress-range
+                     (list
                       (cons (1+ (caar (last gnus-agent-article-alist)))
                             (cdr (gnus-active group)))))))
     ;; Fetch them.
@@ -1062,15 +1076,17 @@ the actual number of articles toggled is returned."
        articles))))
 
 (defsubst gnus-agent-copy-nov-line (article)
-  (let (b e)
+  (let (art b e)
     (set-buffer gnus-agent-overview-buffer)
-    (unless (eobp)
+    (while (and (not (eobp))
+               (< (setq art (read (current-buffer))) article))
+      (forward-line 1))
+    (beginning-of-line)
+    (if (or (eobp)
+           (not (eq article art)))
+       (set-buffer nntp-server-buffer)
       (setq b (point))
-      (if (eq article (read (current-buffer)))
-         (setq e (progn (forward-line 1) (point)))
-       (progn
-         (beginning-of-line)
-         (setq e b)))
+      (setq e (progn (forward-line 1) (point)))
       (set-buffer nntp-server-buffer)
       (insert-buffer-substring gnus-agent-overview-buffer b e))))
 
@@ -1081,15 +1097,10 @@ the actual number of articles toggled is returned."
   (erase-buffer)
   (nnheader-insert-file-contents file)
   (goto-char (point-max))
-  (if (or (= (point-min) (point-max))
-         (progn
-           (forward-line -1)
-           (< (read (current-buffer)) (car articles))))
-      ;; We have only headers that are after the older headers,
-      ;; so we just append them.
-      (progn
-       (goto-char (point-max))
-       (insert-buffer-substring gnus-agent-overview-buffer))
+  (unless (or (= (point-min) (point-max))
+             (progn
+               (forward-line -1)
+               (< (read (current-buffer)) (car articles))))
     ;; We do it the hard way.
     (nnheader-find-nov-line (car articles))
     (gnus-agent-copy-nov-line (car articles))
@@ -1102,19 +1113,20 @@ the actual number of articles toggled is returned."
       (beginning-of-line)
       (unless (eobp)
        (gnus-agent-copy-nov-line (car articles))
-       (setq articles (cdr articles))))
-    (set-buffer nntp-server-buffer)
-    (when articles
-      (let (b e)
-       (set-buffer gnus-agent-overview-buffer)
-       (setq b (point)
-             e (point-max))
-       (while (and (not (eobp))
-                   (<= (read (current-buffer)) (car articles)))
-         (forward-line 1)
-         (setq b (point)))
-       (set-buffer nntp-server-buffer)
-       (insert-buffer-substring gnus-agent-overview-buffer b e)))))
+       (setq articles (cdr articles)))))
+  ;; Copy the rest lines
+  (set-buffer nntp-server-buffer)
+  (goto-char (point-max))
+  (when articles
+    (let (start)
+      (set-buffer gnus-agent-overview-buffer)
+      (while (and (not (eobp))
+                 (< (read (current-buffer)) (car articles)))
+       (forward-line 1))
+      (beginning-of-line)
+      (setq start (point))
+      (set-buffer nntp-server-buffer)
+      (insert-buffer-substring gnus-agent-overview-buffer start))))
 
 (defun gnus-agent-load-alist (group &optional dir)
   "Load the article-state alist for GROUP."
@@ -1271,18 +1283,20 @@ the actual number of articles toggled is returned."
       (when arts
        (gnus-agent-fetch-articles group arts)))
     ;; Perhaps we have some additional articles to fetch.
-    (setq arts (assq 'download (gnus-info-marks
-                               (setq info (gnus-get-info group)))))
-    (when (cdr arts)
-      (gnus-message 8 "Agent is downloading marked articles...")
-      (gnus-agent-fetch-articles
-       group (gnus-uncompress-range (cdr arts)))
-      (setq marks (delq arts (gnus-info-marks info)))
-      (gnus-info-set-marks info marks)
-      (gnus-dribble-enter
-       (concat "(gnus-group-set-info '"
-              (gnus-prin1-to-string info)
-              ")")))))
+    (dolist (mark gnus-agent-download-marks)
+      (setq arts (assq mark (gnus-info-marks
+                            (setq info (gnus-get-info group)))))
+      (when (cdr arts)
+       (gnus-message 8 "Agent is downloading marked articles...")
+       (gnus-agent-fetch-articles
+        group (gnus-uncompress-range (cdr arts)))
+       (when (eq mark 'download)
+         (setq marks (delq arts (gnus-info-marks info)))
+         (gnus-info-set-marks info marks)
+         (gnus-dribble-enter
+          (concat "(gnus-group-set-info '"
+                  (gnus-prin1-to-string info)
+                  ")")))))))
 
 ;;;
 ;;; Agent Category Mode
@@ -1840,7 +1854,7 @@ The following commands are available:
          (erase-buffer)
          (let ((nnheader-file-coding-system
                 gnus-agent-file-coding-system))
-           (nnheader-insert-file-contents file))
+           (nnheader-insert-nov-file file (car articles)))
          (nnheader-find-nov-line (car articles))
          (while (not (eobp))
            (when (looking-at "[0-9]")
@@ -1848,7 +1862,7 @@ The following commands are available:
            (forward-line 1))
          (setq cached-articles (nreverse cached-articles))))
       (if (setq uncached-articles 
-               (gnus-set-difference articles cached-articles))
+               (gnus-sorted-difference articles cached-articles))
          (progn
            (set-buffer nntp-server-buffer)
            (erase-buffer)