You can have Gnus check for new mail every 2 minutes:
(gnus-demon-add-handler 'gnus-demon-scan-news 2 t) ; this does a call to gnus-group-get-new-news (gnus-demon-init) ; this is redundant in No Gnus (e.g. Emacs23) since gnus-demon-add-handler does it for you
You don’t need to set any other variables nor load more files.
The parameters to gnus-demon-add-handler are:
Gnus demon is pretty smart, but it’s behavior is not properly documented. Here is how it works. Assume you set gnus-demon-timestep to 1 second, the TIME to 60 and IDLE to 5, then gnus will try to call your function every 60 seconds, but it will first check if you have been idle for 5 seconds. If so, it executes the function, if not, it sets the idle timer which is triggered first time you are idle for 5 sec. Once executed the one minute count starts again and gnus takes it all over again. Thus, you are pretty sure that the intervals between calls are not smaller than (60 sec) + (continuous work time) + (5 idle sec).
If you want to be notified of new and interesting mail, take a look at GnusNotify
Scanning all the news can be slow. If you want a fast scan only of the important lists (mail for example). Set the level of important groups to lower or equal to 3 and add this:
(defun gnus-demon-scan-news-3 () (let ((win (current-window-configuration)) (gnus-read-active-file 'some) (gnus-check-new-newsgroups nil) (gnus-verbose 2) (gnus-verbose-backends 5) (level 3) ) ;; (message "check-mail: %s" (format-time-string "%H:%M:%S")) (while-no-input (unwind-protect (save-window-excursion (when (gnus-alive-p) (with-current-buffer gnus-group-buffer (gnus-group-get-new-news level)))) (set-window-configuration win))))) (setq gnus-demon-timestep 10) (gnus-demon-add-handler 'gnus-demon-scan-news-3 12 1)
This checks your mail every 2 minutes on condition that you have been idle for 10 seconds. No check message is displayed and gnus is not stalling emacs (that is, on user input the process is aborted because of the while-no-input wraper).
(this doesn’t work with virtual groups (gnus bug), remove level in gnus-group-get-new-news call)
I’m thinking of adding something like:
(gnus-demon-add-handler 'gnus-group-save-newsrc 10 t)
Or could it be harmful?
On my laptop if I forgot to unplug Gnus before I went offline the demon would crash Emacs. This solves the problem.
(defadvice gnus-demon-scan-news (around gnus-demon-timeout activate) "Timeout for Gnus." (with-timeout (120 (message "Gnus timed out.")) ad-do-it))
Of course the length of the timeout should be set generously.