From: Philipp Haselwarter <philipp.haselwarter@gmx.de>
To: info-gnus-english@gnu.org
Subject: Re: Gnus and new mail notification
Date: Sat, 25 Dec 2010 14:10:11 +0100 [thread overview]
Message-ID: <87aajuhubw.fsf@nzebook.haselwarter.org> (raw)
In-Reply-To: <87y67evj9j.fsf@savara.sat.thregr.org> (Yuri D'Elia's message of "Sat, 25 Dec 2010 00:33:12 +0100")
[-- Attachment #1: Type: text/plain, Size: 908 bytes --]
looks useful!
On Sat, 25 Dec 2010 00:33:12 +0100, Yuri D'Elia <wavexx@users.sf.net> 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:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch to make `gnus-notify-check' more robust --]
[-- Type: text/x-patch, Size: 549 bytes --]
--- 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)))
[-- Attachment #3: Type: text/plain, Size: 662 bytes --]
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:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: Add functions to turn notification on/off --]
[-- Type: text/x-patch, Size: 732 bytes --]
--- 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)
[-- Attachment #5: Type: text/plain, Size: 153 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: fix `let's --]
[-- Type: text/x-patch, Size: 1048 bytes --]
--- 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))
[-- Attachment #7: Type: text/plain, Size: 107 bytes --]
(don't take this one too seriously ;)
How about making it a global minor mode?
--
Philipp Haselwarter
[-- Attachment #8: Type: text/plain, Size: 161 bytes --]
_______________________________________________
info-gnus-english mailing list
info-gnus-english@gnu.org
http://lists.gnu.org/mailman/listinfo/info-gnus-english
next prev parent reply other threads:[~2010-12-25 13:10 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-24 23:33 Yuri D'Elia
2010-12-25 13:10 ` Philipp Haselwarter [this message]
2010-12-25 15:26 ` Yuri D'Elia
2010-12-25 21:52 ` Tassilo Horn
2010-12-26 20:11 ` Yuri D'Elia
2011-01-02 12:02 ` Philipp Haselwarter
[not found] <mailman.26.1293233609.7272.info-gnus-english@gnu.org>
2010-12-25 13:25 ` e20100633
2010-12-26 18:26 ` Philipp Haselwarter
2010-12-26 18:59 ` Philipp Haselwarter
2010-12-25 20:31 ` Richard Riley
2010-12-25 21:55 ` Tassilo Horn
2010-12-25 22:56 ` Yuri D'Elia
[not found] ` <mailman.13.1293317806.24913.info-gnus-english@gnu.org>
2010-12-25 23:19 ` Richard Riley
2010-12-26 16:22 ` Yuri D'Elia
[not found] ` <mailman.1.1293380566.6185.info-gnus-english@gnu.org>
2010-12-27 8:11 ` Richard Riley
2010-12-27 9:25 ` Thierry Volpiatto
[not found] ` <mailman.2.1293441979.18751.info-gnus-english@gnu.org>
2010-12-27 13:30 ` Richard Riley
2010-12-27 15:39 ` Philipp Haselwarter
2010-12-27 16:04 ` Thierry Volpiatto
[not found] ` <mailman.8.1293465927.24495.info-gnus-english@gnu.org>
2010-12-27 16:42 ` Richard Riley
2010-12-27 17:47 ` Thierry Volpiatto
[not found] ` <mailman.19.1293472126.24495.info-gnus-english@gnu.org>
2010-12-27 18:11 ` Richard Riley
2010-12-27 19:09 ` Thierry Volpiatto
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=87aajuhubw.fsf@nzebook.haselwarter.org \
--to=philipp.haselwarter@gmx.de \
--cc=info-gnus-english@gnu.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).