update
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 airsave.nvim
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
63
lua/airsave/init.lua
Normal file
63
lua/airsave/init.lua
Normal file
@@ -0,0 +1,63 @@
|
||||
-- airsave.nvim - Auto save plugin for Neovim
|
||||
-- Converted from airsave.vim to Lua
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Default configuration
|
||||
M.config = {
|
||||
auto_write = false,
|
||||
no_silent = false,
|
||||
events = { 'TextChanged', 'CursorHold', 'InsertLeave' },
|
||||
}
|
||||
|
||||
local augroup_id = nil
|
||||
|
||||
-- Start auto save
|
||||
function M.start()
|
||||
if augroup_id then
|
||||
M.stop()
|
||||
end
|
||||
|
||||
augroup_id = vim.api.nvim_create_augroup('AirSaveNvim', { clear = true })
|
||||
|
||||
local events = M.config.events
|
||||
|
||||
vim.api.nvim_create_autocmd(events, {
|
||||
group = augroup_id,
|
||||
pattern = '*',
|
||||
callback = function()
|
||||
-- Only save if buffer is modified, not special buffer type, and has a filename
|
||||
if vim.bo.modified and vim.bo.buftype == '' and vim.fn.expand('%') ~= '' then
|
||||
if M.config.no_silent then
|
||||
vim.cmd('update')
|
||||
else
|
||||
vim.cmd('silent! update')
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
-- Stop auto save
|
||||
function M.stop()
|
||||
if augroup_id then
|
||||
vim.api.nvim_del_augroup_by_id(augroup_id)
|
||||
augroup_id = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Check if auto save is running
|
||||
function M.is_running()
|
||||
return augroup_id ~= nil
|
||||
end
|
||||
|
||||
-- Setup function for configuration
|
||||
function M.setup(opts)
|
||||
M.config = vim.tbl_deep_extend('force', M.config, opts or {})
|
||||
|
||||
if M.config.auto_write then
|
||||
M.start()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
28
plugin/airsave.lua
Normal file
28
plugin/airsave.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
-- airsave.nvim plugin initialization
|
||||
|
||||
-- Commands
|
||||
vim.api.nvim_create_user_command('AirSaveStart', function()
|
||||
require('airsave').start()
|
||||
print('Auto save started')
|
||||
end, { desc = 'Start auto save' })
|
||||
|
||||
vim.api.nvim_create_user_command('AirSaveStop', function()
|
||||
require('airsave').stop()
|
||||
print('Auto save stopped')
|
||||
end, { desc = 'Stop auto save' })
|
||||
|
||||
vim.api.nvim_create_user_command('AirSaveToggle', function()
|
||||
local airsave = require('airsave')
|
||||
if airsave.is_running() then
|
||||
airsave.stop()
|
||||
print('Auto save stopped')
|
||||
else
|
||||
airsave.start()
|
||||
print('Auto save started')
|
||||
end
|
||||
end, { desc = 'Toggle auto save' })
|
||||
|
||||
-- Key mappings (using <Plug> mappings for customization)
|
||||
vim.keymap.set('n', '<Plug>(AirSaveStart)', '<cmd>AirSaveStart<cr>', { desc = 'Start auto save' })
|
||||
vim.keymap.set('n', '<Plug>(AirSaveStop)', '<cmd>AirSaveStop<cr>', { desc = 'Stop auto save' })
|
||||
vim.keymap.set('n', '<Plug>(AirSaveToggle)', '<cmd>AirSaveToggle<cr>', { desc = 'Toggle auto save' })
|
Reference in New Issue
Block a user