diff options
author | Yoni Rabkin <yoni@rabkins.net> | 2021-04-29 13:07:43 -0400 |
---|---|---|
committer | Yoni Rabkin <yoni@rabkins.net> | 2021-04-29 13:07:43 -0400 |
commit | d56d7053a08beab4c4cf047628f6c417bfccb2f2 (patch) | |
tree | 189a430110bea25a1e9ef7212a79c855981b2d7c /emms-playing-time.el | |
parent | 3a8ba30d1fb8d94ab3c63aa678a0059cc8b48b2f (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
Diffstat (limited to 'emms-playing-time.el')
-rw-r--r-- | emms-playing-time.el | 43 |
1 files changed, 31 insertions, 12 deletions
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)) |