unofficial mirror of notmuch@notmuchmail.org
 help / color / Atom feed
* Lazily loading notmuch into Emacs
@ 2020-06-01 17:36 Sean Whitton
  2020-06-02 11:41 ` David Edmondson
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Whitton @ 2020-06-01 17:36 UTC (permalink / raw)
  To: notmuch

Hello,

I don't want to put (require 'notmuch) into my Emacs init because that
will slow down initial Emacs startup a fair bit, especially since my
(file which is equivalent to) notmuch-config.el does quite a bit of
processing to populate notmuch-saved-searches.

So I have this:

    ;; Ensure notmuch does its `message-mode' configuration and that my
    ;; notmuch-config.el gets loaded before certain commands happen.  An
    ;; alternative to advising `compose-mail' and friends here would be
    ;; to remap its keys to `notmuch-mua-new-mail', but it is nice to
    ;; have things work correctly if some lisp code somewhere calls
    ;; `compose-mail' or friends
    (defun spw/load-notmuch (&rest ignore)
      (require 'notmuch))
    (dolist (cmd '(compose-mail
                   compose-mail-other-window
                   compose-mail-other-frame
                   notmuch-jump-search
                   notmuch-hello))
      (advice-add cmd :before #'spw/load-notmuch))

    (global-set-key "\C-cs" #'notmuch-search)
    (global-set-key "\C-cm" #'notmuch-jump-search)
    (global-set-key "\C-cM" #'notmuch-hello)

This is not a very idiomatic way to make use of an ELPA package,
however.  Does anyone have a better approach that does not involve
advice-add?  I'm using the elpa-notmuch package on Debian.

-- 
Sean Whitton

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

* Re: Lazily loading notmuch into Emacs
  2020-06-01 17:36 Lazily loading notmuch into Emacs Sean Whitton
@ 2020-06-02 11:41 ` David Edmondson
  2020-06-02 21:50   ` Sean Whitton
  0 siblings, 1 reply; 3+ messages in thread
From: David Edmondson @ 2020-06-02 11:41 UTC (permalink / raw)
  To: Sean Whitton, notmuch

On Monday, 2020-06-01 at 10:36:16 -07, Sean Whitton wrote:

> Hello,
>
> I don't want to put (require 'notmuch) into my Emacs init because that
> will slow down initial Emacs startup a fair bit, especially since my
> (file which is equivalent to) notmuch-config.el does quite a bit of
> processing to populate notmuch-saved-searches.
>
> So I have this:
>
>     ;; Ensure notmuch does its `message-mode' configuration and that my
>     ;; notmuch-config.el gets loaded before certain commands happen.  An
>     ;; alternative to advising `compose-mail' and friends here would be
>     ;; to remap its keys to `notmuch-mua-new-mail', but it is nice to
>     ;; have things work correctly if some lisp code somewhere calls
>     ;; `compose-mail' or friends
>     (defun spw/load-notmuch (&rest ignore)
>       (require 'notmuch))
>     (dolist (cmd '(compose-mail
>                    compose-mail-other-window
>                    compose-mail-other-frame
>                    notmuch-jump-search
>                    notmuch-hello))
>       (advice-add cmd :before #'spw/load-notmuch))
>
>     (global-set-key "\C-cs" #'notmuch-search)
>     (global-set-key "\C-cm" #'notmuch-jump-search)
>     (global-set-key "\C-cM" #'notmuch-hello)
>
> This is not a very idiomatic way to make use of an ELPA package,
> however.  Does anyone have a better approach that does not involve
> advice-add?  I'm using the elpa-notmuch package on Debian.

I'd hoped that:

(require 'notmuch-mua)
(setq mail-user-agent 'notmuch-user-agent)

would be sufficient to get things wired up, but it doesn't seem to be.

If we fix that, would it seem more appropriate? If we get it right then
it shouldn't load any other notmuch code (including notmuch-config.el)
until you actually use one of the functions.

(None of this will configure your chosen bindings of course, you'll
still have to do that yourself.)

dme.
-- 
Everybody's got something to hide, 'cept me and my monkey.

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

* Re: Lazily loading notmuch into Emacs
  2020-06-02 11:41 ` David Edmondson
@ 2020-06-02 21:50   ` Sean Whitton
  0 siblings, 0 replies; 3+ messages in thread
From: Sean Whitton @ 2020-06-02 21:50 UTC (permalink / raw)
  To: David Edmondson, notmuch

Hello David,

On Tue 02 Jun 2020 at 12:41PM +01, David Edmondson wrote:

> I'd hoped that:
>
> (require 'notmuch-mua)
> (setq mail-user-agent 'notmuch-user-agent)
>
> would be sufficient to get things wired up, but it doesn't seem to be.
>
> If we fix that, would it seem more appropriate? If we get it right then
> it shouldn't load any other notmuch code (including notmuch-config.el)
> until you actually use one of the functions.

It's probably better than using advice-add, assuming that bytecompiled
notmuch-mua.el loads quickly.

I wonder if maybe notmuch-mua.el could be split into a small file the
user can 'require in their init, which just has the
define-mail-user-agent call, and then there's a larger .el file
containing an autoload cookie and definition for 'notmuch-mua-mail, and
everything else?

I'm also advising notmuch-jump-search and notmuch-hello, as otherwise I
noticed notmuch-config.el doesn't get loaded if you use one of those
right after starting Emacs.  I think the fix there is to add (require
'notmuch) to the top of notmuch-jump.el and notmuch-hello.el?

-- 
Sean Whitton

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01 17:36 Lazily loading notmuch into Emacs Sean Whitton
2020-06-02 11:41 ` David Edmondson
2020-06-02 21:50   ` Sean Whitton

unofficial mirror of notmuch@notmuchmail.org

Archives are clonable:
	git clone --mirror https://yhetil.org/notmuch/0 notmuch/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 notmuch notmuch/ https://yhetil.org/notmuch \
		notmuch@notmuchmail.org
	public-inbox-index notmuch

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.mail.notmuch.general
	nntp://news.gmane.io/gmane.mail.notmuch.general


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git