Skip to content

Commit

Permalink
Use simple-mpc-extract-status to get playlist-length
Browse files Browse the repository at this point in the history
Replaces simple-mpc-get-amount-of-songs-in-playlist.
  • Loading branch information
josephmturner committed Dec 15, 2022
1 parent 1331f54 commit 40406f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 4 additions & 2 deletions simple-mpc-query.el
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ SEARCH-TYPE is a tag type, SEARCH-QUERY is the actual query."
When a region is active, add all the songs in the region to the
current playlist. When PLAY is non-nil, immediately play them."
(interactive)
(let ((current-amount-in-playlist (simple-mpc-get-amount-of-songs-in-playlist)))
(let ((playlist-length 0))
(when (simple-mpc-extract-status 'playlist-length)
(setq playlist-length (string-to-number (simple-mpc-extract-status 'playlist-length))))
(if (use-region-p)
(let ((first-line-region (line-number-at-pos (region-beginning)))
(last-line-region (if (eq (region-end) (point-max))
Expand All @@ -137,7 +139,7 @@ current playlist. When PLAY is non-nil, immediately play them."
(buffer-substring-no-properties (line-beginning-position) (line-end-position)))))
(forward-line))
(if play
(simple-mpc-call-mpc nil (list "play" (number-to-string (1+ current-amount-in-playlist)))))))
(simple-mpc-call-mpc nil (list "play" (number-to-string (1+ playlist-length)))))))

(defun simple-mpc-query-sort (&optional reverse)
"Sort all query results alphabetically.
Expand Down
6 changes: 0 additions & 6 deletions simple-mpc-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ output as a string."
(simple-mpc-call-mpc t mpc-args)
(buffer-string)))

(defun simple-mpc-get-amount-of-songs-in-playlist ()
"Return the number of songs in the current playlist."
(with-temp-buffer
(simple-mpc-call-mpc t "playlist")
(count-lines (point-min) (point-max))))

(defun simple-mpc-extract-status (type)
"Return the mpc data corresponding to TYPE of current song. TYPE may be one of the keys of `simple-mpc-status-re-groups'."
(with-temp-buffer
Expand Down

0 comments on commit 40406f7

Please sign in to comment.