changeset 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 e7e392be4141
children 0424970d81f8
files autoload/gutentags.vim autoload/gutentags/ctags.vim
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/gutentags.vim	Wed Aug 26 21:20:37 2015 -0700
+++ b/autoload/gutentags.vim	Wed Aug 26 22:21:19 2015 -0700
@@ -256,6 +256,9 @@
     try
         call call("gutentags#".a:module."#generate",
                     \[l:proj_dir, l:tags_file, a:write_mode])
+    catch /^gutentags\:/
+        echom "Error while generating ".a:module." file:"
+        echom v:exception
     finally
         " Restore the current directory...
         execute "chdir " . fnameescape(l:prev_cwd)
--- a/autoload/gutentags/ctags.vim	Wed Aug 26 21:20:37 2015 -0700
+++ b/autoload/gutentags/ctags.vim	Wed Aug 26 22:21:19 2015 -0700
@@ -40,6 +40,18 @@
     " these things.
     let l:prev_cwd = getcwd()
     let l:work_dir = fnamemodify(a:tags_file, ':h')
+    let l:tags_file_exists = filereadable(a:tags_file)
+
+    if l:tags_file_exists
+        let l:first_lines = readfile(a:tags_file, '', 1)
+        if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0
+            call gutentags#throw("File ".a:tags_file." doesn't appear to be ".
+                        \"a ctags file. Please delete it and run ".
+                        \":GutentagsUpdate!.")
+            return
+        endif
+    endif
+
     execute "chdir " . fnameescape(l:work_dir)
 
     try
@@ -48,7 +60,7 @@
         let l:cmd .= ' -e "' . s:get_ctags_executable() . '"'
         let l:cmd .= ' -t "' . a:tags_file . '"'
         let l:cmd .= ' -p "' . a:proj_dir . '"'
-        if a:write_mode == 0 && filereadable(a:tags_file)
+        if a:write_mode == 0 && l:tags_file_exists
             let l:full_path = expand('%:p')
             let l:cmd .= ' -s "' . l:full_path . '"'
         endif