Mercurial > emacs
annotate lisp/gnus/gnus-async.el @ 83228:2a3f27a45698
Merged in changes from CVS trunk.
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-694
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-695
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-696
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-697
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-698
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-699
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-700
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-701
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-702
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-703
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-704
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-705
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-706
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-707
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-708
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-709
Update from CVS: src/indent.c (Fvertical_motion): Fix last change.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-710
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-711
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-712
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-713
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-72
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-73
Merge from emacs--cvs-trunk--0
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-268
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Mon, 22 Nov 2004 11:06:39 +0000 |
parents | 55fd4f77387a |
children | 7503b2a24a3c cce1c0ee76ee |
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 | |
35 (defgroup gnus-asynchronous nil | |
36 "Support for asynchronous operations." | |
37 :group 'gnus) | |
38 | |
39 (defcustom gnus-use-article-prefetch 30 | |
40 "*If non-nil, prefetch articles in groups that allow this. | |
41 If a number, prefetch only that many articles forward; | |
42 if t, prefetch as many articles as possible." | |
43 :group 'gnus-asynchronous | |
44 :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
|
45 (const :tag "all" t) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
46 (integer :tag "some" 0))) |
17493 | 47 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
48 (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
|
49 "*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
|
50 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
|
51 :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
|
52 :type 'boolean) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
53 |
17493 | 54 (defcustom gnus-prefetched-article-deletion-strategy '(read exit) |
55 "List of symbols that say when to remove articles from the prefetch buffer. | |
56 Possible values in this list are `read', which means that | |
57 articles are removed as they are read, and `exit', which means | |
58 that all articles belonging to a group are removed on exit | |
59 from that group." | |
60 :group 'gnus-asynchronous | |
61 :type '(set (const read) (const exit))) | |
62 | |
63 (defcustom gnus-use-header-prefetch nil | |
64 "*If non-nil, prefetch the headers to the next group." | |
65 :group 'gnus-asynchronous | |
66 :type 'boolean) | |
67 | |
68 (defcustom gnus-async-prefetch-article-p 'gnus-async-unread-p | |
69 "Function called to say whether an article should be prefetched or not. | |
70 The function is called with one parameter -- the article data. | |
71 It should return non-nil if the article is to be prefetched." | |
72 :group 'gnus-asynchronous | |
73 :type 'function) | |
74 | |
75 ;;; Internal variables. | |
76 | |
77 (defvar gnus-async-prefetch-article-buffer " *Async Prefetch Article*") | |
78 (defvar gnus-async-article-alist nil) | |
79 (defvar gnus-async-article-semaphore '(nil)) | |
80 (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
|
81 (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
|
82 (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
|
83 (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
|
84 (defvar gnus-async-timer nil) |
17493 | 85 |
86 (defvar gnus-async-prefetch-headers-buffer " *Async Prefetch Headers*") | |
87 (defvar gnus-async-header-prefetched nil) | |
88 | |
89 ;;; Utility functions. | |
90 | |
91 (defun gnus-group-asynchronous-p (group) | |
92 "Say whether GROUP is fetched from a server that supports asynchronicity." | |
93 (gnus-asynchronous-p (gnus-find-method-for-group group))) | |
94 | |
95 ;;; Somewhat bogus semaphores. | |
96 | |
97 (defun gnus-async-get-semaphore (semaphore) | |
98 "Wait until SEMAPHORE is released." | |
99 (while (/= (length (nconc (symbol-value semaphore) (list nil))) 2) | |
100 (sleep-for 1))) | |
101 | |
102 (defun gnus-async-release-semaphore (semaphore) | |
103 "Release SEMAPHORE." | |
104 (setcdr (symbol-value semaphore) nil)) | |
105 | |
106 (defmacro gnus-async-with-semaphore (&rest forms) | |
107 `(unwind-protect | |
108 (progn | |
109 (gnus-async-get-semaphore 'gnus-async-article-semaphore) | |
110 ,@forms) | |
111 (gnus-async-release-semaphore 'gnus-async-article-semaphore))) | |
112 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
113 (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
|
114 (put 'gnus-async-with-semaphore 'edebug-form-spec '(body)) |
17493 | 115 |
116 ;;; | |
117 ;;; Article prefetch | |
118 ;;; | |
119 | |
120 (gnus-add-shutdown 'gnus-async-close 'gnus) | |
121 (defun gnus-async-close () | |
122 (gnus-kill-buffer gnus-async-prefetch-article-buffer) | |
123 (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
|
124 (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
|
125 gnus-async-article-alist nil |
17493 | 126 gnus-async-header-prefetched nil)) |
127 | |
128 (defun gnus-async-set-buffer () | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
129 (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
|
130 (unless gnus-async-hashtb |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
131 (setq gnus-async-hashtb (gnus-make-hashtable 1023)))) |
17493 | 132 |
133 (defun gnus-async-halt-prefetch () | |
134 "Stop prefetching." | |
135 (setq gnus-async-fetch-list nil)) | |
136 | |
137 (defun gnus-async-prefetch-next (group article summary) | |
138 "Possibly prefetch several articles starting with the article after ARTICLE." | |
139 (when (and (gnus-buffer-live-p summary) | |
140 gnus-asynchronous | |
141 (gnus-group-asynchronous-p group)) | |
142 (save-excursion | |
143 (set-buffer gnus-summary-buffer) | |
144 (let ((next (caadr (gnus-data-find-list article)))) | |
145 (when next | |
146 (if (not (fboundp 'run-with-idle-timer)) | |
147 ;; This is either an older Emacs or XEmacs, so we | |
148 ;; do this, which leads to slightly slower article | |
149 ;; buffer display. | |
150 (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
|
151 (when gnus-async-timer |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
152 (ignore-errors |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
153 (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
|
154 (setq gnus-async-timer |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
155 (run-with-idle-timer |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
156 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
|
157 group next summary)))))))) |
17493 | 158 |
159 (defun gnus-async-prefetch-article (group article summary &optional next) | |
160 "Possibly prefetch several articles starting with ARTICLE." | |
161 (if (not (gnus-buffer-live-p summary)) | |
162 (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
|
163 (setq gnus-async-fetch-list nil)) |
17493 | 164 (when (and gnus-asynchronous |
165 (gnus-alive-p)) | |
166 (when next | |
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 (pop gnus-async-fetch-list))) |
17493 | 169 (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
|
170 (do-message t)) ;(eq major-mode 'gnus-summary-mode))) |
17493 | 171 (when (and (gnus-group-asynchronous-p group) |
172 (gnus-buffer-live-p summary) | |
173 (or (not next) | |
174 gnus-async-fetch-list)) | |
175 (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
|
176 (unless next |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
177 (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
|
178 ;; 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
|
179 (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
|
180 ;; 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
|
181 (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
|
182 (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
|
183 d) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
184 (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
|
185 (if (numberp n) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
186 (natnump (decf n)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
187 n)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
188 (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
|
189 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
|
190 (not (natnump article)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
191 (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
|
192 ;; 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
|
193 (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
|
194 (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
|
195 (nreverse gnus-async-fetch-list)))) |
17493 | 196 |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
197 (when do-fetch |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
198 (setq article (car gnus-async-fetch-list)))) |
17493 | 199 |
200 (when (and do-fetch article) | |
201 ;; We want to fetch some more articles. | |
202 (save-excursion | |
203 (set-buffer summary) | |
204 (let (mark) | |
205 (gnus-async-set-buffer) | |
206 (goto-char (point-max)) | |
207 (setq mark (point-marker)) | |
208 (let ((nnheader-callback-function | |
209 (gnus-make-async-article-function | |
210 group article mark summary next)) | |
211 (nntp-server-buffer | |
212 (get-buffer gnus-async-prefetch-article-buffer))) | |
213 (when do-message | |
214 (gnus-message 9 "Prefetching article %d in group %s" | |
215 article group)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
216 (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
|
217 (setq gnus-async-current-prefetch-article article) |
17493 | 218 (gnus-request-article article group)))))))))) |
219 | |
220 (defun gnus-make-async-article-function (group article mark summary next) | |
221 "Return a callback function." | |
222 `(lambda (arg) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
223 (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
|
224 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
225 (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
|
226 "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
|
227 (save-excursion |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
228 (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
|
229 (when arg |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
230 (gnus-async-set-buffer) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
231 (gnus-async-with-semaphore |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
232 (setq |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
233 gnus-async-article-alist |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
234 (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
|
235 gnus-async-hashtb) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
236 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
|
237 group article) |
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 (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
|
240 (gnus-async-with-semaphore |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
241 (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
|
242 (gnus-async-prefetch-article group next summary t)))) |
17493 | 243 |
244 (defun gnus-async-unread-p (data) | |
245 "Return non-nil if DATA represents an unread article." | |
246 (gnus-data-unread-p data)) | |
247 | |
248 (defun gnus-async-request-fetched-article (group article buffer) | |
249 "See whether we have ARTICLE from GROUP and put it in BUFFER." | |
250 (when (numberp article) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
251 (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
|
252 (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
|
253 (gnus-async-wait-for-article article)) |
17493 | 254 (let ((entry (gnus-async-prefetched-article-entry group article))) |
255 (when entry | |
256 (save-excursion | |
257 (gnus-async-set-buffer) | |
258 (copy-to-buffer buffer (cadr entry) (caddr entry)) | |
259 ;; Remove the read article from the prefetch buffer. | |
260 (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
|
261 (gnus-async-delete-prefetched-entry entry)) |
17493 | 262 t))))) |
263 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
264 (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
|
265 "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
|
266 (save-excursion |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
267 (gnus-async-set-buffer) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
268 (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
|
269 (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
|
270 (nntp-have-messaged nil) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
271 (tries 0)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
272 (condition-case nil |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
273 ;; 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
|
274 ;; 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
|
275 ;; 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
|
276 ;; 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
|
277 ;; 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
|
278 (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
|
279 (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
|
280 (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
|
281 (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
|
282 (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
|
283 (= tries 3)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
284 (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
|
285 (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
|
286 (quit |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
287 ;; 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
|
288 ;; 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
|
289 (when (> tries 3) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
290 (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
|
291 (signal 'quit nil))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
292 (when nntp-have-messaged |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
293 (gnus-message 5 ""))))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
294 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
295 (defun gnus-async-delete-prefetched-entry (entry) |
17493 | 296 "Delete ENTRY from buffer and alist." |
297 (ignore-errors | |
298 (delete-region (cadr entry) (caddr entry)) | |
299 (set-marker (cadr entry) nil) | |
300 (set-marker (caddr entry) nil)) | |
301 (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
|
302 (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
|
303 (delq entry gnus-async-article-alist)))) |
17493 | 304 |
305 (defun gnus-async-prefetch-remove-group (group) | |
306 "Remove all articles belonging to GROUP from the prefetch buffer." | |
307 (when (and (gnus-group-asynchronous-p group) | |
308 (memq 'exit gnus-prefetched-article-deletion-strategy)) | |
309 (let ((alist gnus-async-article-alist)) | |
310 (save-excursion | |
311 (gnus-async-set-buffer) | |
312 (while alist | |
313 (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
|
314 (gnus-async-delete-prefetched-entry (car alist))) |
17493 | 315 (pop alist)))))) |
316 | |
317 (defun gnus-async-prefetched-article-entry (group article) | |
318 "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
|
319 (let ((entry (save-excursion |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
320 (gnus-async-set-buffer) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
321 (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
|
322 gnus-async-hashtb) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
22585
diff
changeset
|
323 gnus-async-article-alist)))) |
17493 | 324 ;; Perhaps something has emptied the buffer? |
325 (if (and entry | |
326 (= (cadr entry) (caddr entry))) | |
327 (progn | |
328 (ignore-errors | |
329 (set-marker (cadr entry) nil) | |
330 (set-marker (caddr entry) nil)) | |
331 (setq gnus-async-article-alist | |
332 (delq entry gnus-async-article-alist)) | |
333 nil) | |
334 entry))) | |
335 | |
336 ;;; | |
337 ;;; Header prefetch | |
338 ;;; | |
339 | |
340 (defun gnus-async-prefetch-headers (group) | |
341 "Prefetch the headers for group GROUP." | |
342 (save-excursion | |
343 (let (unread) | |
344 (when (and gnus-use-header-prefetch | |
345 gnus-asynchronous | |
346 (gnus-group-asynchronous-p group) | |
347 (listp gnus-async-header-prefetched) | |
348 (setq unread (gnus-list-of-unread-articles group))) | |
349 ;; Mark that a fetch is in progress. | |
350 (setq gnus-async-header-prefetched t) | |
351 (nnheader-set-temp-buffer gnus-async-prefetch-headers-buffer t) | |
352 (erase-buffer) | |
353 (let ((nntp-server-buffer (current-buffer)) | |
354 (nnheader-callback-function | |
355 `(lambda (arg) | |
356 (setq gnus-async-header-prefetched | |
357 ,(cons group unread))))) | |
358 (gnus-retrieve-headers unread group gnus-fetch-old-headers)))))) | |
359 | |
360 (defun gnus-async-retrieve-fetched-headers (articles group) | |
361 "See whether we have prefetched headers." | |
362 (when (and gnus-use-header-prefetch | |
363 (gnus-group-asynchronous-p group) | |
364 (listp gnus-async-header-prefetched) | |
365 (equal group (car gnus-async-header-prefetched)) | |
366 (equal articles (cdr gnus-async-header-prefetched))) | |
367 (save-excursion | |
368 (nnheader-set-temp-buffer gnus-async-prefetch-headers-buffer t) | |
369 (nntp-decode-text) | |
370 (copy-to-buffer nntp-server-buffer (point-min) (point-max)) | |
371 (erase-buffer) | |
372 (setq gnus-async-header-prefetched nil) | |
373 t))) | |
374 | |
375 (provide 'gnus-async) | |
376 | |
52401 | 377 ;;; arch-tag: fee61de5-3ea2-4de6-8578-2f90ce89391d |
17493 | 378 ;;; gnus-async.el ends here |