(gnus-group-tool-bar-gnome): Replace connect/disconnect with unplugged/plugged.
[gnus] / lisp / gnus-async.el
1 ;;; gnus-async.el --- asynchronous support for Gnus
2
3 ;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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 3 of the License, or
13 ;; (at your option) 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.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile (require 'cl))
28
29 (require 'gnus)
30 (require 'gnus-sum)
31 (require 'nntp)
32
33 (defgroup gnus-asynchronous nil
34   "Support for asynchronous operations."
35   :group 'gnus)
36
37 (defcustom gnus-use-article-prefetch 30
38   "*If non-nil, prefetch articles in groups that allow this.
39 If a number, prefetch only that many articles forward;
40 if t, prefetch as many articles as possible."
41   :group 'gnus-asynchronous
42   :type '(choice (const :tag "off" nil)
43                  (const :tag "all" t)
44                  (integer :tag "some" 0)))
45
46 (defcustom gnus-asynchronous nil
47   "*If nil, inhibit all Gnus asynchronicity.
48 If non-nil, let the other asynch variables be heeded."
49   :group 'gnus-asynchronous
50   :type 'boolean)
51
52 (defcustom gnus-prefetched-article-deletion-strategy '(read exit)
53   "List of symbols that say when to remove articles from the prefetch buffer.
54 Possible values in this list are `read', which means that
55 articles are removed as they are read, and `exit', which means
56 that all articles belonging to a group are removed on exit
57 from that group."
58   :group 'gnus-asynchronous
59   :type '(set (const read) (const exit)))
60
61 (defcustom gnus-use-header-prefetch nil
62   "*If non-nil, prefetch the headers to the next group."
63   :group 'gnus-asynchronous
64   :type 'boolean)
65
66 (defcustom gnus-async-prefetch-article-p 'gnus-async-unread-p
67   "Function called to say whether an article should be prefetched or not.
68 The function is called with one parameter -- the article data.
69 It should return non-nil if the article is to be prefetched."
70   :group 'gnus-asynchronous
71   :type 'function)
72
73 (defcustom gnus-async-post-fetch-function nil
74   "Function called after an article has been prefetched.
75 The function will be called narrowed to the region of the article
76 that was fetched."
77   :group 'gnus-asynchronous
78   :type 'function)
79
80 ;;; Internal variables.
81
82 (defvar gnus-async-prefetch-article-buffer " *Async Prefetch Article*")
83 (defvar gnus-async-article-alist nil)
84 (defvar gnus-async-article-semaphore '(nil))
85 (defvar gnus-async-fetch-list nil)
86 (defvar gnus-async-hashtb nil)
87 (defvar gnus-async-current-prefetch-group nil)
88 (defvar gnus-async-current-prefetch-article nil)
89 (defvar gnus-async-timer nil)
90
91 (defvar gnus-async-prefetch-headers-buffer " *Async Prefetch Headers*")
92 (defvar gnus-async-header-prefetched nil)
93
94 ;;; Utility functions.
95
96 (defun gnus-group-asynchronous-p (group)
97   "Say whether GROUP is fetched from a server that supports asynchronicity."
98   (gnus-asynchronous-p (gnus-find-method-for-group group)))
99
100 ;;; Somewhat bogus semaphores.
101
102 (defun gnus-async-get-semaphore (semaphore)
103   "Wait until SEMAPHORE is released."
104   (while (/= (length (nconc (symbol-value semaphore) (list nil))) 2)
105     (sleep-for 1)))
106
107 (defun gnus-async-release-semaphore (semaphore)
108   "Release SEMAPHORE."
109   (setcdr (symbol-value semaphore) nil))
110
111 (defmacro gnus-async-with-semaphore (&rest forms)
112   `(unwind-protect
113        (progn
114          (gnus-async-get-semaphore 'gnus-async-article-semaphore)
115          ,@forms)
116      (gnus-async-release-semaphore 'gnus-async-article-semaphore)))
117
118 (put 'gnus-async-with-semaphore 'lisp-indent-function 0)
119 (put 'gnus-async-with-semaphore 'edebug-form-spec '(body))
120
121 ;;;
122 ;;; Article prefetch
123 ;;;
124
125 (gnus-add-shutdown 'gnus-async-close 'gnus)