annotate lisp/gnus/gnus-async.el @ 30:ec9a17fef872 r19-15b98

Import from CVS: tag r19-15b98
author cvs
date Mon, 13 Aug 2007 08:52:29 +0200
parents 0293115a14e9
children e04119814345
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
1 ;;; gnus-async.el --- asynchronous support for Gnus
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
3
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
5 ;; Keywords: news
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
6
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
8
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
12 ;; any later version.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
13
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
18
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
23
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
24 ;;; Commentary:
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
25
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
26 ;;; Code:
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
27
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
28 (require 'gnus)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
29 (require 'gnus-sum)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
30 (require 'nntp)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
31
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
32 (defgroup gnus-asynchronous nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
33 "Support for asynchronous operations."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
34 :group 'gnus)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
35
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
36 (defcustom gnus-asynchronous t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
37 "*If nil, inhibit all Gnus asynchronicity.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
38 If non-nil, let the other asynch variables be heeded."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
39 :group 'gnus-asynchronous
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
40 :type 'boolean)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
41
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
42 (defcustom gnus-use-article-prefetch 30
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
43 "*If non-nil, prefetch articles in groups that allow this.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
44 If a number, prefetch only that many articles forward;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
45 if t, prefetch as many articles as possible."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
46 :group 'gnus-asynchronous
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
47 :type '(choice (const :tag "off" nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
48 (const :tag "all" t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
49 (integer :tag "some" 0)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
50
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
51 (defcustom gnus-prefetched-article-deletion-strategy '(read exit)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
52 "List of symbols that say when to remove articles from the prefetch buffer.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
53 Possible values in this list are `read', which means that
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
54 articles are removed as they are read, and `exit', which means
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
55 that all articles belonging to a group are removed on exit
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
56 from that group."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
57 :group 'gnus-asynchronous
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
58 :type '(set (const read) (const exit)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
59
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
60 (defcustom gnus-use-header-prefetch nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
61 "*If non-nil, prefetch the headers to the next group."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
62 :group 'gnus-asynchronous
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
63 :type 'boolean)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
64
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
65 (defcustom gnus-async-prefetch-article-p 'gnus-async-unread-p
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
66 "Function called to say whether an article should be prefetched or not.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
67 The function is called with one parameter -- the article data.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
68 It should return non-nil if the article is to be prefetched."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
69 :group 'gnus-asynchronous
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
70 :type 'function)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
71
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
72 ;;; Internal variables.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
73
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
74 (defvar gnus-async-prefetch-article-buffer " *Async Prefetch Article*")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
75 (defvar gnus-async-article-alist nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
76 (defvar gnus-async-article-semaphore '(nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
77 (defvar gnus-async-fetch-list nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
78
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
79 (defvar gnus-async-prefetch-headers-buffer " *Async Prefetch Headers*")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
80 (defvar gnus-async-header-prefetched nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
81
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
82 ;;; Utility functions.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
83
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
84 (defun gnus-group-asynchronous-p (group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
85 "Say whether GROUP is fetched from a server that supports asynchronicity."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
86 (gnus-asynchronous-p (gnus-find-method-for-group group)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
87
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
88 ;;; Somewhat bogus semaphores.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
89
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
90 (defun gnus-async-get-semaphore (semaphore)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
91 "Wait until SEMAPHORE is released."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
92 (while (/= (length (nconc (symbol-value semaphore) (list nil))) 2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
93 (sleep-for 1)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
94
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
95 (defun gnus-async-release-semaphore (semaphore)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
96 "Release SEMAPHORE."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
97 (setcdr (symbol-value semaphore) nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
98
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
99 (defmacro gnus-async-with-semaphore (&rest forms)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
100 `(unwind-protect
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
101 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
102 (gnus-async-get-semaphore 'gnus-async-article-semaphore)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
103 ,@forms)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
104 (gnus-async-release-semaphore 'gnus-async-article-semaphore)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
105
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
106 (put 'gnus-asynch-with-semaphore 'lisp-indent-function 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
107 (put 'gnus-asynch-with-semaphore 'edebug-form-spec '(body))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
108
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
109 ;;;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
110 ;;; Article prefetch
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
111 ;;;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
112
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
113 (gnus-add-shutdown 'gnus-async-close 'gnus)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
114 (defun gnus-async-close ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
115 (gnus-kill-buffer gnus-async-prefetch-article-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
116 (gnus-kill-buffer gnus-async-prefetch-headers-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
117 (setq gnus-async-article-alist nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
118 gnus-async-header-prefetched nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
119
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
120 (defun gnus-async-set-buffer ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
121 (nnheader-set-temp-buffer gnus-async-prefetch-article-buffer t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
122
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
123 (defun gnus-async-halt-prefetch ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
124 "Stop prefetching."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
125 (setq gnus-async-fetch-list nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
126
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
127 (defun gnus-async-prefetch-next (group article summary)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
128 "Possibly prefetch several articles starting with the article after ARTICLE."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
129 (when (and (gnus-buffer-live-p summary)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
130 gnus-asynchronous
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
131 (gnus-group-asynchronous-p group))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
132 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
133 (set-buffer gnus-summary-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
134 (let ((next (caadr (gnus-data-find-list article))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
135 (when next
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
136 (if (not (fboundp 'run-with-idle-timer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
137 ;; This is either an older Emacs or XEmacs, so we
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
138 ;; do this, which leads to slightly slower article
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
139 ;; buffer display.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
140 (gnus-async-prefetch-article group next summary)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
141 (run-with-idle-timer
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
142 0.1 nil 'gnus-async-prefetch-article group next summary)))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
143
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
144 (defun gnus-async-prefetch-article (group article summary &optional next)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
145 "Possibly prefetch several articles starting with ARTICLE."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
146 (if (not (gnus-buffer-live-p summary))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
147 (gnus-async-with-semaphore
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
148 (setq gnus-async-fetch-list nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
149 (when (and gnus-asynchronous
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
150 (gnus-alive-p))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
151 (when next
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
152 (gnus-async-with-semaphore
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
153 (pop gnus-async-fetch-list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
154 (let ((do-fetch next)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
155 (do-message t)) ;(eq major-mode 'gnus-summary-mode)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
156 (when (and (gnus-group-asynchronous-p group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
157 (gnus-buffer-live-p summary)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
158 (or (not next)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
159 gnus-async-fetch-list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
160 (gnus-async-with-semaphore
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
161 (unless next
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
162 (setq do-fetch (not gnus-async-fetch-list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
163 ;; Nix out any outstanding requests.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
164 (setq gnus-async-fetch-list nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
165 ;; Fill in the new list.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
166 (let ((n gnus-use-article-prefetch)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
167 (data (gnus-data-find-list article))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
168 d)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
169 (while (and (setq d (pop data))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
170 (if (numberp n)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
171 (natnump (decf n))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
172 n))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
173 (unless (or (gnus-async-prefetched-article-entry
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
174 group (setq article (gnus-data-number d)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
175 (not (natnump article))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
176 (not (funcall gnus-async-prefetch-article-p d)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
177 ;; Not already fetched -- so we add it to the list.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
178 (push article gnus-async-fetch-list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
179 (setq gnus-async-fetch-list
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
180 (nreverse gnus-async-fetch-list))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
181
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
182 (when do-fetch
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
183 (setq article (car gnus-async-fetch-list))))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
184
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
185 (when (and do-fetch article)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
186 ;; We want to fetch some more articles.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
187 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
188 (set-buffer summary)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
189 (let (mark)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
190 (gnus-async-set-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
191 (goto-char (point-max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
192 (setq mark (point-marker))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
193 (let ((nnheader-callback-function
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
194 (gnus-make-async-article-function
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
195 group article mark summary next))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
196 (nntp-server-buffer
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
197 (get-buffer gnus-async-prefetch-article-buffer)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
198 (when do-message
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
199 (gnus-message 7 "Prefetching article %d in group %s"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
200 article group))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
201 (gnus-request-article article group))))))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
202
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
203 (defun gnus-make-async-article-function (group article mark summary next)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
204 "Return a callback function."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
205 `(lambda (arg)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
206 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
207 (when arg
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
208 (gnus-async-set-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
209 (gnus-async-with-semaphore
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
210 (push (list ',(intern (format "%s-%d" group article))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
211 ,mark (set-marker (make-marker) (point-max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
212 ,group ,article)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
213 gnus-async-article-alist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
214 (if (not (gnus-buffer-live-p ,summary))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
215 (gnus-async-with-semaphore
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
216 (setq gnus-async-fetch-list nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
217 (gnus-async-prefetch-article ,group ,next ,summary t)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
218
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
219 (defun gnus-async-unread-p (data)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
220 "Return non-nil if DATA represents an unread article."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
221 (gnus-data-unread-p data))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
222
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
223 (defun gnus-async-request-fetched-article (group article buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
224 "See whether we have ARTICLE from GROUP and put it in BUFFER."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
225 (when (numberp article)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
226 (let ((entry (gnus-async-prefetched-article-entry group article)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
227 (when entry
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
228 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
229 (gnus-async-set-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
230 (copy-to-buffer buffer (cadr entry) (caddr entry))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
231 ;; Remove the read article from the prefetch buffer.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
232 (when (memq 'read gnus-prefetched-article-deletion-strategy)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
233 (gnus-async-delete-prefected-entry entry))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
234 t)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
235
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
236 (defun gnus-async-delete-prefected-entry (entry)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
237 "Delete ENTRY from buffer and alist."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
238 (ignore-errors
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
239 (delete-region (cadr entry) (caddr entry))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
240 (set-marker (cadr entry) nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
241 (set-marker (caddr entry) nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
242 (gnus-async-with-semaphore
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
243 (setq gnus-async-article-alist
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
244 (delq entry gnus-async-article-alist))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
245
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
246 (defun gnus-async-prefetch-remove-group (group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
247 "Remove all articles belonging to GROUP from the prefetch buffer."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
248 (when (and (gnus-group-asynchronous-p group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
249 (memq 'exit gnus-prefetched-article-deletion-strategy))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
250 (let ((alist gnus-async-article-alist))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
251 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
252 (gnus-async-set-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
253 (while alist
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
254 (when (equal group (nth 3 (car alist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
255 (gnus-async-delete-prefected-entry (car alist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
256 (pop alist))))))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
257
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
258 (defun gnus-async-prefetched-article-entry (group article)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
259 "Return the entry for ARTICLE in GROUP iff it has been prefetched."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
260 (let ((entry (assq (intern (format "%s-%d" group article))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
261 gnus-async-article-alist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
262 ;; Perhaps something has emptied the buffer?
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
263 (if (and entry
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
264 (= (cadr entry) (caddr entry)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
265 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
266 (ignore-errors
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
267 (set-marker (cadr entry) nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
268 (set-marker (caddr entry) nil))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
269 (setq gnus-async-article-alist
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
270 (delq entry gnus-async-article-alist))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
271 nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
272 entry)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
273
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
274 ;;;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
275 ;;; Header prefetch
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
276 ;;;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
277
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
278 (defun gnus-async-prefetch-headers (group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
279 "Prefetch the headers for group GROUP."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
280 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
281 (let (unread)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
282 (when (and gnus-use-header-prefetch
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
283 gnus-asynchronous
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
284 (gnus-group-asynchronous-p group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
285 (listp gnus-async-header-prefetched)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
286 (setq unread (gnus-list-of-unread-articles group)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
287 ;; Mark that a fetch is in progress.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
288 (setq gnus-async-header-prefetched t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
289 (nnheader-set-temp-buffer gnus-async-prefetch-headers-buffer t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
290 (erase-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
291 (let ((nntp-server-buffer (current-buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
292 (nnheader-callback-function
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
293 `(lambda (arg)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
294 (setq gnus-async-header-prefetched
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
295 ,(cons group unread)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
296 (gnus-retrieve-headers unread group gnus-fetch-old-headers))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
297
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
298 (defun gnus-async-retrieve-fetched-headers (articles group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
299 "See whether we have prefetched headers."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
300 (when (and gnus-use-header-prefetch
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
301 (gnus-group-asynchronous-p group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
302 (listp gnus-async-header-prefetched)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
303 (equal group (car gnus-async-header-prefetched))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
304 (equal articles (cdr gnus-async-header-prefetched)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
305 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
306 (nnheader-set-temp-buffer gnus-async-prefetch-headers-buffer t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
307 (nntp-decode-text)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
308 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
309 (erase-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
310 (setq gnus-async-header-prefetched nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
311 t)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
312
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
313 (provide 'gnus-async)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
314
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
315 ;;; gnus-async.el ends here