Use doc on_save hooks to reload user module

This commit is contained in:
Francesco Abbate 2021-02-17 20:10:39 +01:00
parent 1ce1c114ba
commit 9b27180267
2 changed files with 23 additions and 4 deletions

View File

@ -67,10 +67,7 @@ end
local function save(filename)
doc():save(filename)
if doc().filename == common.normalize_path(USERDIR .. PATHSEP .. "init.lua") then
core.reload_module("core.style")
core.load_user_directory()
end
core.on_doc_save(filename)
core.log("Saved \"%s\"", doc().filename)
end

View File

@ -457,6 +457,19 @@ do
core.on_enter_project = do_nothing
end
core.doc_save_hooks = {}
function core.add_save_hook(fn)
core.doc_save_hooks[#core.doc_save_hooks + 1] = fn
end
function core.on_doc_save(filename)
for _, hook in ipairs(core.doc_save_hooks) do
hook(filename)
end
end
local function quit_with_function(quit_fn, force)
if force then
delete_temp_files()
@ -821,4 +834,13 @@ function core.on_error(err)
end
core.add_save_hook(function(filename)
local doc = core.active_view.doc
if doc and doc:is(Doc) and doc.filename == common.normalize_path(USERDIR .. PATHSEP .. "init.lua") then
core.reload_module("core.style")
core.load_user_directory()
end
end)
return core