From 0a18f3eb9a163b1cd656129dac6164d7914ecc41 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 28 Nov 2013 19:13:48 +0100 Subject: command: allow "current" as argument to playlist_remove command Feature request from github issue #376. --- DOCS/man/en/input.rst | 6 ++++-- mpvcore/input/input.c | 5 ++++- mpvcore/player/command.c | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/DOCS/man/en/input.rst b/DOCS/man/en/input.rst index 53336344af..917584428f 100644 --- a/DOCS/man/en/input.rst +++ b/DOCS/man/en/input.rst @@ -185,9 +185,11 @@ List of Input Commands ``playlist_clear`` Clear the playlist, except the currently played file. -``playlist_remove `` +``playlist_remove current|`` Remove the playlist entry at the given index. Index values start counting - with 0. You cannot remove the entry for the currently played file. + with 0. The special value ``current`` removes the current entry. Note that + removing the current entry also stops playback and starts playing the next + entry. ``playlist_move `` Move the playlist entry at index1, so that it takes the place of the diff --git a/mpvcore/input/input.c b/mpvcore/input/input.c index c000835d58..d36fee3b94 100644 --- a/mpvcore/input/input.c +++ b/mpvcore/input/input.c @@ -112,6 +112,7 @@ struct key_name { #define ARG_DOUBLE OPT_DOUBLE(ARG(d), 0) #define ARG_STRING OPT_STRING(ARG(s), 0) #define ARG_CHOICE(c) OPT_CHOICE(ARG(i), 0, c) +#define ARG_CHOICE_OR_INT(...) OPT_CHOICE_OR_INT(ARG(i), 0, __VA_ARGS__) #define ARG_TIME OPT_TIME(ARG(d), 0) #define OARG_DOUBLE(def) OPT_DOUBLE(ARG(d), 0, OPTDEF_DOUBLE(def)) #define OARG_INT(def) OPT_INT(ARG(i), 0, OPTDEF_INT(def)) @@ -216,7 +217,9 @@ static const struct mp_cmd_def mp_cmds[] = { {"append", 1}, {"1", 1})), }}, { MP_CMD_PLAYLIST_CLEAR, "playlist_clear", }, - { MP_CMD_PLAYLIST_REMOVE, "playlist_remove", { ARG_INT } }, + { MP_CMD_PLAYLIST_REMOVE, "playlist_remove", { + ARG_CHOICE_OR_INT(0, INT_MAX, ({"current", -1})), + }}, { MP_CMD_PLAYLIST_MOVE, "playlist_move", { ARG_INT, ARG_INT } }, { MP_CMD_RUN, "run", { ARG_STRING } }, diff --git a/mpvcore/player/command.c b/mpvcore/player/command.c index c2db56444e..f6aa429b99 100644 --- a/mpvcore/player/command.c +++ b/mpvcore/player/command.c @@ -2701,6 +2701,8 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) case MP_CMD_PLAYLIST_REMOVE: { struct playlist_entry *e = playlist_entry_from_index(mpctx->playlist, cmd->args[0].v.i); + if (cmd->args[0].v.i < 0) + e = mpctx->playlist->current; if (e) { // Can't play a removed entry if (mpctx->playlist->current == e) -- cgit v1.2.3