From bdc37f1f6cba10ce3a643e68a19556136866f751 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 17 Jun 2021 16:26:27 -0400 Subject: [PATCH] Added in remove file function. (#272) * Added in remove file function. * Changed namespace of rename and remove (now delete). --- data/core/commands/doc.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 21866892..c8c27509 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -238,7 +238,7 @@ local commands = { ["doc:lower-case"] = function() doc():replace(string.lower) end, - + ["doc:go-to-line"] = function() local dv = dv() @@ -297,7 +297,7 @@ local commands = { end end, - ["doc:rename"] = function() + ["file:rename"] = function() local old_filename = doc().filename if not old_filename then core.error("Cannot rename unsaved doc") @@ -312,6 +312,21 @@ local commands = { end end, common.path_suggest) end, + + + ["file:delete"] = function() + local filename = doc().abs_filename + if not filename then + core.error("Cannot remove unsaved doc") + return + end + for i,docview in ipairs(core.get_views_referencing_doc(doc())) do + local node = core.root_view.root_node:get_node_for_view(docview) + node:close_view(core.root_view, docview) + end + os.remove(filename) + core.log("Removed \"%s\"", filename) + end }