From bb9481f36d050ee19f25d470e78a4462bc145f25 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Sat, 7 Dec 2019 22:34:59 +0100 Subject: [PATCH] Cleaning up browser. --- emus.el | 60 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/emus.el b/emus.el index b03c09d..c09f386 100644 --- a/emus.el +++ b/emus.el @@ -257,26 +257,40 @@ ;;; Browser ;; -(defun emus-insert-record (record &optional pref-record) - (emus-set-record-browser-pos record (point)) - (let ((current (equal record emus-current-record))) - (insert-text-button - (concat - (if current - (pcase emus-state - ('playing (propertize ">" 'face 'bold)) - ('paused (propertize ")" 'face 'bold)) - ('stopped (propertize "]" 'face 'bold))) - (propertize " " 'face 'default)) - (propertize (format "%-20.20s" (emus-record-artist record)) - 'face 'emus-artist) - (propertize (format "% -20.20s" (emus-record-album record)) - 'face 'emus-album) - (propertize (format " %s" (emus-record-title record)) - 'face 'emus-title)) - 'action #'emus-click-record - 'follow-link t - 'emus-record record)) +(defun emus-insert-record (record &optional prev-record first) + (let ((artist (emus-record-artist record)) + (album (emus-record-album record)) + (title (emus-record-title record))) + (when (or prev-record first) + (unless (equal (emus-record-artist prev-record) artist) + (insert-text-button + (propertize artist 'face 'emus-artist) + 'action #'emus-click-record + 'follow-link t + 'emus-record record) + (insert "\n")) + (unless (equal (emus-record-album prev-record) album) + (insert-text-button + (propertize (concat " " album) 'face 'emus-album) + 'action #'emus-click-record + 'follow-link t + 'emus-record record) + (insert "\n"))) + (emus-set-record-browser-pos record (point)) + (let ((is-current (equal record emus-current-record))) + (insert-text-button + (concat + (if is-current + (pcase emus-state + ('playing (propertize ">" 'face 'bold)) + ('paused (propertize ")" 'face 'bold)) + ('stopped (propertize "]" 'face 'bold))) + (propertize " " 'face 'default)) + (propertize (format " %s" title) + 'face 'emus-title)) + 'action #'emus-click-record + 'follow-link t + 'emus-record record))) (insert "\n")) (defun emus-update-record (record) @@ -299,8 +313,10 @@ (let ((inhibit-read-only t)) (erase-buffer) (goto-char (point-min)) - (dolist (record emus-records) - (emus-insert-record record)))))) + (let ((prev-record nil)) + (dolist (record emus-records) + (emus-insert-record record prev-record (not prev-record)) + (setq prev-record record))))))) (defun emus-click-record (button) (emus-play-record (button-get button 'emus-record))) -- 2.20.1