diff --git a/.emacs.d/lisp/init-notmuch-sync.el b/.emacs.d/lisp/init-notmuch-sync.el new file mode 100644 index 00000000..b3be60da --- /dev/null +++ b/.emacs.d/lisp/init-notmuch-sync.el @@ -0,0 +1,33 @@ +;; TODO: Report notmuch dump/tag sync technique upstream. +(require 'seq) + +(unless (boundp 'notmuch-command) + ;; So that this file can be use in external scripts without require + ;; notmuch.el. + (setq notmuch-command "notmuch")) + +(defun notmuch-all-tags () + (split-string + (with-output-to-string + (with-current-buffer standard-output + (call-process notmuch-command nil t + nil "search" "--output=tags" "--exclude=false" "*"))))) + +(defvar notmuch-unimportant-tags '("attachment" "deleted" "draft" "encrypted" + "flagged" "inbox" "passed" "replied" "sent" + "signed" "unread")) +(defvar notmuch-dump-file (expand-file-name "~/personal/mail/notmuch.dump")) + +(defun notmuch-dump-important-tags (&optional file) + "Dump notmuch tag database to `notmuch-dump-file'. +Messages with only `notmuch-unimportant-tags' are ignored." + (interactive) + (setq file (or file notmuch-dump-file)) + (let* ((important-tags (seq-difference (notmuch-all-tags) notmuch-unimportant-tags)) + (tags-arg (cons (concat "tag:" (car important-tags)) + (cl-loop for tag in (cdr important-tags) + append (list "or" (concat "tag:" tag)))))) + (apply 'call-process notmuch-command nil `(:file ,file) nil + "dump" tags-arg))) + +(provide 'init-notmuch-sync) diff --git a/.emacs.d/lisp/init-notmuch.el b/.emacs.d/lisp/init-notmuch.el index 24e3b852..85fd021e 100644 --- a/.emacs.d/lisp/init-notmuch.el +++ b/.emacs.d/lisp/init-notmuch.el @@ -2,6 +2,7 @@ (require 'init-message) (require 'patch-notmuch) +(require 'init-notmuch-sync) ;; To find files matching email: ;; notmuch search --output=files FOO @@ -41,6 +42,7 @@ notmuch-show-mode-map notmuch-tree-mode-map)) (define-key map "s" 'helm-notmuch))) + (when (require 'org-notmuch nil 'noerror) (dolist (map (list notmuch-show-mode-map notmuch-tree-mode-map)) (define-key map (kbd "C-c C-t") 'org-capture))