1. abudden
  2. TagHighlight


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).

  • Participants
  • Parent commits fd8b4a7
  • Branches default

Comments (0)

Files changed (4)

File autoload/TagHighlight/Generation.vim

View file
 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()
 		call TagHLDebug("Source dir set explicitly to " . TagHighlight#Option#GetOption("SourceDir"), "Information")
+	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
-	call TagHighlight#Generation#UpdateTypesFile()
+	call s:UpdateTypesFile()
 	let SavedTabNr = tabpagenr()
 	let SavedWinNr = winnr()
 	tabdo windo call TagHighlight#ReadTypes#ReadTypesByOption()

File doc/TagHighlight.txt

View file
 		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).

File plugin/TagHighlight/data/options.txt

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

File plugin/TagHighlight/module/worker.py

View file
     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