* gnus.el (gnus-other-frame-function): New user option.
[gnus] / lisp / gnus-demon.el
index 431eb32..2c73b37 100644 (file)
@@ -1,7 +1,9 @@
 ;;; gnus-demon.el --- daemonic Gnus behaviour
-;; Copyright (C) 1995,96 Free Software Foundation, Inc.
 
-;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
+;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
+;;      Free Software Foundation, Inc.
+
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Keywords: news
 
 ;; This file is part of GNU Emacs.
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
+
 (require 'gnus)
+(require 'gnus-int)
+(require 'nnheader)
+(require 'nntp)
+(require 'nnmail)
+(require 'gnus-util)
+(eval-and-compile
+  (if (featurep 'xemacs)
+      (require 'itimer)
+    (require 'timer)))
 
-(eval-when-compile (require 'cl))
+(defgroup gnus-demon nil
+  "Demonic behaviour."
+  :group 'gnus)
 
-(defvar gnus-demon-handlers nil
+(defcustom gnus-demon-handlers nil
   "Alist of daemonic handlers to be run at intervals.
 Each handler is a list on the form
 
 \(FUNCTION TIME IDLE)
 
-FUNCTION is the function to be called. 
-TIME is the number of `gnus-demon-timestep's between each call.  
+FUNCTION is the function to be called.
+TIME is the number of `gnus-demon-timestep's between each call.
 If nil, never call.  If t, call each `gnus-demon-timestep'.
 If IDLE is t, only call if Emacs has been idle for a while.  If IDLE
 is a number, only call when Emacs has been idle more than this number
 of `gnus-demon-timestep's.  If IDLE is nil, don't care about
 idleness.  If IDLE is a number and TIME is nil, then call once each
-time Emacs has been idle for IDLE `gnus-demon-timestep's.")
-
-(defvar gnus-demon-timestep 60
-  "*Number of seconds in each demon timestep.")
+time Emacs has been idle for IDLE `gnus-demon-timestep's."
+  :group 'gnus-demon
+  :type '(repeat (list function
+                      (choice :tag "Time"
+                              (const :tag "never" nil)
+                              (const :tag "one" t)
+                              (integer :tag "steps" 1))
+                      (choice :tag "Idle"
+                              (const :tag "don't care" nil)
+                              (const :tag "for a while" t)
+                              (integer :tag "steps" 1)))))
+
+(defcustom gnus-demon-timestep 60
+  "*Number of seconds in each demon timestep."
+  :group 'gnus-demon
+  :type 'integer)
 
 ;;; Internal variables.
 
@@ -53,12 +80,9 @@ time Emacs has been idle for IDLE `gnus-demon-timestep's.")
 (defvar gnus-demon-idle-has-been-called nil)
 (defvar gnus-demon-idle-time 0)
 (defvar gnus-demon-handler-state nil)
-(defvar gnus-demon-is-idle nil)
-(defvar gnus-demon-last-keys nil) 
-
-(eval-and-compile
-  (autoload 'timezone-parse-date "timezone")
-  (autoload 'timezone-make-arpa-date "timezone"))
+(defvar gnus-demon-last-keys nil)
+(defvar gnus-inhibit-demon nil
+  "*If non-nil, no daemonic function will be run.")
 
 ;;; Functions.
 
@@ -72,41 +96,41 @@ time Emacs has been idle for IDLE `gnus-demon-timestep's.")
 
 (defun gnus-demon-remove-handler (function &optional no-init)
   "Remove the handler FUNCTION from the list of handlers."
-  (setq gnus-demon-handlers 
-       (delq (assq function gnus-demon-handlers)
-             gnus-demon-handlers))
-  (or no-init (gnus-demon-init)))
+  (gnus-pull function gnus-demon-handlers)
+  (unless no-init
+    (gnus-demon-init)))
 
 (defun gnus-demon-init ()
   "Initialize the Gnus daemon."
   (interactive)
   (gnus-demon-cancel)
-  (if (null gnus-demon-handlers)
-      () ; Nothing to do.
-    ;; Set up timer.
-    (setq gnus-demon-timer 
-         (nnheader-run-at-time 
+  (when gnus-demon-handlers
+    ;; Set up the timer.
+    (setq gnus-demon-timer
+         (nnheader-run-at-time
           gnus-demon-timestep gnus-demon-timestep 'gnus-demon))
     ;; Reset control variables.
     (setq gnus-demon-handler-state
-         (mapcar 
+         (mapcar
           (lambda (handler)
             (list (car handler) (gnus-demon-time-to-step (nth 1 handler))
                   (nth 2 handler)))
           gnus-demon-handlers))