commit ed3949bb6ac69dc6f2dbdf6d0ba8b5a59e529bf7 Author: syui Date: Wed Jun 11 08:35:03 2025 +0900 first 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/README.md b/README.md new file mode 100644 index 0000000..62a18d9 --- /dev/null +++ b/README.md @@ -0,0 +1,105 @@ +# airsave.nvim + +Auto save plugin for Neovim, converted from the original airsave.vim to modern Lua. + +## Features + +- Auto save on `TextChanged`, `CursorHold`, and `InsertLeave` events +- Configurable events and options +- Silent or verbose saving modes +- Easy toggle commands +- Modern Lua implementation for Neovim + +## Installation + +### Using vim-plug + +```vim +Plug 'your-username/airsave.nvim' +``` + +### Using packer.nvim + +```lua +use 'your-username/airsave.nvim' +``` + +### Using lazy.nvim + +```lua +{ + 'your-username/airsave.nvim', + config = function() + require('airsave').setup({ + auto_write = true, -- Enable auto save on startup + }) + end +} +``` + +## Configuration + +```lua +require('airsave').setup({ + auto_write = false, -- Enable auto save on startup (default: false) + no_silent = false, -- Show save messages (default: false) + events = { 'TextChanged', 'CursorHold', 'InsertLeave' }, -- Auto save events +}) +``` + +## Commands + +- `:AirSaveStart` - Start auto save +- `:AirSaveStop` - Stop auto save +- `:AirSaveToggle` - Toggle auto save + +## Key Mappings + +The plugin provides `` mappings for customization: + +- `(AirSaveStart)` - Start auto save +- `(AirSaveStop)` - Stop auto save +- `(AirSaveToggle)` - Toggle auto save + +Example custom mappings: + +```lua +vim.keymap.set('n', 'as', '(AirSaveStart)') +vim.keymap.set('n', 'aS', '(AirSaveStop)') +vim.keymap.set('n', 'at', '(AirSaveToggle)') +``` + +## Usage + +### Basic Usage + +```lua +-- Start auto save +require('airsave').start() + +-- Stop auto save +require('airsave').stop() + +-- Check if running +if require('airsave').is_running() then + print('Auto save is active') +end +``` + +### With Configuration + +```lua +require('airsave').setup({ + auto_write = true, -- Start automatically + no_silent = false, -- Silent saves + events = { 'TextChanged', 'InsertLeave' }, -- Custom events +}) +``` + +## Credits + +Based on the original [airsave.vim](https://github.com/syui/airsave.vim) + +## License + +MIT License 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