first
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.
|
105
README.md
Normal file
105
README.md
Normal file
@ -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 `<Plug>` mappings for customization:
|
||||||
|
|
||||||
|
- `<Plug>(AirSaveStart)` - Start auto save
|
||||||
|
- `<Plug>(AirSaveStop)` - Stop auto save
|
||||||
|
- `<Plug>(AirSaveToggle)` - Toggle auto save
|
||||||
|
|
||||||
|
Example custom mappings:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
vim.keymap.set('n', '<leader>as', '<Plug>(AirSaveStart)')
|
||||||
|
vim.keymap.set('n', '<leader>aS', '<Plug>(AirSaveStop)')
|
||||||
|
vim.keymap.set('n', '<leader>at', '<Plug>(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
|
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