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