From 8a2c40a4b7bec8d6dabbf6c6e4b43ec5a4267d24 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 19 Jan 2015 10:36:55 +0100 Subject: [PATCH] Improve queue-related actions of the main view - The queue-related actions of `mu4e~main-view-real` have been extracted to their own `mu4e~main-view-queue` method. - The queue toggling action now has the word "currently" to easily. distinguish between the current state and the toggle (e.g., "currently queued" instead of just "queued"). - The "[f]lush queued emails" is only visible if there is at least 1 email in the queue. - The number of emails in the queue is visible in the flushing action (e.g., "[f]lush 10 queued emails"). --- mu4e/mu4e-main.el | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/mu4e/mu4e-main.el b/mu4e/mu4e-main.el index c285914a..1003e448 100644 --- a/mu4e/mu4e-main.el +++ b/mu4e/mu4e-main.el @@ -138,15 +138,9 @@ clicked." 'mu4e-update-mail-and-index) ;; show the queue functions if `smtpmail-queue-dir' is defined - (if (file-directory-p smtpmail-queue-dir) - (concat - (mu4e~main-action-str "\t* toggle [m]ail sending mode " - 'mu4e~main-toggle-mail-sending-mode) - "(" (propertize (if smtpmail-queue-mail "queued" "direct") - 'face 'mu4e-header-key-face) ")\n" - (mu4e~main-action-str "\t* [f]lush queued mail\n" - 'smtpmail-send-queued-mail)) - "") + (if (file-directory-p smtpmail-queue-dir) + (mu4e~main-view-queue) + "") "\n" (mu4e~main-action-str "\t* [A]bout mu4e\n" 'mu4e-about) (mu4e~main-action-str "\t* [H]elp\n" 'mu4e-display-manual) @@ -154,6 +148,34 @@ clicked." (mu4e-main-mode) ))) +(defun mu4e~main-view-queue () + "Display queue-related actions in the main view." + (concat + (mu4e~main-action-str "\t* toggle [m]ail sending mode " + 'mu4e~main-toggle-mail-sending-mode) + "(currently " + (propertize (if smtpmail-queue-mail "queued" "direct") + 'face 'mu4e-header-key-face) + ")\n" + (let ((queue-size (mu4e~main-queue-size))) + (if (zerop queue-size) + "" + (mu4e~main-action-str + (format "\t* [f]lush %s queued %s\n" + (propertize (int-to-string queue-size) + 'face 'mu4e-header-key-face) + (if (> queue-size 1) "mails" "mail")) + 'smtpmail-send-queued-mail))))) + +(defun mu4e~main-queue-size () + "Return, as an int, the number of emails in the queue." + (condition-case nil + (with-temp-buffer + (insert-file-contents (expand-file-name smtpmail-queue-index-file + smtpmail-queue-dir)) + (count-lines (point-min) (point-max))) + (error 0))) + (defun mu4e~main-view () "Create the mu4e main-view, and switch to it." (mu4e~main-view-real nil nil)