Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* Gnus state, feed commands
@ 2013-11-16 18:17 Emanuel Berg
  2013-11-16 19:31 ` W. Greenhouse
       [not found] ` <mailman.6381.1384630484.10748.info-gnus-english@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Emanuel Berg @ 2013-11-16 18:17 UTC (permalink / raw)
  To: info-gnus-english

In Gnus, I have a group like this:

mail.misc (5)

to collect incomings mails.

I'm thinking, wouldn't it be cool if you never had to
check for mails, instead Emacs did that, and then told
you "you have 5 mails" in the mode line?

I guess I could schedule checking with
`run-with-idle-timer' - coincidentally, that's great,
because when you work (i.e., type) you don't want to be
disturbed and get mails, but when you idle for some
time, it would be a good slot for Emacs to check for
them.

To change the mode line, I have this in my .emacs:

(defun set-mode-line ()
  "Mode line: Show the mode line elements if the
respective global booleans are set."
  (interactive)
  (setq-default mode-line-format
   `(" "
     (*show-mode-line-modified* mode-line-modified)
     (*show-mode-line-modified* " ")
     (*show-mode-line-caption* *mode-line-caption*)
     (*show-mode-line-caption* " ")
     (*show-default-directory* default-directory)
     (*show-mode-line-buffer-identification* mode-line-buffer-identification)
     (*show-mode-line-buffer-identification* " ")
     (line-number-mode   "[%l] ")
     (column-number-mode "{%c} ")
     (*show-mode-line-modes* mode-line-modes)
     )))
(set-mode-line)

So you see, putting that information in the mode line
shouldn't be that difficult.

But what I don't know is: how do I access the "state"
of Gnus? I.e., how do I get that number "5"? And, how
do I feed command to Gnus, in the background, without
switching buffers or triggering any other visual noise?

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Gnus state, feed commands
  2013-11-16 18:17 Gnus state, feed commands Emanuel Berg
@ 2013-11-16 19:31 ` W. Greenhouse
       [not found] ` <mailman.6381.1384630484.10748.info-gnus-english@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: W. Greenhouse @ 2013-11-16 19:31 UTC (permalink / raw)
  To: info-gnus-english-mXXj517/zsQ

Emanuel Berg <embe8573-oe7qfRrRQfc4M/bo5TPICw@public.gmane.org> writes:

[...]

> So you see, putting that information in the mode line
> shouldn't be that difficult.
>
> But what I don't know is: how do I access the "state"
> of Gnus? I.e., how do I get that number "5"? And, how
> do I feed command to Gnus, in the background, without
> switching buffers or triggering any other visual noise?

There are some functions you can use which take the name of the group as
displayed in the *Group* buffer, given as a string.  For example,

(gnus-number-of-unseen-articles-in-group "mail.misc")

which returns an integer.  Obviously, you could track several groups and
add them together, since the return value of this function is a number.

As for the idle timer part of your scheme, consider using (info "(gnus)
Daemons"), which is Gnus's built-in interface to the Emacs timer
facility.  Conveniently, this will let you start the timers when Gnus is
started, and tear them down if you quit Gnus, which saves you from some
of the trouble of handling errors when information from the groups isn't
available.

--
Regards,
WGG

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Gnus state, feed commands
       [not found] ` <mailman.6381.1384630484.10748.info-gnus-english@gnu.org>
@ 2013-11-16 20:03   ` Emanuel Berg
  2013-11-17 23:57     ` Emanuel Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg @ 2013-11-16 20:03 UTC (permalink / raw)
  To: info-gnus-english

wgreenhouse@riseup.net (W. Greenhouse) writes:

> (gnus-number-of-unseen-articles-in-group "mail.misc")

Yes, works!

> As for the idle timer part of your scheme, consider
> using (info "(gnus) Daemons"), which is Gnus's
> built-in interface to the Emacs timer facility.
> Conveniently, this will let you start the timers when
> Gnus is started, and tear them down if you quit Gnus,
> which saves you from some of the trouble of handling
> errors when information from the groups isn't
> available.

Good point, will do.

I don't have "info" on Gnus, but I take it this is the
same:

http://www.gnu.org/software/emacs/manual/html_node/gnus/Daemons.html

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Gnus state, feed commands
  2013-11-16 20:03   ` Emanuel Berg
@ 2013-11-17 23:57     ` Emanuel Berg
  2013-11-20 23:00       ` W. Greenhouse
       [not found]       ` <mailman.6725.1384988464.10748.info-gnus-english@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Emanuel Berg @ 2013-11-17 23:57 UTC (permalink / raw)
  To: info-gnus-english

I "sort of" solved this. Check out the comments.

(defvar *unread-mails*)
(setq *unread-mails* "")
(defun update-unread-mails ()
  (let ((num-msgs (gnus-number-of-unseen-articles-in-group "alt.test")))
    (setq *unread-mails*
          (if (< 0 num-msgs) "* MAIL *" "") )))
;; I found it to be much better not to use the number.
;; Then you stare at that digit - could be 0, could be
;; 7, could it be... Zzz...  until you get dizzy. The
;; idea was to have the computer tell you about mails,
;; not have *you* stare into a digit.

(defun gnus-get-news-bg ()
  (interactive)
  (let ((ori-buffer (current-buffer)))
    (gnus-start-or-show) ; basically (gnus)
    (switch-to-buffer ori-buffer) )) ; can this be avoided?

(defun gnus-after-init ()
  (gnus-demon-add-handler 'gnus-get-news-bg 1 t)
  (gnus-demon-init) )
(add-hook 'gnus-started-hook 'gnus-after-init)
(add-hook 'gnus-get-new-news-hook        'update-unread-mails)
(add-hook 'gnus-agent-fetched-hook       'update-unread-mails)
(add-hook 'gnus-group-catchup-group-hook 'update-unread-mails)
;; One would think, there should be just one hook, to
;; reflect the change of state of the set of groups
;; *and* their unseen articles.

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Gnus state, feed commands
  2013-11-17 23:57     ` Emanuel Berg
@ 2013-11-20 23:00       ` W. Greenhouse
       [not found]       ` <mailman.6725.1384988464.10748.info-gnus-english@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: W. Greenhouse @ 2013-11-20 23:00 UTC (permalink / raw)
  To: info-gnus-english-mXXj517/zsQ

Emanuel Berg <embe8573-oe7qfRrRQfc4M/bo5TPICw@public.gmane.org> writes:

> I "sort of" solved this. Check out the comments.

[...]


Cool.

An alternate approach to the problem: track the place Gnus is getting
its mail from.  `display-time-mode' has some built-in support for this.

My MTA delivers new mails for me to a Maildir at ~/Maildir, so with

(setq display-time-mail-directory "~/Maildir/new/") 

I can get "Mail" in my mode line when display-time-mode is on and mail
arrives at ~/Maildir.  In the Maildir format, the new/ subdir is where
mails arrive; when Gnus processes them, whether by marking them unread
or flagged or splitting them to other folders, they are moved to cur/,
so new/ will only contain new, unprocessed mail.

There are also options to use an mbox file or an arbitrary function to
test for the rpesence of new mail every time `display-time' updates.  If
you use Gnus `mail-sources' to control where your mail comes from, you
might try

(setq display-time-mail-function 'mail-source-new-mail-p)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Gnus state, feed commands
       [not found]       ` <mailman.6725.1384988464.10748.info-gnus-english@gnu.org>
@ 2013-11-21 22:54         ` Emanuel Berg
  0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2013-11-21 22:54 UTC (permalink / raw)
  To: info-gnus-english

wgreenhouse@riseup.net (W. Greenhouse) writes:

>> I "sort of" solved this. Check out the comments.
>
> Cool.

Well, it works but of all the cool things I did, I'm
not that happy with this particular hack, for the
reasons mentioned in the comments:

1. The visual switch between buffers - this is
   something that is done for the human eye, switching
   back and forth so a computer can do its (supposedly
   background) job doesn't make sense.

2. The setup of *three* hooks to do one thing: once
   there is a change, update the variable.

> An alternate approach ...

The strange (?) thing is, I don't understand any of
that. Are we using the same stuff to begin with, or am
I just plain stupid?

You can check out my Gnus setup (for mails, mailing
lists, and Usenet) here [1]. If you can confirm we are
using the same stuff I'll make a second attempt to
understand your solution :)

[1] http://user.it.uu.se/~embe8573/conf/.emacs-gnus

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-11-21 22:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-16 18:17 Gnus state, feed commands Emanuel Berg
2013-11-16 19:31 ` W. Greenhouse
     [not found] ` <mailman.6381.1384630484.10748.info-gnus-english@gnu.org>
2013-11-16 20:03   ` Emanuel Berg
2013-11-17 23:57     ` Emanuel Berg
2013-11-20 23:00       ` W. Greenhouse
     [not found]       ` <mailman.6725.1384988464.10748.info-gnus-english@gnu.org>
2013-11-21 22:54         ` Emanuel Berg

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).