comparison autoload/gutentags/ctags.vim @ 84:96bfe5c37f37

Error and abort if we'll be overwriting a non-ctags file.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 26 Aug 2015 22:21:19 -0700
parents d12543f11eb9
children 7872cc9bbc2d
comparison
equal deleted inserted replaced
83:e7e392be4141 84:96bfe5c37f37
38 function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort 38 function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort
39 " Get to the tags file directory because ctags is finicky about 39 " Get to the tags file directory because ctags is finicky about
40 " these things. 40 " these things.
41 let l:prev_cwd = getcwd() 41 let l:prev_cwd = getcwd()
42 let l:work_dir = fnamemodify(a:tags_file, ':h') 42 let l:work_dir = fnamemodify(a:tags_file, ':h')
43 let l:tags_file_exists = filereadable(a:tags_file)
44
45 if l:tags_file_exists
46 let l:first_lines = readfile(a:tags_file, '', 1)
47 if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0
48 call gutentags#throw("File ".a:tags_file." doesn't appear to be ".
49 \"a ctags file. Please delete it and run ".
50 \":GutentagsUpdate!.")
51 return
52 endif
53 endif
54
43 execute "chdir " . fnameescape(l:work_dir) 55 execute "chdir " . fnameescape(l:work_dir)
44 56
45 try 57 try
46 " Build the command line. 58 " Build the command line.
47 let l:cmd = gutentags#get_execute_cmd() . s:runner_exe 59 let l:cmd = gutentags#get_execute_cmd() . s:runner_exe
48 let l:cmd .= ' -e "' . s:get_ctags_executable() . '"' 60 let l:cmd .= ' -e "' . s:get_ctags_executable() . '"'
49 let l:cmd .= ' -t "' . a:tags_file . '"' 61 let l:cmd .= ' -t "' . a:tags_file . '"'
50 let l:cmd .= ' -p "' . a:proj_dir . '"' 62 let l:cmd .= ' -p "' . a:proj_dir . '"'
51 if a:write_mode == 0 && filereadable(a:tags_file) 63 if a:write_mode == 0 && l:tags_file_exists
52 let l:full_path = expand('%:p') 64 let l:full_path = expand('%:p')
53 let l:cmd .= ' -s "' . l:full_path . '"' 65 let l:cmd .= ' -s "' . l:full_path . '"'
54 endif 66 endif
55 " Pass the Gutentags options file first, and then the project specific 67 " Pass the Gutentags options file first, and then the project specific
56 " one, so that users can override the default behaviour. 68 " one, so that users can override the default behaviour.