From aecf561c6ad78096a6a224e8b78d242712ed453f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renaud=20Casenave-P=C3=A9r=C3=A9?= Date: Fri, 26 Aug 2011 19:49:48 +0900 Subject: [PATCH] Add the possibility to talk to the server synchronously. --- empc.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/empc.el b/empc.el index 3c3686f..533c67d 100644 --- a/empc.el +++ b/empc.el @@ -106,6 +106,7 @@ playlist is a vector of song ids, keeping the order of the songs Leave the idle state beforehand if necessary." (if (empc-queue object) (when (string= (empc-queue-head-command object) "idle\n") + (setcar (caaar object) "noidle\n") (process-send-string (empc-process object) "noidle\n")) (when command (process-send-string (empc-process object) command))) @@ -113,6 +114,11 @@ Leave the idle state beforehand if necessary." (nconc (empc-queue object) (list (cons command (cons closure fn)))))) +(defun empc-queue-sync (object) + "Empty object's queue synchronously." + (while (and (not (string= (empc-queue-head-command object) "idle\n")) + (accept-process-output (empc-process object) 10)))) + (defun empc-queue-pop (object) "Pop the head of the queue then send the next command. If there is no command left to send, put the client in idle state." @@ -612,6 +618,18 @@ CLOSURE will be called on the parsed response." (empc-queue-push empc-object command closure (if handler handler 'empc-handle-response))) +(defun empc-send-sync (command &optional closure handler) + "Send COMMAND synchronously. That means empc will push the + command to the queue before synchronously emptying it." + (empc-send command closure handler) + (empc-queue-sync empc-object)) + +(defun empc-send-output (command) + "Send COMMAND synchronously and return the server response as string." + (let ((output)) + (empc-send-sync command nil (lambda (closures msg) (setq output msg))) + output)) + (defun empc-send-list (&rest commands) "Send COMMANDS to the mpd server using command_list. COMMANDS is a list of cons of the form: '(COMMAND . CLOSURE),