Added in remove file function. (#272)

* Added in remove file function.

* Changed namespace of rename and remove (now delete).
This commit is contained in:
Adam 2021-06-17 16:26:27 -04:00 committed by GitHub
parent 1ad4289e76
commit bdc37f1f6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 2 deletions

View File

@ -238,7 +238,7 @@ local commands = {
["doc:lower-case"] = function() ["doc:lower-case"] = function()
doc():replace(string.lower) doc():replace(string.lower)
end, end,
["doc:go-to-line"] = function() ["doc:go-to-line"] = function()
local dv = dv() local dv = dv()
@ -297,7 +297,7 @@ local commands = {
end end
end, end,
["doc:rename"] = function() ["file:rename"] = function()
local old_filename = doc().filename local old_filename = doc().filename
if not old_filename then if not old_filename then
core.error("Cannot rename unsaved doc") core.error("Cannot rename unsaved doc")
@ -312,6 +312,21 @@ local commands = {
end end
end, common.path_suggest) end, common.path_suggest)
end, 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
} }