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
" save. So if you make changes to them then you need to manually reload this
" file using <leader>rv or whatever. :ReloadVimrcError
function! DoSingleWrite()
function! WriteCurrentFileAndCreateCtags()
write!
call CreateCtags()
endfunction
function! DoSingleWriteThenQuit()
function! WriteCurrentFileAndCreateCtagsThenQuit()
write!
call CreateCtags()
quit
endfunction
" @fixme Sometimes a :wa that saves multiple files causes vim to hang and use
" a lot of CPU.
function! DoMultiWrite()
let l:current_buffer = bufnr("%")
bufdo wa
" Restore the last buffer because it may have changed.
exec "buffer " . l:current_buffer
" @fixme Sometimes a :wa that saves multiple files causes vim to hang and use a lot of CPU.
function! WriteAllModifiedFilesAndCreateCtags()
wall!
call CreateCtags()
endfunction
cnoreabbrev w :call DoSingleWrite()
cnoreabbrev W :call DoSingleWrite()
cnoreabbrev wa :call DoMultiWrite()
cnoreabbrev Wa :call DoMultiWrite()
cnoreabbrev WA :call DoMultiWrite()
cnoreabbrev wq :call DoSingleWriteThenQuit()
cnoreabbrev Wq :call DoSingleWriteThenQuit()
cnoreabbrev WQ :call DoSingleWriteThenQuit()
cnoreabbrev w :call WriteCurrentFileAndCreateCtags()
cnoreabbrev W :call WriteCurrentFileAndCreateCtags()
cnoreabbrev wa :call WriteAllModifiedFilesAndCreateCtags()
cnoreabbrev Wa :call WriteAllModifiedFilesAndCreateCtags()
cnoreabbrev WA :call WriteAllModifiedFilesAndCreateCtags()
cnoreabbrev wq :call WriteCurrentFileAndCreateCtagsThenQuit()
cnoreabbrev Wq :call WriteCurrentFileAndCreateCtagsThenQuit()
cnoreabbrev WQ :call WriteCurrentFileAndCreateCtagsThenQuit()
nnoremap <leader>w :call DoSingleWrite()<cr>
nnoremap <leader>x :call DoSingleWriteThenQuit()<cr>
nnoremap <leader>w :call WriteCurrentFileAndCreateCtags()<cr>
nnoremap <leader>x :call WriteCurrentFileAndCreateCtagsThenQuit()<cr>
nnoremap <leader>q :q<cr>
cnoreabbrev Q q
@ -1158,7 +1154,7 @@ endfunction
function! Build(optimized=0, silent=0)
let l:ext = tolower(expand('%:e'))
let l:parent_dir = expand('%:p:h')
let l:async_cmd = "AsyncRun! -save=2 "
let l:async_cmd = "AsyncRun! "
if a:silent
let l:async_cmd .= "-post=call\\ HideAsyncResults() "
endif
@ -1196,6 +1192,10 @@ function! Build(optimized=0, silent=0)
if l:is_jai
let l:cmd .= ' '.g:campo_jai_build_args
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
endfunction