From: Mark Wooding Date: Sat, 15 Jul 2017 00:09:11 +0000 (+0100) Subject: dot/emacs, el/dot-emacs.el: Configuration for Emacs `mpc' support. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/0f81a1314ae8d217805a705a74e425f63b513f9b dot/emacs, el/dot-emacs.el: Configuration for Emacs `mpc' support. I can control audio from Emacs. That's kind of cool. Admittedly, `mpc' is annoying and deficient in a number of ways, but it's still cool. Right? --- diff --git a/dot/emacs b/dot/emacs index 3de2694..757306b 100644 --- a/dot/emacs +++ b/dot/emacs @@ -606,6 +606,11 @@ (global-set-key [?\C-c ?m ?d] 'magit-dispatch-popup) (global-set-key [?\C-c ?m ?w] 'magit-wip-log) (global-set-key [?\C-c ?m ?r] 'magit-list-repositories) + (global-set-key [?\C-c ?p ?p] 'mdw-mpc-play-or-pause) + (global-set-key [?\C-c ?p ?s] 'mpc-stop) + (global-set-key [?\C-c ?p ?<] 'mpc-prev) + (global-set-key [?\C-c ?p ?>] 'mpc-next) + (global-set-key [?\C-c ?p ??] 'mdw-mpc-now-playing) (global-set-key [?\C-c ?k] 'compile) (global-set-key [?\C-x ?3] 'mdw-split-window-horizontally) (global-set-key [?\M-#] 'calc-dispatch) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 704c486..6ed0e04 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -3752,6 +3752,64 @@ (defun mdw-repolist-column-unpushed-to-upstream (_id) (propertize (number-to-string n) 'face (if (> n 0) 'bold 'shadow)))))) +;;;-------------------------------------------------------------------------- +;;; MPC configuration. + +(defun mdw-mpc-play-or-pause () + (interactive) + (require 'mpc) + (if (member (cdr (assq 'state (mpc-cmd-status))) '("play")) + (mpc-pause) + (mpc-play))) + +(setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist)) + +(defun mdw-mpc-now-playing () + (interactive) + (require 'mpc) + (save-excursion + (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong")))) + (mpc--status-callback)) + (let ((state (cdr (assq 'state mpc-status)))) + (cond ((member state '("stop")) + (message "mpd stopped.")) + ((member state '("play" "pause")) + (let* ((artist (cdr (assq 'Artist mpc-status))) + (album (cdr (assq 'Album mpc-status))) + (title (cdr (assq 'Title mpc-status))) + (file (cdr (assq 'file mpc-status))) + (duration-string (cdr (assq 'Time mpc-status))) + (time-string (cdr (assq 'time mpc-status))) + (time (and time-string + (parse-integer + (if (string-match ":" time-string) + (substring time-string + 0 (match-beginning 0)) + (time-string))))) + (duration (and duration-string + (parse-integer duration-string))) + (pos (and time duration + (format " [%d:%02d/%d:%02d]" + (/ time 60) (mod time 60) + (/ duration 60) (mod duration 60)))) + (fmt (cond ((and artist title) + (format "`%s' by %s%s" title artist + (if album (format ", from `%s'" album) + ""))) + (file + (format "`%s' (no tags)" file)) + (t + "(no idea what's playing!)")))) + (if (string= state "play") + (message "mpd playing %s%s" fmt (or pos "")) + (message "mpd paused in %s%s" fmt (or pos ""))))) + (t + (message "mpd in unknown state `%s'" state))))) + +(autoload 'mpc-pause "mpc") +(autoload 'mpc-next "mpc") +(autoload 'mpc-prev "mpc") + ;;;-------------------------------------------------------------------------- ;;; Inferior Emacs Lisp.