[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/mpv d9125d8d1d 09/12: Use index as parameters to playlist
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/mpv d9125d8d1d 09/12: Use index as parameters to playlist and chapter functions |
Date: |
Mon, 1 Aug 2022 09:58:52 -0400 (EDT) |
branch: elpa/mpv
commit d9125d8d1d897a99d979a1a01ccd5b9975073129
Author: Johann Klähn <johann@jklaehn.de>
Commit: Johann Klähn <johann@jklaehn.de>
Use index as parameters to playlist and chapter functions
The formatted entry text is hard to guess for callers and may not be unique.
---
mpv.el | 141 ++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 69 insertions(+), 72 deletions(-)
diff --git a/mpv.el b/mpv.el
index 8a7d784996..503c2ff1cb 100644
--- a/mpv.el
+++ b/mpv.el
@@ -244,11 +244,6 @@ passes unsolicited event messages to `mpv-on-event-hook'."
(json-false 'false))
,@body))
-(cl-defmacro mpv--with-entry ((var entry list) &body body)
- "Binds VAR to the ENTRY index of LIST and evaluates BODY with it."
- `(let ((,var (cl-position ,entry ,list :test #'equal)))
- ,@body))
-
(defun mpv-toggle-loop (&optional playlist)
"Cycles between 'inf' and 'no' values for the current file,
or PLAYLIST if provided."
@@ -267,79 +262,81 @@ or PLAYLIST if provided."
(interactive)
(mpv-cycle-property "video"))
-(defun mpv-show-playlist ()
- "Shows an interactive completion prompt drawn from the current playlist
entries."
- (interactive)
- (completing-read "Playlist entries: "
- (lambda (string pred action)
- (if (eq action 'metadata)
- `(metadata
- (category . mpv-file)
- (display-sort-function . ,#'identity))
- (complete-with-action action
(mpv--get-formatted-playlist) string pred)))))
-
-(defun mpv-show-chapters ()
- "Presents an interactive completion list drawn from the available chapters
-in the current mpv playback."
- (interactive)
- (completing-read "Chapters: "
- (lambda (string pred action)
- (if (eq action 'metadata)
- `(metadata
- (category . mpv-chapter)
- (display-sort-function . ,#'identity))
- (complete-with-action action
(mpv--get-formatted-chapters) string pred)))))
+(defun mpv--completing-read-playlist-entry-index ()
+ "Read a playlist entry with completion and return its index in the playlist."
+ (let* ((choices (seq-map-indexed 'cons (mpv--get-formatted-playlist)))
+ (choice
+ (completing-read "Playlist entries: "
+ (lambda (string pred action)
+ (if (eq action 'metadata)
+ `(metadata
+ (category . mpv-file)
+ (display-sort-function . ,#'identity))
+ (complete-with-action action choices string
pred)))
+ nil 'require-match)))
+ (cdr (assoc choice choices))))
+
+(defun mpv--completing-read-chapter-index ()
+ "Read a chapter with completion and return its index."
+ (let* ((choices (seq-map-indexed 'cons (mpv--get-formatted-chapters)))
+ (choice
+ (completing-read "Chapters: "
+ (lambda (string pred action)
+ (if (eq action 'metadata)
+ `(metadata
+ (category . mpv-chapter)
+ (display-sort-function . ,#'identity))
+ (complete-with-action action choices string
pred)))
+ nil 'require-match)))
+ (cdr (assoc choice choices))))
(defun mpv-jump-to-chapter (chapter)
- "Selects CHAPTER to jump to from list of currently available chapters."
- (interactive
- (list (mpv-show-chapters)))
- (mpv--with-entry
- (entry chapter (mpv--get-formatted-chapters))
- (mpv-set-property "chapter" entry)))
+ "Jump to chapter CHAPTER.
-(defun mpv-jump-to-file (file)
- "Selects FILE to jump to from list of available playlist entries."
- (interactive
- (list (mpv-show-playlist)))
- (mpv--with-entry
- (entry file (mpv--get-formatted-playlist))
- (mpv-run-command "playlist-play-index" entry)))
+When called interactively, the chapter is read from the
+minibuffer with completion."
+ (interactive (list (mpv--completing-read-chapter-index)))
+ (mpv-set-property "chapter" chapter))
-(defun mpv-remove-file (file)
- "Deletes current FILE from the mpv playlist."
- (interactive
- (list (mpv-show-playlist)))
- (mpv--with-entry
- (entry file (mpv--get-formatted-playlist))
- (mpv-run-command "playlist-remove" entry)))
+(defun mpv-jump-to-playlist-entry (index)
+ "Jump to entry INDEX of the mpv playlist.
+
+When called interactively, the playlist entry is read from the
+minibuffer with completion."
+ (interactive (list (mpv--completing-read-playlist-entry-index)))
+ (mpv-run-command "playlist-play-index" index))
+
+(defun mpv-remove-playlist-entry (index)
+ "Remove entry INDEX from the mpv playlist.
+
+When called interactively, the playlist entry is read from the
+minibuffer with completion."
+ (interactive (list (mpv--completing-read-playlist-entry-index)))
+ (mpv-run-command "playlist-remove" index))
(defun mpv-set-chapter-ab-loop (chapter)
- "Toggles an A-B loop for the timestamps between where CHAPTER is bound."
- (interactive
- (list (mpv-show-chapters)))
- (mpv--with-entry
- (entry chapter (mpv--get-formatted-chapters))
- (let* ((current-chapter (nth entry
- (mpv--with-json
- (mpv-get-property "chapter-list"))))
- (current-timestamp (alist-get 'time current-chapter))
- (title (mpv-get-property (format "chapter-list/%s/title" entry))))
- (if (eql (mpv-get-property "ab-loop-a") current-timestamp)
- (progn
- (mpv-set-property "ab-loop-a" "no")
- (mpv-set-property "ab-loop-b" "no")
- (message "Removed A-B loop from chapter \"%s\"" title))
- (progn
- (mpv-set-property "ab-loop-a" current-timestamp)
- (if (eql (mpv-get-property "chapters") (1+ entry))
- (mpv-set-property "ab-loop-b" (mpv-get-property "duration"))
- (thread-last
- (1+ entry)
- (format "chapter-list/%s/time")
- (mpv-get-property)
- (mpv-set-property "ab-loop-b")))
- (message "Chapter \"%s\" set to A-B loop" title))))))
+ "Toggle an A-B loop for the timestamps between where CHAPTER is bound."
+ (interactive (list (mpv--completing-read-chapter-index)))
+ (let* ((current-chapter (nth chapter
+ (mpv--with-json
+ (mpv-get-property "chapter-list"))))
+ (current-timestamp (alist-get 'time current-chapter))
+ (title (mpv-get-property (format "chapter-list/%s/title" chapter))))
+ (if (eql (mpv-get-property "ab-loop-a") current-timestamp)
+ (progn
+ (mpv-set-property "ab-loop-a" "no")
+ (mpv-set-property "ab-loop-b" "no")
+ (message "Removed A-B loop from chapter \"%s\"" title))
+ (progn
+ (mpv-set-property "ab-loop-a" current-timestamp)
+ (if (eql (mpv-get-property "chapters") (1+ chapter))
+ (mpv-set-property "ab-loop-b" (mpv-get-property "duration"))
+ (thread-last
+ (1+ chapter)
+ (format "chapter-list/%s/time")
+ (mpv-get-property)
+ (mpv-set-property "ab-loop-b")))
+ (message "Chapter \"%s\" set to A-B loop" title)))))
(defun mpv-set-ab-loop ()
"Invokes an A-B loop command in the current mpv playback."
- [nongnu] elpa/mpv updated (1d2629ba36 -> 9fc833bf34), ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv 03ca4a6700 02/12: Fixes time formatting, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv 191081e577 03/12: Fixes mpv-quit condition, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv de7a9a6d01 07/12: Merge pull request #23 from efimerspan/feature-listing-commands, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv d9125d8d1d 09/12: Use index as parameters to playlist and chapter functions,
ELPA Syncer <=
- [nongnu] elpa/mpv e10e14ff2b 10/12: Cosmetic changes to docstrings, messages and function signatures, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv 31b630d192 11/12: Rename mpv-entry-format to mpv-entry-with-offset-format, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv a43b1813fc 05/12: Makes listing functions use built-in Emacs completion APIs, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv fb775e339b 08/12: Use format-spec for mpv-entry-format, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv 9fc833bf34 12/12: Rename mpv-enqueue to mpv-playlist-append and simplify, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv e5a6c76612 01/12: Adds listing interactive functions and other commands, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv 331aeb6e26 04/12: Adds completion categories, ELPA Syncer, 2022/08/01
- [nongnu] elpa/mpv 028d85efae 06/12: Notify of AB-loop status upon invocation, ELPA Syncer, 2022/08/01