chore: Deprecate unneeded utils, don't print enable/disable msg (#60)

This commit is contained in:
Toni Müller
2024-12-04 07:17:34 +01:00
committed by GitHub
parent 5fbcaac0a2
commit f8e3ac2857
5 changed files with 39 additions and 59 deletions
-14
View File
@@ -1,14 +0,0 @@
SHELL:=/usr/bin/env bash
LOG_INFO=$(shell date +"%H:%M:%S") \e[0;34mINFO\e[0m
LOG_ERROR=$(shell date +"%H:%M:%S") \e[1;31mERROR\e[0m
LOG_WARNING=$(shell date +"%H:%M:%S") \e[0;33mWARNING\e[0m
LOG_SUCCESS=$(shell date +"%H:%M:%S") \e[0;32mSUCCESS\e[0m
GIT_ROOT=$(shell git rev-parse --show-toplevel)
.DEFAULT_GOAL := load
load:
@echo -e "$(LOG_INFO) Loading dev env..."
@echo -e "$(LOG_WARNING) Opening $(GIT_ROOT)"
nvim --cmd "set rtp+=$(GIT_ROOT)"
+36 -17
View File
@@ -65,10 +65,10 @@ use({
"okuuva/auto-save.nvim", "okuuva/auto-save.nvim",
tag = 'v1*', tag = 'v1*',
config = function() config = function()
require("auto-save").setup { require("auto-save").setup({
-- your config goes here -- your config goes here
-- or just leave it empty :) -- or just leave it empty :)
} })
end, end,
}) })
``` ```
@@ -78,10 +78,10 @@ use({
```vim ```vim
Plug 'okuuva/auto-save.nvim', { 'tag': 'v1*' } Plug 'okuuva/auto-save.nvim', { 'tag': 'v1*' }
lua << EOF lua << EOF
require("auto-save").setup { require("auto-save").setup({
-- your config goes here -- your config goes here
-- or just leave it empty :) -- or just leave it empty :)
} })
EOF EOF
``` ```
@@ -124,7 +124,7 @@ It is also possible to pass a pattern to a trigger event, if you only want to ex
{ {
trigger_events = { trigger_events = {
immediate_save = { immediate_save = {
{ "BufLeave", pattern = {"*.c", "*.h"} } { "BufLeave", pattern = { "*.c", "*.h" } }
} }
} }
} }
@@ -134,19 +134,18 @@ It is also possible to pass a pattern to a trigger event, if you only want to ex
The `condition` field of the configuration allows the user to exclude **auto-save** from saving specific buffers. The `condition` field of the configuration allows the user to exclude **auto-save** from saving specific buffers.
Here is an example using a helper function from `auto-save.utils.data` that disables auto-save for specified file types: Here is an example that disables auto-save for specified file types:
```lua ```lua
{ {
condition = function(buf) condition = function(buf)
local fn = vim.fn local filetype = vim.fn.getbufvar(buf, "&filetype")
local utils = require("auto-save.utils.data")
-- don't save for `sql` file types -- don't save for `sql` file types
if utils.not_in(fn.getbufvar(buf, "&filetype"), {'sql'}) then if vim.list_contains({ "sql" }, filetype) then
return true return false
end end
return false return true
end end
} }
``` ```
@@ -156,10 +155,8 @@ You may also exclude `special-buffers` see (`:h buftype` and `:h special-buffers
```lua ```lua
{ {
condition = function(buf) condition = function(buf)
local fn = vim.fn
-- don't save for special-buffers -- don't save for special-buffers
if fn.getbufvar(buf, "&buftype") ~= '' then if vim.fn.getbufvar(buf, "&buftype") ~= '' then
return false return false
end end
return true return true
@@ -178,7 +175,7 @@ Besides running auto-save at startup (if you have `enabled = true` in your confi
You may want to set up a key mapping for toggling: You may want to set up a key mapping for toggling:
```lua ```lua
vim.api.nvim_set_keymap("n", "<leader>n", ":ASToggle<CR>", {}) vim.api.nvim_set_keymap("n", "<leader>n", "<cmd>ASToggle<CR>", {})
``` ```
or as part of the `lazy.nvim` plugin spec: or as part of the `lazy.nvim` plugin spec:
@@ -187,7 +184,7 @@ or as part of the `lazy.nvim` plugin spec:
{ {
"okuuva/auto-save.nvim", "okuuva/auto-save.nvim",
keys = { keys = {
{ "<leader>n", ":ASToggle<CR>", desc = "Toggle auto-save" }, { "<leader>n", "<cmd>ASToggle<CR>", desc = "Toggle auto-save" },
}, },
... ...
}, },
@@ -216,12 +213,34 @@ vim.api.nvim_create_autocmd('User', {
callback = function(opts) callback = function(opts)
if opts.data.saved_buffer ~= nil then if opts.data.saved_buffer ~= nil then
local filename = vim.api.nvim_buf_get_name(opts.data.saved_buffer) local filename = vim.api.nvim_buf_get_name(opts.data.saved_buffer)
print('AutoSave: saved ' .. filename .. ' at ' .. vim.fn.strftime('%H:%M:%S')) vim.notify('AutoSave: saved ' .. filename .. ' at ' .. vim.fn.strftime('%H:%M:%S'), vim.log.levels.INFO)
end end
end, end,
}) })
``` ```
Another example to print a message when enabling/disabling autosave:
```lua
local group = vim.api.nvim_create_augroup('autosave', {})
vim.api.nvim_create_autocmd('User', {
pattern = 'AutoSaveEnable',
group = group,
callback = function(opts)
vim.notify('AutoSave enabled', vim.log.levels.INFO)
end,
})
vim.api.nvim_create_autocmd('User', {
pattern = 'AutoSaveDisable',
group = group,
callback = function(opts)
vim.notify('AutoSave disabled', vim.log.levels.INFO)
end,
})
```
If you want more Events, feel free to open an issue. If you want more Events, feel free to open an issue.
## 🤝 Contributing ## 🤝 Contributing
-3
View File
@@ -2,7 +2,6 @@ local M = {}
--- @class Config --- @class Config
local cnf = require("auto-save.config") local cnf = require("auto-save.config")
local echo = require("auto-save.utils.echo")
local autocmds = require("auto-save.utils.autocommands") local autocmds = require("auto-save.utils.autocommands")
local api = vim.api local api = vim.api
@@ -155,10 +154,8 @@ end
function M.toggle() function M.toggle()
if autosave_running then if autosave_running then
M.off() M.off()
echo("off")
else else
M.on() M.on()
echo("on")
end end
end end
+3
View File
@@ -1,5 +1,7 @@
--- @deprecated
local M = {} local M = {}
--- @deprecated
function M.set_of(list) function M.set_of(list)
local set = {} local set = {}
for i = 1, #list do for i = 1, #list do
@@ -8,6 +10,7 @@ function M.set_of(list)
return set return set
end end
--- @deprecated
function M.not_in(var, arr) function M.not_in(var, arr)
if M.set_of(arr)[var] == nil then if M.set_of(arr)[var] == nil then
return true return true
-25
View File
@@ -1,25 +0,0 @@
local TITLE = "auto-save"
return function(msg, kind)
local has_notify_plugin = pcall(require, "notify")
local level = {}
if kind == "error" then
level.log = vim.log.levels.ERROR
level.type = "error"
elseif kind == "warn" then
level.log = vim.log.levels.WARN
level.type = "error"
else
level.log = kind or vim.log.levels.INFO
level.type = "info"
end
if has_notify_plugin then
vim.notify(msg, level.log, {
title = TITLE,
})
else
vim.notify(("%s: %s"):format(TITLE, msg), level.log)
end
end