feat: allow to disable execution_message

Squashed changes from https://github.com/Pocco81/auto-save.nvim/pull/50
Got too hairy for a GH noob like me to fix properly.
This commit is contained in:
Jakub Łuczyński
2022-08-16 14:05:42 +02:00
committed by Oula Kuuva
parent 492bab0c47
commit 4db41a2155
3 changed files with 17 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
<p align="center"> <p align="center">
<h2 align="center">🧶 auto-save.nvim</h2> <h2 align="center">🧶 auto-save.nvim</h2>
</p> </p>
<p align="center"> <p align="center">
@@ -38,7 +38,7 @@ This plugin has been renamed from `AutoSave` to `auto-save`, and this repository
### 📚 Requirements ### 📚 Requirements
- Neovim >= 0.5.0 - Neovim >= 0.5.0
&nbsp; &nbsp;
@@ -86,15 +86,16 @@ EOF
```lua ```lua
{ {
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it) enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
execution_message = { execution_message = {
enabled = true,
message = function() -- message to print on save message = function() -- message to print on save
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S")) return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
end, end,
dim = 0.18, -- dim the color of `message` dim = 0.18, -- dim the color of `message`
cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea
}, },
trigger_events = {"InsertLeave", "TextChanged"}, -- vim events that trigger auto-save. See :h events trigger_events = {"InsertLeave", "TextChanged"}, -- vim events that trigger auto-save. See :h events
-- function that determines whether to save the current buffer or not -- function that determines whether to save the current buffer or not
-- return true: if buffer is ok to be saved -- return true: if buffer is ok to be saved
-- return false: if it's not ok to be saved -- return false: if it's not ok to be saved
@@ -109,8 +110,8 @@ EOF
end end
return false -- can't save return false -- can't save
end, end,
write_all_buffers = false, -- write all buffers when the current one meets `condition` write_all_buffers = false, -- write all buffers when the current one meets `condition`
debounce_delay = 135, -- saves the file at most every `debounce_delay` milliseconds debounce_delay = 135, -- saves the file at most every `debounce_delay` milliseconds
callbacks = { -- functions to be executed at different intervals callbacks = { -- functions to be executed at different intervals
enabling = nil, -- ran when enabling auto-save enabling = nil, -- ran when enabling auto-save
disabling = nil, -- ran when disabling auto-save disabling = nil, -- ran when disabling auto-save

View File

@@ -2,6 +2,7 @@ Config = {
opts = { opts = {
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it) enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
execution_message = { execution_message = {
enabled = true,
message = function() -- message to print on save message = function() -- message to print on save
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S")) return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
end, end,

View File

@@ -82,15 +82,14 @@ function M.save(buf)
callback("after_saving") callback("after_saving")
api.nvim_echo({ if cnf.opts.execution_message.enabled == true then
{ echo_execution_message()
( end
type(cnf.opts.execution_message.message) == "function" and cnf.opts.execution_message.message() end
or cnf.opts.execution_message.message
), local function echo_execution_message()
AUTO_SAVE_COLOR, local msg = type(cnf.opts.execution_message.message) == "function" and cnf.opts.execution_message.message() or cnf.opts.execution_message.message
}, api.nvim_echo({ { msg, AUTO_SAVE_COLOR } }, true, {})
}, true, {})
if cnf.opts.execution_message.cleaning_interval > 0 then if cnf.opts.execution_message.cleaning_interval > 0 then
fn.timer_start(cnf.opts.execution_message.cleaning_interval, function() fn.timer_start(cnf.opts.execution_message.cleaning_interval, function()
cmd([[echon '']]) cmd([[echon '']])