From 476404c21a152db51d3b6bf2130b41754908798b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jefferson=20Gonz=C3=A1lez?= Date: Wed, 26 May 2021 01:50:04 -0400 Subject: [PATCH] Added ability to register on_doc_close hooks. (#220) --- data/core/init.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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