Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplicate tags when updating files #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions autoload/gutentags/ctags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ function! gutentags#ctags#generate(proj_dir, tags_file, gen_opts) abort
if l:write_mode == 0 && l:tags_file_exists
let l:cur_file_path = expand('%:p')
if empty(g:gutentags_cache_dir) && l:tags_file_is_local
let l:alt_file_path = l:cur_file_path
let l:cur_file_path = fnamemodify(l:cur_file_path, ':.')
else
let l:alt_file_path = fnamemodify(l:cur_file_path, ':.')
endif
let l:cmd += ['-s', '"' . l:cur_file_path . '"']
let l:cmd += ['-a', '"' . l:alt_file_path . '"']
else
let l:file_list_cmd = gutentags#get_project_file_list_cmd(l:actual_proj_dir)
if !empty(l:file_list_cmd)
Expand Down
16 changes: 14 additions & 2 deletions plat/unix/update_tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LOG_FILE=
FILE_LIST_CMD=
FILE_LIST_CMD_IS_ABSOLUTE=0
UPDATED_SOURCE=
ALT_UPDATED_SOURCE=
POST_PROCESS_CMD=
PAUSE_BEFORE_EXIT=0

Expand All @@ -27,6 +28,8 @@ ShowUsage() {
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 " -a [file=]: Alternative path to the source file that needs"
echo " to be removed from the tags file"
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"
Expand All @@ -36,7 +39,7 @@ ShowUsage() {
}


while getopts "h?e:x:t:p:l:L:s:o:O:P:cA" opt; do
while getopts "h?e:x:t:p:l:L:s:a:o:O:P:cA" opt; do
case $opt in
h|\?)
ShowUsage
Expand Down Expand Up @@ -66,6 +69,9 @@ while getopts "h?e:x:t:p:l:L:s:o:O:P:cA" opt; do
s)
UPDATED_SOURCE=$OPTARG
;;
a)
ALT_UPDATED_SOURCE=$OPTARG
;;
c)
PAUSE_BEFORE_EXIT=1
;;
Expand Down Expand Up @@ -98,8 +104,14 @@ INDEX_WHOLE_PROJECT=1
if [ -f "$TAGS_FILE" ]; then
if [ "$UPDATED_SOURCE" != "" ]; then
echo "Removing references to: $UPDATED_SOURCE"
if [ "$ALT_UPDATED_SOURCE" != "" ]; then
echo "Removing references to: $ALT_UPDATED_SOURCE"
regex="($UPDATED_SOURCE|$ALT_UPDATED_SOURCE)"
else
regex=$UPDATED_SOURCE
fi
tab=" "
cmd="grep --text -Ev '^[^$tab]+$tab$UPDATED_SOURCE$tab' '$TAGS_FILE' > '$TAGS_FILE.temp'"
cmd="grep --text -Ev '^[^$tab]+$tab$regex$tab' '$TAGS_FILE' > '$TAGS_FILE.temp'"
echo "$cmd"
eval "$cmd" || true
INDEX_WHOLE_PROJECT=0
Expand Down
7 changes: 7 additions & 0 deletions plat/win32/update_tags.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set PROJECT_ROOT=
set FILE_LIST_CMD=
set FILE_LIST_CMD_IS_ABSOLUTE=0
set UPDATED_SOURCE=
set ALT_UPDATED_SOURCE=
set POST_PROCESS_CMD=
set PAUSE_BEFORE_EXIT=0
set LOG_FILE=
Expand Down Expand Up @@ -52,6 +53,11 @@ if [%1]==[-s] (
shift
goto :LoopParseArgs
)
if [%1]==[-a] (
set ALT_UPDATED_SOURCE=%~2
shift
goto :LoopParseArgs
)
if [%1]==[-c] (
set PAUSE_BEFORE_EXIT=1
goto :LoopParseArgs
Expand Down Expand Up @@ -101,6 +107,7 @@ if exist "%TAGS_FILE%" (
echo Removing references to: %UPDATED_SOURCE% >> %LOG_FILE%
echo findstr /V /C:"%UPDATED_SOURCE%" "%TAGS_FILE%" ^> "%TAGS_FILE%.temp" >> %LOG_FILE%
findstr /V /C:"%UPDATED_SOURCE%" "%TAGS_FILE%" > "%TAGS_FILE%.temp"
rem XXX should also remove %ALT_UPDATED_SOURCE%
set CTAGS_ARGS=%CTAGS_ARGS% --append "%UPDATED_SOURCE%"
set INDEX_WHOLE_PROJECT=0
)
Expand Down