* mu4e: improve version checks, startup handling

This commit is contained in:
djcb
2012-09-15 18:04:39 +03:00
parent c46024cfda
commit 0844984095
2 changed files with 29 additions and 23 deletions

View File

@ -92,9 +92,10 @@ the length (in hex).")
(defun mu4e~proc-is-running () (defun mu4e~proc-is-running ()
"Whether the mu process is running." "Whether the mu process is running."
(and mu4e~proc-process (when (and mu4e~proc-process
(memq (process-status mu4e~proc-process) (memq (process-status mu4e~proc-process)
'(run open listen connect stop)))) '(run open listen connect stop)))
t))
(defsubst mu4e~proc-eat-sexp-from-buf () (defsubst mu4e~proc-eat-sexp-from-buf ()

View File

@ -32,7 +32,7 @@
(require 'mu4e-vars) (require 'mu4e-vars)
(require 'mu4e-about) (require 'mu4e-about)
(require 'doc-view) (require 'doc-view)
(defcustom mu4e-html2text-command nil (defcustom mu4e-html2text-command nil
"Shell command that converts HTML from stdin into plain text on "Shell command that converts HTML from stdin into plain text on
stdout. If this is not defined, the emacs `html2text' tool will be stdout. If this is not defined, the emacs `html2text' tool will be
@ -176,7 +176,7 @@ Function will return the cdr of the list element."
(if chosen (if chosen
(cdr chosen) (cdr chosen)
(mu4e-warn "Unknown shortcut '%c'" response)))) (mu4e-warn "Unknown shortcut '%c'" response))))
(defun mu4e~get-maildirs-1 (path mdir) (defun mu4e~get-maildirs-1 (path mdir)
"Get maildirs under path, recursively, as a list of relative "Get maildirs under path, recursively, as a list of relative
@ -624,6 +624,13 @@ This is used by the completion function in mu4e-compose."
(defun mu4e~check-requirements () (defun mu4e~check-requirements ()
"Check for the settings required for running mu4e."
(unless (>= emacs-major-version 23)
(mu4e-error "Emacs >= 23.x is required for mu4e"))
(when mu4e~server-props
(let ((version (plist-get mu4e~server-props :version)))
(unless (string= version mu4e-mu-version)
(mu4e-error "mu server has version %s, but we need %s"
version mu4e-mu-version)))) version mu4e-mu-version))))
(unless (and mu4e-mu-binary (file-executable-p mu4e-mu-binary)) (unless (and mu4e-mu-binary (file-executable-p mu4e-mu-binary))
(mu4e-error "Please set `mu4e-mu-binary' to the full path to the mu (mu4e-error "Please set `mu4e-mu-binary' to the full path to the mu
@ -648,40 +655,37 @@ This is used by the completion function in mu4e-compose."
(unless (mu4e-create-maildir-maybe path) (unless (mu4e-create-maildir-maybe path)
(mu4e-error "%s (%S) does not exist" path var))))) (mu4e-error "%s (%S) does not exist" path var)))))
(defun mu4e~start (&optional func) (defun mu4e~start (&optional func)
"If mu4e is already running, execute function FUNC (if non-nil). Otherwise, "If mu4e is already running, execute function FUNC (if non-nil). Otherwise,
check various requirements, then start mu4e. When succesful, call check various requirements, then start mu4e. When succesful, call
FUNC (if non-nil) afterwards." FUNC (if non-nil) afterwards."
;; if we're already running, simply go to the main view ;; if we're already running, simply go to the main view
(if (mu4e~proc-is-running) ;; already running? (if (mu4e~proc-is-running) ;; already running?
(when func (when func ;; yes! run func if defined
(funcall func))) ;; yup! (funcall func))
(progn ;; nope: check whether all is okay; (progn
(mu4e~check-requirements) ;; no! do some checks, set up pong handler and ping the server
;; explicit version checks are a bit questionable,
;; better to check for specific features (lexical-let ((func func))
(unless (>= emacs-major-version 23) (mu4e~check-requirements)
(mu4e-error "Emacs >= 23.x is required for mu4e"))
;; set up the 'pong' handler func
;; set up the 'pong' handler func ;; set up the 'pong' handler func
(setq mu4e-pong-func (setq mu4e-pong-func
(lambda (props)
(setq mu4e~server-props props) ;; save the props we got from the server (setq mu4e~server-props props) ;; save the props we got from the server
(let ((version (plist-get props :version)) (let ((version (plist-get props :version))
(doccount (plist-get props :doccount))) (doccount (plist-get props :doccount)))
(unless (string= version mu4e-mu-version)
(mu4e-error "mu server has version %s, but we need %s"
(mu4e~check-requirements) (mu4e~check-requirements)
(when func (funcall func)) (when func (funcall func))
(when (and mu4e-update-interval (null mu4e~update-timer)) (when (and mu4e-update-interval (null mu4e~update-timer))
(setq mu4e~update-timer (setq mu4e~update-timer
(run-at-time (run-at-time
0 mu4e-update-interval 'mu4e-update-mail))) 0 mu4e-update-interval 'mu4e-update-mail)))
(mu4e-message "Started mu4e with %d message%s in store" (mu4e-message "Started mu4e with %d message%s in store"
doccount (if (= doccount 1) "" "s")) doccount (if (= doccount 1) "" "s"))))))
;; save the props we got from the server
(setq mu4e~server-props props)))))
(mu4e~proc-ping)
;; get the address list if it's not already set. ;; get the address list if it's not already set.
(when (and mu4e-compose-complete-addresses (when (and mu4e-compose-complete-addresses
@ -691,7 +695,8 @@ FUNC (if non-nil) afterwards."
mu4e-compose-complete-only-personal mu4e-compose-complete-only-personal
(when mu4e-compose-complete-only-after (when mu4e-compose-complete-only-after
(float-time (float-time
(apply 'encode-time (apply 'encode-time
(mu4e-parse-time-string mu4e-compose-complete-only-after)))))))))
(defun mu4e~stop () (defun mu4e~stop ()