command: add load-config-file

Unlike set include mpv.conf, this works after playback has started. It
can be used to auto reload the configuration, e.g. in vim:
autocmd BufWritePost ~/.config/mpv/mpv.conf silent !echo load-config-file %:p | socat - /tmp/mpvsocket

Partially fixes #6362.
This commit is contained in:
Guido Cella 2024-01-11 00:43:12 +01:00 committed by Dudemanguy
parent 27cb193f0e
commit e2284fba18
4 changed files with 44 additions and 10 deletions

View File

@ -42,6 +42,7 @@ Interface changes
- add `forced` choice to `subs-with-matching-audio`
- remove `--term-remaining-playtime` option
- change fallback deinterlace to bwdif
- add the command `load-config-file`
--- mpv 0.37.0 ---
- `--save-position-on-quit` and its associated commands now store state files
in %LOCALAPPDATA% instead of %APPDATA% directory by default on Windows.

View File

@ -1336,6 +1336,11 @@ Input Commands that are Possibly Subject to Change
relevant mode. Prints a warning if nothing could be done. See
`Runtime profiles`_ for details.
``load-config-file <filename>``
Load a configuration file, similar to the ``--include`` option. If the file
was already included, its previous options are not reset before it is
reparsed.
``load-script <filename>``
Load a script, similar to the ``--script`` option. Whether this waits for
the script to finish initialization or not changed multiple times, and the

View File

@ -55,6 +55,7 @@
#include "options/m_option.h"
#include "options/m_property.h"
#include "options/m_config_frontend.h"
#include "options/parse_configfile.h"
#include "osdep/getpid.h"
#include "video/out/gpu/context.h"
#include "video/out/vo.h"
@ -6270,6 +6271,23 @@ static void cmd_apply_profile(void *p)
}
}
static void cmd_load_config_file(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
char *config_file = cmd->args[0].v.s;
int r = m_config_parse_config_file(mpctx->mconfig, mpctx->global,
config_file, NULL, 0);
if (r < 1) {
cmd->success = false;
return;
}
mp_notify_property(mpctx, "profile-list");
}
static void cmd_load_script(void *p)
{
struct mp_cmd_ctx *cmd = p;
@ -6807,6 +6825,8 @@ const struct mp_cmd_def mp_cmds[] = {
.flags = MP_CMD_OPT_ARG}, }
},
{ "load-config-file", cmd_load_config_file, {{"filename", OPT_STRING(v.s)}} },
{ "load-script", cmd_load_script, {{"filename", OPT_STRING(v.s)}} },
{ "dump-cache", cmd_dump_cache, { {"start", OPT_TIME(v.d),

View File

@ -164,8 +164,8 @@ local function compile_cond(name, s)
return chunk
end
local function load_profiles()
for i, v in ipairs(mp.get_property_native("profile-list")) do
local function load_profiles(profiles_property)
for _, v in ipairs(profiles_property) do
local cond = v["profile-cond"]
if cond and #cond > 0 then
local profile = {
@ -182,17 +182,25 @@ local function load_profiles()
end
end
load_profiles()
mp.observe_property("profile-list", "native", function (_, profiles_property)
profiles = {}
watched_properties = {}
cached_properties = {}
properties_to_profiles = {}
mp.unobserve_property(on_property_change)
if #profiles < 1 and mp.get_property("load-auto-profiles") == "auto" then
-- make it exit immediately
_G.mp_event_loop = function() end
return
end
load_profiles(profiles_property)
if #profiles < 1 and mp.get_property("load-auto-profiles") == "auto" then
-- make it exit immediately
_G.mp_event_loop = function() end
return
end
on_idle() -- re-evaluate all profiles immediately
end)
mp.register_idle(on_idle)
for _, name in ipairs({"on_load", "on_preloaded", "on_before_start_file"}) do
mp.add_hook(name, 50, on_hook)
end
on_idle() -- re-evaluate all profiles immediately