Skip to content

Instantly share code, notes, and snippets.

@hkjels
Created September 25, 2022 15:07
Show Gist options
  • Save hkjels/0d5cf7e8cd4ef13ab466c04efa5f6a76 to your computer and use it in GitHub Desktop.
Save hkjels/0d5cf7e8cd4ef13ab466c04efa5f6a76 to your computer and use it in GitHub Desktop.
Use mbsync periodically from within Emacs
(defun elan-sync-mail ()
"Synchronize mail-accounts using mbsync."
(interactive)
(if (get-buffer "*mbsync*")
(user-error "There is already a sync in progress")
(let* ((output-buffer (get-buffer-create "*mbsync*"))
(proc (progn
(async-shell-command "mbsync -q -a" output-buffer "*mbsync-error*")
(get-buffer-process output-buffer))))
(when (process-live-p proc)
(spinner-start elan-sync-mail-spinner)
(set-process-sentinel
proc
(lambda (process signal)
(when (memq (process-status process) '(exit signal))
(setq elan-notmuch-last-update (current-time-string))
(kill-buffer "*mbsync*")
(spinner-stop elan-sync-mail-spinner)
(run-hooks 'elan-sync-mail-hook))))))))
(add-to-list 'display-buffer-alist '("*mbsync*" (display-buffer-no-window)))
(let ((minutes 60))
(run-with-timer 1 (* 15 minutes) 'elan-sync-mail))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment