- (unless number
- (setq number gnus-use-article-prefetch))
- (when (and number
- (or (not (numberp number))
- (> number 0))
- (gnus-group-asynchronous-p group)
- (gnus-buffer-live-p summary))
- (when (numberp number)
- (decf number))
- (while (and article (gnus-async-prefetched-article-entry group article))
- (setq article (caadr (gnus-data-find-list article)))
- (when (numberp number)
- (decf number)))
- (when article
- ;; We want to fetch some more articles.
- (save-excursion
- (set-buffer summary)
- (let ((next (caadr (gnus-data-find-list article)))
- mark)
- (nnheader-set-temp-buffer gnus-async-prefetch-article-buffer t)
- (goto-char (point-max))
- (setq mark (point-marker))
- (let ((nnheader-callback-function
- `(lambda (arg)
- (save-excursion
- (nnheader-set-temp-buffer
- gnus-async-prefetch-article-buffer t)
- (push (list ',(intern (format "%s-%d" group article))
- ,mark (set-marker (make-marker) (point-max))
- ,group ,article)
- gnus-async-article-alist)
- (when (gnus-buffer-live-p ,summary)
- ,(when next
- `(gnus-async-prefetch-article
- ,group ,next ,summary ,number))))))
- (nntp-server-buffer (get-buffer
- gnus-async-prefetch-article-buffer)))
- (gnus-message 7 "Prefetching article %d in group %s"
- article group)
- (gnus-request-article article group)))))))
+ (if (not (gnus-buffer-live-p summary))
+ (gnus-async-with-semaphore
+ (setq gnus-async-fetch-list nil))
+ (when (and gnus-asynchronous
+ (gnus-alive-p))
+ (when next
+ (gnus-async-with-semaphore
+ (pop gnus-async-fetch-list)))
+ (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)
+ gnus-async-fetch-list))
+ (gnus-async-with-semaphore
+ (unless next
+ (setq do-fetch (not gnus-async-fetch-list))
+ ;; Nix out any outstanding requests.
+ (setq gnus-async-fetch-list nil)
+ ;; Fill in the new list.
+ (let ((n gnus-use-article-prefetch)
+ (data (gnus-data-find-list article))
+ d)
+ (while (and (setq d (pop data))
+ (if (numberp n)
+ (natnump (decf n))
+ n))
+ (unless (or (gnus-async-prefetched-article-entry
+ group (setq article (gnus-data-number d)))
+ (not (natnump article))
+ (not (funcall gnus-async-prefetch-article-p d)))
+ ;; Not already fetched -- so we add it to the list.
+ (push article gnus-async-fetch-list)))
+ (setq gnus-async-fetch-list
+ (nreverse gnus-async-fetch-list))))
+
+ (when do-fetch
+ (setq article (car gnus-async-fetch-list))))
+
+ (when (and do-fetch article)
+ ;; We want to fetch some more articles.
+ (save-excursion
+ (set-buffer summary)
+ (let (mark)
+ (gnus-async-set-buffer)
+ (goto-char (point-max))
+ (setq mark (point-marker))
+ (let ((nnheader-callback-function
+ (gnus-make-async-article-function
+ group article mark summary next))
+ (nntp-server-buffer
+ (get-buffer gnus-async-prefetch-article-buffer)))
+ (when do-message
+ (gnus-message 9 "Prefetching article %d in group %s"
+ article group))
+ (setq gnus-async-current-prefetch-group group)
+ (setq gnus-async-current-prefetch-article article)
+ (gnus-request-article article group))))))))))
+
+(defun gnus-make-async-article-function (group article mark summary next)
+ "Return a callback function."
+ `(lambda (arg)
+ (gnus-async-article-callback arg ,group ,article ,mark ,summary ,next)))
+
+(defun gnus-async-article-callback (arg group article mark summary next)
+ "Function called when an async article is done being fetched."
+ (save-excursion
+ (setq gnus-async-current-prefetch-article nil)
+ (when arg
+ (gnus-async-set-buffer)
+ (gnus-async-with-semaphore
+ (setq
+ gnus-async-article-alist
+ (cons (list (intern (format "%s-%d" group article)
+ gnus-async-hashtb)
+ mark (set-marker (make-marker) (point-max))
+ group article)
+ gnus-async-article-alist))))
+ (if (not (gnus-buffer-live-p summary))
+ (gnus-async-with-semaphore
+ (setq gnus-async-fetch-list nil))
+ (gnus-async-prefetch-article group next summary t))))
+
+(defun gnus-async-unread-p (data)
+ "Return non-nil if DATA represents an unread article."
+ (gnus-data-unread-p data))