reddit / emacs

Is it possible to load mu4e asynchronously in the background when Emacs start?

zoliky · 2022-08-03 00:30
I have this code added to my init.el which starts mu4e ten seconds after Emacs loads. ;; Load mu4e in the background when Emacs starts (run-at-time "10 sec" nil (lambda () (let ((current-prefix-arg '(4))) (call-interactively 'mu4e) (message nil)))) The problem is that when it happens my Emacs hangs for a fraction of second. I was wondering if it's possible to load the mu4e thing in an asynchronous manner.
xenodium · 2022-08-03 07:07
I lazy load via use-package with something like: (use-package mu4e :ensure t :bind (:map global-map ("M-m" . ar/mu4e-view-my-unread-messages)) :config (defun ar/mu4e-view-my-unread-messages () (interactive) (mu4e~start) (mu4e-headers-search-bookmark "flag:unread AND NOT flag:trashed"))) > The problem is that when it happens my Emacs hangs for a fraction of second. I pay for it when I first invoke `M-m`, rather than at Emacs load time.
7890yuiop · 2022-08-03 10:49
> The problem is that when it happens my Emacs hangs for a fraction of second. Horrors. > I was wondering if it's possible to load the mu4e thing in an asynchronous manner. No, you can't load anything in an asynchronous manner. Everything which gets loaded has to be processed by the main thread. I think the best you could do is to check all of the dependencies loaded by `mu4e`, and load them yourself, piecemeal, in a bottom-up sequence, with a delay between each one. Try `M-x trace-function RET require` before loading `mu4e`. (n.b. I cannot imagine it being worthwhile going to that kind of trouble over this, and I agree with /u/xenodium -- why load it at all before you need it?)
zoliky · 2022-08-03 11:14
I wanted to be loaded so the mails are fetched every 10 minutes. Or should I fetch them by setting up a cron job instead?
xenodium · 2022-08-03 11:59
I’m guessing you use either mbsync or offlineimap for the actual syncing. Both can be run as services outside of emacs. If on macOS, brew services should help.
zoliky · 2022-08-03 12:03
Yes, I'm using mbsyncrc. Thank you!