From 054aaa0808f5b77fa777369a3b3fda967ce1af3f Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Wed, 1 Dec 2021 13:57:38 -0500 Subject: [PATCH] Stop vim from creating ctags when the process is already running --- vimrc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/vimrc b/vimrc index ef6e35b..77048a4 100644 --- a/vimrc +++ b/vimrc @@ -118,6 +118,10 @@ let g:campo_custom_search_args = "" " in this comment string) " let g:campo_custom_ctags_args = \"--exclude=3rd_party" let g:campo_custom_ctags_args = "" + +" Default files and directories that ctags should ignore. +let s:default_ctags_exclude_args = "--exclude=.git --exclude=*.md --exclude=*.txt --exclude=*.config --exclude=*.css --exclude=*.html --exclude=*.htm --exclude=*.json --exclude=node_modules --exclude=.cache" + " --------------------------------------------------------------------------- "################################################################ @@ -464,7 +468,7 @@ augroup campoCmds " Automatically wrap at N characters. autocmd FileType gitcommit setlocal colorcolumn=72 - autocmd BufRead,BufNewFile *.{md,txt,plan} execute "setlocal textwidth=" .s:max_line_length + autocmd BufRead,BufNewFile *.{md,txt,plan} exec "setlocal textwidth=" .s:max_line_length " Spell checking. autocmd FileType gitcommit,markdown,text setlocal spell @@ -493,11 +497,14 @@ augroup campoCmds " The ampersand at the end is to make this run in the background. I had to " group the commands in parens to make the chained commands run in the " background. - " @improve: don't run a bunch of ctags for the same project when mass - " saving files. They all try to write and move newtags which tends to - " lock up vim and/or spew errors. - let l:ctags_cmd = "!(ctags --c-types=+l --c++-types=+l --exclude=*.md --exclude=*.txt --exclude=*.config --exclude=*.css --exclude=*.js --exclude=*.html --exclude=*.htm --exclude=*.json --exclude=node_modules --exclude=.git --exclude=.cache " . g:campo_custom_ctags_args . " --recurse=yes -o newtags; mv newtags tags) &" - exec l:ctags_cmd | redraw! + let l:lock_file = "ctags.lock" + if !filereadable(l:lock_file) && !filereadable("newtags") + " Will include local variables for C-like languages. + let l:ctags_cmd = "!(touch ".l:lock_file."; ctags --c-types=+l --c++-types=+l ".s:default_ctags_exclude_args." ". g:campo_custom_ctags_args." --recurse=yes -o newtags; mv newtags tags; rm ".l:lock_file.") &" + silent! exec l:ctags_cmd | redraw! + else + PrintError "ctags already running (found ".l:lock_file.")" + endif endfun " Generate ctags on save.