* mu4e(-main|-proc-|utils).el: refactoring, some cleanup/improvements

- move all mu4e startup functions to mu4e-utils
  - add `mu4e' function to mu4e.el that call these mu4e-utils function
  - now easy to start mu4e without showing ui
  - mu4e~proc-is-running moved to mu4e-proc
  - made mu4e-read-option a bit smarter
  - renamed some more functions from mu4e- => mu4e~ (i.e.., mark them private)
This commit is contained in:
djcb
2012-04-26 17:59:34 +03:00
parent 5ea06f1469
commit 084ecc71d2
4 changed files with 182 additions and 135 deletions

View File

@ -26,7 +26,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'mu4e-utils) ;; utility functions
(defconst mu4e-main-buffer-name "*mu4e-main*"
(defconst mu4e~main-buffer-name "*mu4e-main*"
"*internal* Name of the mu4e main view buffer.")
(defvar mu4e-main-mode-map
@ -40,7 +40,7 @@
(define-key map "j" 'mu4e-jump-to-maildir)
(define-key map "C" 'mu4e-compose-new)
(define-key map "m" 'mu4e-toggle-mail-sending-mode)
(define-key map "m" 'mu4e~main-toggle-mail-sending-mode)
(define-key map "f" 'smtpmail-send-queued-mail)
(define-key map "U" 'mu4e-update-mail-show-window)
@ -60,7 +60,7 @@
overwrite-mode 'overwrite-mode-binary))
(defun mu4e-action-str (str &optional func-or-shortcut)
(defun mu4e~main-action-str (str &optional func-or-shortcut)
"Highlight the first occurence of [..] in STR. If
FUNC-OR-SHORTCUT is non-nil and if it is a function, call it when
STR is clicked (using RET or mouse-2); if FUNC-OR-SHORTCUT is a
@ -84,12 +84,12 @@ clicked."
(define-key map (kbd "RET") func)
(put-text-property 0 (length newstr) 'keymap map newstr)
(put-text-property (string-match "\\w" newstr)
(- (length newstr) 1) 'mouse-face 'highlight newstr)
newstr))
(- (length newstr) 1) 'mouse-face 'highlight newstr) newstr))
(defun mu4e-main-view()
(defun mu4e~main-view ()
"Show the mu4e main view."
(let ((buf (get-buffer-create mu4e-main-buffer-name))
(let ((buf (get-buffer-create mu4e~main-buffer-name))
(inhibit-read-only t))
(with-current-buffer buf
(erase-buffer)
@ -99,70 +99,46 @@ clicked."
(propertize mu4e-mu-version 'face 'mu4e-view-header-key-face)
"\n\n"
(propertize " Basics\n\n" 'face 'mu4e-title-face)
(mu4e-action-str "\t* [j]ump to some maildir\n" 'mu4e-jump-to-maildir)
(mu4e-action-str "\t* enter a [s]earch query\n" 'mu4e-search)
(mu4e-action-str "\t* [C]ompose a new message\n" 'mu4e-compose-new)
(mu4e~main-action-str "\t* [j]ump to some maildir\n" 'mu4e-jump-to-maildir)
(mu4e~main-action-str "\t* enter a [s]earch query\n" 'mu4e-search)
(mu4e~main-action-str "\t* [C]ompose a new message\n" 'mu4e-compose-new)
"\n"
(propertize " Bookmarks\n\n" 'face 'mu4e-title-face)
;; TODO: it's a bit uncool to hard-code the "b" shortcut...
(mapconcat
(lambda (bm)
(let* ((query (nth 0 bm)) (title (nth 1 bm)) (key (nth 2 bm)))
(mu4e-action-str
(mu4e~main-action-str
(concat "\t* [b" (make-string 1 key) "] " title)
(concat "b" (make-string 1 key)))))
mu4e-bookmarks "\n")
"\n"
(propertize " Misc\n\n" 'face 'mu4e-title-face)
(mu4e-action-str "\t* [U]pdate email & database\n"
(mu4e~main-action-str "\t* [U]pdate email & database\n"
'mu4e-update-mail-show-window)
;; show the queue functions if `smtpmail-queue-dir' is defined
(if (file-directory-p smtpmail-queue-dir)
(concat
(mu4e-action-str "\t* toggle [m]ail sending mode "
'mu4e-toggle-mail-sending-mode)
(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-view-header-key-face) ")\n"
(mu4e-action-str "\t* [f]lush queued mail\n"
(mu4e~main-action-str "\t* [f]lush queued mail\n"
'smtpmail-send-queued-mail))
"")
"\n"
(mu4e-action-str "\t* [H]elp\n" 'mu4e-display-manual)
(mu4e-action-str "\t* [q]uit\n" 'mu4e-quit))
(mu4e~main-action-str "\t* [H]elp\n" 'mu4e-display-manual)
(mu4e~main-action-str "\t* [q]uit\n" 'mu4e-quit))
(mu4e-main-mode)
(switch-to-buffer buf)
(delete-other-windows))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Interactive functions
(defconst mu4e-update-buffer-name "*mu4e-update*"
"*internal* Name of the buffer for message retrieval / database
updating.")
(defun mu4e-update-mail-show-window ()
"Try to retrieve mail (using the user-provided shell command),
and update the database afterwards, and show the progress in a
split-window."
(interactive)
(unless mu4e-get-mail-command
(error "`mu4e-get-mail-command' is not defined"))
(let ((buf (get-buffer-create mu4e-update-buffer-name))
(win
(split-window (selected-window)
(- (window-height (selected-window)) 8))))
(with-selected-window win
(switch-to-buffer buf)
(set-window-dedicated-p win t)
(erase-buffer)
(insert "\n") ;; FIXME -- needed so output starts
(mu4e-update-mail buf))))
(defun mu4e-toggle-mail-sending-mode ()
(defun mu4e~main-toggle-mail-sending-mode ()
"Toggle sending mail mode, either queued or direct."
(interactive)
(unless (file-directory-p smtpmail-queue-dir)
@ -171,6 +147,7 @@ split-window."
(message
(concat "Outgoing mail will now be "
(if smtpmail-queue-mail "queued" "sent directly")))
(mu4e-main-view))
(mu4e~main-view))
(provide 'mu4e-main)