Skip to content

Commit

Permalink
feat!: Remove deprecated execution message
Browse files Browse the repository at this point in the history
  • Loading branch information
primeapple committed May 6, 2024
1 parent 5fe9ab0 commit 3ab64b0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 162 deletions.
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
- automatically save your changes so the world doesn't collapse
- highly customizable:
- conditionals to assert whether to save or not
- execution message (it can be dimmed and personalized)
- events that trigger auto-save
- debounce the save with a delay
- hook into the lifecycle with autocommands
Expand Down Expand Up @@ -93,14 +92,6 @@ EOF
```lua
{
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
execution_message = {
enabled = true,
message = function() -- message to print on save
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
end,
dim = 0.18, -- dim the color of `message`
cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea
},
trigger_events = { -- See :h events
immediate_save = { "BufLeave", "FocusLost" }, -- vim events that trigger an immediate save
defer_save = { "InsertLeave", "TextChanged" }, -- vim events that trigger a deferred save (saves after `debounce_delay`)
Expand Down Expand Up @@ -212,18 +203,18 @@ The plugin fires events at various points during its lifecycle which users can h

It will always supply the current buffer in the `data.saved_buffer`

An example to always print the file name before a file is getting saved (use `:messages` if the execution message swallows the print):
An example to print a message with the file name after a file got saved:

```lua
local group = vim.api.nvim_create_augroup('autosave', {})

vim.api.nvim_create_autocmd('User', {
pattern = 'AutoSaveWritePre',
pattern = 'AutoSaveWritePost',
group = group,
callback = function(opts)
if opts.data.saved_buffer ~= nil then
local filename = vim.api.nvim_buf_get_name(opts.data.saved_buffer)
print('We are about to save ' .. filename .. ' get ready captain!')
print('File ' .. filename .. ' got saved successfully!')
end
end,
})
Expand Down
30 changes: 18 additions & 12 deletions lua/auto-save/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
Config = {
opts = {
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
execution_message = {
enabled = true,
--- @type string|fun(): string
message = function() -- message to print on save
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
end,
dim = 0.18, -- dim the color of `message`
cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea
},
trigger_events = { -- See :h events
--- @type TriggerEvent[]?
immediate_save = { "BufLeave", "FocusLost" }, -- vim events that trigger an immediate save
Expand All @@ -34,9 +25,24 @@ Config = {
},
}

function Config:set_options(opts)
opts = opts or {}
self.opts = vim.tbl_deep_extend("keep", opts, self.opts)
function Config:handle_deprecations(custom_opts)
if custom_opts["execution_message"] then
vim.notify(
"The `execution_message` has been removed from the auto-save.nvim plugin. Check the Readme on how to add it yourself.",
vim.log.levels.WARN
)
custom_opts["execution_message"] = nil
end

return custom_opts
end

function Config:set_options(custom_opts)
custom_opts = custom_opts or {}

custom_opts = self.handle_deprecations(custom_opts)

self.opts = vim.tbl_deep_extend("keep", custom_opts, self.opts)
end

function Config:get_options()
Expand Down
35 changes: 0 additions & 35 deletions lua/auto-save/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ local M = {}

--- @class Config
local cnf = require("auto-save.config")
local colors = require("auto-save.utils.colors")
local echo = require("auto-save.utils.echo")
local autocmds = require("auto-save.utils.autocommands")

local api = vim.api
local fn = vim.fn
local cmd = vim.cmd
local schedule = vim.schedule

local logger
local autosave_running = nil
Expand Down Expand Up @@ -47,18 +45,6 @@ local function debounce(lfn, duration)
return inner_debounce
end

local function echo_execution_message()
local message = cnf.opts.execution_message.message
local msg = type(message) == "function" and message() or message
---@diagnostic disable-next-line: deprecated
colors.echo_with_highlight(msg --[[@as string]])
if cnf.opts.execution_message.cleaning_interval > 0 then
fn.timer_start(cnf.opts.execution_message.cleaning_interval, function()
cmd([[echon '']])
end)
end
end

--- Determines if the given buffer is modifiable and if the condition from the config yields true for it
--- @param buf number
--- @return boolean
Expand Down Expand Up @@ -102,10 +88,6 @@ local function save(buf)

autocmds.exec_autocmd("AutoSaveWritePost", { saved_buffer = buf })
logger.log(buf, "Saved buffer")

if cnf.opts.execution_message.enabled == true then
echo_execution_message()
end
end

--- @param buf number
Expand Down Expand Up @@ -157,23 +139,6 @@ function M.on()
desc = "Cancel a pending save timer for a buffer",
})

local function setup_dimming()
if cnf.opts.execution_message.enabled then
schedule(function()
---@diagnostic disable-next-line: deprecated
colors.apply_colors(cnf.opts.execution_message.dim)
end)
end
end

setup_dimming()
api.nvim_create_autocmd("ColorScheme", {
callback = function()
setup_dimming()
end,
group = augroup,
})

autosave_running = true

autocmds.exec_autocmd("AutoSaveEnable")
Expand Down
103 changes: 0 additions & 103 deletions lua/auto-save/utils/colors.lua

This file was deleted.

0 comments on commit 3ab64b0

Please sign in to comment.