Gnus development mailing list
 help / color / mirror / Atom feed
* Does Gnus automatically run 'notmuch new' if configured?
@ 2020-09-24  8:32 Pankaj Jangid
  2020-09-24 16:42 ` Eric Abrahamsen
  2020-09-24 17:55 ` Adam Sjøgren
  0 siblings, 2 replies; 18+ messages in thread
From: Pankaj Jangid @ 2020-09-24  8:32 UTC (permalink / raw)
  To: Gnus Users

I have just configured notmuch for searching emails managed by nnml
backend. My configuration is

--8<---------------cut here---------------start------------->8---
(setq nnir-method-default-engines
      '((nnml . notmuch)
	(nnimap . imap)))
--8<---------------cut here---------------end--------------->8---

Notmuch help says that we should run "notmuch new" whenever new mail
arrives.

My question is - does Gnus automatically run "notmuch new" if notmuch is
the configured search engine.

Regards

-- 
Pankaj Jangid


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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-24  8:32 Does Gnus automatically run 'notmuch new' if configured? Pankaj Jangid
@ 2020-09-24 16:42 ` Eric Abrahamsen
  2020-09-24 17:55 ` Adam Sjøgren
  1 sibling, 0 replies; 18+ messages in thread
From: Eric Abrahamsen @ 2020-09-24 16:42 UTC (permalink / raw)
  To: ding

Pankaj Jangid <pankaj@codeisgreat.org> writes:

> I have just configured notmuch for searching emails managed by nnml
> backend. My configuration is
>
> (setq nnir-method-default-engines
>       '((nnml . notmuch)
> 	(nnimap . imap)))
>
> Notmuch help says that we should run "notmuch new" whenever new mail
> arrives.
>
> My question is - does Gnus automatically run "notmuch new" if notmuch is
> the configured search engine.

No, I don't think it does. If I were you I'd write a tiny wrapper
function around `async-shell-command' and run it on `emacs-startup-hook'
or `gnus-startup-hook'.



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-24  8:32 Does Gnus automatically run 'notmuch new' if configured? Pankaj Jangid
  2020-09-24 16:42 ` Eric Abrahamsen
@ 2020-09-24 17:55 ` Adam Sjøgren
  2020-09-25  4:00   ` Pankaj Jangid
  2020-09-25  8:09   ` Eric S Fraga
  1 sibling, 2 replies; 18+ messages in thread
From: Adam Sjøgren @ 2020-09-24 17:55 UTC (permalink / raw)
  To: ding

Pankaj writes:

> does Gnus automatically run "notmuch new" if notmuch is the configured
> search engine.

No, it doesn't. You'll need to arrange for that to happen yourself.

I run it in a cron job once a day.

If you want it run every time you have fetched mail, I think you could
add calling it to a hook, maybe gnus-after-getting-new-news-hook?


  Best regards,

    Adam

-- 
 "It troo! Dat darn Kahlfin stole ma spacechip!"            Adam Sjøgren
                                                       asjo@koldfront.dk



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-24 17:55 ` Adam Sjøgren
@ 2020-09-25  4:00   ` Pankaj Jangid
  2020-09-25  6:05     ` Eric Abrahamsen
  2020-09-25  8:09   ` Eric S Fraga
  1 sibling, 1 reply; 18+ messages in thread
From: Pankaj Jangid @ 2020-09-25  4:00 UTC (permalink / raw)
  To: Adam Sjøgren; +Cc: ding

On Thu, Sep 24 2020, Adam Sjøgren wrote:

>> does Gnus automatically run "notmuch new" if notmuch is the configured
>> search engine.
>
> If you want it run every time you have fetched mail, I think you could
> add calling it to a hook, maybe gnus-after-getting-new-news-hook?

Are hooks asynchronous? Eric had also suggested a similar solution. He
suggested to put this at the time of startup. But my question is - will
it increase the waiting time? I am fetching emails from multiple sources
and it already takes 4-5 seconds to fetch emails when I press 'g'.



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25  4:00   ` Pankaj Jangid
@ 2020-09-25  6:05     ` Eric Abrahamsen
  2020-09-25  7:51       ` Pankaj Jangid
  0 siblings, 1 reply; 18+ messages in thread
From: Eric Abrahamsen @ 2020-09-25  6:05 UTC (permalink / raw)
  To: Pankaj Jangid; +Cc: Adam Sjøgren, ding

Pankaj Jangid <pankaj@codeisgreat.org> writes:

> On Thu, Sep 24 2020, Adam Sjøgren wrote:
>
>>> does Gnus automatically run "notmuch new" if notmuch is the configured
>>> search engine.
>>
>> If you want it run every time you have fetched mail, I think you could
>> add calling it to a hook, maybe gnus-after-getting-new-news-hook?
>
> Are hooks asynchronous? Eric had also suggested a similar solution. He
> suggested to put this at the time of startup. But my question is - will
> it increase the waiting time? I am fetching emails from multiple sources
> and it already takes 4-5 seconds to fetch emails when I press 'g'.

It's not the hook that's synchronous or asynchronous, it's the call to
the external process. You can use `shell-command' for a synchronous call
(probably not what you want), or `async-shell-command' for... async.

The async call should return more or less instantly. I'm sure notmuch is
capable of continuing to handle search queries while it's in the middle
of an update, so there's not actually any harm in calling it more often,
apart from burning CPU cycles.

Otherwise, your wait while Gnus fetches new mail is totally unrelated to
notmuch updating its index, as that happens in a completely separate
process.

HTH,
Eric


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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25  6:05     ` Eric Abrahamsen
@ 2020-09-25  7:51       ` Pankaj Jangid
  0 siblings, 0 replies; 18+ messages in thread
From: Pankaj Jangid @ 2020-09-25  7:51 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: Pankaj Jangid, Adam Sjøgren, ding

On Thu, Sep 24 2020, Eric Abrahamsen wrote:

> It's not the hook that's synchronous or asynchronous, it's the call to
> the external process. You can use `shell-command' for a synchronous call
> (probably not what you want), or `async-shell-command' for... async.

Thanks a lot. I'll implement using `async-shell-command'.


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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-24 17:55 ` Adam Sjøgren
  2020-09-25  4:00   ` Pankaj Jangid
@ 2020-09-25  8:09   ` Eric S Fraga
  2020-09-25  9:31     ` Adam Sjøgren
  1 sibling, 1 reply; 18+ messages in thread
From: Eric S Fraga @ 2020-09-25  8:09 UTC (permalink / raw)
  To: ding

On Thursday, 24 Sep 2020 at 19:55, Adam Sjøgren wrote:
> I run it in a cron job once a day.

cron is the way to go!

"notmuch new" is (for me, at least) very fast so I have my cron job run
every hour at minimum (I up it to every 15 minutes during busy times of
the year).  Once a day is not enough with the volume of email I have to
deal with.

-- 
Eric S Fraga via Emacs 28.0.50 & org 9.4 on Debian bullseye/sid



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25  8:09   ` Eric S Fraga
@ 2020-09-25  9:31     ` Adam Sjøgren
  2020-09-25 14:44       ` Pankaj Jangid
  2020-09-25 18:25       ` Adam Sjøgren
  0 siblings, 2 replies; 18+ messages in thread
From: Adam Sjøgren @ 2020-09-25  9:31 UTC (permalink / raw)
  To: ding

Eric writes:

> On Thursday, 24 Sep 2020 at 19:55, Adam Sjøgren wrote:
>> I run it in a cron job once a day.

> cron is the way to go!

I think it depends a lot on how often and for what you search.

Integrating the update into the fetching of emails would be nice from
the "always updated" perspective, and since notmuch indexing is fast, it
probably isn't a problem timewise.

Yeah, running 'notmuch new' takes 0.085s for me with 1 new email, and
~95K emails already indexed.

I search my email perhaps once a month, so I'm a very casual user of
notmuch, nnir and nnselect, and I almost always search for old email, so
a lazy cronjob is sufficient for me.

But now this discussion makes me want to have it in a hook...

Pankaj, please share your hook function, when you get it implemented O:-)


  Best regards,

    Adam

-- 
 "Religion - is a smile on a dog"                           Adam Sjøgren
                                                       asjo@koldfront.dk



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25  9:31     ` Adam Sjøgren
@ 2020-09-25 14:44       ` Pankaj Jangid
  2020-09-25 16:31         ` Eric Abrahamsen
  2020-09-25 18:25       ` Adam Sjøgren
  1 sibling, 1 reply; 18+ messages in thread
From: Pankaj Jangid @ 2020-09-25 14:44 UTC (permalink / raw)
  To: Adam Sjøgren; +Cc: ding

On Fri, Sep 25 2020, Adam Sjøgren wrote:

> Integrating the update into the fetching of emails would be nice from
> the "always updated" perspective, and since notmuch indexing is fast,
> it probably isn't a problem timewise.

Not only that. I want to keep all the Emacs/Gnus setup in one place; so
that it is portable. On a new machine I'll just have to clone my
.emacs.d.git. Cron is another thing to remember if I go via that route.

> Yeah, running 'notmuch new' takes 0.085s for me with 1 new email, and
> ~95K emails already indexed.
>
> ...
>
> But now this discussion makes me want to have it in a hook...
>
> Pankaj, please share your hook function, when you get it implemented
> O:-)

Now that I have put a lambda function to invoke `async-shell-command`,
it opens up *Async Shell Command* buffer in another window whenever I
press `g`. I want the messages in *Async Shell Command* buffer. But I
don't want it to open up on every call to `gnus-group-get-new-news`.


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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25 14:44       ` Pankaj Jangid
@ 2020-09-25 16:31         ` Eric Abrahamsen
  2020-09-25 17:47           ` Pankaj Jangid
  0 siblings, 1 reply; 18+ messages in thread
From: Eric Abrahamsen @ 2020-09-25 16:31 UTC (permalink / raw)
  To: Pankaj Jangid; +Cc: Adam Sjøgren, ding

Pankaj Jangid <pankaj@codeisgreat.org> writes:

[...]

> Now that I have put a lambda function to invoke `async-shell-command`,
> it opens up *Async Shell Command* buffer in another window whenever I
> press `g`. I want the messages in *Async Shell Command* buffer. But I
> don't want it to open up on every call to `gnus-group-get-new-news`.

Ahem, I may have led you astray with `async-shell-command', which is
mostly meant to be called interactively -- in which case you usually
want to see the output. In lisp code that runs in the background, you're
better off using `start-process', where you can tell it not to keep the
output:

(start-process "unnecessary label" nil "/path/to/notmuch" '("new"))

This returns a process object that you're supposed to continue
interacting with, but in your case you can just disregard it.

Sorry about that! Wasn't thinking clearly.

Eric


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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25 16:31         ` Eric Abrahamsen
@ 2020-09-25 17:47           ` Pankaj Jangid
  2020-09-25 18:16             ` Adam Sjøgren
  2020-09-25 18:45             ` Eric Abrahamsen
  0 siblings, 2 replies; 18+ messages in thread
From: Pankaj Jangid @ 2020-09-25 17:47 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: Pankaj Jangid, Adam Sjøgren, ding

On Fri, Sep 25 2020, Eric Abrahamsen wrote:

> Ahem, I may have led you astray with `async-shell-command', which is
> mostly meant to be called interactively -- in which case you usually
> want to see the output. In lisp code that runs in the background,
> you're better off using `start-process', where you can tell it not to
> keep the output:

I had explored a little bit of `start-process` and `call-process` when I
was reading help on `async-shell-comman`. But then I thought these are
low level methods and I don't need that much control.

> (start-process "unnecessary label" nil "/path/to/notmuch" '("new"))

This is nice. I am using this now. Just a correction. Last argument is
not list. List was giving error. I am using below code,

(start-process "notmuch" "*Notmuch*" "notmuch" "new")

Now, I have another related question - which hook is best for the
purpose? Currently I am using `gnus-after-getting-new-news-hook`. But
that is run only when I press `g` (gnus-group-get-new-news). It seems
that the hook is not invoked when I start Gnus. Also the hook is
probably invoked before splitting.

Since I am using `nnml` backend, there are couple of choices for my
use-case. One is `nnmail-read-incoming-mail`. The documentation also
says, "use this hook to notify any mail watch programs". But I also use
simple splittig (`nnmail-split-methods`). And the documentation also has
a `nnmail-split-hook`. But from the documentation it looks like that
this hook is run, after the splitting has started, and not after the
splitting is over -

--8<---------------cut here---------------start------------->8---
‘nnmail-split-hook’
     Hook run in the buffer where the mail headers of each message is
     kept just before the splitting based on these headers is done.  The
     hook is free to modify the buffer contents in any way it sees
     fit—the buffer is discarded after the splitting has been done, and
     no changes performed in the buffer will show up in any files.
     ‘gnus-article-decode-encoded-words’ is one likely function to add
     to this hook.
--8<---------------cut here---------------end--------------->8---

In such case if I run `notmuch new` then the indexing might create links
to non-existing paths.

Any other hook that you can think of?


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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25 17:47           ` Pankaj Jangid
@ 2020-09-25 18:16             ` Adam Sjøgren
  2020-09-25 18:45             ` Eric Abrahamsen
  1 sibling, 0 replies; 18+ messages in thread
From: Adam Sjøgren @ 2020-09-25 18:16 UTC (permalink / raw)
  To: ding

Pankaj writes:

> which hook is best for the purpose? Currently I am using
> `gnus-after-getting-new-news-hook`. But that is run only when I press
> `g` (gnus-group-get-new-news). It seems that the hook is not invoked
> when I start Gnus.

Hm. That seems like a bug to me - I would expect it to fire after
getting new news, regardless of whether it was fetched by startup or by
explicit action.

You could advice M-x gnus to run notmuch after startup:

  (defadvice gnus (after gnus-notmuch-new activate)
    (your-run-notmuch-new-function))

in addition to the hook.

But it still feels wrong that the hook doesn't fire - doesn't it?


  Best regards,

    Adam

-- 
 "I'm so glad to have you, and it's getting worse           Adam Sjøgren
  I'm so mad to love you, and your evil curse"         asjo@koldfront.dk



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25  9:31     ` Adam Sjøgren
  2020-09-25 14:44       ` Pankaj Jangid
@ 2020-09-25 18:25       ` Adam Sjøgren
  1 sibling, 0 replies; 18+ messages in thread
From: Adam Sjøgren @ 2020-09-25 18:25 UTC (permalink / raw)
  To: ding

Adam writes:

> But now this discussion makes me want to have it in a hook...

In case anyone cares/for reference, here is what I ended up with in my
.emacs, inspired by this thread:

  (defun asjo-notmuch-new ()
    "Run notmuch new"
    (start-process "notmuch" "*Notmuch*" "notmuch" "new"))

  (defadvice gnus (after gnus-notmuch-new activate)
    (asjo-notmuch-new))

and in my .gnus:

  (add-hook 'gnus-after-getting-new-news-hook 'asjo-notmuch-new)

I think this is nicer than the cron job, even though the advice feels
hacky.

Never again shall I think "Oh, maybe it wasn't in the search results
because the index isn't up to date"!


  Best regards,

    Adam

-- 
 "The key to performance is elegance, not battalions        Adam Sjøgren
  of special cases."                                   asjo@koldfront.dk



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25 17:47           ` Pankaj Jangid
  2020-09-25 18:16             ` Adam Sjøgren
@ 2020-09-25 18:45             ` Eric Abrahamsen
  2020-09-25 18:52               ` Adam Sjøgren
  2020-09-26  1:29               ` Pankaj Jangid
  1 sibling, 2 replies; 18+ messages in thread
From: Eric Abrahamsen @ 2020-09-25 18:45 UTC (permalink / raw)
  To: ding

Pankaj Jangid <pankaj@codeisgreat.org> writes:

> On Fri, Sep 25 2020, Eric Abrahamsen wrote:
>
>> Ahem, I may have led you astray with `async-shell-command', which is
>> mostly meant to be called interactively -- in which case you usually
>> want to see the output. In lisp code that runs in the background,
>> you're better off using `start-process', where you can tell it not to
>> keep the output:
>
> I had explored a little bit of `start-process` and `call-process` when I
> was reading help on `async-shell-comman`. But then I thought these are
> low level methods and I don't need that much control.
>
>> (start-process "unnecessary label" nil "/path/to/notmuch" '("new"))
>
> This is nice. I am using this now. Just a correction. Last argument is
> not list. List was giving error. I am using below code,
>
> (start-process "notmuch" "*Notmuch*" "notmuch" "new")

Oops, sorry!

[...]

>> which hook is best for the purpose? Currently I am using
>> `gnus-after-getting-new-news-hook`. But that is run only when I press
>> `g` (gnus-group-get-new-news). It seems that the hook is not invoked
>> when I start Gnus.
>
> Hm. That seems like a bug to me - I would expect it to fire after
> getting new news, regardless of whether it was fetched by startup or by
> explicit action.
>
> You could advice M-x gnus to run notmuch after startup:
>
> (defadvice gnus (after gnus-notmuch-new activate)
> (your-run-notmuch-new-function))
>
> in addition to the hook.
>
> But it still feels wrong that the hook doesn't fire - doesn't it?

It is weird, but the code is very clear: startup runs
`gnus-get-unread-articles' directly, and the hook isn't run there. "g"
in the group buffer runs `gnus-group-get-new-news', which first calls
`gnus-get-unread-articles', then runs the hook.

You could certainly argue that that's weird, but that's how it currently
works.

Rather than an advice, I would just add your function to the
`gnus-startup-hook', as well.

Eric



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25 18:45             ` Eric Abrahamsen
@ 2020-09-25 18:52               ` Adam Sjøgren
  2020-09-26  1:29               ` Pankaj Jangid
  1 sibling, 0 replies; 18+ messages in thread
From: Adam Sjøgren @ 2020-09-25 18:52 UTC (permalink / raw)
  To: ding

Eric writes:

> Rather than an advice, I would just add your function to the
> `gnus-startup-hook', as well.

Good point, thanks!


  Best regards,

    Adam

-- 
 "Jeg synes, at hvis hun vil have mig begravet med          Adam Sjøgren
  hende, at hun skal gøre mig til kongegemal.          asjo@koldfront.dk
  Færdig!"



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-25 18:45             ` Eric Abrahamsen
  2020-09-25 18:52               ` Adam Sjøgren
@ 2020-09-26  1:29               ` Pankaj Jangid
  2020-09-26 11:48                 ` Adam Sjøgren
  1 sibling, 1 reply; 18+ messages in thread
From: Pankaj Jangid @ 2020-09-26  1:29 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: ding

>> (start-process "notmuch" "*Notmuch*" "notmuch" "new")

>>> which hook is best for the purpose? Currently I am using
>>> `gnus-after-getting-new-news-hook`. But that is run only when I
>>> press `g` (gnus-group-get-new-news). It seems that the hook is not
>>> invoked when I start Gnus.

>> (defadvice gnus (after gnus-notmuch-new activate)
>> (your-run-notmuch-new-function))

> Rather than an advice, I would just add your function to the
> `gnus-startup-hook', as well.

There was one more enquiry in this regard. Probably most of the Gnus
users are using splitting as well... probably, and I am sure "notmuch
new" should be run after the splitting action is over. Is there a hook
for that?


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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-26  1:29               ` Pankaj Jangid
@ 2020-09-26 11:48                 ` Adam Sjøgren
  2020-09-26 17:08                   ` Pankaj Jangid
  0 siblings, 1 reply; 18+ messages in thread
From: Adam Sjøgren @ 2020-09-26 11:48 UTC (permalink / raw)
  To: ding

Pankaj writes:

> I am sure "notmuch new" should be run after the splitting action is
> over. Is there a hook for that?

I think both gnus-after-getting-new-news-hook and gnus-startup-hook run
after splitting?


  Best regards,

    Adam

-- 
 "Numerical solution was considered the last resort         Adam Sjøgren
  of an incompetent mathematician. The opposite, of    asjo@koldfront.dk
  course, is true."



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

* Re: Does Gnus automatically run 'notmuch new' if configured?
  2020-09-26 11:48                 ` Adam Sjøgren
@ 2020-09-26 17:08                   ` Pankaj Jangid
  0 siblings, 0 replies; 18+ messages in thread
From: Pankaj Jangid @ 2020-09-26 17:08 UTC (permalink / raw)
  To: Adam Sjøgren; +Cc: ding

On Sat, Sep 26 2020, Adam Sjøgren wrote:

>> I am sure "notmuch new" should be run after the splitting action is
>> over. Is there a hook for that?
>
> I think both gnus-after-getting-new-news-hook and gnus-startup-hook run
> after splitting?

Yes and no. `gnus-after-getting-new-news-hook` runs after
splitting but `gnus-startup-hook` does not. I just tested it.

But I have found that `gnus-started-hook` runs after splitting.

That solves my case. ;-)

-- 
Pankaj Jangid


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

end of thread, other threads:[~2020-09-26 17:09 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-24  8:32 Does Gnus automatically run 'notmuch new' if configured? Pankaj Jangid
2020-09-24 16:42 ` Eric Abrahamsen
2020-09-24 17:55 ` Adam Sjøgren
2020-09-25  4:00   ` Pankaj Jangid
2020-09-25  6:05     ` Eric Abrahamsen
2020-09-25  7:51       ` Pankaj Jangid
2020-09-25  8:09   ` Eric S Fraga
2020-09-25  9:31     ` Adam Sjøgren
2020-09-25 14:44       ` Pankaj Jangid
2020-09-25 16:31         ` Eric Abrahamsen
2020-09-25 17:47           ` Pankaj Jangid
2020-09-25 18:16             ` Adam Sjøgren
2020-09-25 18:45             ` Eric Abrahamsen
2020-09-25 18:52               ` Adam Sjøgren
2020-09-26  1:29               ` Pankaj Jangid
2020-09-26 11:48                 ` Adam Sjøgren
2020-09-26 17:08                   ` Pankaj Jangid
2020-09-25 18:25       ` Adam Sjøgren

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