Mercurial > emacs
annotate lisp/gnus/gnus-async.el @ 63092:80ef8a2a052d
(debug): Don't bury the buffer unless it's in a dedicated window.
| author | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| date | Mon, 06 Jun 2005 19:47:05 +0000 |
| parents | 7503b2a24a3c |
| children | 18a818a2ee7c 30ad2795fdab |
| rev | line source |
|---|---|
| 17493 | 1 ;;; gnus-async.el --- asynchronous support for Gnus |
|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2003 |
|
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
3 ;; Free Software Foundation, Inc. |
| 17493 | 4 |
|
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 17493 | 6 ;; Keywords: news |
| 7 | |
| 8 ;; This file is part of GNU Emacs. | |
| 9 | |
| 10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 11 ;; it under the terms of the GNU General Public License as published by | |
| 12 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 13 ;; any later version. | |
| 14 | |
| 15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 ;; GNU General Public License for more details. | |
| 19 | |
| 20 ;; You should have received a copy of the GNU General Public License | |
| 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
| 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 23 ;; Boston, MA 02111-1307, USA. | |
| 24 | |
| 25 ;;; Commentary: | |
| 26 | |
| 27 ;;; Code: | |
| 28 | |
|
19521
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
|
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
30 |
| 17493 | 31 (require 'gnus) |
| 32 (require 'gnus-sum) | |
| 33 (require 'nntp) | |
| 34 | |
|
60696
7503b2a24a3c
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-187
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
35 (eval-when-compile |
|
7503b2a24a3c
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-187
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
36 (when (featurep 'xemacs) |
|
7503b2a24a3c
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-187
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
37 (require 'timer-funcs))) |
|
7503b2a24a3c
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-187
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
38 |
| 17493 | 39 (defgroup gnus-asynchronous nil |
| 40 "Support for asynchronous operations." | |
| 41 :group 'gnus) | |
| 42 | |
| 43 (defcustom gnus-use-article-prefetch 30 | |
| 44 "*If non-nil, prefetch articles in groups that allow this. | |
| 45 If a number, prefetch only that many articles forward; | |
| 46 if t, prefetch as many articles as possible." | |
| 47 :group 'gnus-asynchronous | |
| 48 :type '(choice (const :tag "off" nil) | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
49 (const :tag "all" t) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
50 (integer :tag "some" 0))) |
| 17493 | 51 |
|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
52 (defcustom gnus-asynchronous nil |
|
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
53 "*If nil, inhibit all Gnus asynchronicity. |
|
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
54 If non-nil, let the other asynch variables be heeded." |
|
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
55 :group 'gnus-asynchronous |
|
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
56 :type 'boolean) |
|
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
57 |
| 17493 | 58 (defcustom gnus-prefetched-article-deletion-strategy '(read exit) |
| 59 "List of symbols that say when to remove articles from the prefetch buffer. | |
| 60 Possible values in this list are `read', which means that | |
| 61 articles are removed as they are read, and `exit', which means | |
| 62 that all articles belonging to a group are removed on exit | |
| 63 from that group." | |
| 64 :group 'gnus-asynchronous | |
| 65 :type '(set (const read) (const exit))) | |
| 66 | |
| 67 (defcustom gnus-use-header-prefetch nil | |
| 68 "*If non-nil, prefetch the headers to the next group." | |
| 69 :group 'gnus-asynchronous | |
| 70 :type 'boolean) | |
| 71 | |
| 72 (defcustom gnus-async-prefetch-article-p 'gnus-async-unread-p | |
| 73 "Function called to say whether an article should be prefetched or not. | |
| 74 The function is called with one parameter -- the article data. | |
| 75 It should return non-nil if the article is to be prefetched." | |
| 76 :group 'gnus-asynchronous | |
| 77 :type 'function) | |
| 78 | |
| 79 ;;; Internal variables. | |
| 80 | |
| 81 (defvar gnus-async-prefetch-article-buffer " *Async Prefetch Article*") | |
| 82 (defvar gnus-async-article-alist nil) | |
| 83 (defvar gnus-async-article-semaphore '(nil)) | |
| 84 (defvar gnus-async-fetch-list nil) | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
85 (defvar gnus-async-hashtb nil) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
86 (defvar gnus-async-current-prefetch-group nil) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
87 (defvar gnus-async-current-prefetch-article nil) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
88 (defvar gnus-async-timer nil) |
| 17493 | 89 |
| 90 (defvar gnus-async-prefetch-headers-buffer " *Async Prefetch Headers*") | |
| 91 (defvar gnus-async-header-prefetched nil) | |
| 92 | |
| 93 ;;; Utility functions. | |
| 94 | |
| 95 (defun gnus-group-asynchronous-p (group) | |
| 96 "Say whether GROUP is fetched from a server that supports asynchronicity." | |
| 97 (gnus-asynchronous-p (gnus-find-method-for-group group))) | |
| 98 | |
| 99 ;;; Somewhat bogus semaphores. | |
| 100 | |
| 101 (defun gnus-async-get-semaphore (semaphore) | |
| 102 "Wait until SEMAPHORE is released." | |
| 103 (while (/= (length (nconc (symbol-value semaphore) (list nil))) 2) | |
| 104 (sleep-for 1))) | |
| 105 | |
| 106 (defun gnus-async-release-semaphore (semaphore) | |
| 107 "Release SEMAPHORE." | |
| 108 (setcdr (symbol-value semaphore) nil)) | |
| 109 | |
| 110 (defmacro gnus-async-with-semaphore (&rest forms) | |
| 111 `(unwind-protect | |
| 112 (progn | |
| 113 (gnus-async-get-semaphore 'gnus-async-article-semaphore) | |
| 114 ,@forms) | |
| 115 (gnus-async-release-semaphore 'gnus-async-article-semaphore))) | |
| 116 | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
117 (put 'gnus-async-with-semaphore 'lisp-indent-function 0) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
118 (put 'gnus-async-with-semaphore 'edebug-form-spec '(body)) |
| 17493 | 119 |
| 120 ;;; | |
| 121 ;;; Article prefetch | |
| 122 ;;; | |
| 123 | |
| 124 (gnus-add-shutdown 'gnus-async-close 'gnus) | |
| 125 (defun gnus-async-close () | |
| 126 (gnus-kill-buffer gnus-async-prefetch-article-buffer) | |
| 127 (gnus-kill-buffer gnus-async-prefetch-headers-buffer) | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
128 (setq gnus-async-hashtb nil |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
129 gnus-async-article-alist nil |
| 17493 | 130 gnus-async-header-prefetched nil)) |
| 131 | |
| 132 (defun gnus-async-set-buffer () | |
|
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
133 (nnheader-set-temp-buffer gnus-async-prefetch-article-buffer t) |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
134 (unless gnus-async-hashtb |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
135 (setq gnus-async-hashtb (gnus-make-hashtable 1023)))) |
| 17493 | 136 |
| 137 (defun gnus-async-halt-prefetch () | |
| 138 "Stop prefetching." | |
| 139 (setq gnus-async-fetch-list nil)) | |
| 140 | |
| 141 (defun gnus-async-prefetch-next (group article summary) | |
| 142 "Possibly prefetch several articles starting with the article after ARTICLE." | |
| 143 (when (and (gnus-buffer-live-p summary) | |
| 144 gnus-asynchronous | |
| 145 (gnus-group-asynchronous-p group)) | |
| 146 (save-excursion | |
| 147 (set-buffer gnus-summary-buffer) | |
| 148 (let ((next (caadr (gnus-data-find-list article)))) | |
| 149 (when next | |
| 150 (if (not (fboundp 'run-with-idle-timer)) | |
| 151 ;; This is either an older Emacs or XEmacs, so we | |
| 152 ;; do this, which leads to slightly slower article | |
| 153 ;; buffer display. | |
| 154 (gnus-async-prefetch-article group next summary) | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
155 (when gnus-async-timer |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
156 (ignore-errors |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
157 (nnheader-cancel-timer 'gnus-async-timer))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
158 (setq gnus-async-timer |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
159 (run-with-idle-timer |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
160 0.1 nil 'gnus-async-prefetch-article |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
161 group next summary)))))))) |
| 17493 | 162 |
| 163 (defun gnus-async-prefetch-article (group article summary &optional next) | |
| 164 "Possibly prefetch several articles starting with ARTICLE." | |
| 165 (if (not (gnus-buffer-live-p summary)) | |
| 166 (gnus-async-with-semaphore | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
167 (setq gnus-async-fetch-list nil)) |
| 17493 | 168 (when (and gnus-asynchronous |
| 169 (gnus-alive-p)) | |
| 170 (when next | |
| 171 (gnus-async-with-semaphore | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
172 (pop gnus-async-fetch-list))) |
| 17493 | 173 (let ((do-fetch next) |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
174 (do-message t)) ;(eq major-mode 'gnus-summary-mode))) |
| 17493 | 175 (when (and (gnus-group-asynchronous-p group) |
| 176 (gnus-buffer-live-p summary) | |
| 177 (or (not next) | |
| 178 gnus-async-fetch-list)) | |
| 179 (gnus-async-with-semaphore | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
180 (unless next |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
181 (setq do-fetch (not gnus-async-fetch-list)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
182 ;; Nix out any outstanding requests. |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
183 (setq gnus-async-fetch-list nil) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
184 ;; Fill in the new list. |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
185 (let ((n gnus-use-article-prefetch) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
186 (data (gnus-data-find-list article)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
187 d) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
188 (while (and (setq d (pop data)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
189 (if (numberp n) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
190 (natnump (decf n)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
191 n)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
192 (unless (or (gnus-async-prefetched-article-entry |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
193 group (setq article (gnus-data-number d))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
194 (not (natnump article)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
195 (not (funcall gnus-async-prefetch-article-p d))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
196 ;; Not already fetched -- so we add it to the list. |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
197 (push article gnus-async-fetch-list))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
198 (setq gnus-async-fetch-list |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
199 (nreverse gnus-async-fetch-list)))) |
| 17493 | 200 |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
201 (when do-fetch |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
202 (setq article (car gnus-async-fetch-list)))) |
| 17493 | 203 |
| 204 (when (and do-fetch article) | |
| 205 ;; We want to fetch some more articles. | |
| 206 (save-excursion | |
| 207 (set-buffer summary) | |
| 208 (let (mark) | |
| 209 (gnus-async-set-buffer) | |
| 210 (goto-char (point-max)) | |
| 211 (setq mark (point-marker)) | |
| 212 (let ((nnheader-callback-function | |
| 213 (gnus-make-async-article-function | |
| 214 group article mark summary next)) | |
| 215 (nntp-server-buffer | |
| 216 (get-buffer gnus-async-prefetch-article-buffer))) | |
| 217 (when do-message | |
| 218 (gnus-message 9 "Prefetching article %d in group %s" | |
| 219 article group)) | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
220 (setq gnus-async-current-prefetch-group group) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
221 (setq gnus-async-current-prefetch-article article) |
| 17493 | 222 (gnus-request-article article group)))))))))) |
| 223 | |
| 224 (defun gnus-make-async-article-function (group article mark summary next) | |
| 225 "Return a callback function." | |
| 226 `(lambda (arg) | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
227 (gnus-async-article-callback arg ,group ,article ,mark ,summary ,next))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
228 |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
229 (defun gnus-async-article-callback (arg group article mark summary next) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
230 "Function called when an async article is done being fetched." |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
231 (save-excursion |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
232 (setq gnus-async-current-prefetch-article nil) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
233 (when arg |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
234 (gnus-async-set-buffer) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
235 (gnus-async-with-semaphore |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
236 (setq |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
237 gnus-async-article-alist |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
238 (cons (list (intern (format "%s-%d" group article) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
239 gnus-async-hashtb) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
240 mark (set-marker (make-marker) (point-max)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
241 group article) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
242 gnus-async-article-alist)))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
243 (if (not (gnus-buffer-live-p summary)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
244 (gnus-async-with-semaphore |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
245 (setq gnus-async-fetch-list nil)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
246 (gnus-async-prefetch-article group next summary t)))) |
| 17493 | 247 |
| 248 (defun gnus-async-unread-p (data) | |
| 249 "Return non-nil if DATA represents an unread article." | |
| 250 (gnus-data-unread-p data)) | |
| 251 | |
| 252 (defun gnus-async-request-fetched-article (group article buffer) | |
| 253 "See whether we have ARTICLE from GROUP and put it in BUFFER." | |
| 254 (when (numberp article) | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
255 (when (and (equal group gnus-async-current-prefetch-group) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
256 (eq article gnus-async-current-prefetch-article)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
257 (gnus-async-wait-for-article article)) |
| 17493 | 258 (let ((entry (gnus-async-prefetched-article-entry group article))) |
| 259 (when entry | |
| 260 (save-excursion | |
| 261 (gnus-async-set-buffer) | |
| 262 (copy-to-buffer buffer (cadr entry) (caddr entry)) | |
| 263 ;; Remove the read article from the prefetch buffer. | |
| 264 (when (memq 'read gnus-prefetched-article-deletion-strategy) | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
265 (gnus-async-delete-prefetched-entry entry)) |
| 17493 | 266 t))))) |
| 267 | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
268 (defun gnus-async-wait-for-article (article) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
269 "Wait until ARTICLE is no longer the currently-being-fetched article." |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
270 (save-excursion |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
271 (gnus-async-set-buffer) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
272 (let ((proc (nntp-find-connection (current-buffer))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
273 (nntp-server-buffer (current-buffer)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
274 (nntp-have-messaged nil) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
275 (tries 0)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
276 (condition-case nil |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
277 ;; FIXME: we could stop waiting after some |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
278 ;; timeout, but this is the wrong place to do it. |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
279 ;; rather than checking time-spent-waiting, we |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
280 ;; should check time-since-last-output, which |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
281 ;; needs to be done in nntp.el. |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
282 (while (eq article gnus-async-current-prefetch-article) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
283 (incf tries) |
|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
284 (when (nntp-accept-process-output proc) |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
285 (setq tries 0)) |
|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
286 (when (and (not nntp-have-messaged) |
|
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
287 (= tries 3)) |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
288 (gnus-message 5 "Waiting for async article...") |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
289 (setq nntp-have-messaged t))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
290 (quit |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
291 ;; if the user interrupted on a slow/hung connection, |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
292 ;; do something friendly. |
|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
293 (when (> tries 3) |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
294 (setq gnus-async-current-prefetch-article nil)) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
295 (signal 'quit nil))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
296 (when nntp-have-messaged |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
297 (gnus-message 5 ""))))) |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
298 |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
299 (defun gnus-async-delete-prefetched-entry (entry) |
| 17493 | 300 "Delete ENTRY from buffer and alist." |
| 301 (ignore-errors | |
| 302 (delete-region (cadr entry) (caddr entry)) | |
| 303 (set-marker (cadr entry) nil) | |
| 304 (set-marker (caddr entry) nil)) | |
| 305 (gnus-async-with-semaphore | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
306 (setq gnus-async-article-alist |
|
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
307 (delq entry gnus-async-article-alist)))) |
| 17493 | 308 |
| 309 (defun gnus-async-prefetch-remove-group (group) | |
| 310 "Remove all articles belonging to GROUP from the prefetch buffer." | |
| 311 (when (and (gnus-group-asynchronous-p group) | |
| 312 (memq 'exit gnus-prefetched-article-deletion-strategy)) | |
| 313 (let ((alist gnus-async-article-alist)) | |
| 314 (save-excursion | |
| 315 (gnus-async-set-buffer) | |
| 316 (while alist | |
| 317 (when (equal group (nth 3 (car alist))) | |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
318 (gnus-async-delete-prefetched-entry (car alist))) |
| 17493 | 319 (pop alist)))))) |
| 320 | |
| 321 (defun gnus-async-prefetched-article-entry (group article) | |
| 322 "Return the entry for ARTICLE in GROUP iff it has been prefetched." | |
|
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
323 (let ((entry (save-excursion |
|
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
324 (gnus-async-set-buffer) |
|
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
325 (assq (intern (format "%s-%d" group article) |
|
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
326 gnus-async-hashtb) |
|
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
327 gnus-async-article-alist)))) |
| 17493 | 328 ;; Perhaps something has emptied the buffer? |
| 329 (if (and entry | |
| 330 (= (cadr entry) (caddr entry))) | |
| 331 (progn | |
| 332 (ignore-errors | |
| 333 (set-marker (cadr entry) nil) | |
| 334 (set-marker (caddr entry) nil)) | |
| 335 (setq gnus-async-article-alist | |
| 336 (delq entry gnus-async-article-alist)) | |
| 337 nil) | |
| 338 entry))) | |
| 339 | |
| 340 ;;; | |
| 341 ;;; Header prefetch | |
| 342 ;;; | |
| 343 | |
| 344 (defun gnus-async-prefetch-headers (group) | |
| 345 "Prefetch the headers for group GROUP." | |
| 346 (save-excursion | |
| 347 (let (unread) | |
| 348 (when (and gnus-use-header-prefetch | |
| 349 gnus-asynchronous | |
| 350 (gnus-group-asynchronous-p group) | |
| 351 (listp gnus-async-header-prefetched) | |
| 352 (setq unread (gnus-list-of-unread-articles group))) | |
| 353 ;; Mark that a fetch is in progress. | |
| 354 (setq gnus-async-header-prefetched t) | |
| 355 (nnheader-set-temp-buffer gnus-async-prefetch-headers-buffer t) | |
| 356 (erase-buffer) | |
| 357 (let ((nntp-server-buffer (current-buffer)) | |
| 358 (nnheader-callback-function | |
| 359 `(lambda (arg) | |
| 360 (setq gnus-async-header-prefetched | |
| 361 ,(cons group unread))))) | |
| 362 (gnus-retrieve-headers unread group gnus-fetch-old-headers)))))) | |
| 363 | |
| 364 (defun gnus-async-retrieve-fetched-headers (articles group) | |
| 365 "See whether we have prefetched headers." | |
| 366 (when (and gnus-use-header-prefetch | |
| 367 (gnus-group-asynchronous-p group) | |
| 368 (listp gnus-async-header-prefetched) | |
| 369 (equal group (car gnus-async-header-prefetched)) | |
| 370 (equal articles (cdr gnus-async-header-prefetched))) | |
| 371 (save-excursion | |
| 372 (nnheader-set-temp-buffer gnus-async-prefetch-headers-buffer t) | |
| 373 (nntp-decode-text) | |
| 374 (copy-to-buffer nntp-server-buffer (point-min) (point-max)) | |
| 375 (erase-buffer) | |
| 376 (setq gnus-async-header-prefetched nil) | |
| 377 t))) | |
| 378 | |
| 379 (provide 'gnus-async) | |
| 380 | |
| 52401 | 381 ;;; arch-tag: fee61de5-3ea2-4de6-8578-2f90ce89391d |
| 17493 | 382 ;;; gnus-async.el ends here |
