[Emacs] Add hydra for controlling MPD from Emacs

This commit is contained in:
Lucien Cartier-Tilet 2021-10-22 12:09:22 +02:00
parent ab3ec171e5
commit 8d247d4733
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -1912,7 +1912,7 @@ notification system, and Ill activate the modeline notification.
(setq mu4e-alert-interesting-mail-query "flag:unread")) (setq mu4e-alert-interesting-mail-query "flag:unread"))
#+end_src #+end_src
*** EMMS *** EMMS and Media
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: Packages-Configuration-Applications-EMMS-ij71fr61v8j0 :CUSTOM_ID: Packages-Configuration-Applications-EMMS-ij71fr61v8j0
:END: :END:
@ -1923,6 +1923,7 @@ configuration [[file:mpd.org][here]]).
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package emms (use-package emms
:defer t :defer t
:after all-the-icons
:straight (:build t) :straight (:build t)
:init :init
(require 'emms-setup) (require 'emms-setup)
@ -1931,6 +1932,7 @@ configuration [[file:mpd.org][here]]).
(add-to-list 'emms-player-list 'emms-player-mpd) (add-to-list 'emms-player-list 'emms-player-mpd)
(emms-player-mpd-connect) (emms-player-mpd-connect)
(add-hook 'emms-playlist-cleared-hook #'emms-player-mpd-clear) (add-hook 'emms-playlist-cleared-hook #'emms-player-mpd-clear)
<<emms-media-hydra>>
:general :general
(:keymaps 'emms-browser-mode-map (:keymaps 'emms-browser-mode-map
:states '(normal emacs) :states '(normal emacs)
@ -1963,8 +1965,11 @@ configuration [[file:mpd.org][here]]).
(:states 'normal (:states 'normal
:prefix "SPC" :prefix "SPC"
"m" '(nil :which-key "media") "m" '(nil :which-key "media")
"m." #'hydra-media/body
"m<" #'emms-player-mpd-previous "m<" #'emms-player-mpd-previous
"m«" #'emms-player-mpd-previous
"m>" #'emms-player-mpd-next "m>" #'emms-player-mpd-next
"m»" #'emms-player-mpd-next
"mc" #'emms-player-mpd-clear "mc" #'emms-player-mpd-clear
"me" '(nil :which-key "emms") "me" '(nil :which-key "emms")
"meb" #'emms-browser "meb" #'emms-browser
@ -1982,7 +1987,35 @@ configuration [[file:mpd.org][here]]).
(emms-player-mpd-music-directory (expand-file-name "~/Music")))) (emms-player-mpd-music-directory (expand-file-name "~/Music"))))
#+end_src #+end_src
#+RESULTS: I also want to create a small hydra for manipulating MPD:
#+name: emms-media-hydra
#+begin_src emacs-lisp :tangle no
(let ((shell-command-and-echo (lambda (command &optional echo)
(with-temp-buffer
(shell-command command
(current-buffer)
(current-buffer)))
(when echo
(message "mpc %s"
(string-trim
(shell-command-to-string "mpc volume")))))))
(defhydra hydra-media ()
"
^Tracks^ ^Volume^ ^Other^
^^^^^^^^----------------------------
[_c_] %s(all-the-icons-material \"skip_previous\" :height 1.0 :v-adjust -0.2) [_t_] %s(all-the-icons-material \"volume_up\" :height 1.0 :v-adjust -0.2) [_p_] %s(all-the-icons-material \"play_arrow\" :height 1.0 :v-adjust -0.2)
[_r_] %s(all-the-icons-material \"skip_next\" :height 1.0 :v-adjust -0.2) [_s_] %s(all-the-icons-material \"volume_down\" :height 1.0 :v-adjust -0.2) [_S_] %s(all-the-icons-material \"stop\" :height 1.0 :v-adjust -0.2)
[_q_] quit
"
("c" emms-player-mpd-previous)
("r" emms-player-mpd-next)
("t" (apply shell-command-and-echo '("mpc volume -2" "mpc volume")))
("s" (apply shell-command-and-echo '("mpc volume +2" "mpc volume")))
("p" (apply shell-command-and-echo '("mpc toggle")))
("S" emms-player-mpd-stop)
("q" nil :exit t)))
#+end_src
*** Nov *** Nov
:PROPERTIES: :PROPERTIES: