From 15e54145b44fc4e0e69207d1dc2bfa12f4ed0eb4 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 10 Apr 2013 09:17:27 -0400 Subject: [PATCH] * lisp/mpc.el (mpc-proc): Add `restart' argument. (mpc-proc-cmd): Use it. (mpc--status-timer-run): Also catch signals from `mpc-proc'. (mpc-status-buffer-show, mpc-tagbrowser-dir-toggle): Call `mpc-proc' less often. --- lisp/ChangeLog | 8 ++++++++ lisp/mpc.el | 33 ++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0188762025..9ca8db15cc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-04-10 Stefan Monnier + + * mpc.el (mpc-proc): Add `restart' argument. + (mpc-proc-cmd): Use it. + (mpc--status-timer-run): Also catch signals from `mpc-proc'. + (mpc-status-buffer-show, mpc-tagbrowser-dir-toggle): Call `mpc-proc' + less often. + 2013-04-10 Masatake YAMATO * progmodes/sh-script.el: Implement `sh-mode' own diff --git a/lisp/mpc.el b/lisp/mpc.el index 9d9da27f6d..ad7381bb4b 100644 --- a/lisp/mpc.el +++ b/lisp/mpc.el @@ -320,10 +320,11 @@ defaults to 6600 and HOST defaults to localhost." (if tmp (push (nreverse tmp) alists)) (nreverse alists))) -(defun mpc-proc () +(defun mpc-proc (&optional restart) (unless (and mpc-proc (buffer-live-p (process-buffer mpc-proc)) - (not (memq (process-status mpc-proc) '(closed)))) + (not (and restart + (memq (process-status mpc-proc) '(closed))))) (mpc--proc-connect mpc-host)) mpc-proc) @@ -356,7 +357,7 @@ 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))) + (let ((proc (mpc-proc 'restart))) (if (and callback (not (process-get proc 'ready))) (let ((old (process-get proc 'callback))) (process-put proc 'callback @@ -491,10 +492,10 @@ to call FUN for any change whatsoever.") (cancel-timer mpc--status-timer) (setq mpc--status-timer nil))) (defun mpc--status-timer-run () - (when (process-get (mpc-proc) 'ready) (condition-case err - (with-local-quit (mpc-status-refresh)) - (error (message "MPC: %s" err))))) + (when (process-get (mpc-proc) 'ready) + (with-local-quit (mpc-status-refresh))) + (error (message "MPC: %s" err)))) (defvar mpc--status-idle-timer nil) (defun mpc--status-idle-timer-start () @@ -1177,14 +1178,15 @@ If PLAYLIST is t or nil or missing, use the main playlist." (defun mpc-status-buffer-show () (interactive) - (let* ((buf (mpc-proc-buffer (mpc-proc) 'status)) - (songs-buf (mpc-proc-buffer (mpc-proc) 'songs)) + (let* ((proc (mpc-proc)) + (buf (mpc-proc-buffer proc 'status)) + (songs-buf (mpc-proc-buffer proc 'songs)) (songs-win (if songs-buf (get-buffer-window songs-buf 0)))) (unless (buffer-live-p buf) (setq buf (get-buffer-create "*MPC-Status*")) (with-current-buffer buf (mpc-status-mode)) - (mpc-proc-buffer (mpc-proc) 'status buf)) + (mpc-proc-buffer proc 'status buf)) (if (null songs-win) (pop-to-buffer buf) (let ((_win (split-window songs-win 20 t))) (set-window-dedicated-p songs-win nil) @@ -1692,13 +1694,14 @@ Return non-nil if a selection was deactivated." (mpc-event-set-point event) (let ((name (buffer-substring (line-beginning-position) (line-end-position))) - (prop (intern mpc-tag))) - (if (not (member name (process-get (mpc-proc) prop))) - (process-put (mpc-proc) prop - (cons name (process-get (mpc-proc) prop))) - (let ((new (delete name (process-get (mpc-proc) prop)))) + (prop (intern mpc-tag)) + (proc (mpc-proc))) + (if (not (member name (process-get proc prop))) + (process-put proc prop + (cons name (process-get proc prop))) + (let ((new (delete name (process-get proc prop)))) (setq name (concat name "/")) - (process-put (mpc-proc) prop + (process-put proc prop (delq nil (mapcar (lambda (x) (if (string-prefix-p name x) -- 2.20.1