Fix a bug that prevented sending any command.
This commit is contained in:
parent
f82a7a8b01
commit
1c129c9313
1 changed files with 8 additions and 7 deletions
15
empc.el
15
empc.el
|
|
@ -164,6 +164,7 @@ SERVICE is the name of the service desired, or an integer specifying
|
||||||
|
|
||||||
(let* ((process (open-network-stream name buffer host service))
|
(let* ((process (open-network-stream name buffer host service))
|
||||||
(object `((nil ,process) nil nil))) ;; this weird form represents an empty object as described in empc-object
|
(object `((nil ,process) nil nil))) ;; this weird form represents an empty object as described in empc-object
|
||||||
|
(empc-commands-set object '("password" "commands" "status" "idle"))
|
||||||
(empc-queue-push object nil nil `(lambda (proc string)
|
(empc-queue-push object nil nil `(lambda (proc string)
|
||||||
(message "Connection to %s established" ',host)))
|
(message "Connection to %s established" ',host)))
|
||||||
(set-process-filter process `(lambda (proc string)
|
(set-process-filter process `(lambda (proc string)
|
||||||
|
|
@ -671,7 +672,7 @@ Send the password or retrieve available commands."
|
||||||
"Send COMMAND to the mpd server.
|
"Send COMMAND to the mpd server.
|
||||||
CLOSURE will be called on the parsed response."
|
CLOSURE will be called on the parsed response."
|
||||||
(empc-ensure-connected)
|
(empc-ensure-connected)
|
||||||
(if (memq command (empc-commands empc-object))
|
(if (member (car (split-string command)) (empc-commands empc-object))
|
||||||
(progn
|
(progn
|
||||||
(unless (string= (substring command -1) "\n")
|
(unless (string= (substring command -1) "\n")
|
||||||
(setq command (concat command "\n")))
|
(setq command (concat command "\n")))
|
||||||
|
|
@ -721,7 +722,7 @@ If the stream process is killed for whatever the reason, pause mpd if possible."
|
||||||
"Update the status and execute the forms in BODY."
|
"Update the status and execute the forms in BODY."
|
||||||
`(if (empc-status empc-object)
|
`(if (empc-status empc-object)
|
||||||
,@body
|
,@body
|
||||||
(empc-send "status\n" '(empc-response-get-status (lambda (data) ,@body)))))
|
(empc-send "status" '(empc-response-get-status (lambda (data) ,@body)))))
|
||||||
|
|
||||||
(defmacro empc-define-simple-command (command &optional closure)
|
(defmacro empc-define-simple-command (command &optional closure)
|
||||||
"Define a simple command that doesn't need an argument."
|
"Define a simple command that doesn't need an argument."
|
||||||
|
|
@ -730,7 +731,7 @@ If the stream process is killed for whatever the reason, pause mpd if possible."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((debug-on-error t))
|
(let ((debug-on-error t))
|
||||||
(empc-send (concat ,command (when arg (concat " " (if (stringp arg)
|
(empc-send (concat ,command (when arg (concat " " (if (stringp arg)
|
||||||
arg (number-to-string arg)))) "\n")
|
arg (number-to-string arg)))))
|
||||||
,closure))))
|
,closure))))
|
||||||
|
|
||||||
(defmacro empc-define-toggle-command (command &optional state-name attr &rest body)
|
(defmacro empc-define-toggle-command (command &optional state-name attr &rest body)
|
||||||
|
|
@ -740,7 +741,7 @@ If the stream process is killed for whatever the reason, pause mpd if possible."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((debug-on-error t))
|
(let ((debug-on-error t))
|
||||||
(if state
|
(if state
|
||||||
(empc-send (concat ,(concat command " ") (int-to-string state) "\n"))
|
(empc-send (concat ,(concat command " ") (int-to-string state)))
|
||||||
(with-updated-status
|
(with-updated-status
|
||||||
(let ((,(if attr attr
|
(let ((,(if attr attr
|
||||||
(intern command))
|
(intern command))
|
||||||
|
|
@ -750,7 +751,7 @@ If the stream process is killed for whatever the reason, pause mpd if possible."
|
||||||
,(if body
|
,(if body
|
||||||
`(progn ,@body)
|
`(progn ,@body)
|
||||||
`(empc-send (concat ,command (if (= ,(if attr attr
|
`(empc-send (concat ,command (if (= ,(if attr attr
|
||||||
(intern command)) 1) " 0" " 1") "\n")))))))))
|
(intern command)) 1) " 0" " 1"))))))))))
|
||||||
|
|
||||||
(defmacro empc-define-command-with-pos (command &optional closure)
|
(defmacro empc-define-command-with-pos (command &optional closure)
|
||||||
"Define a command that need a position either as a parameter or
|
"Define a command that need a position either as a parameter or
|
||||||
|
|
@ -763,7 +764,7 @@ computed using point in buffer."
|
||||||
(unless pos
|
(unless pos
|
||||||
(setq pos (count-lines (point-min) (point))))
|
(setq pos (count-lines (point-min) (point))))
|
||||||
(let ((id (elt (empc-playlist empc-object) pos)))
|
(let ((id (elt (empc-playlist empc-object) pos)))
|
||||||
(empc-send (concat ,(concat command "id ") (number-to-string id) "\n") ,closure)))))
|
(empc-send (concat ,(concat command "id ") (number-to-string id)) ,closure)))))
|
||||||
|
|
||||||
(defmacro empc-define-command-with-current-id (command &optional closure)
|
(defmacro empc-define-command-with-current-id (command &optional closure)
|
||||||
"Define a command that uses the current song as a parameter."
|
"Define a command that uses the current song as a parameter."
|
||||||
|
|
@ -773,7 +774,7 @@ computed using point in buffer."
|
||||||
(let ((debug-on-error t))
|
(let ((debug-on-error t))
|
||||||
(empc-send (concat ,(concat command "id ")
|
(empc-send (concat ,(concat command "id ")
|
||||||
(number-to-string (empc-status-get empc-object :songid))
|
(number-to-string (empc-status-get empc-object :songid))
|
||||||
(when arg (concat " " (if (stringp arg) arg (number-to-string arg)))) "\n")
|
(when arg (concat " " (if (stringp arg) arg (number-to-string arg)))))
|
||||||
,closure))))
|
,closure))))
|
||||||
|
|
||||||
;; Querying MPD's status
|
;; Querying MPD's status
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue