diff options
author | Fran Burstall <feb@maths.bath.ac.uk> | 2018-10-05 23:53:58 +0100 |
---|---|---|
committer | Fran Burstall <feb@maths.bath.ac.uk> | 2018-10-05 23:53:58 +0100 |
commit | 23ea5748244c8f2794e2d90a7ed564e2a326ec5a (patch) | |
tree | 3e790ab9001695b5ccf7b2fbc228eafdca410113 /lisp | |
parent | 8d35c26cd6f5cfd4ec97ee5bc274e931809f4094 (diff) |
* lisp/emms-playlist-limit.el: limit by track description
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/emms-playlist-limit.el | 56 |
1 files changed, 36 insertions, 20 deletions
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) "<unknown year>"))) + ((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 |