From 23ea5748244c8f2794e2d90a7ed564e2a326ec5a Mon Sep 17 00:00:00 2001 From: Fran Burstall Date: Fri, 5 Oct 2018 23:53:58 +0100 Subject: * lisp/emms-playlist-limit.el: limit by track description --- lisp/emms-playlist-limit.el | 56 +++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'lisp/emms-playlist-limit.el') diff --git a/lisp/emms-playlist-limit.el b/lisp/emms-playlist-limit.el index 5f0cb28..9fcc74b 100644 --- a/lisp/emms-playlist-limit.el +++ b/lisp/emms-playlist-limit.el @@ -45,6 +45,7 @@ ;; / a emms-playlist-limit-to-info-artist ;; / b emms-playlist-limit-to-info-album ;; / c emms-playlist-limit-to-info-composer +;; / d emms-playlist-limit-to-description ;; / g emms-playlist-limit-to-info-genre ;; / n emms-playlist-limit-to-name ;; / p emms-playlist-limit-to-info-performer @@ -79,11 +80,11 @@ the current playlist." attribute) (interactive (list (let* ((curr - (or (emms-track-get + (or (emms-playlist-limit-track-get (or (emms-playlist-track-at) (emms-playlist-track-at (max 1 (1- (point))))) ; at eol (quote ,attribute)) - (emms-track-get + (emms-playlist-limit-track-get (emms-playlist-selected-track) (quote ,attribute)))) (attr-name ,(emms-replace-regexp-in-string "info-" "" (symbol-name attribute))) @@ -92,11 +93,11 @@ the current playlist." attribute) (format "Limit to %s (regexp): " attr-name)))) (read-string fmt)))) (when (string= regexp "") - (setq regexp (or (emms-track-get + (setq regexp (or (emms-playlist-limit-track-get (or (emms-playlist-track-at) (emms-playlist-track-at (max 1 (1- (point))))) ; at eol (quote ,attribute)) - (emms-track-get + (emms-playlist-limit-track-get (emms-playlist-selected-track) (quote ,attribute))))) (if regexp (emms-playlist-limit-do (quote ,attribute) regexp) @@ -110,6 +111,7 @@ the current playlist." attribute) (define-emms-playlist-limit info-year) (define-emms-playlist-limit info-genre) (define-emms-playlist-limit name) +(define-emms-playlist-limit description) (defvar-local emms-playlist-limit--original-playlist nil "Playlist buffer from which we derive the limited playlist.") @@ -137,6 +139,7 @@ If this playlist is current, make the playlist we switch to current." (define-key emms-playlist-mode-map (kbd "/ b") 'emms-playlist-limit-to-info-album) (define-key emms-playlist-mode-map (kbd "/ y") 'emms-playlist-limit-to-info-year) (define-key emms-playlist-mode-map (kbd "/ g") 'emms-playlist-limit-to-info-genre) +(define-key emms-playlist-mode-map (kbd "/ d") 'emms-playlist-limit-to-description) (define-key emms-playlist-mode-map (kbd "/ /") 'emms-playlist-limit-to-all) @@ -145,9 +148,12 @@ If this playlist is current, make the playlist we switch to current." (defun emms-playlist-limit-track-get (track type) "Return the value of TYPE from TRACK. -This is a wrapper around `emms-track-get' that also tries -'info-originalyear, 'info-originaldate and 'info-date to get a -usable date when TYPE is 'info-year." +Here TYPE is a field available to `emms-track-get' or +'description which gives the result of +`emms-track-description-function'. + +When type is 'info-year, also tries 'info-originalyear, + 'info-originaldate and 'info-date to get a usable date." (cond ((eq type 'info-year) (let ((date (or (emms-track-get track 'info-originaldate) (emms-track-get track 'info-originalyear) @@ -155,26 +161,34 @@ usable date when TYPE is 'info-year." (emms-track-get track 'info-year)))) (or (emms-format-date-to-year date) ""))) + ((eq type 'description) (funcall emms-track-description-function track)) (t (emms-track-get track type)))) -(defun emms-playlist-limit--limit-playlist (playlist type regexp) - "Return new playlist containing the tracks of PLAYLIST with TYPE matching REGEXP." - (let* ((bufname (concat (buffer-name playlist) - (format "/%s=%s" - (emms-replace-regexp-in-string "info-" "" (symbol-name type)) regexp))) - (tracks (nreverse (with-current-buffer playlist +(defun emms-playlist-limit--derive-playlist (playlist pred name) + "Return a new playlist NAME of tracks in PLAYLIST for which (PRED track) +is non-nil." + (let* ((tracks (nreverse (with-current-buffer playlist (save-excursion (emms-playlist-tracks-in-region (point-min) (point-max)))))) - (filtered-tracks (seq-filter - (lambda (track) (let ((field (emms-playlist-limit-track-get track type))) - (and field (string-match regexp field)))) - tracks)) - (new-playlist (or (get-buffer bufname) - (emms-playlist-new bufname)))) + (filtered-tracks (seq-filter pred tracks)) + (new-playlist (or (get-buffer name) + (emms-playlist-new name)))) (with-current-buffer new-playlist (emms-with-inhibit-read-only-t (erase-buffer)) (mapc #'emms-playlist-insert-track filtered-tracks)) new-playlist)) +(defun emms-playlist-limit--limit-playlist (playlist type regexp) + "Return a new playlist of tracks in PLAYLIST with TYPE matching REGEXP." + (let* ((bufname (concat (buffer-name playlist) + (format "/%s=%s" + (emms-replace-regexp-in-string "info-" "" (symbol-name type)) regexp)))) + (emms-playlist-limit--derive-playlist + playlist + `(lambda (track) (let ((field (emms-playlist-limit-track-get track (quote ,type)))) + (and field (string-match ,regexp field)))) + bufname))) + + (defun emms-playlist-limit-do (type regexp) "Switch to a derived playlist containing the tracks with TYPE matching REGEXP. @@ -194,7 +208,9 @@ See `emms-info-mp3find-arguments' for possible options for TYPE." (kill-buffer)) (let ((pos (when curr (text-property-any (point-min) (point-max) 'emms-track curr)))) - (emms-playlist-select (or pos 1))) + (if pos + (emms-playlist-select pos) + (emms-playlist-select-first))) (emms-playlist-mode-center-current) (setq emms-playlist-limit--original-playlist old-buf) (when old-buf-is-current-playlist -- cgit v1.2.3 From 83503e6b276bf2382c8d0d1975d5b0e4dc8eacef Mon Sep 17 00:00:00 2001 From: Fran Burstall Date: Sat, 6 Oct 2018 09:08:21 +0100 Subject: * lisp/emms-playlist-limit.el: fix up whitespace. --- lisp/emms-playlist-limit.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lisp/emms-playlist-limit.el') diff --git a/lisp/emms-playlist-limit.el b/lisp/emms-playlist-limit.el index 9fcc74b..8e0bc10 100644 --- a/lisp/emms-playlist-limit.el +++ b/lisp/emms-playlist-limit.el @@ -41,16 +41,16 @@ ;; Key bindings ;; ------------------------------------------------------------------ -;; / / emms-playlist-limit-to-all -;; / a emms-playlist-limit-to-info-artist -;; / b emms-playlist-limit-to-info-album -;; / c emms-playlist-limit-to-info-composer -;; / d emms-playlist-limit-to-description -;; / g emms-playlist-limit-to-info-genre -;; / n emms-playlist-limit-to-name -;; / p emms-playlist-limit-to-info-performer -;; / t emms-playlist-limit-to-info-title -;; / y emms-playlist-limit-to-info-year +;; / / emms-playlist-limit-to-all +;; / a emms-playlist-limit-to-info-artist +;; / b emms-playlist-limit-to-info-album +;; / c emms-playlist-limit-to-info-composer +;; / d emms-playlist-limit-to-description +;; / g emms-playlist-limit-to-info-genre +;; / n emms-playlist-limit-to-name +;; / p emms-playlist-limit-to-info-performer +;; / t emms-playlist-limit-to-info-title +;; / y emms-playlist-limit-to-info-year ;;; Code: -- cgit v1.2.3