2018-01-07 04:50:52 +00:00
|
|
|
|
;;; funcs.el --- Notmuch Layer functions File for Spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
|
|
|
|
;;
|
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//notmuch-inbox-p (saved-search-property-item)
|
|
|
|
|
"Returns non-nil if item is the inbox."
|
2017-08-11 18:46:41 +00:00
|
|
|
|
(string-equal (plist-get saved-search-property-item :name) "inbox"))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/notmuch-inbox ()
|
2018-01-07 04:50:52 +00:00
|
|
|
|
"Search inbox."
|
2017-08-11 18:46:41 +00:00
|
|
|
|
(interactive)
|
2018-01-07 04:50:52 +00:00
|
|
|
|
(notmuch-search
|
|
|
|
|
(plist-get (nth 0 (-filter 'spacemacs//notmuch-inbox-p notmuch-saved-searches))
|
|
|
|
|
:query)))
|
2017-08-11 18:46:41 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/notmuch-search-archive-thread-down ()
|
2018-01-07 04:50:52 +00:00
|
|
|
|
"Search thread up."
|
2017-08-11 18:46:41 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(notmuch-search-archive-thread))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/notmuch-search-archive-thread-up ()
|
2018-01-07 04:50:52 +00:00
|
|
|
|
"Search thread down."
|
2017-08-11 18:46:41 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(notmuch-search-archive-thread)
|
|
|
|
|
(notmuch-search-previous-thread)
|
|
|
|
|
(notmuch-search-previous-thread))
|
|
|
|
|
|
2018-01-07 04:50:52 +00:00
|
|
|
|
(defun spacemacs//notmuch-message-delete (go-next)
|
|
|
|
|
"Delete message and select GO-NEXT message."
|
2018-01-15 04:12:24 +00:00
|
|
|
|
(notmuch-search-tag notmuch-message-deleted-tags)
|
2018-01-07 04:50:52 +00:00
|
|
|
|
(if (eq 'up go-next )
|
2017-08-11 18:46:41 +00:00
|
|
|
|
(notmuch-search-previous-thread)
|
|
|
|
|
(notmuch-search-next-thread)))
|
2018-01-07 04:50:52 +00:00
|
|
|
|
|
2018-05-25 19:35:35 +00:00
|
|
|
|
(defun spacemacs/notmuch-show-as-patch ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(notmuch-show-choose-mime-of-part "text/x-patch"))
|
|
|
|
|
|
2017-08-11 18:46:41 +00:00
|
|
|
|
(defun spacemacs/notmuch-message-delete-down ()
|
2018-01-07 04:50:52 +00:00
|
|
|
|
"Delete a message and select the next message."
|
2017-08-11 18:46:41 +00:00
|
|
|
|
(interactive)
|
2018-01-07 04:50:52 +00:00
|
|
|
|
(spacemacs//notmuch-message-delete 'down))
|
2017-08-11 18:46:41 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/notmuch-message-delete-up ()
|
2018-01-07 04:50:52 +00:00
|
|
|
|
"Delete a message and select the previous message."
|
2017-08-11 18:46:41 +00:00
|
|
|
|
(interactive)
|
2018-01-07 04:50:52 +00:00
|
|
|
|
(spacemacs//notmuch-message-delete 'up))
|
2017-08-11 18:46:41 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/notmuch-show-close-all ()
|
2018-01-07 04:50:52 +00:00
|
|
|
|
"Close all."
|
2017-08-11 18:46:41 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(goto-char (point-min))
|
2018-01-07 04:50:52 +00:00
|
|
|
|
(let ((current-prefix-arg '(4)))
|
|
|
|
|
(call-interactively 'notmuch-show-open-or-close-all)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; 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")))))
|
2017-08-11 18:46:41 +00:00
|
|
|
|
|
2018-01-07 04:50:52 +00:00
|
|
|
|
|
|
|
|
|
;; GitHub
|
2017-08-11 18:46:41 +00:00
|
|
|
|
|
|
|
|
|
;; Thanks to Kyle Meyer (@kyleam)
|
2018-01-07 04:50:52 +00:00
|
|
|
|
(defun spacemacs//notmuch-open-github-patch (buffer)
|
2017-08-11 18:46:41 +00:00
|
|
|
|
"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
|
2018-01-07 04:50:52 +00:00
|
|
|
|
(spacemacs//notmuch-open-github-patch (current-buffer))))
|
2017-08-11 18:46:41 +00:00
|
|
|
|
|
2018-01-07 05:44:50 +00:00
|
|
|
|
|
|
|
|
|
;; persp
|
|
|
|
|
|
2018-01-10 04:01:34 +00:00
|
|
|
|
(defun spacemacs//notmuch-persp-filter-save-buffers-function (buffer)
|
|
|
|
|
"Filter for notmuch layout."
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(memq major-mode notmuch-modes)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//notmuch-buffer-to-persp ()
|
|
|
|
|
"Add buffer to notmuch layout."
|
2018-01-07 05:44:50 +00:00
|
|
|
|
(persp-add-buffer (current-buffer)
|
|
|
|
|
(persp-get-by-name notmuch-spacemacs-layout-name)))
|