aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--lisp/emms-playlist-limit.el74
2 files changed, 48 insertions, 31 deletions
diff --git a/NEWS b/NEWS
index 46fa8ee..ef12058 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,8 @@
News since version 5.0
- - Improve emms-playlist-limit implementation. Now operates on the
- current buffer rather than the current playlist.
+ - Improve emms-playlist-limit implementation. Now operates on the
+ current buffer rather than the current playlist. Add
+ emms-playlist-limit-to-description.
- Rewrite mpv backend to use long-running mpv instances controlled over
json-rpc protocol for newer versions.
diff --git a/lisp/emms-playlist-limit.el b/lisp/emms-playlist-limit.el
index 5f0cb28..8e0bc10 100644
--- a/lisp/emms-playlist-limit.el
+++ b/lisp/emms-playlist-limit.el
@@ -41,15 +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
-;; / 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:
@@ -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