From d1c149394597a226a3f05acc817837ee6435835f Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Fri, 29 Oct 2021 16:30:03 +0200 Subject: [PATCH] [Emacs] Better media control keybinds and `shell-command-and-echo' `shell-command-and-echo' now takes an additional argument that will prefix the output of its ECHO argument. Also add documentation for the function This commit removes keybind `SPC m P' in favor of only `SPC m p' which toggles the state of MPD between play and pause. --- org/config/emacs.org | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/org/config/emacs.org b/org/config/emacs.org index 0c212f4..1ebfd22 100644 --- a/org/config/emacs.org +++ b/org/config/emacs.org @@ -1975,8 +1975,10 @@ configuration [[file:mpd.org][here]]). "meb" #'emms-browser "mep" #'emms-playlist-mode-go "mes" #'emms-player-mpd-show - "mp" #'emms-player-mpd-play - "mP" #'emms-player-mpd-pause + "mp" '((lambda () + (interactive) + (shell-command-and-echo "mpc toggle")) + :which-key "mpc toggle") "mu" '(nil :which-key "update") "mum" #'emms-player-mpd-update-all "muc" #'emms-cache-set-from-mpd-all) @@ -1990,14 +1992,26 @@ configuration [[file:mpd.org][here]]). I also want to create a small hydra for manipulating MPD: #+name: emms-media-hydra #+begin_src emacs-lisp :tangle no -(defun shell-command-and-echo (command &optional echo) +(defun shell-command-and-echo (command &optional echo prefix) + "Run COMMAND and display the result of ECHO prefixed by PREFIX. + +Run COMMAND as a shell command. + +If ECHO is non nil, display the result of its execution as a +shell command to the minibuffer through `MESSAGE'. + +If PREFIX is non nil, it will prefix the output of ECHO in the +minibuffer, both separated by a single space." (progn (with-temp-buffer (shell-command command (current-buffer) (current-buffer)) (when echo - (message "mpc %s" + (message "%s%s" + (if prefix + (concat prefix " ") + "") (string-trim (shell-command-to-string "mpc volume"))))))) @@ -2012,8 +2026,8 @@ I also want to create a small hydra for manipulating MPD: " ("c" emms-player-mpd-previous) ("r" emms-player-mpd-next) - ("t" (shell-command-and-echo "mpc volume -2" "mpc volume")) - ("s" (shell-command-and-echo "mpc volume +2" "mpc volume")) + ("t" (shell-command-and-echo "mpc volume -2" "mpc volume" "mpc")) + ("s" (shell-command-and-echo "mpc volume +2" "mpc volume" "mpc")) ("p" (shell-command-and-echo "mpc toggle")) ("S" emms-player-mpd-stop) ("q" nil :exit t))