[Geany-Users] script to delete currently viewed document

pauriem at gmail.com pauriem at xxxxx
Thu May 2 21:41:13 UTC 2013


-- in case anyone finds it helpful, here is a script to delete from disk
-- the document currently being viewed, which is something that some of
-- the other text editors out there have a button or menu command for
local keys_to_read, path, code, alerts, gloss, i, j
geany.banner = "Lua Script: Close and unlink"
i = 60
if (geany.count () > 0) then
 path = geany.filename ()
 keys_to_read = geany.fileinfo ()
else
 path = nil
 keys_to_read = nil
end
if ((path == nil) or (keys_to_read == nil) or (keys_to_read["changed"])) then
 alerts = "No saved document to unlink"
elseif (keys_to_read["readonly"]) then
 alerts = "Read-only document cannot be unlinked"
else
 gloss = ("Unlink \"" .. path) .. "\"?"
 j = string.len (gloss)
 if (j < i) then j = i end
 alerts = gloss .. ("\n" .. string.rep ("_", j))
 if (geany.confirm (" ", alerts, false)) then
   geany.close ()
   code, alerts = os.remove (path)
   if (code) then
     alerts = ("Unlinked \"" .. path) .."\""
   else
     if (alerts == nil) then gloss ="unknown OS error" else gloss = alerts end
     alerts = ("Unable to unlink \"" .. path) .. (("\" ("  .. gloss) .. ")")
   end
 else
   alerts = "" end
end
j = string.len (alerts)
if j > 0 then
 if (j < i) then j = i end
 geany.message (alerts .. ("\n" .. string.rep ("_", j)))
end


More information about the Users mailing list