added BufWritePost
This commit is contained in:
parent
1b3dcf1128
commit
597b40a56a
@ -118,7 +118,7 @@ local save_change_file = function(buf_info, lines, save_file)
|
|||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local save_change_file_entries = function(buf_info, entries, save_file)
|
local save_change_file_entries = function(entries, save_file)
|
||||||
active_saves[save_file] = nil
|
active_saves[save_file] = nil
|
||||||
|
|
||||||
local file, err = io.open(save_file, "w+")
|
local file, err = io.open(save_file, "w+")
|
||||||
@ -136,7 +136,7 @@ local save_change_file_entries = function(buf_info, entries, save_file)
|
|||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local read_change_file = function(buf_info, save_file)
|
local read_change_file = function(save_file)
|
||||||
local file, err = io.open(save_file, "r")
|
local file, err = io.open(save_file, "r")
|
||||||
if file == nil then
|
if file == nil then
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -154,7 +154,7 @@ local read_change_file = function(buf_info, save_file)
|
|||||||
while #entries > haven_config.max_history_count do
|
while #entries > haven_config.max_history_count do
|
||||||
table.remove(entries, 1)
|
table.remove(entries, 1)
|
||||||
end
|
end
|
||||||
save_change_file_entries(buf_info, entries, save_file)
|
save_change_file_entries(entries, save_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
return entries
|
return entries
|
||||||
@ -182,7 +182,7 @@ local process_file_changed = function(buf_info)
|
|||||||
|
|
||||||
local lines = vim.api.nvim_buf_get_lines(buf_info.bufnr, 0, -1, true)
|
local lines = vim.api.nvim_buf_get_lines(buf_info.bufnr, 0, -1, true)
|
||||||
|
|
||||||
local entries, _ = read_change_file(buf_info, save_file)
|
local entries, _ = read_change_file(save_file)
|
||||||
if entries ~= nil then
|
if entries ~= nil then
|
||||||
if
|
if
|
||||||
diff_strings(
|
diff_strings(
|
||||||
@ -266,6 +266,14 @@ local setup_autocmds = function()
|
|||||||
callback = handle_buffer_changed
|
callback = handle_buffer_changed
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
vim.api.nvim_create_autocmd(
|
||||||
|
"BufWritePost",
|
||||||
|
{
|
||||||
|
group = group_id,
|
||||||
|
pattern = "*",
|
||||||
|
callback = handle_buffer_changed
|
||||||
|
}
|
||||||
|
)
|
||||||
vim.api.nvim_create_autocmd(
|
vim.api.nvim_create_autocmd(
|
||||||
"InsertLeave",
|
"InsertLeave",
|
||||||
{
|
{
|
||||||
@ -574,7 +582,7 @@ M.history = function(bufname)
|
|||||||
buf_info = buf_info[1]
|
buf_info = buf_info[1]
|
||||||
local save_file = create_save_file(buf_info)
|
local save_file = create_save_file(buf_info)
|
||||||
if vim.fn.filereadable(save_file) ~= 0 then
|
if vim.fn.filereadable(save_file) ~= 0 then
|
||||||
local entries, err = read_change_file(buf_info, save_file)
|
local entries, err = read_change_file(save_file)
|
||||||
if entries == nil then
|
if entries == nil then
|
||||||
print_message(true, err)
|
print_message(true, err)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user