Use doc on_save hooks to reload user module
This commit is contained in:
parent
1ce1c114ba
commit
9b27180267
|
@ -67,10 +67,7 @@ end
|
||||||
|
|
||||||
local function save(filename)
|
local function save(filename)
|
||||||
doc():save(filename)
|
doc():save(filename)
|
||||||
if doc().filename == common.normalize_path(USERDIR .. PATHSEP .. "init.lua") then
|
core.on_doc_save(filename)
|
||||||
core.reload_module("core.style")
|
|
||||||
core.load_user_directory()
|
|
||||||
end
|
|
||||||
core.log("Saved \"%s\"", doc().filename)
|
core.log("Saved \"%s\"", doc().filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -457,6 +457,19 @@ do
|
||||||
core.on_enter_project = do_nothing
|
core.on_enter_project = do_nothing
|
||||||
end
|
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)
|
local function quit_with_function(quit_fn, force)
|
||||||
if force then
|
if force then
|
||||||
delete_temp_files()
|
delete_temp_files()
|
||||||
|
@ -821,4 +834,13 @@ function core.on_error(err)
|
||||||
end
|
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
|
return core
|
||||||
|
|
Loading…
Reference in New Issue