mirror of https://github.com/djcb/mu.git
mu4e: add command mu4e-server-repl
This for testing the mu4e server.
This commit is contained in:
parent
3d4805de0c
commit
8b16e5a449
|
@ -386,46 +386,65 @@ As per issue #2198."
|
||||||
(signal-process proc 'SIGKILL)))) ;; forcefully
|
(signal-process proc 'SIGKILL)))) ;; forcefully
|
||||||
(process-list)))
|
(process-list)))
|
||||||
|
|
||||||
|
(defun mu4e--server-args()
|
||||||
|
"Return the command line args for the command to start the mu4e-server."
|
||||||
|
;; [--debug] server [--muhome=..]
|
||||||
|
(seq-filter #'identity ;; filter out nil
|
||||||
|
`(,(when mu4e-mu-debug "--debug")
|
||||||
|
"server"
|
||||||
|
,(when mu4e-mu-home (format "--muhome=%s" mu4e-mu-home)))))
|
||||||
|
|
||||||
|
(defun mu4e-server-repl ()
|
||||||
|
"Start a mu4e-server repl.
|
||||||
|
|
||||||
|
This is meant for debugging/testing - the repl is designed for
|
||||||
|
machines, not for humans.
|
||||||
|
|
||||||
|
You cannot run the repl when mu4e is running (or vice-versa)."
|
||||||
|
(interactive)
|
||||||
|
(if (mu4e-running-p)
|
||||||
|
(mu4e-error "Cannot run repl when mu4e is running")
|
||||||
|
(let ((cmd (string-join (cons mu4e-mu-binary (mu4e--server-args)) " ")))
|
||||||
|
(term cmd)
|
||||||
|
(rename-buffer "*mu4e-repl*" 'unique)
|
||||||
|
(message "invoked: '%s'" cmd))))
|
||||||
|
|
||||||
(defun mu4e--server-start ()
|
(defun mu4e--server-start ()
|
||||||
"Start the mu server process."
|
"Start the mu server process."
|
||||||
(let ((default-directory temporary-file-directory)) ;;ensure it's local.
|
(let ((default-directory temporary-file-directory)) ;;ensure it's local.
|
||||||
;; sanity-check 1
|
;; sanity-check 1
|
||||||
(unless (and mu4e-mu-binary (file-executable-p mu4e-mu-binary))
|
(unless (and mu4e-mu-binary (file-executable-p mu4e-mu-binary))
|
||||||
(mu4e-error
|
|
||||||
"Cannot find mu, please set `mu4e-mu-binary' to the mu executable path"))
|
|
||||||
;; sanity-check 2
|
|
||||||
(let ((version (let ((s (shell-command-to-string
|
|
||||||
(concat mu4e-mu-binary " --version"))))
|
|
||||||
(and (string-match "version \\([.0-9]+\\)" s)
|
|
||||||
(match-string 1 s)))))
|
|
||||||
(unless (string= version mu4e-mu-version)
|
|
||||||
(mu4e-error
|
(mu4e-error
|
||||||
(concat
|
"Cannot find mu, please set `mu4e-mu-binary' to the mu executable path"))
|
||||||
"Found mu version %s, but mu4e needs version %s"
|
;; sanity-check 2
|
||||||
"; please set `mu4e-mu-binary' "
|
(let ((version (let ((s (shell-command-to-string
|
||||||
"accordingly") version mu4e-mu-version)))
|
(concat mu4e-mu-binary " --version"))))
|
||||||
;; kill old/stale servers, if any.
|
(and (string-match "version \\([.0-9]+\\)" s)
|
||||||
(mu4e--kill-stale)
|
(match-string 1 s)))))
|
||||||
(let* ((process-connection-type nil) ;; use a pipe
|
(unless (string= version mu4e-mu-version)
|
||||||
(args
|
(mu4e-error
|
||||||
;; [--debug] server [--muhome=..]
|
(concat
|
||||||
(seq-filter (lambda (arg) arg) ;; filter out nil
|
"Found mu version %s, but mu4e needs version %s"
|
||||||
`(,(when mu4e-mu-debug "--debug")
|
"; please set `mu4e-mu-binary' "
|
||||||
"server"
|
"accordingly")
|
||||||
,(when mu4e-mu-home (format "--muhome=%s" mu4e-mu-home))))))
|
version mu4e-mu-version)))
|
||||||
(setq mu4e--server-buf "")
|
;; kill old/stale servers, if any.
|
||||||
(mu4e-log 'misc "* invoking '%s' with parameters %s" mu4e-mu-binary
|
(mu4e--kill-stale)
|
||||||
(mapconcat (lambda (arg) (format "'%s'" arg)) args " "))
|
(let* ((process-connection-type nil) ;; use a pipe
|
||||||
(setq mu4e--server-process (apply 'start-process
|
(args (mu4e--server-args)))
|
||||||
mu4e--server-name mu4e--server-name
|
(setq mu4e--server-buf "")
|
||||||
mu4e-mu-binary args))
|
(mu4e-log 'misc "* invoking '%s' with parameters %s" mu4e-mu-binary
|
||||||
;; register a function for (:info ...) sexps
|
(mapconcat (lambda (arg) (format "'%s'" arg)) args " "))
|
||||||
(unless mu4e--server-process
|
(setq mu4e--server-process (apply 'start-process
|
||||||
(mu4e-error "Failed to start the mu4e backend"))
|
mu4e--server-name mu4e--server-name
|
||||||
(set-process-query-on-exit-flag mu4e--server-process nil)
|
mu4e-mu-binary args))
|
||||||
(set-process-coding-system mu4e--server-process 'binary 'utf-8-unix)
|
;; register a function for (:info ...) sexps
|
||||||
(set-process-filter mu4e--server-process 'mu4e--server-filter)
|
(unless mu4e--server-process
|
||||||
(set-process-sentinel mu4e--server-process 'mu4e--server-sentinel))))
|
(mu4e-error "Failed to start the mu4e backend"))
|
||||||
|
(set-process-query-on-exit-flag mu4e--server-process nil)
|
||||||
|
(set-process-coding-system mu4e--server-process 'binary 'utf-8-unix)
|
||||||
|
(set-process-filter mu4e--server-process 'mu4e--server-filter)
|
||||||
|
(set-process-sentinel mu4e--server-process 'mu4e--server-sentinel))))
|
||||||
|
|
||||||
(defun mu4e--server-kill ()
|
(defun mu4e--server-kill ()
|
||||||
"Kill the mu server process."
|
"Kill the mu server process."
|
||||||
|
|
Loading…
Reference in New Issue