More vim ctag improvements

This commit is contained in:
Michael Campagnaro 2021-12-02 21:07:47 -05:00
parent afc89a1725
commit 3d91c1d4f0
3 changed files with 71 additions and 25 deletions

View File

@ -970,9 +970,12 @@ alias gwip="git add . && git commit -m \"WIP\""
#################################################################################################### ####################################################################################################
# Elixir # Elixir
#################################################################################################### ####################################################################################################
alias ei='rlwrap iex -S mix phx.server' alias iex='rlwrap iex'
alias et='mix test' alias iexw='rlwrap iex --werl'
alias ep='iex -S mix phx.server'
alias ei='iex -S mix'
alias er='mix phx.server' alias er='mix phx.server'
alias et='mix test'
#################################################################################################### ####################################################################################################
# Haxe # Haxe

85
vimrc
View File

@ -118,20 +118,33 @@ let g:campo_custom_search_args = ""
"""""""""""""" """"""""""""""
" CTAGS " CTAGS
"""""""""""""" """"""""""""""
" If one of these file types are saved then the ctags creation function will be called.
let g:campo_extensions_that_run_ctags = "*.{cs,js,py,h,hpp,c,cpp,inc,asm,ex,exs}"
" Default files and directories that ctags should ignore. " If != 0 then ctag generation will always happen on a file save, otherwise
let g: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" " it'll only be triggered if the file being saved has an extension in the
" g:campo_extensions_that_run_ctags list.
let g:campo_force_ctags_regardless_of_extension = 0
" If one of these file types are saved then the ctags creation function will be called.
" You can append to this list in another config like so:
" let g:campo_extensions_that_run_ctags = g:campo_extensions_that_run_ctags + ['foo', 'bar']
let g:campo_extensions_that_run_ctags = ['c','cpp','h','hpp','inc','cs','js','py','asm','ex','exs']
" Default files and directories that ctags should ignore when doing a
" recursive crawl.
" @note The RunCtags function will always ignore .git and node_modules
" regardless of this variable's value.
let g:campo_ctags_exclude = ['*.txt', '*.config', '.cache']
" This is included in the ctags autocmd args. You can use this to customize " This is included in the ctags autocmd args. You can use this to customize
" how ctags are built. For example, you can exclude a directory that's not in " how ctags are built.
" g:default_ctags_exclude_args like so (remove the backslash from the first " Examples:
" quote as that's just here to escape it in this comment string) " * Recursive ctag generation with `let g:campo_custom_ctags_args = '-R'`
" let g:campo_custom_ctags_args = \"--exclude=3rd_party" " * Create tags for specific langauges: `let g:campo_custom_ctags_args = '--languages=C,C++,Elixir'
" * You can see a list of languages with `ctags --list-languages`
" * For C# you have to escape the ampersand like so: `--languages=C\\#`
" * Exclude a directory with `let g:campo_custom_ctags_args = '--exclude=3rd_party'`
let g:campo_custom_ctags_args = "" let g:campo_custom_ctags_args = ""
"################################################################ "################################################################
"################################################################ "################################################################
"################################################################ "################################################################
@ -518,22 +531,52 @@ augroup campoCmds
autocmd BufWritePost ~/.vimrc.private source $MYVIMRC autocmd BufWritePost ~/.vimrc.private source $MYVIMRC
function! s:RunCtags() function! s:RunCtags()
" The ampersand at the end is to make this run in the background. I had to " Only allow one instance of ctags to run in this directory at any given time.
" group the commands in parens to make the chained commands run in the
" background.
let l:lock_file = "ctags.lock" let l:lock_file = "ctags.lock"
if !filereadable(l:lock_file) && !filereadable("newtags") if filereadable(l:lock_file) || filereadable("newtags")
" Will include local variables for C-like languages. call PrintError("ctags already running (found ".l:lock_file." or newtags file)")
let l:ctags_cmd = "!(touch ".l:lock_file."; ctags --c-types=+l --c++-types=+l ".g:default_ctags_exclude_args." ". g:campo_custom_ctags_args." --recurse=yes -o newtags; mv newtags tags; rm ".l:lock_file.") &" return
silent! exec l:ctags_cmd | redraw!
else
call PrintError("ctags already running (found ".l:lock_file.")")
endif endif
let l:extension = tolower(expand('%:e'))
if (g:campo_force_ctags_regardless_of_extension == 0) && (index(g:campo_extensions_that_run_ctags, l:extension) < 0)
echo "Skipping ctags generation"
return
endif
" Abort if we're editing a text file. This won't be an exhaustive
" filter. We can restrict what goes into the tag file
" First determine if we're in a root drive directory. If we are then
" we bail because we don't want to recurse across the entire drive!
let l:path = expand('%:p:h')
let l:path_without_slashes = substitute(l:path, "/", "", "g")
if (strchars(l:path) - strchars(l:path_without_slashes)) <= 1
call PrintError("Not going to run ctags because the file is in a root drive directory")
return
endif
" Always ignore .git and node_modules
let g:campo_ctags_exclude = g:campo_ctags_exclude + ['.git', 'node_modules']
let l:exclude_list = ""
for name in g:campo_ctags_exclude
let l:exclude_list = l:exclude_list . "--exclude=" . name . " "
endfor
" Include local variables for C-like languages.
let l:ctags_cmd = 'ctags '.l:exclude_list.' '.g:campo_custom_ctags_args.' --c-types=+l --c++-types=+l -o newtags'
" If there's an error running ctags then this echo will cause the
" error msg to be displayed on a new line.
echo ''
" 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.
let l:cmd = '!(touch '.l:lock_file.'; '.l:ctags_cmd.'; mv newtags tags &>/dev/null; rm '.l:lock_file.') &'
silent! exec l:cmd
endfun endfun
" Generate ctags on save. In order to use the variable we have to put the " Generate ctags on save.
" autocmd in an exec statement. autocmd BufWritePost * call s:RunCtags()
exec "autocmd BufWritePost ".g:campo_extensions_that_run_ctags." call s:RunCtags()"
" Remove trailing whitespace when saving any file. " Remove trailing whitespace when saving any file.
function! s:StripTrailingWhitespaces() function! s:StripTrailingWhitespaces()

View File

@ -213,8 +213,8 @@ processor time and is generally useless.
### Setting up ctags ### Setting up ctags
* Install the latest Universal ctags build: https://github.com/universal-ctags/ctags-win32/releases * Download the latest Universal ctags build: https://github.com/universal-ctags/ctags-win32/releases
* Place it in `~/bin`. * Place ctags.exe and readtags.exe in `~/bin` or in `~/.dev/tools`.
## Setting up Visual Studio ## Setting up Visual Studio