aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Nazarewicz2012-08-04 03:37:27 -0400
committerStefan Monnier2012-08-04 03:37:27 -0400
commit00340faf00fcb59e9a2cf16d9ff8395c9c48a167 (patch)
tree91442a9c56844d97a8eb7caf10748c1b58b044da
parent185ee1468eede6b20587e15b3b81aebe66b6479a (diff)
downloademacs-00340faf00fcb59e9a2cf16d9ff8395c9c48a167.tar.gz
emacs-00340faf00fcb59e9a2cf16d9ff8395c9c48a167.zip
* lisp/mpc.el: Support password in host argument.
(mpc--proc-connect): Parse and use new password element. Set mpc-proc variable instead of returning process. (mpc-proc): Adjust accordingly.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/mpc.el59
2 files changed, 43 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0d206f5368f..91a280211d3 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12012-08-04 Michal Nazarewicz <mina86@mina86.com> (tiny change)
2
3 * lisp/mpc.el: Support password in host argument.
4 (mpc--proc-connect): Parse and use new password element.
5 Set mpc-proc variable instead of returning process.
6 (mpc-proc): Adjust accordingly.
7
12012-08-03 Eli Zaretskii <eliz@gnu.org> 82012-08-03 Eli Zaretskii <eliz@gnu.org>
2 9
3 * whitespace.el (whitespace-display-mappings): Use Unicode 10 * whitespace.el (whitespace-display-mappings): Use Unicode
diff --git a/lisp/mpc.el b/lisp/mpc.el
index ff5ce801c63..f1dbb3803b6 100644
--- a/lisp/mpc.el
+++ b/lisp/mpc.el
@@ -199,9 +199,10 @@ numerically rather than lexicographically."
199(defcustom mpc-host 199(defcustom mpc-host
200 (concat (or (getenv "MPD_HOST") "localhost") 200 (concat (or (getenv "MPD_HOST") "localhost")
201 (if (getenv "MPD_PORT") (concat ":" (getenv "MPD_PORT")))) 201 (if (getenv "MPD_PORT") (concat ":" (getenv "MPD_PORT"))))
202 "Host (and port) where the Music Player Daemon is running. 202 "Host (and port) where the Music Player Daemon is running. The
203The format is \"HOST\" or \"HOST:PORT\" where PORT defaults to 6600 203format is \"HOST\", \"HOST:PORT\", \"PASSWORD@HOST\" or
204and HOST defaults to localhost." 204\"PASSWORD@HOST:PORT\" where PASSWORD defaults to no password, PORT
205defaults to 6600 and HOST defaults to localhost."
205 :type 'string) 206 :type 'string)
206 207
207(defvar mpc-proc nil) 208(defvar mpc-proc nil)
@@ -252,20 +253,30 @@ and HOST defaults to localhost."
252 (funcall callback))))))))) 253 (funcall callback)))))))))
253 254
254(defun mpc--proc-connect (host) 255(defun mpc--proc-connect (host)
255 (mpc--debug "Connecting to %s..." host) 256 (let ((port 6600)
256 (with-current-buffer (get-buffer-create (format " *mpc-%s*" host)) 257 pass)
257 ;; (pop-to-buffer (current-buffer)) 258
258 (let (proc) 259 (when (string-match "\\`\\(?:\\(.*\\)@\\)?\\(.*?\\)\\(?::\\(.*\\)\\)?\\'"
259 (while (and (setq proc (get-buffer-process (current-buffer))) 260 host)
260 (progn ;; (debug) 261 (let ((v (match-string 1 host)))
261 (delete-process proc))))) 262 (when (and (stringp v) (not (string= "" v)))
262 (erase-buffer) 263 (setq pass v)))
263 (let ((port 6600)) 264 (let ((v (match-string 3 host)))
264 (when (string-match ":[^.]+\\'" host) 265 (setq host (match-string 2 host))
265 (setq port (substring host (1+ (match-beginning 0)))) 266 (when (and (stringp v) (not (string= "" v)))
266 (setq host (substring host 0 (match-beginning 0))) 267 (setq port
267 (unless (string-match "[^[:digit:]]" port) 268 (if (string-match "[^[:digit:]]" v)
268 (setq port (string-to-number port)))) 269 (string-to-number v)
270 v)))))
271
272 (mpc--debug "Connecting to %s:%s..." host port)
273 (with-current-buffer (get-buffer-create (format " *mpc-%s:%s*" host port))
274 ;; (pop-to-buffer (current-buffer))
275 (let (proc)
276 (while (and (setq proc (get-buffer-process (current-buffer)))
277 (progn ;; (debug)
278 (delete-process proc)))))
279 (erase-buffer)
269 (let* ((coding-system-for-read 'utf-8-unix) 280 (let* ((coding-system-for-read 'utf-8-unix)
270 (coding-system-for-write 'utf-8-unix) 281 (coding-system-for-write 'utf-8-unix)
271 (proc (open-network-stream "MPC" (current-buffer) host port))) 282 (proc (open-network-stream "MPC" (current-buffer) host port)))
@@ -282,7 +293,9 @@ and HOST defaults to localhost."
282 (set-process-query-on-exit-flag proc nil) 293 (set-process-query-on-exit-flag proc nil)
283 ;; This may be called within a process filter ;-( 294 ;; This may be called within a process filter ;-(
284 (with-local-quit (mpc-proc-sync proc)) 295 (with-local-quit (mpc-proc-sync proc))
285 proc)))) 296 (setq mpc-proc proc)
297 (when pass
298 (mpc-proc-cmd (list "password" pass) nil))))))
286 299
287(defun mpc--proc-quote-string (s) 300(defun mpc--proc-quote-string (s)
288 (if (numberp s) (number-to-string s) 301 (if (numberp s) (number-to-string s)
@@ -306,11 +319,11 @@ and HOST defaults to localhost."
306 (nreverse alists))) 319 (nreverse alists)))
307 320
308(defun mpc-proc () 321(defun mpc-proc ()
309 (or (and mpc-proc 322 (unless (and mpc-proc
310 (buffer-live-p (process-buffer mpc-proc)) 323 (buffer-live-p (process-buffer mpc-proc))
311 (not (memq (process-status mpc-proc) '(closed))) 324 (not (memq (process-status mpc-proc) '(closed))))
312 mpc-proc) 325 (mpc--proc-connect mpc-host))
313 (setq mpc-proc (mpc--proc-connect mpc-host)))) 326 mpc-proc)
314 327
315(defun mpc-proc-check (proc) 328(defun mpc-proc-check (proc)
316 (let ((error-text (process-get proc 'mpc-proc-error))) 329 (let ((error-text (process-get proc 'mpc-proc-error)))