Skip to content

Commit 4db41a2

Browse files
Jakub Łuczyńskiokuuva
authored andcommitted
feat: allow to disable execution_message
Squashed changes from pocco81/auto-save.nvim#50 Got too hairy for a GH noob like me to fix properly.
1 parent 492bab0 commit 4db41a2

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<h2 align="center">🧶 auto-save.nvim</h2>
2+
<h2 align="center">🧶 auto-save.nvim</h2>
33
</p>
44

55
<p align="center">
@@ -38,7 +38,7 @@ This plugin has been renamed from `AutoSave` to `auto-save`, and this repository
3838

3939
### 📚 Requirements
4040

41-
- Neovim >= 0.5.0
41+
- Neovim >= 0.5.0
4242

4343
&nbsp;
4444

@@ -86,15 +86,16 @@ EOF
8686

8787
```lua
8888
{
89-
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
90-
execution_message = {
89+
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
90+
execution_message = {
91+
enabled = true,
9192
message = function() -- message to print on save
9293
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
9394
end,
9495
dim = 0.18, -- dim the color of `message`
9596
cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea
9697
},
97-
trigger_events = {"InsertLeave", "TextChanged"}, -- vim events that trigger auto-save. See :h events
98+
trigger_events = {"InsertLeave", "TextChanged"}, -- vim events that trigger auto-save. See :h events
9899
-- function that determines whether to save the current buffer or not
99100
-- return true: if buffer is ok to be saved
100101
-- return false: if it's not ok to be saved
@@ -109,8 +110,8 @@ EOF
109110
end
110111
return false -- can't save
111112
end,
112-
write_all_buffers = false, -- write all buffers when the current one meets `condition`
113-
debounce_delay = 135, -- saves the file at most every `debounce_delay` milliseconds
113+
write_all_buffers = false, -- write all buffers when the current one meets `condition`
114+
debounce_delay = 135, -- saves the file at most every `debounce_delay` milliseconds
114115
callbacks = { -- functions to be executed at different intervals
115116
enabling = nil, -- ran when enabling auto-save
116117
disabling = nil, -- ran when disabling auto-save

lua/auto-save/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Config = {
22
opts = {
33
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
44
execution_message = {
5+
enabled = true,
56
message = function() -- message to print on save
67
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
78
end,

lua/auto-save/init.lua

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,14 @@ function M.save(buf)
8282

8383
callback("after_saving")
8484

85-
api.nvim_echo({
86-
{
87-
(
88-
type(cnf.opts.execution_message.message) == "function" and cnf.opts.execution_message.message()
89-
or cnf.opts.execution_message.message
90-
),
91-
AUTO_SAVE_COLOR,
92-
},
93-
}, true, {})
85+
if cnf.opts.execution_message.enabled == true then
86+
echo_execution_message()
87+
end
88+
end
89+
90+
local function echo_execution_message()
91+
local msg = type(cnf.opts.execution_message.message) == "function" and cnf.opts.execution_message.message() or cnf.opts.execution_message.message
92+
api.nvim_echo({ { msg, AUTO_SAVE_COLOR } }, true, {})
9493
if cnf.opts.execution_message.cleaning_interval > 0 then
9594
fn.timer_start(cnf.opts.execution_message.cleaning_interval, function()
9695
cmd([[echon '']])

0 commit comments

Comments
 (0)