aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoni Rabkin <yoni@rabkins.net>2021-04-29 13:07:43 -0400
committerYoni Rabkin <yoni@rabkins.net>2021-04-29 13:07:43 -0400
commitd56d7053a08beab4c4cf047628f6c417bfccb2f2 (patch)
tree189a430110bea25a1e9ef7212a79c855981b2d7c
parent3a8ba30d1fb8d94ab3c63aa678a0059cc8b48b2f (diff)
emms-(playing-time|mode-line).el: Use `define-minor-mode`
* emms-mode-line.el (emms-mode-line-active-p): Rename to `emms-mode-line-mode`. (emms-mode-line-mode): New minor mode, extracted from `emms-mode-line`. (emms-mode-line): Use it and mark as obsolete. (emms-mode-line-enable, emms-mode-line-toggle): Adjust accordingly and mark as obsolete as well. (emms-mode-line-disable): Adjust accordingly. * emms-playing-time.el (emms-playing-time-display-p): Rename to `emms-playing-time-display-mode`. (emms-playing-time-display-mode): New minor mode. (emms-playing-time-p): Rename to `emms-playing-time-mode`. (emms-playing-time-mode): New minor mode, extracted from `emms-playing-time`. (emms-playing-time): Use it and mark as obsolete. (emms-playing-time-display-mode, emms-playing-time-display-mode): Adjust and mark as obsolete. * emms-setup.el (emms-all): Avoid the now obsolete functions. patch by Stefan Monnier
-rw-r--r--emms-mode-line.el27
-rw-r--r--emms-playing-time.el43
-rw-r--r--emms-setup.el4
3 files changed, 47 insertions, 27 deletions
diff --git a/emms-mode-line.el b/emms-mode-line.el
index f35750d..dc28bf2 100644
--- a/emms-mode-line.el
+++ b/emms-mode-line.el
@@ -56,19 +56,23 @@
(format emms-mode-line-format (emms-track-description
(emms-playlist-current-selected-track))))
-(defvar emms-mode-line-active-p nil
- "If non-nil, emms mode line is active.")
+(define-obsolete-variable-alias 'emms-mode-line-active-p
+ 'emms-mode-line-mode "Apr 2021")
(defvar emms-mode-line-string "")
(defvar emms-mode-line-initial-titlebar frame-title-format)
(defun emms-mode-line (arg)
+ (declare (obsolete emms-mode-line-mode "Apr 2021"))
+ (emms-mode-line-mode (if (and arg (> arg 0)) 1 -1)))
+
+;;;###autoload
+(define-minor-mode emms-mode-line-mode
"Turn on `emms-mode-line' if ARG is positive, off otherwise."
- (interactive "p")
+ :global t
(or global-mode-string (setq global-mode-string '("")))
- (if (and arg (> arg 0))
+ (if emms-mode-line-mode
(progn
- (setq emms-mode-line-active-p t)
(add-hook 'emms-track-updated-functions #'emms-mode-line-alter)
(add-hook 'emms-player-finished-hook #'emms-mode-line-blank)
(add-hook 'emms-player-stopped-hook #'emms-mode-line-blank)
@@ -79,7 +83,6 @@
(append global-mode-string
'(emms-mode-line-string))))
(when emms-player-playing-p (emms-mode-line-alter)))
- (setq emms-mode-line-active-p nil)
(remove-hook 'emms-track-updated-functions #'emms-mode-line-alter)
(remove-hook 'emms-player-finished-hook #'emms-mode-line-blank)
(remove-hook 'emms-player-stopped-hook #'emms-mode-line-blank)
@@ -91,23 +94,21 @@
(defun emms-mode-line-enable ()
"Turn on `emms-mode-line'."
(interactive)
- (emms-mode-line 1)
- (message "emms mode line enabled"))
+ (declare (obsolete emms-mode-line-mode "Apr 2021"))
+ (emms-mode-line-mode 1))
;;;###autoload
(defun emms-mode-line-disable ()
"Turn off `emms-mode-line'."
(interactive)
- (emms-mode-line -1)
- (message "emms mode line disabled"))
+ (emms-mode-line-mode -1))
;;;###autoload
(defun emms-mode-line-toggle ()
"Toggle `emms-mode-line'."
(interactive)
- (if emms-mode-line-active-p
- (emms-mode-line-disable)
- (emms-mode-line-enable)))
+ (declare (obsolete emms-mode-line-mode "Apr 2021"))
+ (emms-mode-line-mode 'toggle))
(defun emms-mode-line-alter (&optional track)
"Alter mode-line/titlebar.
diff --git a/emms-playing-time.el b/emms-playing-time.el
index e99dc64..c52d13a 100644
--- a/emms-playing-time.el
+++ b/emms-playing-time.el
@@ -68,8 +68,9 @@ and `downtime' (e.g. -03:58)."
;;; Emms Playing Time
-(defvar emms-playing-time-display-p nil
- "Whether to display playing time on mode line or not")
+(define-obsolete-variable-alias 'emms-playing-time-display-p
+ 'emms-playing-time-display-mode "Apr 2021")
+(defvar emms-playing-time-display-mode)
(defvar emms-playing-time 0
"Time elapsed in current track.")
@@ -78,8 +79,8 @@ and `downtime' (e.g. -03:58)."
(defvar emms-playing-time-display-timer nil)
-(defvar emms-playing-time-p nil
- "Whether emms-playing-time module is enabled or not")
+(define-obsolete-variable-alias 'emms-playing-time-p
+ 'emms-playing-time-mode "Apr 2021")
(defun emms-playing-time-start ()
"Get ready for display playing time."
@@ -119,6 +120,11 @@ and `downtime' (e.g. -03:58)."
(setq emms-playing-time 0)))
(defun emms-playing-time (arg)
+ (declare (obsolete emms-playing-time-mode "Apr 2021"))
+ (emms-playing-time-mode (if (and arg (> arg 0)) 1 -1)))
+
+
+(define-minor-mode emms-playing-time-mode
"Turn on emms playing time if ARG is positive, off otherwise.
Note: `(emms-playing-time -1)' will disable emms-playing-time
@@ -128,10 +134,13 @@ modules may rely on it, such as `emms-lastfm.el')
Instead, to toggle displaying playing time on mode line, one
could call `emms-playing-time-enable-display' and
`emms-playing-time-disable-display'."
- (if (and arg (> arg 0))
+ :global t
+ (if emms-playing-time-mode
(progn
- (setq emms-playing-time-p t
- emms-playing-time-display-p t)
+ ;; FIXME: Maybe we shouldn't set this here, and instead the users
+ ;; should call `emms-playing-time-display-mode' if that's what
+ ;; they want.
+ (setq emms-playing-time-display-mode t)
(emms-playing-time-mode-line)
(add-hook 'emms-player-started-hook #'emms-playing-time-start)
(add-hook 'emms-player-stopped-hook #'emms-playing-time-stop)
@@ -139,8 +148,7 @@ could call `emms-playing-time-enable-display' and
(add-hook 'emms-player-paused-hook #'emms-playing-time-pause)
(add-hook 'emms-player-seeked-functions #'emms-playing-time-seek)
(add-hook 'emms-player-time-set-functions #'emms-playing-time-set))
- (setq emms-playing-time-p nil
- emms-playing-time-display-p nil)
+ (setq emms-playing-time-display-mode nil)
(emms-playing-time-stop)
(emms-playing-time-restore-mode-line)
(remove-hook 'emms-player-started-hook #'emms-playing-time-start)
@@ -151,22 +159,33 @@ could call `emms-playing-time-enable-display' and
(remove-hook 'emms-player-time-set-functions #'emms-playing-time-set)))
;;;###autoload
+(define-minor-mode emms-playing-time-display-mode
+ "Minor mode to display playing time on mode line."
+ :global t
+ ;; When disabling the mode, don't disable `emms-playing-time-display-mode'
+ ;; since that may be used by other packages.
+ (if emms-playing-time-display-mode
+ (emms-playing-time-display-mode 1)))
+
+;;;###autoload
(defun emms-playing-time-enable-display ()
"Display playing time on mode line."
+ (declare (obsolete emms-playing-time-display-mode "Apr 2021"))
(interactive)
- (setq emms-playing-time-display-p t))
+ (setq emms-playing-time-display-mode t))
;;;###autoload
(defun emms-playing-time-disable-display ()
"Remove playing time from mode line."
+ (declare (obsolete emms-playing-time-display-mode "Apr 2021"))
(interactive)
- (setq emms-playing-time-display-p nil))
+ (setq emms-playing-time-display-mode nil))
(defun emms-playing-time-display ()
"Display playing time on the mode line."
(setq emms-playing-time (round (1+ emms-playing-time)))
(setq emms-playing-time-string
- (if (null emms-playing-time-display-p)
+ (if (null emms-playing-time-display-mode)
""
(let* ((min (/ emms-playing-time 60))
(sec (% emms-playing-time 60))
diff --git a/emms-setup.el b/emms-setup.el
index 67d0aa0..d086878 100644
--- a/emms-setup.el
+++ b/emms-setup.el
@@ -118,10 +118,10 @@ the stable features which come with the Emms distribution."
(setq emms-track-description-function #'emms-info-track-description)
(when (fboundp 'emms-cache) ; work around compiler warning
(emms-cache 1))
- (emms-mode-line 1)
+ (emms-mode-line-mode 1)
(emms-mode-line-blank)
(emms-lyrics 1)
- (emms-playing-time 1)
+ (emms-playing-time-mode 1)
(add-hook 'emms-player-started-hook #'emms-last-played-update-current)
(emms-score 1))