Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhuster committed Nov 8, 2024
1 parent b56f9dc commit 9bec4ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
18 changes: 18 additions & 0 deletions lua/autosave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ function M.execute(args)
end
end

function M.cmdlineComplete(_A)
local ArgLead = _A[1]
local CmdLine = _A[2]
local subcommands = { "on", "off", "toggle", "status" }
local subcommand = vim.fn.split(CmdLine, " ")[2]
local completion = {}
if not subcommand then
completion = subcommands
elseif subcommand == ArgLead then
for _, value in ipairs(subcommands) do
if value:sub(1, #ArgLead) == ArgLead then
table.insert(completion, value)
end
end
end
return bool(vim.fn.has('nvim')) and completion or vim.list(completion)
end

--- Check if a buffer can be autosaved
--- @return boolean
function M.check_buffer()
Expand Down
12 changes: 1 addition & 11 deletions plugin/autosave.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,7 @@ augroup END
command! -nargs=1 -complete=customlist,AutosaveComplete Autosave call luaeval("require'autosave'.execute(_A)", [<f-args>])

function! AutosaveComplete(ArgLead, CmdLine, CursorPos) abort
let subcommands = ['on', 'off', 'toggle', 'status']
let cmd_parts = split(a:CmdLine, ' ')
if len(cmd_parts) < 2
return subcommands
endif
let subcommand = cmd_parts[1]
if empty(subcommand)
return subcommands
elseif subcommand == a:ArgLead
return filter(subcommands, 'v:val =~ "^' . a:ArgLead . '"')
endif
return luaeval("require'autosave'.cmdlineComplete(_A)", [a:ArgLead, a:CmdLine, a:CursorPos])
endfunction

set autowriteall

0 comments on commit 9bec4ce

Please sign in to comment.