Added ability to register on_doc_close hooks. (#220)

This commit is contained in:
Jefferson González 2021-05-26 01:50:04 -04:00 committed by GitHub
parent 63a613fe17
commit 476404c21a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

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