From: Christophe Rhodes Date: Fri, 12 Dec 2014 17:28:29 +0000 (+0000) Subject: convenience for squeeze connection parameters X-Git-Url: http://christophe.rhodes.io/gitweb/?a=commitdiff_plain;h=cd22a4a10128e91b436564361159093e9e12ffd9;p=squeeze-el.git convenience for squeeze connection parameters also define a `squeeze-control-reconnect' command --- diff --git a/squeeze.el b/squeeze.el index f44bce8..1d4a92d 100644 --- a/squeeze.el +++ b/squeeze.el @@ -53,6 +53,7 @@ (define-key map (kbd "<") 'squeeze-control-previous-track) (define-key map (kbd "s") 'squeeze-control-select-player) (define-key map (kbd "a") 'squeeze-list-albums) + (define-key map (kbd "!") 'squeeze-control-reconnect) map)) (defvar squeeze-control-current-player nil) @@ -564,33 +565,41 @@ (port (read-number "Port: " port))) (cons host port))) +(cl-defmacro with-squeeze-parameters ((address port) &body body) + (declare (indent 1)) + `(progn + (unless ,address (setq ,address squeeze-server-address)) + (unless ,port (setq ,port squeeze-server-port)) + (when current-prefix-arg + (let ((parameters (squeeze-read-server-parameters ,address ,port))) + (setq ,address (car parameters) + ,port (cdr parameters)))) + ,@body)) + (defun squeeze (&optional address port) (interactive) - (unless address (setq address squeeze-server-address)) - (unless port (setq port squeeze-server-port)) - (when current-prefix-arg - (let ((parameters (squeeze-read-server-parameters address port))) - (setq address (car parameters) - port (cdr parameters)))) - (let ((buffer (make-comint-in-buffer "squeeze" nil (cons address port)))) - (switch-to-buffer buffer) - (squeeze-mode))) + (with-squeeze-parameters (address port) + (let ((buffer (make-comint-in-buffer "squeeze" nil (cons address port)))) + (switch-to-buffer buffer) + (squeeze-mode)))) (defun squeeze-control (&optional address port) (interactive) - (unless address (setq address squeeze-server-address)) - (unless port (setq port squeeze-server-port)) - (when current-prefix-arg - (let ((parameters (squeeze-read-server-parameters address port))) - (setq address (car parameters) - port (cdr parameters)))) - (let ((current-prefix-arg nil)) - (squeeze address port)) - (let ((buffer (get-buffer-create "*squeeze-control*"))) - (switch-to-buffer buffer) - (squeeze-control-listen) - (squeeze-control-refresh) - (squeeze-control-display-players))) + (with-squeeze-parameters (address port) + (let ((current-prefix-arg nil)) + (squeeze address port)) + (let ((buffer (get-buffer-create "*squeeze-control*"))) + (switch-to-buffer buffer) + (squeeze-control-listen) + (squeeze-control-refresh) + (squeeze-control-display-players)))) + +(defun squeeze-control-reconnect (&optional address port) + (interactive) + (with-squeeze-parameters (address port) + (kill-buffer (get-buffer "*squeeze*")) + (let ((current-prefix-arg nil)) + (squeeze-control address port)))) (defun squeeze-list-albums () (interactive)