Function: mpc-proc-cmd

mpc-proc-cmd is a byte-compiled function defined in mpc.el.gz.

Signature

(mpc-proc-cmd CMD &optional CALLBACK)

Documentation

Send command CMD to the MPD server.

If CALLBACK is nil, wait for the command to finish before returning, otherwise return immediately and call CALLBACK with no argument when the command terminates. CMD can be a string which is passed as-is to MPD or a list of strings which will be concatenated with proper quoting before passing them to MPD.

Source Code

;; Defined in /usr/src/emacs/lisp/mpc.el.gz
(defun mpc-proc-cmd (cmd &optional callback)
  "Send command CMD to the MPD server.
If CALLBACK is nil, wait for the command to finish before returning,
otherwise return immediately and call CALLBACK with no argument
when the command terminates.
CMD can be a string which is passed as-is to MPD or a list of strings
which will be concatenated with proper quoting before passing them to MPD."
  (let ((proc (mpc-proc 'restart)))
    (if (and callback (not (process-get proc 'ready)))
        (let ((old (process-get proc 'callback)))
          (process-put proc 'callback
                       (lambda ()
                         (funcall old)
                         (mpc-proc-cmd cmd callback))))
      ;; Wait for any pending async command to terminate.
      (mpc-proc-sync proc)
      (process-put proc 'ready nil)
      (with-current-buffer (process-buffer proc)
        (erase-buffer)
        (mpc--debug "Send \"%s\"" cmd)
        (process-send-string
         proc (concat (if (stringp cmd) cmd
                        (mapconcat #'mpc--proc-quote-string cmd " "))
                      "\n")))
      (if callback
          ;; (let ((buf (current-buffer)))
          (process-put proc 'callback
                       callback
                       ;; (lambda ()
                       ;;   (funcall callback
                       ;;            (prog1 (current-buffer)
                       ;;              (set-buffer buf)))))
                       )
        ;; If `callback' is nil, we're executing synchronously.
        (process-put proc 'callback #'ignore)
        ;; This returns the process's buffer.
        (mpc-proc-sync proc)))))