diff options
author | jao <jao@gnu.org> | 2021-06-02 03:20:42 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2021-06-02 03:51:05 +0100 |
commit | 3d81e177f001cc4f8518cc9f3274ef5a264c022c (patch) | |
tree | 1a5a719435b11b348cd3dfa4f049efe9c29d0677 /lib | |
parent | 1aae66195191dfd72ec015d273e375d0decb9953 (diff) | |
download | elibs-3d81e177f001cc4f8518cc9f3274ef5a264c022c.tar.gz elibs-3d81e177f001cc4f8518cc9f3274ef5a264c022c.tar.bz2 |
jao-mpc: proper handling of local port
Diffstat (limited to 'lib')
-rw-r--r-- | lib/media/jao-mpc.el | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el index ab8eef0..614557c 100644 --- a/lib/media/jao-mpc.el +++ b/lib/media/jao-mpc.el @@ -34,10 +34,12 @@ (defconst jao-mpc--albums "*MPC Albums*") (defconst jao-mpc--playlist "*MPC Playlist*") -(defvar-local jao-mpc-port 6600) +(defvar jao-mpc-port 6600) +(defvar-local jao-mpc--port nil) (defun jao-mpc--cmd (cmd &optional port) - (shell-command-to-string (format "mpc -p %s %s" (or port jao-mpc-port) cmd))) + (let ((port (or port jao-mpc--port jao-mpc-port))) + (shell-command-to-string (format "mpc -p %s %s" port cmd)))) (defconst jao-mpc--fields '(artist album composer originaldate genre title track position time name)) @@ -134,14 +136,14 @@ (define-key jao-mpc-albums-mode-map (kbd "RET") #'jao-mpc--add-and-play) (define-key jao-mpc-albums-mode-map (kbd "q") #'bury-buffer) -(define-derived-mode jao-mpc-playlist-mode fundamental-mode "MPC Playlist" +(define-derived-mode jao-mpc-playlist-mode nil "MPC Playlist" "Mode to display the list of playlist known by mpd." (read-only-mode -1) (delete-region (point-min) (point-max)) - (setq-local jao-mpc-port jao-mpc-port) + (setq-local jao-mpc--port jao-mpc-port) (insert (jao-mpc--cmd "playlist")) (goto-char (point-min)) - (display-line-numbers-mode) + (display-line-numbers-mode 1) (read-only-mode 1)) (defun jao-mpc--playlist-goto-current () @@ -165,8 +167,7 @@ (defun jao-mpc--playlist-buffer (&optional port) (with-current-buffer (get-buffer-create jao-mpc--playlist) - (setq-local jao-mpc-port (or port jao-mpc-port)) - (jao-mpc-playlist-mode) + (let ((jao-mpc-port port)) (jao-mpc-playlist-mode)) (current-buffer))) ;;;###autoload @@ -235,17 +236,19 @@ (cons (match-string 2 c) (match-string 1 c)))))) ;;;###autoload +(defun jao-mpc-connect (&optional port) + (interactive) + (jao-mpc--idle-loop port) + (when (jao-mpc--playing-p port) (jao-mpc--set-current-str port))) + +;;;###autoload (defun jao-mpc-setup (&optional secondary-port) (setq jao-lyrics-info-function #'jao-mpc-lyrics-track-data) (jao-random-album-setup #'jao-mpc--album-buffer #'jao-mpc--add-and-play #'jao-mpc-stop) - (jao-mpc--idle-loop) - (when (jao-mpc--playing-p) (jao-mpc--set-current-str)) - (when secondary-port - (jao-mpc--idle-loop secondary-port) - (when (jao-mpc--playing-p secondary-port) - (jao-mpc--set-current-str secondary-port))) + (jao-mpc-connect) + (when secondary-port (jao-mpc-connect secondary-port)) (jao-minibuffer-add-msg-variable 'jao-mpc-minibuffer-str 1)) (provide 'jao-mpc) |