gnus: Daemons

 
 9.9 Daemons
 ===========
 
 Gnus, being larger than any program ever written (allegedly), does lots
 of strange stuff that you may wish to have done while you’re not
 present.  For instance, you may want it to check for new mail once in a
 while.  Or you may want it to close down all connections to all servers
 when you leave Emacs idle.  And stuff like that.
 
    Gnus will let you do stuff like that by defining various “handlers”.
 Each handler consists of three elements: A FUNCTION, a TIME, and an IDLE
 parameter.
 
    Here’s an example of a handler that closes connections when Emacs has
 been idle for thirty minutes:
 
      (gnus-demon-close-connections nil 30)
 
    Here’s a handler that scans for PGP headers every hour when Emacs is
 idle:
 
      (gnus-demon-scan-pgp 60 t)
 
    This TIME parameter and that IDLE parameter work together in a
 strange, but wonderful fashion.  Basically, if IDLE is ‘nil’, then the
 function will be called every TIME minutes.
 
    If IDLE is ‘t’, then the function will be called after TIME minutes
 only if Emacs is idle.  So if Emacs is never idle, the function will
 never be called.  But once Emacs goes idle, the function will be called
 every TIME minutes.
 
    If IDLE is a number and TIME is a number, the function will be called
 every TIME minutes only when Emacs has been idle for IDLE minutes.
 
    If IDLE is a number and TIME is ‘nil’, the function will be called
 once every time Emacs has been idle for IDLE minutes.
 
    And if TIME is a string, it should look like ‘07:31’, and the
 function will then be called once every day somewhere near that time.
 Modified by the IDLE parameter, of course.
 
    (When I say “minute” here, I really mean ‘gnus-demon-timestep’
 seconds.  This is 60 by default.  If you change that variable, all the
 timings in the handlers will be affected.)
 
    So, if you want to add a handler, you could put something like this
 in your ‘~/.gnus.el’ file:
 
      (gnus-demon-add-handler 'gnus-demon-close-connections 30 t)
 
    Some ready-made functions to do this have been created:
 ‘gnus-demon-add-disconnection’, ‘gnus-demon-add-nntp-close-connection’,
 ‘gnus-demon-add-scan-timestamps’, ‘gnus-demon-add-rescan’, and
 ‘gnus-demon-add-scanmail’.  Just put those functions in your
 ‘~/.gnus.el’ if you want those abilities.
 
    If you add handlers to ‘gnus-demon-handlers’ directly, you should run
 ‘gnus-demon-init’ to make the changes take hold.  To cancel all daemons,
 you can use the ‘gnus-demon-cancel’ function.
 
    Note that adding daemons can be pretty naughty if you over do it.
 Adding functions that scan all news and mail from all servers every two
 seconds is a sure-fire way of getting booted off any respectable system.
 So behave.