Adapt evil-collection-mu4e for latest mu4e development version
Changes taken from Tim Cross <theophilusx@gmail.com> (@theophilusx) in https://github.com/emacs-evil/evil-collection/issues/695#issuecomment-1437577481.
This commit is contained in:
parent
5092f5e04c
commit
7313ce9f70
|
@ -68,39 +68,11 @@
|
|||
(require 'evil-collection)
|
||||
(require 'mu4e nil t)
|
||||
|
||||
(declare-function mu4e--main-action-str "mu4e-main")
|
||||
(declare-function mu4e--main-view-queue "mu4e-main")
|
||||
(declare-function mu4e--longest-of-maildirs-and-bookmarks "mu4e-main")
|
||||
(declare-function mu4e--longest-of-maildirs-and-bookmarks "mu4e-main")
|
||||
(declare-function mu4e--maildirs-with-query "mu4e-folders")
|
||||
(defvar mu4e--server-props)
|
||||
(defvar mu4e-main-hide-fully-read)
|
||||
|
||||
(defun evil-collection-mu4e--main-action-str (&rest args)
|
||||
"Wrapper for `mu4e--main-action-str' to maintain compatibility
|
||||
with older release versions of `mu4e.'"
|
||||
(apply (if (fboundp 'mu4e~main-action-str)
|
||||
#'mu4e~main-action-str
|
||||
#'mu4e--main-action-str)
|
||||
args))
|
||||
|
||||
(defun evil-collection-mu4e--main-view-queue (&rest args)
|
||||
"Wrapper for `mu4e--main-view-queue' to maintain compatibility
|
||||
with older release versions of `mu4e.'"
|
||||
(apply (if (fboundp 'mu4e~main-view-queue)
|
||||
#'mu4e~main-view-queue
|
||||
#'mu4e--main-view-queue)
|
||||
args))
|
||||
|
||||
(defvar smtpmail-send-queued-mail)
|
||||
(defvar smtpmail-queue-dir)
|
||||
|
||||
(defconst evil-collection-mu4e-maps '(mu4e-main-mode-map
|
||||
mu4e-headers-mode-map
|
||||
mu4e-view-mode-map
|
||||
mu4e-compose-mode-map))
|
||||
|
||||
|
||||
mu4e-compose-mode-map
|
||||
mu4e-search-minor-mode-map))
|
||||
|
||||
(defun evil-collection-mu4e-set-state ()
|
||||
"Set the appropriate initial state of all mu4e modes."
|
||||
|
@ -111,6 +83,7 @@ with older release versions of `mu4e.'"
|
|||
(evil-set-initial-state mode 'normal))
|
||||
(evil-set-initial-state 'mu4e-compose-mode 'insert))
|
||||
|
||||
|
||||
;; When using org-mu4e, the above leads to an annoying behaviour, because
|
||||
;; switching from message body to header activates mu4e-compose-mode, thus
|
||||
;; putting the user into insert-state. The below code, together with the hooks
|
||||
|
@ -121,10 +94,6 @@ with older release versions of `mu4e.'"
|
|||
(defun evil-collection-mu4e-org-set-header-to-insert-mode ()
|
||||
(evil-set-initial-state 'mu4e-compose-mode 'insert))
|
||||
|
||||
|
||||
;;; Define bindings
|
||||
|
||||
;; TODO: Inhibit insert-state functions as per Evil Collection.
|
||||
(defvar evil-collection-mu4e-mode-map-bindings
|
||||
`((mu4e-main-mode-map
|
||||
"J" mu4e~headers-jump-to-maildir
|
||||
|
@ -208,11 +177,14 @@ with older release versions of `mu4e.'"
|
|||
"ZQ" mu4e-message-kill-buffer
|
||||
"ZZ" message-send-and-exit)
|
||||
|
||||
(mu4e-search-minor-mode-map
|
||||
"J" mu4e-search-maildir)
|
||||
|
||||
(mu4e-view-mode-map
|
||||
" " mu4e-view-scroll-up-or-next
|
||||
[tab] shr-next-link
|
||||
[backtab] shr-previous-link
|
||||
"q" mu4e~view-quit-buffer
|
||||
"q" mu4e-view-quit
|
||||
"gx" mu4e-view-go-to-url
|
||||
"gX" mu4e-view-fetch-url
|
||||
"C" mu4e-compose-new
|
||||
|
@ -283,134 +255,14 @@ with older release versions of `mu4e.'"
|
|||
(evil-collection-define-operator-key 'yank 'mu4e-view-mode-map
|
||||
"u" 'mu4e-view-save-url))
|
||||
|
||||
|
||||
;;; Update mu4e-main-view
|
||||
;;; To avoid confusion the main-view is updated to show the keys that are in use
|
||||
;;; for evil-mu4e.
|
||||
|
||||
(defvar evil-collection-mu4e-begin-region-basic "\n Basics"
|
||||
"The place where to start overriding Basic section.")
|
||||
|
||||
(defvar evil-collection-mu4e-end-region-basic "a new message\n"
|
||||
"The place where to end overriding Basic section.")
|
||||
|
||||
(defvar evil-collection-mu4e-new-region-basic
|
||||
(concat (evil-collection-mu4e--main-action-str "\t* [J]ump to some maildir\n" 'mu4e-jump-to-maildir)
|
||||
(evil-collection-mu4e--main-action-str "\t* enter a [s]earch query\n" 'mu4e-search)
|
||||
(evil-collection-mu4e--main-action-str "\t* [C]ompose a new message\n" 'mu4e-compose-new))
|
||||
"Define the evil-mu4e Basic region.")
|
||||
|
||||
(defvar evil-collection-mu4e-begin-region-misc "\n Misc"
|
||||
"The place where to start overriding Misc section.")
|
||||
|
||||
(defvar evil-collection-mu4e-end-region-misc "q]uit"
|
||||
"The place where to end overriding Misc section.")
|
||||
|
||||
(defun evil-collection-mu4e-new-region-misc ()
|
||||
"Define the evil-mu4e Misc region."
|
||||
(concat
|
||||
(evil-collection-mu4e--main-action-str "\t* [;]Switch focus\n" 'mu4e-context-switch)
|
||||
(evil-collection-mu4e--main-action-str "\t* [u]pdate email & database\n"
|
||||
'mu4e-update-mail-and-index)
|
||||
|
||||
;; show the queue functions if `smtpmail-queue-dir' is defined
|
||||
(if (file-directory-p smtpmail-queue-dir)
|
||||
(evil-collection-mu4e--main-view-queue)
|
||||
"")
|
||||
"\n"
|
||||
|
||||
(evil-collection-mu4e--main-action-str "\t* [N]ews\n" 'mu4e-news)
|
||||
(evil-collection-mu4e--main-action-str "\t* [A]bout mu4e\n" 'mu4e-about)
|
||||
(evil-collection-mu4e--main-action-str "\t* [H]elp\n" 'mu4e-display-manual)
|
||||
(evil-collection-mu4e--main-action-str "\t* [q]uit\n" 'mu4e-quit)))
|
||||
|
||||
(defvar evil-collection-mu4e-begin-region-maildir "\n Maildirs"
|
||||
"The place where to end overriding Maildirs section.")
|
||||
|
||||
(defvar evil-collection-mu4e-end-region-maildir "\n\n Misc"
|
||||
"The place where to end overriding Maildirs section.")
|
||||
|
||||
(defun evil-collection-mu4e-new-region-maildir ()
|
||||
"Define the evil-mu4e Maildirs region."
|
||||
(concat
|
||||
;; minorly edited version of mu4e--main-bookmarks mu4e-main.el
|
||||
(cl-loop with mds = (mu4e--maildirs-with-query)
|
||||
with longest = (mu4e--longest-of-maildirs-and-bookmarks)
|
||||
with queries = (plist-get mu4e--server-props :queries)
|
||||
for m in mds
|
||||
for key = (string (plist-get m :key))
|
||||
for name = (plist-get m :name)
|
||||
for query = (plist-get m :query)
|
||||
for qcounts = (and (stringp query)
|
||||
(cl-loop for q in queries
|
||||
when (string=
|
||||
(decode-coding-string
|
||||
(plist-get q :query)
|
||||
'utf-8 t)
|
||||
query)
|
||||
collect q))
|
||||
for unread = (and qcounts (plist-get (car qcounts) :unread))
|
||||
when (not (plist-get m :hide))
|
||||
when (not (and mu4e-main-hide-fully-read (eq unread 0)))
|
||||
concat (concat
|
||||
;; menu entry
|
||||
(evil-collection-mu4e--main-action-str
|
||||
(concat "\t* [J" key "] " name)
|
||||
(concat "J" key))
|
||||
;; append all/unread numbers, if available.
|
||||
(if qcounts
|
||||
(let ((unread (plist-get (car qcounts) :unread))
|
||||
(count (plist-get (car qcounts) :count)))
|
||||
(format
|
||||
"%s (%s/%s)"
|
||||
(make-string (- longest (string-width name)) ? )
|
||||
(propertize (number-to-string unread)
|
||||
'face 'mu4e-header-key-face)
|
||||
count))
|
||||
"")
|
||||
"\n"))
|
||||
(propertize "\n Misc" 'face 'mu4e-title-face)))
|
||||
|
||||
(defun evil-collection-mu4e-replace-region (new-region start end)
|
||||
"Replace region between START and END with NEW-REGION.
|
||||
START end END end are regular expressions."
|
||||
;; move to start of region
|
||||
(goto-char (point-min))
|
||||
(re-search-forward start)
|
||||
|
||||
;; insert new headings
|
||||
(insert "\n\n")
|
||||
(insert new-region)
|
||||
;; Delete text until end of region.
|
||||
(let ((start-point (point))
|
||||
(end-point (re-search-forward end)))
|
||||
(delete-region start-point end-point)))
|
||||
|
||||
(defun evil-collection-mu4e-update-main-view ()
|
||||
"Update `Basic', `Maildir', and `Misc' regions to reflect the new keybindings."
|
||||
(evil-collection-mu4e-replace-region evil-collection-mu4e-new-region-basic
|
||||
evil-collection-mu4e-begin-region-basic
|
||||
evil-collection-mu4e-end-region-basic)
|
||||
(evil-collection-mu4e-replace-region (evil-collection-mu4e-new-region-misc)
|
||||
evil-collection-mu4e-begin-region-misc
|
||||
evil-collection-mu4e-end-region-misc)
|
||||
(evil-collection-mu4e-replace-region (evil-collection-mu4e-new-region-maildir)
|
||||
evil-collection-mu4e-begin-region-maildir
|
||||
evil-collection-mu4e-end-region-maildir))
|
||||
|
||||
|
||||
;;; Initialize evil-collection-mu4e
|
||||
|
||||
;;;###autoload
|
||||
(defun evil-collection-mu4e-setup ()
|
||||
"Initialize evil-mu4e if necessary.
|
||||
If mu4e-main-mode is in evil-state-motion-modes, initialization
|
||||
is already done earlier."
|
||||
(evil-collection-mu4e-set-state)
|
||||
(evil-collection-mu4e-set-bindings)
|
||||
(add-hook 'mu4e-main-mode-hook 'evil-collection-mu4e-update-main-view)
|
||||
(add-hook 'org-mode-hook #'evil-collection-mu4e-org-set-header-to-normal-mode)
|
||||
(add-hook 'mu4e-compose-pre-hook #'evil-collection-mu4e-org-set-header-to-insert-mode))
|
||||
(evil-collection-mu4e-set-bindings))
|
||||
|
||||
(provide 'evil-collection-mu4e)
|
||||
;;; evil-collection-mu4e.el ends here
|
||||
|
|
Loading…
Reference in New Issue