Function: mpc--proc-connect

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

Signature

(mpc--proc-connect HOST)

Source Code

;; Defined in /usr/src/emacs/lisp/mpc.el.gz
(defun mpc--proc-connect (host)
  (let ((port 6600)
        local
        pass)

    (when (string-match "\\`\\(?:\\(.*\\)@\\)?\\(.*?\\)\\(?::\\(.*\\)\\)?\\'"
                        host)
      (let ((v (match-string 1 host)))
        (when (and (stringp v) (not (string= "" v)))
          (setq pass v)))
      (let ((v (match-string 3 host)))
        (setq host (match-string 2 host))
        (when (and (stringp v) (not (string= "" v)))
          (setq port v))))
    (when (file-name-absolute-p host)
      ;; Expand file name because `file-name-absolute-p'
      ;; considers paths beginning with "~" as absolute
      (setq host (expand-file-name host))
      (setq local t))

    (mpc--debug "Connecting to %s:%s..." host port)
    (with-current-buffer (get-buffer-create (format " *mpc-%s:%s*" host port))
      ;; (pop-to-buffer (current-buffer))
      (let (proc)
        (while (and (setq proc (get-buffer-process (current-buffer)))
                    (progn ;; (debug)
                      (delete-process proc)))))
      (erase-buffer)
      (let* ((coding-system-for-read 'utf-8-unix)
             (coding-system-for-write 'utf-8-unix)
             (proc (condition-case err
                       (make-network-process :name "MPC" :buffer (current-buffer)
                                             :host (unless local host)
                                             :service (if local host port)
                                             :family (if local 'local))
                     (error (user-error (error-message-string err))))))
        (when (processp mpc-proc)
          ;; Inherit the properties of the previous connection.
          (let ((plist (process-plist mpc-proc)))
            (while plist (process-put proc (pop plist) (pop plist)))))
        (mpc-proc-buffer proc 'mpd-commands (current-buffer))
        (process-put proc 'callback #'ignore)
        (process-put proc 'ready nil)
        (clrhash mpc--find-memoize)
        (set-process-filter proc #'mpc--proc-filter)
        (set-process-sentinel proc #'ignore)
        (set-process-query-on-exit-flag proc nil)
        ;; This may be called within a process filter ;-(
        (with-local-quit (mpc-proc-sync proc))
        (setq mpc-proc proc)
        (when pass
          (mpc-proc-cmd (list "password" pass) nil))))))