# HG changeset patch # User Ludovic Chabant # Date 1487392776 28800 # Node ID 0f6605a9398bbbc2eb944c506f535c058849d656 # Parent 97e1b266d0457831e2ad18a4acb1a34b7b2c5993# Parent 84dbc92c42438dd4a9682d6f89f71e1e58769d39 Merge pull request #112 from GitHub. diff -r 84dbc92c4243 -r 0f6605a9398b autoload/gutentags.vim --- a/autoload/gutentags.vim Mon Feb 06 18:28:06 2017 +0800 +++ b/autoload/gutentags.vim Fri Feb 17 20:39:36 2017 -0800 @@ -97,11 +97,12 @@ let l:markers = get(g:gutentags_file_list_command, 'markers', []) if type(l:markers) == type({}) for [marker, file_list_cmd] in items(l:markers) - if getftype(a:path . '/' . marker) != "" + if !empty(globpath(a:path, marker, 1)) return gutentags#validate_cmd(file_list_cmd) endif endfor endif + return get(g:gutentags_file_list_command, 'default', "") endif return "" endfunction @@ -125,7 +126,7 @@ endif while l:path != l:previous_path for root in l:markers - if getftype(l:path . '/' . root) != "" + if !empty(globpath(l:path, root)) let l:proj_dir = simplify(fnamemodify(l:path, ':p')) let l:proj_dir = gutentags#stripslash(l:proj_dir) if l:proj_dir == '' diff -r 84dbc92c4243 -r 0f6605a9398b autoload/gutentags/ctags.vim --- a/autoload/gutentags/ctags.vim Mon Feb 06 18:28:06 2017 +0800 +++ b/autoload/gutentags/ctags.vim Fri Feb 17 20:39:36 2017 -0800 @@ -7,6 +7,8 @@ let g:gutentags_auto_set_tags = get(g:, 'gutentags_auto_set_tags', 1) let g:gutentags_ctags_options_file = get(g:, 'gutentags_ctags_options_file', '.gutctags') let g:gutentags_ctags_check_tagfile = get(g:, 'gutentags_ctags_check_tagfile', 0) +let g:gutentags_ctags_extra_args = get(g:, 'gutentags_ctags_extra_args', []) +let g:gutentags_ctags_post_process_cmd = get(g:, 'gutentags_ctags_post_process_cmd', '') " }}} @@ -39,6 +41,8 @@ " Get to the tags file directory because ctags is finicky about " these things. let l:prev_cwd = getcwd() + execute "chdir " . fnameescape(a:proj_dir) + let l:tags_file_exists = filereadable(a:tags_file) if l:tags_file_exists && g:gutentags_ctags_check_tagfile @@ -54,14 +58,13 @@ if empty(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. + " as specified by the user, since it's relative to the project root, + " and we are already `chdir`'d into it. " 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. @@ -84,6 +87,14 @@ else let l:file_list_cmd = gutentags#get_project_file_list_cmd(l:actual_proj_dir) if !empty(l:file_list_cmd) + let l:suffopts = matchstrpos(l:file_list_cmd, '///') + if l:suffopts[1] > 0 + let l:suffoptstr = strpart(l:file_list_cmd, l:suffopts[2]) + let l:file_list_cmd = strpart(l:file_list_cmd, 0, l:suffopts[1]) + if l:suffoptstr == 'absolute' + let l:cmd .= ' -A' + endif + endif let l:cmd .= ' -L ' . '"' . l:file_list_cmd. '"' endif endif @@ -93,6 +104,12 @@ " Omit --recursive if this project uses a file list command. let l:cmd .= ' -o "' . gutentags#get_res_file('ctags_recursive.options') . '"' endif + if !empty(g:gutentags_ctags_extra_args) + let l:cmd .= ' -O '.shellescape(join(g:gutentags_ctags_extra_args)) + endif + if !empty(g:gutentags_ctags_post_process_cmd) + let l:cmd .= ' -P '.shellescape(g:gutentags_ctags_post_process_cmd) + endif let l:proj_options_file = a:proj_dir . '/' . \g:gutentags_ctags_options_file if filereadable(l:proj_options_file) diff -r 84dbc92c4243 -r 0f6605a9398b plat/unix/update_tags.sh --- a/plat/unix/update_tags.sh Mon Feb 06 18:28:06 2017 +0800 +++ b/plat/unix/update_tags.sh Fri Feb 17 20:39:36 2017 -0800 @@ -8,7 +8,9 @@ TAGS_FILE=tags PROJECT_ROOT= FILE_LIST_CMD= +FILE_LIST_CMD_IS_ABSOLUTE=0 UPDATED_SOURCE= +POST_PROCESS_CMD= PAUSE_BEFORE_EXIT=0 @@ -20,15 +22,19 @@ echo " -t [file=tags]: The path to the ctags file to update" echo " -p [dir=]: The path to the project root" echo " -L [cmd=]: The file list command to run" + echo " -A: Specifies that the file list command returns " + echo " absolute paths" echo " -s [file=]: The path to the source file that needs updating" echo " -x [pattern=]: A pattern of files to exclude" echo " -o [options=]: An options file to read additional options from" + echo " -O [params=]: Parameters to pass to ctags" + echo " -P [cmd=]: Post process command to run on the tags file" echo " -c: Ask for confirmation before exiting" echo "" } -while getopts "h?e:x:t:p:L:s:o:c" opt; do +while getopts "h?e:x:t:p:L:s:o:O:P:cA" opt; do case $opt in h|\?) ShowUsage @@ -49,6 +55,9 @@ L) FILE_LIST_CMD=$OPTARG ;; + A) + FILE_LIST_CMD_IS_ABSOLUTE=1 + ;; s) UPDATED_SOURCE=$OPTARG ;; @@ -58,6 +67,12 @@ o) CTAGS_ARGS="$CTAGS_ARGS --options=$OPTARG" ;; + O) + CTAGS_ARGS="$CTAGS_ARGS $OPTARG" + ;; + P) + POST_PROCESS_CMD=$OPTARG + ;; esac done @@ -88,7 +103,7 @@ if [ $INDEX_WHOLE_PROJECT -eq 1 ]; then if [ -n "${FILE_LIST_CMD}" ]; then - if [ "${PROJECT_ROOT}" = "." ]; then + if [ "${PROJECT_ROOT}" = "." ] || [ $FILE_LIST_CMD_IS_ABSOLUTE -eq 1 ]; then $FILE_LIST_CMD > "${TAGS_FILE}.files" else # If using a tags cache directory, use absolute paths @@ -107,6 +122,12 @@ $CTAGS_EXE -f "$TAGS_FILE.temp" $CTAGS_ARGS --append "$UPDATED_SOURCE" fi +if [ "$POST_PROCESS_CMD" != "" ]; then + echo "Running post process" + echo "$POST_PROCESS_CMD \"$TAGS_FILE.temp\"" + $POST_PROCESS_CMD "$TAGS_FILE.temp" +fi + echo "Replacing tags file" echo "mv -f \"$TAGS_FILE.temp\" \"$TAGS_FILE\"" mv -f "$TAGS_FILE.temp" "$TAGS_FILE" diff -r 84dbc92c4243 -r 0f6605a9398b plat/win32/update_tags.cmd --- a/plat/win32/update_tags.cmd Mon Feb 06 18:28:06 2017 +0800 +++ b/plat/win32/update_tags.cmd Fri Feb 17 20:39:36 2017 -0800 @@ -10,7 +10,9 @@ set TAGS_FILE=tags set PROJECT_ROOT= set FILE_LIST_CMD= +set FILE_LIST_CMD_IS_ABSOLUTE=0 set UPDATED_SOURCE= +set POST_PROCESS_CMD= set PAUSE_BEFORE_EXIT=0 set LOG_FILE= @@ -41,6 +43,10 @@ shift goto :LoopParseArgs ) +if [%1]==[-A] ( + set FILE_LIST_CMD_IS_ABSOLUTE=1 + goto :LoopParseArgs +) if [%1]==[-s] ( set UPDATED_SOURCE=%~2 shift @@ -60,6 +66,16 @@ shift goto :LoopParseArgs ) +if [%1]==[-O] ( + set CTAGS_ARGS=%CTAGS_ARGS% %~2 + shift + goto :LoopParseArgs +) +if [%1]==[-P] ( + set POST_PROCESS_CMD=%~2 + shift + goto :LoopParseArgs +) echo Invalid Argument: %1 goto :Usage @@ -93,7 +109,11 @@ set CTAGS_ARGS=%CTAGS_ARGS% "%PROJECT_ROOT%" if not ["%FILE_LIST_CMD%"]==[""] ( echo Running custom file lister >> %LOG_FILE% - if ["%PROJECT_ROOT%"]==["."] ( + set use_raw_list=0 + if ["%PROJECT_ROOT%"]==["."] set use_raw_list=1 + if ["%FILE_LIST_CMD_IS_ABSOLUTE%"]==["1"] set use_raw_list=1 + rem No idea why we need to use delayed expansion here to make it work :( + if ["!use_raw_list!"]==["1"] ( echo call %FILE_LIST_CMD% ^> %TAGS_FILE%.files >> %LOG_FILE% call %FILE_LIST_CMD% > %TAGS_FILE%.files ) else ( @@ -115,6 +135,16 @@ goto :Unlock ) +if not ["%POST_PROCESS_CMD%"]==[""] ( + echo Running post process >> %LOG_FILE% + echo call %POST_PROCESS_CMD% %TAGS_FILE%.temp >> %LOG_FILE% + call %POST_PROCESS_CMD% %TAGS_FILE%.temp >> %LOG_FILE% 2>&1 + if ERRORLEVEL 1 ( + echo ERROR: Post process returned non-zero code. >> %LOG_FILE% + goto :Unlock + ) +) + echo Replacing tags file >> %LOG_FILE% echo move /Y "%TAGS_FILE%.temp" "%TAGS_FILE%" >> %LOG_FILE% move /Y "%TAGS_FILE%.temp" "%TAGS_FILE%" >> %LOG_FILE% 2>&1 @@ -150,6 +180,8 @@ echo -t [file=tags]: The path to the ctags file to update echo -p [dir=]: The path to the project root echo -L [cmd=]: The file list command to run +echo -A: Specifies that the file list command returns +echo absolute paths echo -s [file=]: The path to the source file that needs updating echo -l [log=]: The log file to output to echo -o [options=]: An options file to read additional options from diff -r 84dbc92c4243 -r 0f6605a9398b plugin/gutentags.vim --- a/plugin/gutentags.vim Mon Feb 06 18:28:06 2017 +0800 +++ b/plugin/gutentags.vim Fri Feb 17 20:39:36 2017 -0800 @@ -55,7 +55,7 @@ if !exists('g:gutentags_cache_dir') let g:gutentags_cache_dir = '' -else +elseif !empty(g:gutentags_cache_dir) " Make sure we get an absolute/resolved path (e.g. expanding `~/`), and " strip any trailing slash. let g:gutentags_cache_dir = fnamemodify(g:gutentags_cache_dir, ':p')