aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2025-06-29 17:16:44 +1000
committerYuchen Pei <id@ypei.org>2025-06-29 17:16:44 +1000
commit76ecdb1bb0f7f7b670b8885428b91b93ba27e60e (patch)
tree0d751b732aa66caeda247646aa6bfab512f00fe9 /emacs/.emacs.d/lisp
parentf29dbe5b84140223e3e9e6ed79c7b67e58a20a5a (diff)
[emacs] emms mark boundaries when soundtrack chosen
Diffstat (limited to 'emacs/.emacs.d/lisp')
-rw-r--r--emacs/.emacs.d/lisp/my/my-emms.el57
1 files changed, 40 insertions, 17 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-emms.el b/emacs/.emacs.d/lisp/my/my-emms.el
index 799c5f3..50c1310 100644
--- a/emacs/.emacs.d/lisp/my/my-emms.el
+++ b/emacs/.emacs.d/lisp/my/my-emms.el
@@ -464,26 +464,49 @@ under /zzz-seren/."
(min end-ln maybe-group-end))))
(cons group-start group-end))))
+(defun my-emms-playlist-mark-bounds (group-end)
+ "Mark bounds of the current track group.
+
+An up arrow at the first played in the current group, and a down
+arrow at the end of the track group."
+ (overlay-put
+ (make-overlay (point) (point))
+ 'before-string (propertize
+ "x" 'display
+ `(left-fringe up-arrow emms-playlist-selected-face)))
+ (save-excursion
+ (goto-line (1- group-end))
+ (overlay-put
+ (make-overlay (point) (point))
+ 'before-string (propertize
+ "x" 'display
+ `(left-fringe down-arrow emms-playlist-selected-face)))))
+
(defun my-emms-playlist-random-group ()
(interactive)
(with-current-emms-playlist
(remove-overlays)
- (goto-line (1+ (random (count-lines (point-min) (point-max)))))
- (pcase-let ((`(,group-start . ,group-end) (my-emms-playlist-group-bounds)))
- (goto-line group-start)
- (overlay-put
- (make-overlay (point) (point))
- 'before-string (propertize
- "x" 'display
- `(left-fringe down-arrow emms-playlist-selected-face)))
- (save-excursion
- (goto-line (1- group-end))
- (overlay-put
- (make-overlay (point) (point))
- 'before-string (propertize
- "x" 'display
- `(left-fringe up-arrow emms-playlist-selected-face))))
- (emms-playlist-mode-play-current-track))))
+ (let ((random-line (1+ (random (count-lines (point-min) (point-max))))))
+ (goto-line random-line)
+ (pcase-let ((`(,group-start . ,group-end) (my-emms-playlist-group-bounds)))
+ (message "my-emms-playlist-random-group: (%d, %d)" random-line group-start)
+ (goto-line group-start)
+ (my-emms-playlist-mark-bounds group-end)
+ (emms-playlist-mode-play-current-track)))))
+
+(defun my-emms-playlist-maybe-mark-bounds ()
+ "Used as an `emms-player-started-hook'.
+
+If the last command is `emms-playlist-mode-play-smart' i.e. the
+user manually chose the track to play, and if
+`emms-player-next-function' is
+`my-emms-next-track-or-random-group', then mark boundaries since
+it would not have been marked otherwise."
+ (when (and (eq last-command 'emms-playlist-mode-play-smart)
+ (eq emms-player-next-function 'my-emms-next-track-or-random-group))
+ (with-current-emms-playlist
+ (pcase-let ((`(_ . ,group-end) (my-emms-playlist-group-bounds)))
+ (my-emms-playlist-mark-bounds group-end)))))
(defun my-emms-next-track-or-random-group ()
(interactive)
@@ -563,7 +586,7 @@ character."
(defvar my-emms-score-delta 1)
(defun my-emms-score-up-playing ()
- "Increase score by `my-emms-score-delta', then reset it to 1."
+ "Increase score by `my-emms-score-delta', then reset the score delta to 1."
(emms-score-change-score
my-emms-score-delta
(my-emms-get-display-name-1 (emms-score-current-selected-track-filename)))