Integrate gnus and notmuch with multiple accounts
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Gnus and notmuch .... | |
;; - Sets up searching with notmuch, when looking at the message it's possible | |
;; to switch to gnus article view with C-c C-c | |
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(require 'notmuch) | |
(add-hook 'gnus-group-mode-hook 'lch-notmuch-shortcut) | |
(require 'org-gnus) | |
(defun lch-notmuch-shortcut () | |
(define-key gnus-group-mode-map "GG" 'notmuch-search) | |
) | |
(defun notmuch-file-to-group (file) | |
"Calculate the Gnus group name from the given file name." | |
(let ((group (file-name-directory (directory-file-name (file-name-directory file))))) | |
(if (string-match ".*/Maildir/Silverbullet" file) | |
(setq group (replace-regexp-in-string ".*/Maildir/Account1/\." "nnimap+account2:" group)) | |
) | |
(if (string-match ".*/Maildir/Private" file) | |
(setq group (replace-regexp-in-string ".*/Maildir/Account2/\." "nnimap+account2:" group)) | |
) | |
(setq group (replace-regexp-in-string "/$" "" group)) | |
(if (string-match ":$" group) | |
(concat group "INBOX") | |
(replace-regexp-in-string ":\\." ":" group)))) | |
(defun notmuch-goto-message-in-gnus () | |
"Open a summary buffer containing the current notmuch | |
article." | |
(interactive) | |
(unless (gnus-alive-p) (with-temp-buffer (gnus))) | |
(let ((group (notmuch-file-to-group (notmuch-show-get-filename))) | |
(message-id | |
(replace-regexp-in-string "\"" "" | |
(replace-regexp-in-string "^id:" "" | |
(notmuch-show-get-message-id))))) | |
(if (and group message-id) | |
(progn | |
(gnus-summary-read-group group 1) ; have to show at least one old message | |
(gnus-summary-refer-article message-id)) ; simpler than org-gnus method? | |
(message "Couldn't get relevant infos for switching to Gnus.")))) | |
(define-key notmuch-show-mode-map (kbd "C-c C-c") 'notmuch-goto-message-in-gnus) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment