- (when (equal host "")
- (setf host nil))
- (when (equal port "")
- (setf port nil))
- (let ((connection (open-network-stream "ampc"
- (with-current-buffer
- (get-buffer-create " *mpc*")
- (delete-region (point-min)
- (point-max))
- (current-buffer))
- (or host "localhost")
- (or port 6600)
- :type 'plain :return-list t)))
- (unless (car connection)
- (error "Failed connecting to server: %s"
- (plist-get ampc-connection :error)))
- (setf ampc-connection (car connection)))
- (setf ampc-outstanding-commands '((setup)))
- (set-process-coding-system ampc-connection 'utf-8-unix 'utf-8-unix)
- (set-process-filter ampc-connection 'ampc-filter)
- (set-process-query-on-exit-flag ampc-connection nil)
+ (when (or (not host) (equal host ""))
+ (setf host "localhost"))
+ (when (or (not port) (equal port ""))
+ (setf port 6600))
+ (when (and ampc-connection
+ (or (not (equal host ampc-host))
+ (not (equal port ampc-port))
+ (not (ampc-on-p))))
+ (ampc-quit))
+ (unless ampc-connection
+ (let ((connection (open-network-stream "ampc"
+ (with-current-buffer
+ (get-buffer-create " *mpc*")
+ (delete-region (point-min)
+ (point-max))
+ (current-buffer))
+ host
+ port
+ :type 'plain :return-list t)))
+ (unless (car connection)
+ (error "Failed connecting to server: %s"
+ (plist-get ampc-connection :error)))
+ (setf ampc-connection (car connection)
+ ampc-host host
+ ampc-port port))
+ (set-process-coding-system ampc-connection 'utf-8-unix 'utf-8-unix)
+ (set-process-filter ampc-connection 'ampc-filter)
+ (set-process-query-on-exit-flag ampc-connection nil)
+ (setf ampc-outstanding-commands '((setup))))