From 4b80d8816c01eda27731b0e41fe0fa00f43128b2 Mon Sep 17 00:00:00 2001 From: syui Date: Wed, 11 Jun 2025 06:16:47 +0900 Subject: [PATCH] update --- LICENSE | 21 +++++++++++++++ lua/airsave/init.lua | 63 ++++++++++++++++++++++++++++++++++++++++++++ plugin/airsave.lua | 28 ++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 LICENSE create mode 100644 lua/airsave/init.lua create mode 100644 plugin/airsave.lua diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2a2e71c --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/lua/airsave/init.lua b/lua/airsave/init.lua new file mode 100644 index 0000000..45902d5 --- /dev/null +++ b/lua/airsave/init.lua @@ -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 \ No newline at end of file diff --git a/plugin/airsave.lua b/plugin/airsave.lua new file mode 100644 index 0000000..27059e8 --- /dev/null +++ b/plugin/airsave.lua @@ -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 mappings for customization) +vim.keymap.set('n', '(AirSaveStart)', 'AirSaveStart', { desc = 'Start auto save' }) +vim.keymap.set('n', '(AirSaveStop)', 'AirSaveStop', { desc = 'Stop auto save' }) +vim.keymap.set('n', '(AirSaveToggle)', 'AirSaveToggle', { desc = 'Toggle auto save' }) \ No newline at end of file