diff --git a/data/core/init.lua b/data/core/init.lua index cb4abbfa..8d2edec7 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -563,6 +563,22 @@ function core.on_doc_save(filename) end end + +core.doc_close_hooks = {} +function core.add_close_hook(fn) + core.doc_close_hooks[#core.doc_close_hooks + 1] = fn +end + + +function core.on_doc_close(doc) + core.log_quiet("Closed doc \"%s\"", doc:get_name()) + + for _, hook in ipairs(core.doc_close_hooks) do + hook(doc) + end +end + + local function quit_with_function(quit_fn, force) if force then delete_temp_files() @@ -918,7 +934,7 @@ function core.step() local doc = core.docs[i] if #core.get_views_referencing_doc(doc) == 0 then table.remove(core.docs, i) - core.log_quiet("Closed doc \"%s\"", doc:get_name()) + core.on_doc_close(doc) end end