command: allow "current" as argument to playlist_remove command

Feature request from github issue #376.
This commit is contained in:
wm4 2013-11-28 19:13:48 +01:00
parent 5318a1bea1
commit 0a18f3eb9a
3 changed files with 10 additions and 3 deletions

View File

@ -185,9 +185,11 @@ List of Input Commands
``playlist_clear``
Clear the playlist, except the currently played file.
``playlist_remove <index>``
``playlist_remove current|<index>``
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 <index1> <index2>``
Move the playlist entry at index1, so that it takes the place of the

View File

@ -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 } },

View File

@ -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)