annotate lisp/gnus/gnus-demon.el @ 112034:6957ace4e43f

* doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files. Not yet enabled via auto-mode-list. (doc-view-unoconv-program): New custom variable. (doc-view-mode-p): Handle new odf document type. (doc-view-odf->pdf): New conversion function. (doc-view-convert-current-doc): Call it for odf files. (doc-view-mode): Recognize newly supported file extensions.
author Tassilo Horn <tassilo@member.fsf.org>
date Thu, 30 Dec 2010 14:45:09 +0100
parents c587007a09f2
children 417b1e4d63cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
96376
c3309dba6542 American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents: 94662
diff changeset
1 ;;; gnus-demon.el --- daemonic Gnus behavior
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
2
74547
183eba998a4d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 73269
diff changeset
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 104050
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
5
24357
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
7 ;; Keywords: news
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
8
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
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
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
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
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
15
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
20
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
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
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
23
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
24 ;;; Commentary:
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
25
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
26 ;;; Code:
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
27
19493
8d840c4548c0 Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents: 17493
diff changeset
28 (eval-when-compile (require 'cl))
8d840c4548c0 Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents: 17493
diff changeset
29
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
30 (require 'gnus)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
31 (require 'gnus-int)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
32 (require 'nnheader)
24357
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
33 (require 'nntp)
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
34 (require 'nnmail)
61304
a1964e18a9ba Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-234
Miles Bader <miles@gnu.org>
parents: 56927
diff changeset
35
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
36 (defgroup gnus-demon nil
79417
88b6f45cc12b (gnus-demon): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 78224
diff changeset
37 "Demonic behavior."
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
38 :group 'gnus)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
39
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
40 (defcustom gnus-demon-handlers nil
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
41 "Alist of daemonic handlers to be run at intervals.
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
42 Each handler is a list on the form
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
43
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
44 \(FUNCTION TIME IDLE)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
45
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
46 FUNCTION is the function to be called. TIME is the number of
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
47 `gnus-demon-timestep's between each call.
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
48 If nil, never call. If t, call each `gnus-demon-timestep'.
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
49
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
50 If IDLE is t, only call each time Emacs has been idle for TIME.
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
51 If IDLE is a number, only call when Emacs has been idle more than
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
52 this number of `gnus-demon-timestep's.
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
53 If IDLE is nil, don't care about idleness.
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
54 If IDLE is a number and TIME is nil, then call once each time
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
55 Emacs has been idle for IDLE `gnus-demon-timestep's."
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
56 :group 'gnus-demon
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
57 :type '(repeat (list function
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
58 (choice :tag "Time"
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
59 (const :tag "never" nil)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
60 (const :tag "one" t)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
61 (integer :tag "steps" 1))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
62 (choice :tag "Idle"
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
63 (const :tag "don't care" nil)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
64 (const :tag "for a while" t)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
65 (integer :tag "steps" 1)))))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
66
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
67 (defcustom gnus-demon-timestep 60
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
68 "Number of seconds in each demon timestep."
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
69 :group 'gnus-demon
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
70 :type 'integer)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
71
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
72 ;;; Internal variables.
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
73
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
74 (defvar gnus-demon-timers nil
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
75 "List of idle timers which are running.")
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
76 (defvar gnus-inhibit-demon nil
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
77 "If non-nil, no daemonic function will be run.")
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
78
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
79 ;;; Functions.
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
80
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
81 (defun gnus-demon-add-handler (function time idle)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
82 "Add the handler FUNCTION to be run at TIME and IDLE."
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
83 ;; First remove any old handlers that use this function.
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
84 (gnus-demon-remove-handler function)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
85 ;; Then add the new one.
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
86 (push (list function time idle) gnus-demon-handlers)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
87 (gnus-demon-init))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
88
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
89 (defun gnus-demon-remove-handler (function &optional no-init)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
90 "Remove the handler FUNCTION from the list of handlers."
110859
7aa4fdb60d57 shr.el (shr-insert): Don't insert double spaces.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110583
diff changeset
91 (gnus-alist-pull function gnus-demon-handlers)
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
92 (unless no-init
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
93 (gnus-demon-init)))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
94
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
95 (defun gnus-demon-idle-since ()
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
96 "Return the number of seconds since when Emacs is idle."
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
97 (if (featurep 'xemacs)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
98 (itimer-time-difference (current-time) last-command-event-time)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
99 (float-time (or (current-idle-time)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
100 '(0 0 0)))))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
101
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
102 (defun gnus-demon-run-callback (func &optional idle)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
103 "Run FUNC if Emacs has been idle for longer than IDLE seconds."
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
104 (unless gnus-inhibit-demon
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
105 (when (or (not idle)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
106 (<= idle (gnus-demon-idle-since)))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
107 (with-local-quit
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
108 (ignore-errors
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
109 (funcall func))))))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
110
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
111 (defun gnus-demon-init ()
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
112 "Initialize the Gnus daemon."
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
113 (interactive)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
114 (gnus-demon-cancel)
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
115 (dolist (handler gnus-demon-handlers)
24357
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
116 ;; Set up the timer.
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
117 (let* ((func (nth 0 handler))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
118 (time (nth 1 handler))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
119 (idle (nth 2 handler))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
120 ;; Compute time according with timestep.
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
121 ;; If t, replace by 1
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
122 (time (cond ((eq time t)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
123 gnus-demon-timestep)
111812
5e488dbb17f7 nnir.el: Rearrange code to allow macros to be autoloaded by gnus-sum.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 111811
diff changeset
124 ((null time) nil)
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
125 (t (* time gnus-demon-timestep))))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
126 (timer
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
127 (cond
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
128 ;; (func number t)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
129 ;; Call when Emacs has been idle for `time'
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
130 ((and (numberp time) (eq idle t))
111855
c587007a09f2 gnus-demon.el (gnus-demon-init): Call run-with-timer with time as argument, not t. XEmacs does not support that.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 111812
diff changeset
131 (run-with-timer time time 'gnus-demon-run-callback func time))
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
132 ;; (func number number)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
133 ;; Call every `time' when Emacs has been idle for `idle'
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
134 ((and (numberp time) (numberp idle))
111855
c587007a09f2 gnus-demon.el (gnus-demon-init): Call run-with-timer with time as argument, not t. XEmacs does not support that.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 111812
diff changeset
135 (run-with-timer time time 'gnus-demon-run-callback func idle))
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
136 ;; (func nil number)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
137 ;; Only call when Emacs has been idle for `idle'
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
138 ((and (null time) (numberp idle))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
139 (run-with-idle-timer (* idle gnus-demon-timestep) t
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
140 'gnus-demon-run-callback func))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
141 ;; (func number nil)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
142 ;; Call every `time'
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
143 ((and (numberp time) (null idle))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
144 (run-with-timer t time 'gnus-demon-run-callback func)))))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
145 (when timer
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
146 (add-to-list 'gnus-demon-timers timer)))))
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
147
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
148 (gnus-add-shutdown 'gnus-demon-cancel 'gnus)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
149
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
150 (defun gnus-demon-cancel ()
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
151 "Cancel any Gnus daemons."
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
152 (interactive)
111180
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
153 (dolist (timer gnus-demon-timers)
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
154 (nnheader-cancel-timer timer))
2009890b5ebf gnus-util.el: Remove `gnus-with-local-quit'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110859
diff changeset
155 (setq gnus-demon-timers nil))
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
156
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
157 (defun gnus-demon-add-disconnection ()
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
158 "Add daemonic server disconnection to Gnus."
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
159 (gnus-demon-add-handler 'gnus-demon-close-connections nil 30))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
160
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
161 (defun gnus-demon-close-connections ()
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
162 (save-window-excursion
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
163 (gnus-close-backends)))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
164
24357
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
165 (defun gnus-demon-add-nntp-close-connection ()
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
166 "Add daemonic nntp server disconnection to Gnus.
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
167 If no commands have gone out via nntp during the last five
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
168 minutes, the connection is closed."
104050
8ee742481c0a (gnus-demon-add-nntp-close-connection): Fix typo. (Bug#3903)
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
169 (gnus-demon-add-handler 'gnus-demon-nntp-close-connection 5 nil))
24357
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
170
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
171 (defun gnus-demon-nntp-close-connection ()
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
172 (save-window-excursion
31716
9968f55ad26e Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents: 24357
diff changeset
173 (when (time-less-p '(0 300) (time-since nntp-last-command-time))
24357
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
174 (nntp-close-server))))
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
175
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
176 (defun gnus-demon-add-scanmail ()
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
177 "Add daemonic scanning of mail from the mail backends."
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
178 (gnus-demon-add-handler 'gnus-demon-scan-mail 120 60))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
179
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
180 (defun gnus-demon-scan-mail ()
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
181 (save-window-excursion
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
182 (let ((servers gnus-opened-servers)
31716
9968f55ad26e Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents: 24357
diff changeset
183 server
9968f55ad26e Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents: 24357
diff changeset
184 (nnmail-fetched-sources (list t)))
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
185 (while (setq server (car (pop servers)))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
186 (and (gnus-check-backend-function 'request-scan (car server))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
187 (or (gnus-server-opened server)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
188 (gnus-open-server server))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
189 (gnus-request-scan nil server))))))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
190
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
191 (defun gnus-demon-add-rescan ()
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
192 "Add daemonic scanning of new articles from all backends."
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
193 (gnus-demon-add-handler 'gnus-demon-scan-news 120 60))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
194
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
195 (defun gnus-demon-scan-news ()
24357
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
196 (let ((win (current-window-configuration)))
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
197 (unwind-protect
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
198 (save-window-excursion
110410
f2e111723c3a Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110102
diff changeset
199 (when (gnus-alive-p)
f2e111723c3a Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110102
diff changeset
200 (with-current-buffer gnus-group-buffer
f2e111723c3a Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110102
diff changeset
201 (gnus-group-get-new-news))))
24357
15fc6acbae7a Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 19969
diff changeset
202 (set-window-configuration win))))
17493
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
203
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
204 (defun gnus-demon-add-scan-timestamps ()
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
205 "Add daemonic updating of timestamps in empty newgroups."
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
206 (gnus-demon-add-handler 'gnus-demon-scan-timestamps nil 30))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
207
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
208 (defun gnus-demon-scan-timestamps ()
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
209 "Set the timestamp on all newsgroups with no unread and no ticked articles."
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
210 (when (gnus-alive-p)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
211 (let ((cur-time (current-time))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
212 (newsrc (cdr gnus-newsrc-alist))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
213 info group unread has-ticked)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
214 (while (setq info (pop newsrc))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
215 (setq group (gnus-info-group info)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
216 unread (gnus-group-unread group)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
217 has-ticked (cdr (assq 'tick (gnus-info-marks info))))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
218 (when (and (numberp unread)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
219 (= unread 0)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
220 (not has-ticked))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
221 (gnus-group-set-parameter group 'timestamp cur-time))))))
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
222
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
223 (provide 'gnus-demon)
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
224
e6935c08cf0b Initial revision
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
diff changeset
225 ;;; gnus-demon.el ends here