summaryrefslogtreecommitdiff
path: root/durand-bongo.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-12-23 20:12:27 +0800
committerJSDurand <mmemmew@gmail.com>2022-12-23 20:12:27 +0800
commit375b7a701a60bf61e6f4a6ed875808f2071b23c8 (patch)
tree9a8f7aa8b6060b2fa248e2ce55080d1c219efa53 /durand-bongo.el
parent89f6d391067802fc2e67081a50b95633011c1a12 (diff)
bongo: add functions to navigate in a cyclic manner
* durand-bongo.el (durand-bongo-next-or-first) (durand-bongo-previous-or-last): Cyclic navigation
Diffstat (limited to 'durand-bongo.el')
-rw-r--r--durand-bongo.el36
1 files changed, 36 insertions, 0 deletions
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.