1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 14:00:05 +08:00

perf(autocmd): move autocmds.vim to lua

This commit is contained in:
Eric Wong 2024-06-04 23:36:20 +08:00
parent 6a97b72dc3
commit 74ba9cc90a
2 changed files with 150 additions and 35 deletions

View File

@ -66,36 +66,10 @@ if has('nvim-0.10.0')
au!
autocmd BufWinEnter quickfix nnoremap <silent> <buffer>
\ q :call <SID>close_quickfix()<cr>
autocmd QuitPre * call SpaceVim#plugins#windowsmanager#UpdateRestoreWinInfo()
autocmd WinEnter * call SpaceVim#plugins#windowsmanager#MarkBaseWin()
autocmd BufLeave * call SpaceVim#plugins#history#savepos()
autocmd BufWinLeave * let b:_winview = winsaveview()
autocmd BufWinEnter * if(exists('b:_winview')) | call winrestview(b:_winview) | endif
au StdinReadPost * call s:disable_welcome()
if !has('nvim-0.5.0')
autocmd InsertEnter * call s:fixindentline()
endif
autocmd BufEnter,FileType * call SpaceVim#mapping#space#refrashLSPC()
if executable('synclient') && g:spacevim_auto_disable_touchpad
let s:touchpadoff = 0
autocmd InsertEnter * call s:disable_touchpad()
autocmd InsertLeave * call s:enable_touchpad()
autocmd FocusLost * call system('synclient touchpadoff=0')
autocmd FocusGained * call s:reload_touchpad_status()
endif
autocmd ColorScheme gruvbox,jellybeans,nord,srcery,NeoSolarized,one,SpaceVim call s:fix_colorschem_in_SpaceVim()
autocmd VimEnter * call SpaceVim#autocmds#VimEnter()
autocmd BufEnter * let b:_spacevim_project_name = get(g:, '_spacevim_project_name', '')
autocmd SessionLoadPost * let g:_spacevim_session_loaded = 1
autocmd VimLeavePre * call SpaceVim#plugins#manager#terminal()
if has('nvim')
autocmd VimEnter,FocusGained * call SpaceVim#plugins#history#readcache()
autocmd FocusLost,VimLeave * call SpaceVim#plugins#history#writecache()
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ call SpaceVim#plugins#history#jumppos() |
\ endif
endif
augroup END
endfunction
else

View File

@ -11,6 +11,24 @@ local log = require('spacevim.logger')
local create_autocmd = vim.api.nvim_create_autocmd
local touchpadoff
local function disable_touchpad(_)
touchpadoff = 1
vim.fn.system('synclient touchpadoff=1')
end
local function enable_touchpad(_)
touchpadoff = 0
vim.fn.system('synclient touchpadoff=0')
end
local function reload_touchpad_status(_)
if touchpadoff == 1 then
disable_touchpad()
end
end
function M.init()
log.debug('init spacevim_core autocmd group')
local spacevim_core = vim.api.nvim_create_augroup('spacevim_core', { clear = true })
@ -100,23 +118,146 @@ function M.init()
end,
})
-- ensure every file does syntax highlighting (full)
create_autocmd({'BufEnter'}, {
pattern = {'*'},
create_autocmd({ 'BufEnter' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.cmd('syntax sync fromstart')
end
vim.b._spacevim_project_name = vim.g._spacevim_project_name or ''
end,
})
create_autocmd({'BufEnter'}, {
pattern = {'*'},
create_autocmd({ 'BufEnter' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
if vim.fn.winnr('$') == 1 and vim.o.buftype == 'quickfix' then
vim.cmd('bd')
vim.cmd('q')
end
end
end,
})
create_autocmd({ 'BufEnter', 'FileType' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn['SpaceVim#mapping#space#refrashLSPC']()
end,
})
create_autocmd({ 'VimEnter' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn['SpaceVim#autocmds#VimEnter']()
end,
})
create_autocmd({ 'VimLeavePre' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn['SpaceVim#plugins#manager#terminal']()
end,
})
create_autocmd({ 'QuitPre' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn['SpaceVim#plugins#windowsmanager#UpdateRestoreWinInfo']()
end,
})
create_autocmd({ 'WinEnter' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn['SpaceVim#plugins#windowsmanager#MarkBaseWin']()
end,
})
create_autocmd({ 'BufLeave' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn['SpaceVim#plugins#history#savepos']()
end,
})
create_autocmd({ 'VimEnter', 'FocusGained' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn['SpaceVim#plugins#history#readcache']()
end,
})
create_autocmd({ 'FocusLost', 'VimLeave' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn['SpaceVim#plugins#history#writecache']()
end,
})
create_autocmd({ 'BufReadPost' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn['SpaceVim#plugins#history#jumppos']()
end,
})
create_autocmd({ 'BufWinLeave' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.b._winview = vim.fn.winsaveview()
end,
})
create_autocmd({ 'BufWinEnter' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
if vim.fn.exists('b:_winview') == 1 then
vim.fn.winrestview(vim.b._winview)
end
end,
})
create_autocmd({'StdinReadPost'}, {
pattern = {'*'},
group = spacevim_core,
callback = function(_)
vim.api.nvim_create_augroup('SPwelcome', {clear = true})
end,
})
create_autocmd({'SessionLoadPost'}, {
pattern = {'*'},
group = spacevim_core,
callback = function(_)
vim.g._spacevim_session_loaded = 1
end,
})
if vim.fn.executable('synclient') == 1 and vim.g.spacevim_auto_disable_touchpad == 1 then
touchpadoff = 0
create_autocmd({ 'InsertEnter' }, {
pattern = { '*' },
group = spacevim_core,
callback = disable_touchpad,
})
create_autocmd({ 'InsertLeave' }, {
pattern = { '*' },
group = spacevim_core,
callback = enable_touchpad,
})
create_autocmd({ 'FocusGained' }, {
pattern = { '*' },
group = spacevim_core,
callback = reload_touchpad_status,
})
create_autocmd({ 'FocusLost' }, {
pattern = { '*' },
group = spacevim_core,
callback = function(_)
vim.fn.system('synclient touchpadoff=0')
end,
})
end
end
return M