mu4e: auto start mu4e when sending command
Start mu4e if not already; with the transient menus it's easier possible to try to do things with mu4e before it is started, so handle that automatically.
This commit is contained in:
@ -211,11 +211,6 @@ It is the mu4e-version of \"mu find <query> --analyze\"."
|
|||||||
mu4e--last-query-buffer-name
|
mu4e--last-query-buffer-name
|
||||||
(mu4e-server-last-query)))
|
(mu4e-server-last-query)))
|
||||||
|
|
||||||
;; temporary
|
|
||||||
(defun mu4e--server-xapian-single-threaded-p()
|
|
||||||
"Are we using Xapian in single-threaded mode?"
|
|
||||||
(plist-get mu4e--server-props :xapian-single-threaded))
|
|
||||||
|
|
||||||
;;; Handling raw server data
|
;;; Handling raw server data
|
||||||
|
|
||||||
(defvar mu4e--server-buf nil
|
(defvar mu4e--server-buf nil
|
||||||
@ -300,7 +295,6 @@ This for the few sexps we get from the mu server that support
|
|||||||
(read (current-buffer)))
|
(read (current-buffer)))
|
||||||
val)))
|
val)))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e--server-filter (_proc str)
|
(defun mu4e--server-filter (_proc str)
|
||||||
"Filter string STR from PROC.
|
"Filter string STR from PROC.
|
||||||
This processes the \"mu server\" output. It accumulates the
|
This processes the \"mu server\" output. It accumulates the
|
||||||
@ -565,12 +559,18 @@ You cannot run the repl when mu4e is running (or vice-versa)."
|
|||||||
(t
|
(t
|
||||||
(error "Something bad happened to the mu server process")))))
|
(error "Something bad happened to the mu server process")))))
|
||||||
|
|
||||||
|
(declare-function mu4e "mu4e")
|
||||||
|
(defvar mu4e--initialized)
|
||||||
|
|
||||||
(defun mu4e--server-call-mu (form)
|
(defun mu4e--server-call-mu (form)
|
||||||
"Call the mu server with some command FORM."
|
"Call the mu server with some command FORM."
|
||||||
|
(unless mu4e--initialized
|
||||||
|
(mu4e 'background))
|
||||||
|
;; ensure the server is running as well
|
||||||
(unless (mu4e-running-p)
|
(unless (mu4e-running-p)
|
||||||
(mu4e--server-start))
|
(mu4e--server-start))
|
||||||
;; in single-threaded mode, mu can't accept our command right now.
|
;; in single-threaded mode, mu can't accept our command right now.
|
||||||
(when (and (mu4e--server-xapian-single-threaded-p) mu4e--server-indexing)
|
(when mu4e--server-indexing
|
||||||
(mu4e-message "Cannot handle command while indexing, please retry later."))
|
(mu4e-message "Cannot handle command while indexing, please retry later."))
|
||||||
(let* ((print-length nil) (print-level nil)
|
(let* ((print-length nil) (print-level nil)
|
||||||
(cmd (format "%S" form)))
|
(cmd (format "%S" form)))
|
||||||
|
|||||||
@ -56,13 +56,16 @@
|
|||||||
(with-eval-after-load 'desktop
|
(with-eval-after-load 'desktop
|
||||||
(eval '(add-to-list 'desktop-modes-not-to-save 'mu4e-compose-mode)))
|
(eval '(add-to-list 'desktop-modes-not-to-save 'mu4e-compose-mode)))
|
||||||
|
|
||||||
|
(defvar mu4e--initialized nil
|
||||||
|
"Is mu4e initialized? Only needed once per session.")
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mu4e (&optional background)
|
(defun mu4e (&optional background)
|
||||||
"If mu4e is not running yet, start it.
|
"If mu4e is not running yet, start it.
|
||||||
Then, show the main window, unless BACKGROUND (prefix-argument)
|
Then, show the main window, unless BACKGROUND (prefix-argument)
|
||||||
is non-nil."
|
is non-nil."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(if (not (mu4e-running-p))
|
(if (not mu4e--initialized)
|
||||||
(progn
|
(progn
|
||||||
(mu4e--init-handlers)
|
(mu4e--init-handlers)
|
||||||
(mu4e--start (unless background #'mu4e--main-view)))
|
(mu4e--start (unless background #'mu4e--main-view)))
|
||||||
@ -148,12 +151,13 @@ Otherwise, check requirements, then start mu4e. When successful, invoke
|
|||||||
(mu4e-modeline-mode (if mu4e-modeline-support 1 -1))
|
(mu4e-modeline-mode (if mu4e-modeline-support 1 -1))
|
||||||
;; redraw main buffer if there is one.
|
;; redraw main buffer if there is one.
|
||||||
(add-hook 'mu4e-query-items-updated-hook #'mu4e--main-redraw)
|
(add-hook 'mu4e-query-items-updated-hook #'mu4e--main-redraw)
|
||||||
(mu4e--query-items-refresh 'reset-baseline)
|
(setq mu4e--initialized t) ;; last before we call the server.
|
||||||
(mu4e--server-ping)
|
(mu4e--server-ping)
|
||||||
;; ask for the maildir-list
|
;; ask for the maildir-list
|
||||||
(mu4e--server-data 'maildirs)
|
(mu4e--server-data 'maildirs)
|
||||||
;; maybe request the list of contacts, automatically refreshed after
|
;; maybe request the list of contacts, automatically refreshed after
|
||||||
;; re-indexing
|
;; re-indexing
|
||||||
|
(mu4e--query-items-refresh 'reset-baseline)
|
||||||
(unless mu4e--contacts-set
|
(unless mu4e--contacts-set
|
||||||
(mu4e--request-contacts-maybe)))
|
(mu4e--request-contacts-maybe)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user