Gnus development mailing list
 help / color / mirror / Atom feed
From: Dan Christensen <jdc@uwo.ca>
To: ding@gnus.org
Subject: Re: IMAP IDLE command
Date: Mon, 29 Nov 2010 16:37:03 -0500	[thread overview]
Message-ID: <87sjyj4xs0.fsf@uwo.ca> (raw)
In-Reply-To: <87mxorrfem.fsf@kotik.lan>

You can get an external IDLE-aware program to notify Gnus using
emacsclient.  I used mail-notification for a while, and I've heard of
mswatch being used.

To avoid this happening while an IMAP command is already in progress, I
get emacsclient to call jdc-gnus-demon-scan-both below, which checks
the idle time.

One annoying thing: when emacsclient runs a function in emacs, it
seems to reset the idle time to zero.  So other things that you may
have set up to run after long idle times can get starved.  I don't
think this behaviour of emacs is correct:  unless there is human
interaction, I think emacs should be considered idle.

Dan


(defun jdc-gnus-demon-scan-both ()
  ; gnus-demon-idle-since returns the idle time in seconds as a float.
  ; These checks shouldn't be needed when this is run from gnus-demon, 
  ; but will help when it is run from ~/bin/mail-arrived.
  (when (and (not gnus-inhibit-demon)
	     (< 5 (gnus-demon-idle-since)))
    ; Setting gnus-inhibit-demon to t should prevent multiple occurrences from 
    ; running at once, either from mail-arrived or gnus-demon.  There is in 
    ; theory a race between the check above and setting the var below, but I 
    ; think emacs only allows context switches when waiting for
    ; output from a process.  In fact, if I cut and paste these into the shell:
    ;   emacsclient --no-wait --eval '(jdc-gnus-demon-scan-both)' &
    ;   emacsclient --no-wait --eval '(jdc-gnus-demon-scan-both)' &
    ; even without setting gnus-inhibit-demon to t here, still only one of 
    ; them does anything, probably because both the scan-mail and scan-news
    ; functions call functions that themselves inhibit the demon.  Still,
    ; better safe than sorry.
    (let ((gnus-inhibit-demon t))
      ; with-local-quit is used by gnus-demon, so do it here too for
      ; when we are called from mail-arrived:
      (with-local-quit
	(message "jdc-gnus-demon-scan-both running")
	(jdc-gnus-demon-scan-mail)
	(jdc-gnus-demon-scan-news)
	(message "jdc-gnus-demon-scan-both done")))))

; like stock function in gnus-demon.el, with a message, and also
; restricting to mail folders:  Hmm, the request-scan check seems to
; already limit to mainly mail servers, but also includes nnagent and
; nnweb.
(defun jdc-gnus-demon-scan-mail ()
  (interactive)
  (save-window-excursion
    (let ((servers gnus-opened-servers)
	  server
	  (nnmail-fetched-sources (list t)))
      (while (setq server (car (pop servers)))
	(and (member (car server) '(nnimap nnfolder nnml))
	     (gnus-check-backend-function 'request-scan (car server))
	     (or (gnus-server-opened server)
		 (gnus-open-server server))
	     (message "Scanning server: %s" server)
	     (gnus-request-scan nil server))))))

; like stock function, but limits to level <= 2.
; I think "news" is misleading; this is needed to update the 
; summary buffer when mail is fetched with jdc-gnus-demon-scan-mail.
; My version also has an extra save-excursion.
(defun jdc-gnus-demon-scan-news ()
  (interactive)
  (message "jdc-gnus-demon-scan-news running")
  (let ((win (current-window-configuration)))
    (unwind-protect
	(save-window-excursion
	  (when (gnus-alive-p)
	    (save-excursion
	      (with-current-buffer gnus-group-buffer
		(gnus-group-get-new-news 2)))))
      (set-window-configuration win))))




  reply	other threads:[~2010-11-29 21:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-28 17:09 Łukasz Stelmach
2010-11-28 17:31 ` Byung-Hee HWANG
2010-11-28 21:21   ` Łukasz Stelmach
2010-11-28 21:23   ` Łukasz Stelmach
2010-11-29  4:36 ` Lars Magne Ingebrigtsen
2010-11-29  5:10   ` Daniel Pittman
2010-11-29  6:21     ` Łukasz Stelmach
2010-11-29  7:38       ` Frank Schmitt
2010-11-29 21:25         ` Łukasz Stelmach
2010-11-29 21:37           ` Dan Christensen [this message]
2010-12-14 23:20     ` Ted Zlatanov
2010-12-15 19:34       ` Lars Magne Ingebrigtsen
2010-12-15 21:04         ` Ted Zlatanov
2010-11-29 21:39   ` Tibor Simko
2010-12-01  1:05     ` Łukasz Stelmach
2010-12-01  8:50       ` Steinar Bang
2010-12-02  0:12         ` Łukasz Stelmach
2010-12-02  9:07           ` Steinar Bang
2010-12-02 10:19             ` Łukasz Stelmach
2010-12-02 13:29               ` Steinar Bang
2010-12-02 18:25                 ` Łukasz Stelmach
2010-12-02 13:37               ` Julien Danjou
2010-12-02 18:13                 ` Łukasz Stelmach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sjyj4xs0.fsf@uwo.ca \
    --to=jdc@uwo.ca \
    --cc=ding@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).