1 ;;; gnus-demon.el --- daemonic Gnus behavior
3 ;; Copyright (C) 1995-2011 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
27 (eval-when-compile (require 'cl))
35 (defgroup gnus-demon nil
39 (defcustom gnus-demon-handlers nil
40 "Alist of daemonic handlers to be run at intervals.
41 Each handler is a list on the form
45 FUNCTION is the function to be called. TIME is the number of
46 `gnus-demon-timestep's between each call.
47 If nil, never call. If t, call each `gnus-demon-timestep'.
49 If IDLE is t, only call each time Emacs has been idle for TIME.
50 If IDLE is a number, only call when Emacs has been idle more than
51 this number of `gnus-demon-timestep's.
52 If IDLE is nil, don't care about idleness.
53 If IDLE is a number and TIME is nil, then call once each time
54 Emacs has been idle for IDLE `gnus-demon-timestep's."
56 :type '(repeat (list function
58 (const :tag "never" nil)
60 (integer :tag "steps" 1))
62 (const :tag "don't care" nil)
63 (const :tag "for a while" t)
64 (integer :tag "steps" 1)))))
66 (defcustom gnus-demon-timestep 60
67 "Number of seconds in each demon timestep."
71 ;;; Internal variables.
73 (defvar gnus-demon-timers nil
74 "List of idle timers which are running.")
75 (defvar gnus-inhibit-demon nil
76 "If non-nil, no daemonic function will be run.")
80 (defun gnus-demon-add-handler (function time idle)
81 "Add the handler FUNCTION to be run at TIME and IDLE."
82 ;; First remove any old handlers that use this function.
83 (gnus-demon-remove-handler function)
84 ;; Then add the new one.
85 (push (list function time idle) gnus-demon-handlers)
88 (defun gnus-demon-remove-handler (function &optional no-init)