*** empty log message ***
[gnus] / lisp / gnus-async.el
index 1389ce7..8da43cc 100644 (file)
@@ -1,7 +1,7 @@
 ;;; gnus-async.el --- asynchronous support for Gnus
-;; Copyright (C) 1996 Free Software Foundation, Inc.
+;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
 
-;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Keywords: news
 
 ;; This file is part of GNU Emacs.
@@ -25,6 +25,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
+
 (require 'gnus)
 (require 'gnus-sum)
 (require 'nntp)
@@ -50,7 +52,7 @@ if t, prefetch as many articles as possible."
 
 (defcustom gnus-prefetched-article-deletion-strategy '(read exit)
   "List of symbols that say when to remove articles from the prefetch buffer.
-Possible values in this list are `read', which means that 
+Possible values in this list are `read', which means that
 articles are removed as they are read, and `exit', which means
 that all articles belonging to a group are removed on exit
 from that group."
@@ -75,6 +77,7 @@ It should return non-nil if the article is to be prefetched."
 (defvar gnus-async-article-alist nil)
 (defvar gnus-async-article-semaphore '(nil))
 (defvar gnus-async-fetch-list nil)
+(defvar gnus-asynch-obarray nil)
 
 (defvar gnus-async-prefetch-headers-buffer " *Async Prefetch Headers*")
 (defvar gnus-async-header-prefetched nil)
@@ -105,7 +108,7 @@ It should return non-nil if the article is to be prefetched."
 
 (put 'gnus-asynch-with-semaphore 'lisp-indent-function 0)
 (put 'gnus-asynch-with-semaphore 'edebug-form-spec '(body))
-       
+
 ;;;
 ;;; Article prefetch
 ;;;
@@ -118,7 +121,14 @@ It should return non-nil if the article is to be prefetched."
        gnus-async-header-prefetched nil))
 
 (defun gnus-async-set-buffer ()
-  (nnheader-set-temp-buffer gnus-async-prefetch-article-buffer t))
+  (nnheader-set-temp-buffer gnus-async-prefetch-article-buffer t)
+  (unless gnus-asynch-obarray
+    (set (make-local-variable 'gnus-asynch-obarray)
+        (gnus-make-hashtable 1023))))
+
+(defun gnus-async-halt-prefetch ()
+  "Stop prefetching."
+  (setq gnus-async-fetch-list nil))
 
 (defun gnus-async-prefetch-next (group article summary)
   "Possibly prefetch several articles starting with the article after ARTICLE."
@@ -134,7 +144,7 @@ It should return non-nil if the article is to be prefetched."
              ;; do this, which leads to slightly slower article
              ;; buffer display.
              (gnus-async-prefetch-article group next summary)
-           (run-with-idle-timer 
+           (run-with-idle-timer
             0.1 nil 'gnus-async-prefetch-article group next summary)))))))
 
 (defun gnus-async-prefetch-article (group article summary &optional next)
@@ -147,7 +157,8 @@ It should return non-nil if the article is to be prefetched."
       (when next
        (gnus-async-with-semaphore
         (pop gnus-async-fetch-list)))
-      (let ((do-fetch next))
+      (let ((do-fetch next)
+           (do-message t)) ;(eq major-mode 'gnus-summary-mode)))
        (when (and (gnus-group-asynchronous-p group)
                   (gnus-buffer-live-p summary)
                   (or (not next)
@@ -176,7 +187,7 @@ It should return non-nil if the article is to be prefetched."
 
           (when do-fetch
             (setq article (car gnus-async-fetch-list))))
-    
+
          (when (and do-fetch article)
            ;; We want to fetch some more articles.
            (save-excursion
@@ -186,12 +197,13 @@ It should return non-nil if the article is to be prefetched."
                (goto-char (point-max))
                (setq mark (point-marker))
                (let ((nnheader-callback-function
-                      (gnus-make-async-article-function 
+                      (gnus-make-async-article-function
                        group article mark summary next))
-                     (nntp-server-buffer 
+                     (nntp-server-buffer
                       (get-buffer gnus-async-prefetch-article-buffer)))
-                 (gnus-message 7 "Prefetching article %d in group %s"
-                               article group)
+                 (when do-message
+                   (gnus-message 9 "Prefetching article %d in group %s"
+                                 article group))
                  (gnus-request-article article group))))))))))
 
 (defun gnus-make-async-article-function (group article mark summary next)
@@ -201,7 +213,8 @@ It should return non-nil if the article is to be prefetched."
        (when arg
         (gnus-async-set-buffer)
         (gnus-async-with-semaphore
-         (push (list ',(intern (format "%s-%d" group article))
+         (push (list ',(intern (format "%s-%d" group article)
+                               gnus-asynch-obarray)
                      ,mark (set-marker (make-marker) (point-max))
                      ,group ,article)
                gnus-async-article-alist)))
@@ -229,11 +242,12 @@ It should return non-nil if the article is to be prefetched."
 
 (defun gnus-async-delete-prefected-entry (entry)
   "Delete ENTRY from buffer and alist."
-  (delete-region (cadr entry) (caddr entry))
-  (set-marker (cadr entry) nil)
-  (set-marker (caddr entry) nil)
+  (ignore-errors
+    (delete-region (cadr entry) (caddr entry))
+    (set-marker (cadr entry) nil)
+    (set-marker (caddr entry) nil))
   (gnus-async-with-semaphore
-   (setq gnus-async-article-alist 
+   (setq gnus-async-article-alist
         (delq entry gnus-async-article-alist))))
 
 (defun gnus-async-prefetch-remove-group (group)
@@ -247,11 +261,25 @@ It should return non-nil if the article is to be prefetched."
          (when (equal group (nth 3 (car alist)))
            (gnus-async-delete-prefected-entry (car alist)))
          (pop alist))))))
-         
+
 (defun gnus-async-prefetched-article-entry (group article)
   "Return the entry for ARTICLE in GROUP iff it has been prefetched."
-  (assq (intern (format "%s-%d" group article))
-       gnus-async-article-alist))
+  (let ((entry (save-excursion
+                (gnus-async-set-buffer)
+                (assq (intern (format "%s-%d" group article)
+                              gnus-asynch-obarray)
+                      gnus-async-article-alist))))
+    ;; Perhaps something has emptied the buffer?
+    (if (and entry
+            (= (cadr entry) (caddr entry)))
+       (progn
+         (ignore-errors
+           (set-marker (cadr entry) nil)
+           (set-marker (caddr entry) nil))
+         (setq gnus-async-article-alist
+               (delq entry gnus-async-article-alist))
+         nil)
+      entry)))
 
 ;;;
 ;;; Header prefetch
@@ -291,7 +319,7 @@ It should return non-nil if the article is to be prefetched."
       (erase-buffer)
       (setq gnus-async-header-prefetched nil)
       t)))
-  
+
 (provide 'gnus-async)
 
 ;;; gnus-async.el ends here