From 365f12472a6ea5cdaa65a988278358eeaef202e5 Mon Sep 17 00:00:00 2001 From: Anders Johansson Date: Thu, 17 Oct 2019 15:08:06 +0200 Subject: [PATCH] Fix customization and documentation for spotify-keymap-prefix - Add a customize set function for correctly redefining spotify-mode-map when spotify-keymap-prefix is set - Update documentation to reflect this change --- README.md | 59 +++++++++++++++++++++++------------------------ spotify-remote.el | 26 ++++++++++++--------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 5fef3d7..a8398ab 100644 --- a/README.md +++ b/README.md @@ -39,14 +39,8 @@ disk, add that directory in the `load-path`, and require the `spotify` module: ;; Settings (setq spotify-oauth2-client-secret "") (setq spotify-oauth2-client-id "") -(define-key spotify-mode-map (kbd "C-c .") 'spotify-command-map) ```` -That keymap prefix is just a suggestion, following the conventions suggested for minor modes as -defined in the Emacs manual [Key Binding -Conventions](https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html#Key-Binding-Conventions). Previous -versions of this package used "M-p" - In order to get the the client ID and client secret, you need to create [a Spotify app](https://developer.spotify.com/my-applications), specifying as the redirect URI. @@ -80,32 +74,37 @@ Finally, scroll to the end of the page and hit **Save**. ### Remote Minor Mode -Whenever you enable the `spotify-remote-mode` minor mode you get the following -key bindings: - -| Key | Function | Description | -|:---------------------|:-----------------------------|:-------------------------------------------| -| C-c . M-s | `spotify-toggle-shuffle` | Turn shuffle on/off [1] | -| C-c . M-r | `spotify-toggle-repeat` | Turn repeat on/off [1] | -| C-c . M-p | `spotify-toggle-play` | Play/pause | -| C-c . M-f | `spotify-next-track` | Next track | -| C-c . M-b | `spotify-previous-track` | Previous track | -| C-c . p m | `spotify-my-playlists` | Show your playlists | -| C-c . p f | `spotify-featured-playlists` | Show the featured playlists | -| C-c . p s | `spotify-playlist-search` | Search for playlists | -| C-c . p u | `spotify-user-playlists` | Show playlists for the given user | -| C-c . p c | `spotify-create-playlist` | Create a new playlist | -| C-c . t r | `spotify-recently-played` | List of recently played tracks | -| C-c . t s | `spotify-track-search` | Search for tracks | -| C-c . v u | `spotify-volume-up` | Increase the volume [2] | -| C-c . v d | `spotify-volume-down` | Decrease the volume [2] | -| C-c . v m | `spotify-volume-mute-unmute` | Alternate the volume between 0 and 100 [2] | -| C-c . d | `spotify-select-device` | Select a playback device [2] | +Enabling the `spotify-remote-mode` minor mode gives you convenient keybindings +under a user defined prefix. Set `spotify-keymap-prefix` before loading +`spotify.el` or use the customize interface to set it. A suggestion is C-c +., following the conventions suggested for minor modes as defined in the +Emacs manual [Key Binding +Conventions](https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html#Key-Binding-Conventions). +Previous versions of this package used M-p. + +| Key | Function | Description | +|:----------------------|:-----------------------------|:-------------------------------------------| +| PREFIX M-s | `spotify-toggle-shuffle` | Turn shuffle on/off [1] | +| PREFIX M-r | `spotify-toggle-repeat` | Turn repeat on/off [1] | +| PREFIX M-p | `spotify-toggle-play` | Play/pause | +| PREFIX M-f | `spotify-next-track` | Next track | +| PREFIX M-b | `spotify-previous-track` | Previous track | +| PREFIX p m | `spotify-my-playlists` | Show your playlists | +| PREFIX p f | `spotify-featured-playlists` | Show the featured playlists | +| PREFIX p s | `spotify-playlist-search` | Search for playlists | +| PREFIX p u | `spotify-user-playlists` | Show playlists for the given user | +| PREFIX p c | `spotify-create-playlist` | Create a new playlist | +| PREFIX t r | `spotify-recently-played` | List of recently played tracks | +| PREFIX t s | `spotify-track-search` | Search for tracks | +| PREFIX v u | `spotify-volume-up` | Increase the volume [2] | +| PREFIX v d | `spotify-volume-down` | Decrease the volume [2] | +| PREFIX v m | `spotify-volume-mute-unmute` | Alternate the volume between 0 and 100 [2] | +| PREFIX d | `spotify-select-device` | Select a playback device [2] | The current song being played by the Spotify client is displayed in the mode -line along with the player status (playing, paused). The interval in which the -player status is updated can be configured via the -`spotify-player-status-refresh-interval` variable: +line or title bar (see `spotify-status-location`) along with the player status +(playing, paused). The interval in which the player status is updated can be +configured via the `spotify-player-status-refresh-interval` variable: ````el ;; Updates the player status every 10 seconds (default is 5) diff --git a/spotify-remote.el b/spotify-remote.el index 4e5b10b..2950ca7 100644 --- a/spotify-remote.el +++ b/spotify-remote.el @@ -9,7 +9,9 @@ (defcustom spotify-keymap-prefix nil "Spotify remote keymap prefix." :group 'spotify - :type 'string) + :type '(choice (const :tag "Disable keymap" nil) + (string :tag "Prefix")) + :set #'spotify-set-mode-map) (defcustom spotify-status-location 'modeline "Specify where to show the player status: one of '(modeline title-bar nil)." @@ -43,16 +45,20 @@ (define-key map (kbd "t s") #'spotify-track-search) (define-key map (kbd "d") #'spotify-select-device) map) - "Keymap for Spotify commands after 'spotify-keymap-prefix'.") + "Keymap for Spotify commands after `spotify-keymap-prefix'.") (fset 'spotify-command-map spotify-command-map) -(defvar spotify-mode-map - (let ((map (make-sparse-keymap))) - (when spotify-keymap-prefix - (define-key map spotify-keymap-prefix 'spotify-command-map)) - map) +(defvar spotify-mode-map nil "Keymap for Spotify remote mode.") +(defun spotify-set-mode-map (variable value) + "Set value for `spotify-keymap-prefix' and update `spotify-mode-map’" + (set-default variable value) + (let ((map (make-sparse-keymap))) + (when value + (define-key map (kbd value) 'spotify-command-map)) + (set 'spotify-mode-map map))) + (defun spotify-add-frame-title-status (status title-section) "Return the TITLE-SECTION or part thereof with the player STATUS appended." (if (stringp title-section) @@ -90,10 +96,8 @@ A positive prefix argument enables the mode, any other prefix argument disables it. From Lisp, argument omitted or nil enables the mode, `toggle' toggles the state. -When Spotify Remote mode is enabled, it's possible to toggle -the repeating and shuffling status of the running Spotify process. -See commands \\[spotify-toggle-repeating] and -\\[spotify-toggle-shuffling]." +\\{spotify-mode-map}. +" :group 'spotify :init-value nil :keymap spotify-mode-map