Do our own save call when compiling files in vim

This commit is contained in:
Michael Campagnaro 2023-02-01 17:11:25 -05:00
parent 2f9dc3aba7
commit d664ba882c

40
vimrc
View File

@ -657,38 +657,34 @@ endfun
" These write functions below will not be reloaded because they initiate the " These write functions below will not be reloaded because they initiate the
" save. So if you make changes to them then you need to manually reload this " save. So if you make changes to them then you need to manually reload this
" file using <leader>rv or whatever. :ReloadVimrcError " file using <leader>rv or whatever. :ReloadVimrcError
function! DoSingleWrite() function! WriteCurrentFileAndCreateCtags()
write! write!
call CreateCtags() call CreateCtags()
endfunction endfunction
function! DoSingleWriteThenQuit() function! WriteCurrentFileAndCreateCtagsThenQuit()
write! write!
call CreateCtags() call CreateCtags()
quit quit
endfunction endfunction
" @fixme Sometimes a :wa that saves multiple files causes vim to hang and use " @fixme Sometimes a :wa that saves multiple files causes vim to hang and use a lot of CPU.
" a lot of CPU. function! WriteAllModifiedFilesAndCreateCtags()
function! DoMultiWrite() wall!
let l:current_buffer = bufnr("%")
bufdo wa
" Restore the last buffer because it may have changed.
exec "buffer " . l:current_buffer
call CreateCtags() call CreateCtags()
endfunction endfunction
cnoreabbrev w :call DoSingleWrite() cnoreabbrev w :call WriteCurrentFileAndCreateCtags()
cnoreabbrev W :call DoSingleWrite() cnoreabbrev W :call WriteCurrentFileAndCreateCtags()
cnoreabbrev wa :call DoMultiWrite() cnoreabbrev wa :call WriteAllModifiedFilesAndCreateCtags()
cnoreabbrev Wa :call DoMultiWrite() cnoreabbrev Wa :call WriteAllModifiedFilesAndCreateCtags()
cnoreabbrev WA :call DoMultiWrite() cnoreabbrev WA :call WriteAllModifiedFilesAndCreateCtags()
cnoreabbrev wq :call DoSingleWriteThenQuit() cnoreabbrev wq :call WriteCurrentFileAndCreateCtagsThenQuit()
cnoreabbrev Wq :call DoSingleWriteThenQuit() cnoreabbrev Wq :call WriteCurrentFileAndCreateCtagsThenQuit()
cnoreabbrev WQ :call DoSingleWriteThenQuit() cnoreabbrev WQ :call WriteCurrentFileAndCreateCtagsThenQuit()
nnoremap <leader>w :call DoSingleWrite()<cr> nnoremap <leader>w :call WriteCurrentFileAndCreateCtags()<cr>
nnoremap <leader>x :call DoSingleWriteThenQuit()<cr> nnoremap <leader>x :call WriteCurrentFileAndCreateCtagsThenQuit()<cr>
nnoremap <leader>q :q<cr> nnoremap <leader>q :q<cr>
cnoreabbrev Q q cnoreabbrev Q q
@ -1158,7 +1154,7 @@ endfunction
function! Build(optimized=0, silent=0) function! Build(optimized=0, silent=0)
let l:ext = tolower(expand('%:e')) let l:ext = tolower(expand('%:e'))
let l:parent_dir = expand('%:p:h') let l:parent_dir = expand('%:p:h')
let l:async_cmd = "AsyncRun! -save=2 " let l:async_cmd = "AsyncRun! "
if a:silent if a:silent
let l:async_cmd .= "-post=call\\ HideAsyncResults() " let l:async_cmd .= "-post=call\\ HideAsyncResults() "
endif endif
@ -1196,6 +1192,10 @@ function! Build(optimized=0, silent=0)
if l:is_jai if l:is_jai
let l:cmd .= ' '.g:campo_jai_build_args let l:cmd .= ' '.g:campo_jai_build_args
endif endif
" I was originally passing -save=2 to AsyncRun! in order to save all
" modified files (it just does a `silent! wall` call), but I want ctags to
" be generated so we're handling the save ourselves.
call WriteAllModifiedFilesAndCreateCtags()
exec l:async_cmd . l:cmd exec l:async_cmd . l:cmd
endfunction endfunction