gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Gnus notify and Newsticker notify.


From: Andy Stewart
Subject: Gnus notify and Newsticker notify.
Date: Thu, 02 Oct 2008 02:15:17 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Hi, everyone!

I have write some functions to notify gnus news and newsticker news in
mode-line when coming new news.

;; Below is functions and configuration with gnus notify

(defface gnus-update-news-modeline-face
  '((((class color) (background dark))
     (:foreground "Gold")))
  "Face for highlighting gnus news number in mode line"
  :group 'gnus)

(defvar gnus-update-news-string nil
  "The highlight string of `global-mode-string' after call 
`guns-update-news-string'.")

(defvar gnus-update-news-repeat 100
  "The repeat second that call `gnus-update-news'.")

(unless (member 'gnus-update-news-string global-mode-string)
  (setq global-mode-string (append global-mode-string
                                   (list 'gnus-update-news-string))))

(defun gnus-update-news ()
  "Update gnus news and display notify message in mode-line."
  (interactive)
  (let (gnus-news-number)
    (force-mode-line-update t)
    ;; (gnus-group-get-new-news)
    (flet ((message (&rest args))) (gnus-group-get-new-news))
    (setq gnus-news-number (gnus-get-unread-news-number))
    (if (> gnus-news-number 0)
        (progn
          ;; the property `risky-local-variable' is a security measure for mode 
line
          ;; variable that have properties
          (put 'gnus-update-news-string 'risky-local-variable t)
          (setq gnus-update-news-string (propertize (format " [Gnus: %d]" 
gnus-news-number)
                                                    'face 
'gnus-update-news-modeline-face)))
      (setq gnus-update-news-string ""))))

(defun gnus-get-unread-news-number ()
  "Get the total number of unread news of gnus group."
  (let (total-unread-news-number)
    (setq total-unread-news-number 0)
    (mapc '(lambda (g)
             (let* ((group (car g))
                    (unread (gnus-group-unread group)))
               (when (and (numberp unread)
                          (> unread 0))
                 (setq total-unread-news-number (+ total-unread-news-number 
unread)))))
          gnus-newsrc-alist)
    total-unread-news-number))

(run-with-timer 0 gnus-update-news-repeat 'gnus-update-news) ;update gnus and 
display notify in mode-line

;; Below is functions and configuration with newsticker notify
;; NOTE: I use Newsticker 1.99, early version couldn't use those functions.

(defface newsticker-update-news-modeline-face
  '((((class color) (background dark))
     (:foreground "khaki")))
  "Face for highlighting newsticker news number in mode line"
  :group 'newsticker)

(defvar newsticker-update-news-string nil
  "The highlight string of `global-mode-string' after call 
`newsticker-update-news'.")

(defvar newsticker-update-news-repeat 60
  "The repeat second that `newsticker-update-news'.")

(unless (member 'newsitcker-update-news-string global-mode-string)
  (setq global-mode-string (append global-mode-string
                                   (list 'newsticker-update-news-string))))

(defun newsticker-update-news ()
  "Update newsticker news and display notify message in mode-line."
  (interactive)
  (let (newsticker-news-number)
    (force-mode-line-update t)
    (setq newsticker-news-number (newsticker--stat-num-items-total 'new))
    (if (> newsticker-news-number 0)
        (progn
          ;; the property `risky-local-variable' is a security measure for mode 
line
          ;; variable that have properties
          (put 'newsticker-update-news-string 'risky-local-variable t)
          (setq newsticker-update-news-string
                (propertize (format " [Newsticker: %d]" newsticker-news-number)
                            'face 'newsticker-update-news-modeline-face)))
      (setq newsticker-update-news-string ""))))

(run-with-timer 0 newsticker-update-news-repeat 'newsticker-update-news) 
;update newsticker and display notify in mode-line

Enjoy!

   -- Andy Stewart





reply via email to

[Prev in Thread] Current Thread [Next in Thread]