abudden avatar abudden committed 0cf9363

Added ability to only generate tags if a tags file does not exist (fixes #471).

This is as a distinct option to explicitly requiring that tags file
must exist and ensuring that TagHighlight never generates a tags file.
There are now two options: DoNotGenerateTags (never generate the file)
and DoNotGenerateTagsIfPresent (only generate if it doesn't exist).

Comments (0)

Files changed (4)

autoload/TagHighlight/Generation.vim

 endtry
 let g:loaded_TagHLGeneration = 1
 
-function! TagHighlight#Generation#UpdateTypesFile()
+function! s:UpdateTypesFile()
 	" Load the version information if we haven't already
 	call TagHighlight#Version#LoadVersionInfo()
 
 	else
 		call TagHLDebug("Source dir set explicitly to " . TagHighlight#Option#GetOption("SourceDir"), "Information")
 	endif
+
+	if tag_file_info['Exists'] == 1
+		if TagHighlight#Option#GetOption('DoNotGenerateTagsIfPresent') == 1
+			" This will be unset in UpdateAndRead
+			let b:TagHighlightSettings['DoNotGenerateTags'] = 1
+		endif
+	elseif TagHighlight#Option#GetOption('DoNotGenerateTags') == 1
+		echoerr "Cannot create types file without generating tags: tags file does not exist"
+		return
+	endif
 	
 	call TagHLDebug("Running generator with options:", "Information")
 	for var in ["g:TagHighlightSettings","b:TagHighlightConfigFileOptions","b:TagHighlightSettings"]
 		let b:TagHighlightSettings['DoNotGenerateTags'] = 1
 	endif
 	
-	call TagHighlight#Generation#UpdateTypesFile()
+	call s:UpdateTypesFile()
 	let SavedTabNr = tabpagenr()
 	let SavedWinNr = winnr()
 	tabdo windo call TagHighlight#ReadTypes#ReadTypesByOption()

doc/TagHighlight.txt

 		DoNotGenerateTags                Link:|TagHL-DoNotGenerateTags|
 		   Don't generate tags (use an existing tags file).
 
+		DoNotGenerateTagsIfPresent       Link:|TagHL-DoNotGenerateTagsIfPresent|
+		   Don't generate tags if a tags file is detected.
+
 	How to Run Python and Ctags:
 
 		ForcedPythonVariant              Link:|TagHL-ForcedPythonVariant|
 	DoNotGenerateTags                    *TagHL-DoNotGenerateTags*
 		If this option is set, calling |:UpdateTypesFile| will be functionally
 		equivalent to calling |:UpdateTypesFileOnly|: it will be assumed that
-		a tag file already exists and ctags will not be run.
+		a tag file already exists and ctags will not be run.  This should be
+		used if you NEVER want |TagHighlight| to generate a tags file.
+		Otherwise, you probably want |TagHL-DoNotGenerateTagsIfPresent|.
 
 		Option Type: Boolean
 		Default: False (generate tags)
 
+	DoNotGenerateTagsIfPresent           *TagHL-DoNotGenerateTagsIfPresent*
+		This option is similar to |TagHL-DoNotGenerateTags|.  However, it only
+		applies if a tags file already exists.  If the tags file exists, it
+		will not be regenerated but will be used as is.  If the tags file does
+		not exist, it will be created.  If |TagHL-DoNotGenerateTags| is set,
+		this option is ignored.
+
+		Option Type: Boolean
+		Default: False (always generate tags)
+
 	ExtensionLanguageOverrides           *TagHL-ExtensionLanguageOverrides*
 		If there are any entries in this dictionary, they will be used to
 		force a particular file extension to be treated as representing a
 							 'tags' option to automatically handle tag files
 							 for user libraries (thanks to Alexey Radkov and
 							 Ali Hamdi).  Fixed a bug in the ParsingSkipList
-							 option implementation.
+							 option implementation.  Added option to only
+							 generate the tags file if one is not present
+							 (thanks to Ali Hamdi for the suggestion).
 
 2.1.5: 20th February 2012  : Added support for Scala (thanks to Lee Gauthier).
 

plugin/TagHighlight/data/options.txt

 	VimOptionMap:DoNotGenerateTags
 	Type:bool
 	Default:False
+	Help:Do not generate tags: use an existing file
+ 
+use_existing_tagfile_if_present:
+	CommandLineSwitches:--use-existing-tagfile-if-present
+	VimOptionMap:DoNotGenerateTagsIfPresent
+	Type:bool
+	Default:False
 	Help:Do not generate tags if a tag file already exists
  
 print_py_version:

plugin/TagHighlight/module/worker.py

 
     tag_file_absolute = os.path.join(config['ctags_file_dir'], config['ctags_file'])
     if config['use_existing_tagfile'] and not os.path.exists(tag_file_absolute):
-        Debug("Cannot use existing tagfile as it doesn't exist (checking for " + tag_file_absolute + ")", "Information")
-        config['use_existing_tagfile'] = False
+        Debug("Cannot use existing tagfile as it doesn't exist (checking for " + tag_file_absolute + ")", "Error")
+        return
 
     LoadLanguages()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.