-
Notifications
You must be signed in to change notification settings - Fork 147
/
verbosesaving.lua
42 lines (37 loc) · 1.21 KB
/
verbosesaving.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
return {
name = "Verbose Saving",
description = "Saves a copy of each file on save in a separate directory with date and time appended to the file name.",
author = "Rami Sabbagh",
version = 1.1,
splitFilePath = function(path)
local p,n,e = path:match("(.-)([^\\/]-%.?([^%.\\/]*))$")
n = n:sub(0,-(e:len()+2))
return p,n,e
end,
onRegister = function(self)
self.loc = ide:GetConfig().verbosefolder
if not self.loc then
error("Must set 'verbosefolder' configuration settings in order for verbose file saving to work!")
end
end,
onUnRegister = function(self)
self.loc = nil
end,
onEditorSave = function(self,editor)
if not self.loc then return end
local filename = ide:GetDocument(editor):GetFilePath()
filename = filename:gsub("\\","/")
local path, name, extension = self.splitFilePath(filename)
local data = editor:GetText()
local time = os.date("%Y_%m_%d - %H.%M.%S",os.time())
local savename = name.." - "..time.."."..extension
local file, err = io.open(self.loc..savename,"wb")
if not file then
error(err)
else
file:write(data)
file:flush()
file:close()
end
end
}