changeset 102:7db339a3961f

Merge branch 'user-autocmd' of https://github.com/davidosomething/vim-gutentags into user-autocmd
author David O'Trakoun <me@davidosomething.com>
date Wed, 02 Mar 2016 10:47:55 -0500
parents e9ef45f763d4 (diff) 32e3d047e54e (current diff)
children efbe60d4865d
files autoload/gutentags.vim
diffstat 5 files changed, 49 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/gutentags.vim	Sat Feb 13 15:30:30 2016 -0500
+++ b/autoload/gutentags.vim	Wed Mar 02 10:47:55 2016 -0500
@@ -121,7 +121,7 @@
         " Put the tag file in the cache dir instead of inside the
         " projet root.
         let l:tag_path = g:gutentags_cache_dir . '/' .
-                    \tr(l:tag_path, '\/:', '---')
+                    \tr(l:tag_path, '\/: ', '---_')
         let l:tag_path = substitute(l:tag_path, '/\-', '/', '')
     endif
     let l:tag_path = gutentags#normalizepath(l:tag_path)
--- a/autoload/gutentags/ctags.vim	Sat Feb 13 15:30:30 2016 -0500
+++ b/autoload/gutentags/ctags.vim	Wed Mar 02 10:47:55 2016 -0500
@@ -37,13 +37,20 @@
     if g:gutentags_auto_set_tags
         execute 'setlocal tags^=' . fnameescape(b:gutentags_files['ctags'])
     endif
+
+    " Check if the ctags executable exists.
+    if g:gutentags_enabled && executable(g:gutentags_ctags_executable) == 0
+        let g:gutentags_enabled = 0
+        echoerr "Executable '".g:gutentags_ctags_executable."' can't be found. "
+                    \."Gutentags will be disabled. You can re-enable it by "
+                    \."setting g:gutentags_enabled back to 1."
+    endif
 endfunction
 
 function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort
     " Get to the tags file directory because ctags is finicky about
     " 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 && g:gutentags_ctags_check_tagfile
@@ -56,14 +63,29 @@
         endif
     endif
 
-    execute "chdir " . fnameescape(l:work_dir)
+    if g:gutentags_cache_dir == ""
+        " If we don't use the cache directory, let's just use the tag filename
+        " as specified by the user, and change the working directory to the
+        " project root.
+        " Note that if we don't do this and pass a full path, `ctags` gets
+        " confused if the paths have spaces -- but not if you're *in* the
+        " root directory.
+        let l:actual_proj_dir = '.'
+        let l:actual_tags_file = g:gutentags_tagfile
+        execute "chdir " . fnameescape(a:proj_dir)
+    else
+        " else: the tags file goes in a cache directory, so we need to specify
+        " all the paths absolutely for `ctags` to do its job correctly.
+        let l:actual_proj_dir = a:proj_dir
+        let l:actual_tags_file = a:tags_file
+    endif
 
     try
         " Build the command line.
         let l:cmd = gutentags#get_execute_cmd() . s:runner_exe
         let l:cmd .= ' -e "' . s:get_ctags_executable(a:proj_dir) . '"'
-        let l:cmd .= ' -t "' . a:tags_file . '"'
-        let l:cmd .= ' -p "' . a:proj_dir . '"'
+        let l:cmd .= ' -t "' . l:actual_tags_file . '"'
+        let l:cmd .= ' -p "' . l:actual_proj_dir . '"'
         if a:write_mode == 0 && l:tags_file_exists
             let l:full_path = expand('%:p')
             let l:cmd .= ' -s "' . l:full_path . '"'
@@ -89,9 +111,9 @@
         endif
         if g:gutentags_trace
             if has('win32')
-                let l:cmd .= ' -l "' . a:tags_file . '.log"'
+                let l:cmd .= ' -l "' . l:actual_tags_file . '.log"'
             else
-                let l:cmd .= ' > "' . a:tags_file . '.log" 2>&1'
+                let l:cmd .= ' > "' . l:actual_tags_file . '.log" 2>&1'
             endif
         else
             if !has('win32')
--- a/plat/unix/update_tags.sh	Sat Feb 13 15:30:30 2016 -0500
+++ b/plat/unix/update_tags.sh	Wed Mar 02 10:47:55 2016 -0500
@@ -69,18 +69,25 @@
 # Remove lock and temp file if script is stopped unexpectedly.
 trap "errorcode=$?; rm -f \"$TAGS_FILE.lock\" \"$TAGS_FILE.temp\"; exit $errorcode" INT TERM EXIT
 
+INDEX_WHOLE_PROJECT=1
 if [ -f "$TAGS_FILE" ]; then
     if [ "$UPDATED_SOURCE" != "" ]; then
         echo "Removing references to: $UPDATED_SOURCE"
         echo "grep -v "$UPDATED_SOURCE" \"$TAGS_FILE\" > \"$TAGS_FILE.temp\""
         grep -v "$UPDATED_SOURCE" "$TAGS_FILE" > "$TAGS_FILE.temp"
-        CTAGS_ARGS="$CTAGS_ARGS --append \"$UPDATED_SOURCE\""
+        INDEX_WHOLE_PROJECT=0
     fi
 fi
 
-echo "Running ctags"
-echo "$CTAGS_EXE -f \"$TAGS_FILE.temp\" $CTAGS_ARGS \"$PROJECT_ROOT\""
-$CTAGS_EXE -f "$TAGS_FILE.temp" $CTAGS_ARGS "$PROJECT_ROOT"
+if [ $INDEX_WHOLE_PROJECT -eq 1 ]; then
+    echo "Running ctags on whole project"
+    echo "$CTAGS_EXE -f \"$TAGS_FILE.temp\" $CTAGS_ARGS \"$PROJECT_ROOT\""
+    $CTAGS_EXE -f "$TAGS_FILE.temp" $CTAGS_ARGS "$PROJECT_ROOT"
+else
+    echo "Running ctags on \"$UPDATED_SOURCE\""
+    echo "$CTAGS_EXE -f \"$TAGS_FILE.temp\" $CTAGS_ARGS --append \"$UPDATED_SOURCE\""
+    $CTAGS_EXE -f "$TAGS_FILE.temp" $CTAGS_ARGS --append "$UPDATED_SOURCE"
+fi
 
 echo "Replacing tags file"
 echo "mv -f \"$TAGS_FILE.temp\" \"$TAGS_FILE\""
--- a/plat/win32/update_tags.cmd	Sat Feb 13 15:30:30 2016 -0500
+++ b/plat/win32/update_tags.cmd	Wed Mar 02 10:47:55 2016 -0500
@@ -73,18 +73,23 @@
 echo Locking tags file... > %LOG_FILE%
 echo locked > "%TAGS_FILE%.lock"
 
+set INDEX_WHOLE_PROJECT=1
 if exist "%TAGS_FILE%" (
     if not ["%UPDATED_SOURCE%"]==[""] (
         echo Removing references to: %UPDATED_SOURCE% >> %LOG_FILE%
         echo type "%TAGS_FILE%" ^| findstr /V /C:"%UPDATED_SOURCE%" ^> "%TAGS_FILE%.temp" >> %LOG_FILE%
         findstr /V /C:"%UPDATED_SOURCE%" "%TAGS_FILE%" > "%TAGS_FILE%.temp"
         set CTAGS_ARGS=%CTAGS_ARGS% --append "%UPDATED_SOURCE%"
+        set INDEX_WHOLE_PROJECT=0
     )
 )
+if ["%INDEX_WHOLE_PROJECT%"]==["1"] (
+    set CTAGS_ARGS=%CTAGS_ARGS% "%PROJECT_ROOT%"
+)
 
 echo Running ctags >> %LOG_FILE%
-echo call "%CTAGS_EXE%" -f "%TAGS_FILE%.temp" %CTAGS_ARGS% "%PROJECT_ROOT%" >> %LOG_FILE%
-call "%CTAGS_EXE%" -f "%TAGS_FILE%.temp" %CTAGS_ARGS% "%PROJECT_ROOT%" >> %LOG_FILE% 2>&1
+echo call "%CTAGS_EXE%" -f "%TAGS_FILE%.temp" %CTAGS_ARGS% >> %LOG_FILE%
+call "%CTAGS_EXE%" -f "%TAGS_FILE%.temp" %CTAGS_ARGS% >> %LOG_FILE% 2>&1
 if ERRORLEVEL 1 (
     echo ERROR: Ctags executable returned non-zero code. >> %LOG_FILE%
     goto :Unlock
--- a/plugin/gutentags.vim	Sat Feb 13 15:30:30 2016 -0500
+++ b/plugin/gutentags.vim	Wed Mar 02 10:47:55 2016 -0500
@@ -4,8 +4,8 @@
 
 " Globals {{{
 
-if v:version < 700
-    echoerr "gutentags: this plugin requires vim >= 7.0."
+if v:version < 704
+    echoerr "gutentags: this plugin requires vim >= 7.4."
     finish
 endif