From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.user/14401 Path: news.gmane.org!not-for-mail From: Philipp Haselwarter Newsgroups: gmane.emacs.gnus.user Subject: Re: Gnus and new mail notification Date: Sat, 25 Dec 2010 14:10:11 +0100 Message-ID: <87aajuhubw.fsf@nzebook.haselwarter.org> References: <87y67evj9j.fsf@savara.sat.thregr.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI" X-Trace: dough.gmane.org 1293282629 30598 80.91.229.12 (25 Dec 2010 13:10:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 25 Dec 2010 13:10:29 +0000 (UTC) To: info-gnus-english@gnu.org Original-X-From: info-gnus-english-bounces+gegu-info-gnus-english=m.gmane.org@gnu.org Sat Dec 25 14:10:25 2010 Return-path: Envelope-to: gegu-info-gnus-english@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PWTtB-0003u7-38 for gegu-info-gnus-english@m.gmane.org; Sat, 25 Dec 2010 14:10:25 +0100 Original-Received: from localhost ([127.0.0.1]:55877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PWTtA-0006Ou-2S for gegu-info-gnus-english@m.gmane.org; Sat, 25 Dec 2010 08:10:24 -0500 Original-Received: from [140.186.70.92] (port=35034 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PWTt5-0006Om-J1 for info-gnus-english@gnu.org; Sat, 25 Dec 2010 08:10:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PWTt3-0000WS-Sp for info-gnus-english@gnu.org; Sat, 25 Dec 2010 08:10:19 -0500 Original-Received: from mailout-de.gmx.net ([213.165.64.23]:50887 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PWTt3-0000Vq-CM for info-gnus-english@gnu.org; Sat, 25 Dec 2010 08:10:17 -0500 Original-Received: (qmail invoked by alias); 25 Dec 2010 13:10:15 -0000 Original-Received: from pD9ECF88E.dip.t-dialin.net (EHLO nze.dyndns.org) [217.236.248.142] by mail.gmx.net (mp041) with SMTP; 25 Dec 2010 14:10:15 +0100 X-Authenticated: #26138819 X-Provags-ID: V01U2FsdGVkX1+UbWUCwkOUlQlRAQUm2zn9TtsHTGoJgoijNzxGQm kmWCMuJ//eqFyd Original-Received: from localhost ([::1]:52853 helo=nzebook.haselwarter.org) by nze.dyndns.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1PWTsz-0006bp-Ld for info-gnus-english@gnu.org; Sat, 25 Dec 2010 14:10:14 +0100 X-NSA-Fodder: Semtex FBI Khaddafi afsatcom brigand advisors anarchy Telex X-Emacs-Acronym: Emacs: My Alternative Computer Story In-Reply-To: <87y67evj9j.fsf@savara.sat.thregr.org> (Yuri D'Elia's message of "Sat, 25 Dec 2010 00:33:12 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: info-gnus-english@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Announcements and discussions for GNUS, the GNU Emacs Usenet newsreader \(in English\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: info-gnus-english-bounces+gegu-info-gnus-english=m.gmane.org@gnu.org Errors-To: info-gnus-english-bounces+gegu-info-gnus-english=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.gnus.user:14401 Archived-At: --Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI Content-Type: text/plain looks useful! On Sat, 25 Dec 2010 00:33:12 +0100, Yuri D'Elia said: ---8<---[snipped 23 lines]---8<--- YD> [1] I know there's already a gnus-notify.el script, but I wasn't YD> able to come up with a better name. Please try harder, there are already at least two with that name: http://www.mail-archive.com/gnu-emacs-sources@gnu.org/msg01615.html http://www.emacswiki.org/emacs/gnus-notify.el and you do something different (*desktop notification* instead of *mode line* stuff)! While I was testing you lib, I discovered that `gnus-newsrc-alist'-elements `g' can contain 3 different type elements at (nth 2 g) (ie `gnus-info-read'): - `nil' - a list, like '(1 . 140) - a list of lists, like '((1 . 9)) Obviously, a cdar on a list (eg. (cdar '(1 . 140))) is invalid, which can result in problems in `gnus-notify-check'. So here's a patch to work around that data inconsistency: --Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI Content-Type: text/x-patch Content-Disposition: inline; filename=gnus-notify.cdar.patch Content-Description: patch to make `gnus-notify-check' more robust --- a/gnus-notify.el 2010-12-25 04:28:54.600753814 +0100 +++ b/gnus-notify.el 2010-12-25 04:29:07.473993965 +0100 @@ -110,7 +110,10 @@ (interactive) (let ( (updated-groups '()) ) (dolist (g gnus-newsrc-alist) - (let ( (read (cdar (gnus-info-read g))) ) + (let ( (read (or + (and (listp (car (gnus-info-read g))) + (cdar (gnus-info-read g))) + (cdr (gnus-info-read g)))) ) (when read (let* ( (name (gnus-info-group g)) (unread (gnus-group-unread (car g))) --Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI Content-Type: text/plain Furthermore, I saw that you directly added hooks at the end; referring to the "Emacs Lisp Coding Conventions" at http://www.gnu.org/software/emacs/elisp/html_node/Coding-Conventions.html ,---- | Simply loading a package should not change Emacs's editing | behavior. Include a command or commands to enable and disable the | feature, or to invoke it. | | This convention is mandatory for any file that includes custom | definitions. If fixing such a file to follow this convention requires an | incompatible change, go ahead and make the incompatible change; don't | postpone it. `---- You can simply wrap a function around the adding/removal of the hooks: --Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI Content-Type: text/x-patch Content-Disposition: inline; filename=gnus-notify.hooks.patch Content-Description: Add functions to turn notification on/off --- b/gnus-notify.el 2010-12-25 04:29:07.473993965 +0100 +++ c/gnus-notify.el 2010-12-25 05:13:46.467275657 +0100 @@ -135,7 +135,17 @@ ;; Hooks into gnus -(add-hook 'gnus-after-getting-new-news-hook 'gnus-notify-check) -(add-hook 'gnus-started-hook 'gnus-notify-check) +;;;###autoload +(defun gnus-notify-on () + "Add hooks for `gnus-notify-check'" + (interactive) + (add-hook 'gnus-after-getting-new-news-hook 'gnus-notify-check) + (add-hook 'gnus-started-hook 'gnus-notify-check)) + +(defun gnus-notify-off () + "Remove hooks for `gnus-notify-check'" + (interactive) + (remove-hook 'gnus-after-getting-new-news-hook 'gnus-notify-check) + (remove-hook 'gnus-started-hook 'gnus-notify-check)) (provide 'gnus-notify) --Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI Content-Type: text/plain And I noticed that you put spaces around the enclosing parentheses of your let-assignments, which I found a bit weird, so here's a whitespace patch :p --Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI Content-Type: text/x-patch Content-Disposition: inline; filename=gnus-notify.whitespace.patch Content-Description: fix `let's --- c/gnus-notify.el 2010-12-25 04:29:14.390610600 +0100 +++ d/gnus-notify.el 2010-12-25 04:35:41.004238410 +0100 @@ -108,18 +108,18 @@ (defun gnus-notify-check (&rest ignored) (interactive) - (let ( (updated-groups '()) ) + (let ((updated-groups '())) (dolist (g gnus-newsrc-alist) - (let ( (read (or + (let ((read (or (and (listp (car (gnus-info-read g))) (cdar (gnus-info-read g))) - (cdr (gnus-info-read g)))) ) + (cdr (gnus-info-read g))))) (when read - (let* ( (name (gnus-info-group g)) + (let* ((name (gnus-info-group g)) (unread (gnus-group-unread (car g))) (count (+ read unread)) (old-count (cdr (assoc name gnus-notify-counts))) - (notify (gnus-group-find-parameter name 'group-notify)) ) + (notify (gnus-group-find-parameter name 'group-notify))) (when (or (and (eq gnus-notify-mode 'gnus-notify-all-except) (not notify)) (and (eq gnus-notify-mode 'gnus-notify-explicit) notify)) --Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI Content-Type: text/plain (don't take this one too seriously ;) How about making it a global minor mode? -- Philipp Haselwarter --Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ info-gnus-english mailing list info-gnus-english@gnu.org http://lists.gnu.org/mailman/listinfo/info-gnus-english --Hugo-Chavez/event-security/emc/RSA/red-noise/DMHmbk6wHI--