mu4e-utils: refactor into mu4e-helpers, separate files
Usurp more of the utils code than can be re-used without further dependencies in helpers. Split off specific parts in their own file. After the helper/utils changes, update the rest of mu4e to take the changes into account.
This commit is contained in:
@ -25,14 +25,20 @@
|
||||
;;; Code:
|
||||
|
||||
(require 'smtpmail) ;; the queueing stuff (silence elint)
|
||||
(require 'mu4e-utils) ;; utility functions
|
||||
(require 'mu4e-helpers) ;; utility functions
|
||||
(require 'mu4e-context) ;; the context
|
||||
(require 'mu4e-bookmarks)
|
||||
(require 'mu4e-folders)
|
||||
(require 'mu4e-update)
|
||||
(require 'mu4e-contacts)
|
||||
(require 'mu4e-search)
|
||||
(require 'mu4e-vars) ;; mu-wide variables
|
||||
|
||||
(require 'cl-lib)
|
||||
|
||||
;;; Mode
|
||||
|
||||
|
||||
;; Configuration
|
||||
|
||||
(define-obsolete-variable-alias
|
||||
'mu4e-main-buffer-hide-personal-addresses
|
||||
@ -49,6 +55,37 @@ part of the personal addresses.")
|
||||
"When set to t, do not hide bookmarks or maildirs that have
|
||||
no unread messages.")
|
||||
|
||||
|
||||
;;; Mode
|
||||
(define-derived-mode mu4e-org-mode org-mode "mu4e:org"
|
||||
"Major mode for mu4e documents, derived from
|
||||
`org-mode'.")
|
||||
|
||||
(defun mu4e-info (path)
|
||||
"Show a buffer with the information (an org-file) at PATH."
|
||||
(unless (file-exists-p path)
|
||||
(mu4e-error "Cannot find %s" path))
|
||||
(let ((curbuf (current-buffer)))
|
||||
(find-file path)
|
||||
(mu4e-org-mode)
|
||||
(setq buffer-read-only t)
|
||||
(define-key mu4e-org-mode-map (kbd "q")
|
||||
`(lambda ()
|
||||
(interactive)
|
||||
(bury-buffer)
|
||||
(switch-to-buffer ,curbuf)))))
|
||||
|
||||
(defun mu4e-about ()
|
||||
"Show the mu4e 'about' page."
|
||||
(interactive)
|
||||
(mu4e-info (concat mu4e-doc-dir "/mu4e-about.org")))
|
||||
|
||||
(defun mu4e-news ()
|
||||
"Show the mu4e 'about' page."
|
||||
(interactive)
|
||||
(mu4e-info (concat mu4e-doc-dir "/NEWS.org")))
|
||||
|
||||
|
||||
(defvar mu4e-main-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
|
||||
@ -85,6 +122,7 @@ no unread messages.")
|
||||
overwrite-mode 'overwrite-mode-binary)
|
||||
(mu4e-context-minor-mode)
|
||||
(mu4e-search-minor-mode)
|
||||
(mu4e-update-minor-mode)
|
||||
(set (make-local-variable 'revert-buffer-function) #'mu4e~main-view-real))
|
||||
|
||||
|
||||
@ -121,15 +159,23 @@ clicked."
|
||||
'mouse-face 'highlight newstr)
|
||||
newstr))
|
||||
|
||||
|
||||
|
||||
(defun mu4e--longest-of-maildirs-and-bookmarks ()
|
||||
"Return the length of longest name of bookmarks and maildirs."
|
||||
(cl-loop for b in (append (mu4e-bookmarks)
|
||||
(mu4e--maildirs-with-query))
|
||||
maximize (string-width (plist-get b :name))))
|
||||
|
||||
(defun mu4e~main-bookmarks ()
|
||||
;; TODO: it's a bit uncool to hard-code the "b" shortcut...
|
||||
(cl-loop with bmks = (mu4e-bookmarks)
|
||||
with longest = (mu4e~longest-of-maildirs-and-bookmarks)
|
||||
with longest = (mu4e--longest-of-maildirs-and-bookmarks)
|
||||
with queries = (mu4e-last-query-results)
|
||||
for bm in bmks
|
||||
for key = (string (plist-get bm :key))
|
||||
for name = (plist-get bm :name)
|
||||
for query = (funcall (or mu4e-query-rewrite-function #'identity)
|
||||
for query = (funcall (or mu4e-search-query-rewrite-function #'identity)
|
||||
(plist-get bm :query))
|
||||
for qcounts = (and (stringp query)
|
||||
(cl-loop for q in queries
|
||||
@ -162,8 +208,8 @@ clicked."
|
||||
|
||||
(defun mu4e~main-maildirs ()
|
||||
"Return a string of maildirs with their counts."
|
||||
(cl-loop with mds = (mu4e~maildirs-with-query)
|
||||
with longest = (mu4e~longest-of-maildirs-and-bookmarks)
|
||||
(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))
|
||||
@ -217,13 +263,15 @@ clicked."
|
||||
"The revert buffer function for `mu4e-main-mode'."
|
||||
(mu4e~main-view-real-1 'refresh))
|
||||
|
||||
(declare-function mu4e--start "mu4e")
|
||||
|
||||
(defun mu4e~main-view-real-1 (&optional refresh)
|
||||
"Create `mu4e-main-buffer-name' and set it up.
|
||||
When REFRESH is non nil refresh infos from server."
|
||||
(let ((inhibit-read-only t))
|
||||
;; Maybe refresh infos from server.
|
||||
(if refresh
|
||||
(mu4e~start 'mu4e~main-redraw-buffer)
|
||||
(mu4e--start 'mu4e~main-redraw-buffer)
|
||||
(mu4e~main-redraw-buffer))))
|
||||
|
||||
(defun mu4e~main-redraw-buffer ()
|
||||
|
||||
Reference in New Issue
Block a user