From 375b7a701a60bf61e6f4a6ed875808f2071b23c8 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 23 Dec 2022 20:12:27 +0800 Subject: bongo: add functions to navigate in a cyclic manner * durand-bongo.el (durand-bongo-next-or-first) (durand-bongo-previous-or-last): Cyclic navigation --- durand-bongo.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'durand-bongo.el') diff --git a/durand-bongo.el b/durand-bongo.el index 6eded4b..632a79e 100644 --- a/durand-bongo.el +++ b/durand-bongo.el @@ -105,6 +105,24 @@ (setq-default bongo-next-action #'durand-bongo-play-next-or-first) +(defun durand-bongo-next-or-first (&optional n) + "Make the next track current in the nearest playlist buffer. +If there is no next track, go to the first track. +With prefix argument N, skip that many tracks." + (interactive "P") + (if (bongo-playing-p) + (durand-bongo-play-next-or-first n) + (with-bongo-playlist-buffer + (let ((line-move-ignore-invisible nil)) + (save-excursion + (goto-char (or (bongo-point-at-current-track-line) + (bongo-point-at-first-track-line) + (user-error "No tracks in playlist"))) + (dotimes (_dummy (prefix-numeric-value n)) + (goto-char (or (bongo-point-at-next-track-line) + (bongo-point-at-first-track-line)))) + (bongo-set-current-track-position)))))) + (defun durand-bongo-play-next-or-first (&optional n) "Start playing the next track in the nearest Bongo playlist buffer. If there is no next track to play, signal an error. @@ -132,6 +150,24 @@ insert an action track at point." (durand-bongo-next-or-first n) (bongo-start))))) +(defun durand-bongo-previous-or-last (&optional n) + "Make the previous track current in the nearest playlist buffer. +If there is no previous track, go to the last track. +With prefix argument N, skip that many tracks." + (interactive "p") + (if (bongo-playing-p) + (durand-bongo-play-previous-or-last n) + (with-bongo-playlist-buffer + (let ((line-move-ignore-invisible nil)) + (save-excursion + (goto-char (or (bongo-point-at-current-track-line) + (bongo-point-at-last-track-line) + (user-error "No tracks in playlist"))) + (dotimes (_dummy (prefix-numeric-value n)) + (goto-char (or (bongo-point-at-previous-track-line) + (bongo-point-at-last-track-line)))) + (bongo-set-current-track-position)))))) + (defun durand-bongo-play-previous-or-last (&optional n) "Start playing the previous track in the nearest playlist buffer. If there is no previous track to play, play the last track. -- cgit v1.2.3-18-g5258