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