chiark / gitweb /
dot/emacs, el/dot-emacs.el: Configuration for Emacs `mpc' support.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 15 Jul 2017 00:09:11 +0000 (01:09 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 15 Jul 2017 13:58:41 +0000 (14:58 +0100)
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?

dot/emacs
el/dot-emacs.el

index 3de26941c0b5a48c58badc8e8933854da6ebd10c..757306b0c1fed938fd305b18288bd0b6d8db8926 100644 (file)
--- a/dot/emacs
+++ b/dot/emacs
   (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)
index 704c4868c145243a72228aa1c6c6f822ebb11073..6ed0e0434749768ef26a9ee3bf894a370d5fb206 100644 (file)
@@ -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.