From d664ba882c4b690374cc34d4e2d5b2d52a81c040 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Wed, 1 Feb 2023 17:11:25 -0500 Subject: [PATCH] Do our own save call when compiling files in vim --- vimrc | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/vimrc b/vimrc index d4f666d..9a0e678 100644 --- a/vimrc +++ b/vimrc @@ -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 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 w :call DoSingleWrite() -nnoremap x :call DoSingleWriteThenQuit() +nnoremap w :call WriteCurrentFileAndCreateCtags() +nnoremap x :call WriteCurrentFileAndCreateCtagsThenQuit() nnoremap q :q 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