respect +afew feature flag + fix sync buffer kill

This commit is contained in:
Will Vaughn 2021-04-03 22:17:08 -07:00 committed by William Vaughn
parent ce65645fb8
commit 96dcb4c0d9
No known key found for this signature in database
GPG key ID: 011967635D6D9F61
2 changed files with 34 additions and 24 deletions

View file

@ -29,31 +29,41 @@
(doom-kill-matching-buffers "^\\*notmuch")
(+workspace/delete "*MAIL*"))
(defun notmuch-get-sync-command ()
(let ((afew-cmd "afew -a -t")
(sync-cmd (pcase +notmuch-sync-backend
(`gmi
(concat "cd " +notmuch-mail-folder " && gmi sync && notmuch new"))
(`mbsync
"mbsync -a && notmuch new")
(`mbsync-xdg
"mbsync -c \"$XDG_CONFIG_HOME\"/isync/mbsyncrc -a && notmuch new")
(`offlineimap
"offlineimap && notmuch new")
(`custom +notmuch-sync-command))))
(if (featurep! +afew)
(format "%s && %s" sync-cmd afew-cmd)
sync-cmd)))
;;;###autoload
(defun +notmuch/update ()
"Sync notmuch emails with server."
(interactive)
;; create output buffer and jump to beginning
(let ((buf (get-buffer-create "*notmuch update*")))
(with-current-buffer buf
(erase-buffer))
(pop-to-buffer buf nil t)
(set-process-sentinel
(start-process-shell-command
"notmuch update" buf
(pcase +notmuch-sync-backend
(`gmi
(concat "cd " +notmuch-mail-folder " && gmi push && gmi pull && notmuch new && afew -a -t"))
(`mbsync
"mbsync -a && notmuch new && afew -a -t")
(`mbsync-xdg
"mbsync -c \"$XDG_CONFIG_HOME\"/isync/mbsyncrc -a && notmuch new && afew -a -t")
(`offlineimap
"offlineimap && notmuch new && afew -a -t")
(`custom +notmuch-sync-command)))
;; refresh notmuch buffers if sync was successful
(lambda (_process event)
(if (string= event "finished\n")
(notmuch-refresh-all-buffers))))))
(with-current-buffer (compile (notmuch-get-sync-command))
(let ((w (get-buffer-window (current-buffer))))
(select-window w)
(add-hook
'compilation-finish-functions
(lambda (buf status)
(if (equal status "finished\n")
(progn
(delete-window w)
(kill-buffer buf)
(notmuch-refresh-all-buffers)
(message "Notmuch sync successful"))
(user-error "Failed to sync notmuch data")))
nil
'local))))
;;;###autoload
(defun +notmuch/search-delete ()

View file

@ -64,9 +64,9 @@
#'hide-mode-line-mode)
(map! :localleader
:map (notmuch-search-mode-map notmuch-tree-mode-map notmuch-show-mode-map)
:map (notmuch-hello-mode-map notmuch-search-mode-map notmuch-tree-mode-map notmuch-show-mode-map)
:desc "Compose email" "c" #'+notmuch/compose
:desc "Fetch new email" "u" #'+notmuch/update
:desc "Sync email" "u" #'+notmuch/update
:desc "Quit notmuch" "q" #'+notmuch/quit
:map notmuch-search-mode-map
:desc "Mark as deleted" "d" #'+notmuch/search-delete