changeset 98:d645125192aa

Fix more problems with paths and spaces in them.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 25 Feb 2016 21:04:46 -0800
parents 794ee111bce6
children 05fc1e2172cc e9ef45f763d4 db18090b56f7 7fd3958a1c0d
files autoload/gutentags.vim autoload/gutentags/ctags.vim doc/gutentags.txt
diffstat 3 files changed, 22 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/gutentags.vim	Sun Feb 21 10:34:47 2016 -0800
+++ b/autoload/gutentags.vim	Thu Feb 25 21:04:46 2016 -0800
@@ -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	Sun Feb 21 10:34:47 2016 -0800
+++ b/autoload/gutentags/ctags.vim	Thu Feb 25 21:04:46 2016 -0800
@@ -22,10 +22,6 @@
     let g:gutentags_ctags_check_tagfile = 0
 endif
 
-if !exists('g:gutentags_ctags_no_space_in_paths')
-    let g:gutentags_ctags_no_space_in_paths = 1
-endif
-
 " }}}
 
 " Gutentags Module Interface {{{
@@ -34,15 +30,8 @@
 
 function! gutentags#ctags#init(project_root) abort
     " Figure out the path to the tags file.
-    if g:gutentags_ctags_no_space_in_paths
-        " We need to replace spaces in the project root because `ctags` seems
-        " incapable of reading/writing to tags files with spaces.
-        let l:fixed_project_root = tr(a:project_root, ' ', '_')
-    else
-        let l:fixed_project_root = a:project_root
-    endif
     let b:gutentags_files['ctags'] = gutentags#get_cachefile(
-                \l:fixed_project_root, g:gutentags_tagfile)
+                \a:project_root, g:gutentags_tagfile)
 
     " Set the tags file for Vim to use.
     if g:gutentags_auto_set_tags
@@ -62,7 +51,6 @@
     " 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
@@ -75,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 . '"'
@@ -108,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/doc/gutentags.txt	Sun Feb 21 10:34:47 2016 -0800
+++ b/doc/gutentags.txt	Thu Feb 25 21:04:46 2016 -0800
@@ -378,16 +378,6 @@
                         See |gutentags_ctags_executable_{filetype}| for more
                         information.
 
-                                             *gutentags_ctags_no_space_in_paths*
-g:gutentags_ctags_no_space_in_paths
-                        When set to 1, the root path of a project will have
-                        any spaces replaced by underscores. This is in case
-                        the particular `ctags` implementation you're using
-                        doesn't support tags filenames with spaces, which
-                        seems to be the case with Exuberant Ctags.
-                        Set to 0 to leave project root paths as is.
-                        Defaults to 1.
-
 
 =============================================================================
 5. Project Settings                             *gutentags-project-settings*