spacemacs/layers/+email/notmuch/funcs.el
Francesc Elies Henar fea2b1e037 add notmuch layer
This patch adds a notmuch[1] layer to Spacemacs!

notmuch is a mail indexing system written in C. It provides an emacs
interface, and this patch adds Spacemacs support for this interface.

Thanks to @FrancescElies for starting this work, and working with me to
get it finished. We have been using the layer for awhile now and are
happy with the initial release!

Closes #2163

[1] https://notmuchmail.org/

Tested-by: Francesc Elies <elies@posteo.net>
Tested-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2017-12-17 19:35:05 -05:00

95 lines
3 KiB
EmacsLisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(defun spacemacs/notmuch-inbox-p (saved-search-property-item)
(string-equal (plist-get saved-search-property-item :name) "inbox"))
(defun spacemacs/notmuch-inbox ()
(interactive)
(notmuch-search (plist-get (nth 0
(-filter 'spacemacs/notmuch-inbox-p notmuch-saved-searches))
:query)))
(defun spacemacs/notmuch-search-archive-thread-down ()
(interactive)
(notmuch-search-archive-thread))
(defun spacemacs/notmuch-search-archive-thread-up ()
(interactive)
(notmuch-search-archive-thread)
(notmuch-search-previous-thread)
(notmuch-search-previous-thread))
(defun spacemacs/notmuch-message-delete (go-next)
(interactive)
(notmuch-search-tag '("+deleted" "-inbox" "-unread"))
(if (equal go-next "up")
(notmuch-search-previous-thread)
(notmuch-search-next-thread)))
(defun spacemacs/notmuch-message-delete-down ()
(interactive)
(spacemacs/notmuch-message-delete "down"))
(defun spacemacs/notmuch-message-delete-up ()
(interactive)
(spacemacs/notmuch-message-delete "up"))
(defun spacemacs/notmuch-show-close-all ()
(interactive)
(goto-char (point-min))
(setq current-prefix-arg '(4))
(call-interactively 'notmuch-show-open-or-close-all))
;; Thanks to Kyle Meyer (@kyleam)
(defun spacemacs/notmuch-open-github-patch (buffer)
"Find GitHub patch link in BUFFER and show it in a new buffer."
(let ((url
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(if (re-search-forward "https://github.com/.*\\.patch" nil t)
(match-string-no-properties 0)
(user-error "No patch found"))))))
(with-current-buffer (get-buffer-create
(generate-new-buffer-name "*mail-github-patch*"))
(condition-case exception
(url-insert-file-contents url)
('file-error
;; In case the link is private repository github will respond with a
;; temporary redirect 302 HTTP code and calculate the request-token
;; with javascript. In this case open diff in browser
(browse-url url)))
(diff-mode)
(view-mode 1)
(pop-to-buffer (current-buffer)))))
(defun spacemacs/notmuch-show-open-github-patch ()
"Open patch from GitHub email."
(interactive)
(with-current-notmuch-show-message
(spacemacs/notmuch-open-github-patch (current-buffer))))
;;;;;;;;;
;; git ;;
;;;;;;;;;
(defun spacemacs/notmuch-git-apply-patch (entire-thread)
"Apply patch from a notmuch-show email buffer to a git repository
If ENTIRE-THREAD is non-nil it will apply patches from all open
messages in the current thread"
(interactive "P")
(notmuch-show-pipe-message entire-thread "git am"))
(defun spacemacs/notmuch-git-apply-patch-part ()
"Apply patch attached to a message as MIME part to a git repository."
(interactive)
(let ((mime-type nil))
(notmuch-show-apply-to-current-part-handle (lambda ()
(mm-pipe-part (notmuch-show-current-part-handle mime-type) "git am")))))