Commits

abudden  committed 7364643

Initial implementation for project repository option.

This will be the location for storing all generated files and is based on the
ideas from Alexey Radkov's TagManager project:

http://www.vim.org/scripts/script.php?script_id=4253

  • Participants
  • Parent commits e545159

Comments (0)

Files changed (5)

File autoload/TagHighlight/Find.vim

 	" Result contains 'Found','FullPath','Directory','Filename','Exists']
 	let result = {}
 
+	if TagHighlight#Option#GetOption('UseProjectRepository')
+		call TagHLDebug("UseProjectRepository is set", "Information")
+		let repository = TagHighlight#Option#GetOption('ProjectRepository')
+		if len(repository) > 0 && tolower(repository) != "none"
+			if has_key(b:TagHighlightPrivate, 'InProject') && b:TagHighlightPrivate['InProject']
+				let project_folder = repository
+							\ . '/'
+							\ . s:SanitiseName(b:TagHighlightPrivate['ProjectName'])
+				if ! isdirectory(project_folder)
+					" At the moment, if the repository setting is garbage,
+					" this will throw up an error message, but I'm not sure
+					" whether it can be caught with try...catch...endtry
+					call mkdir(project_folder, 'p')
+				endif
+				let search_priority = ['Explicit']
+				let explicit_location = project_folder
+			endif
+		endif
+	endif
+
 	for search_mode in search_priority
 		if search_mode == 'Explicit' && explicit_location != 'None'
 			" Use explicit location, overriding everything else
 	endif
 	return result
 endfunction
+
+function! s:SanitiseName(name)
+	let validChars = '-a-zA-Z0-9_'
+	return substitute(a:name, '[^'.validChars.']', '_', 'g')
+endfunction

File autoload/TagHighlight/Projects.vim

 
 function! TagHighlight#Projects#GetProjects()
 	let projects = TagHighlight#Option#GetOption('Projects')
+	call TagHLDebug("Projects option set to ".string(projects), "Information")
 	for project in keys(projects)
 		if type(projects[project]) == type("")
 			projects[project] = {'SourceDir': projects[project]}
 					\ has_key(projects[project], 'SourceDir')
 			" Okay
 		else
-			call TagHLDebug("Invalid entry '".project."' in Projects list", "Warning")
+			call TagHLDebug("Invalid entry '".project."' in Projects list (no SourceDir)", "Warning")
 			call remove(projects, project)
 		endif
 	endfor
 endfunction
 
 function! TagHighlight#Projects#LoadProjectOptions(file)
+	call TagHLDebug("Looking for project options for " . a:file, "Information")
 	let full_path = fnamemodify(a:file, ':p')
 	let projects = TagHighlight#Projects#GetProjects()
 	if ! exists('b:TagHighlightSettings')
 	for name in keys(projects)
 		let project = projects[name]
 		if TagHighlight#Utilities#FileIsIn(full_path, project['SourceDir'])
+			call TagHLDebug("Found project: '".name."'", "Information")
 			let b:TagHighlightSettings = extend(b:TagHighlightSettings, project)
+			let b:TagHighlightPrivate['InProject'] = 1
+			let b:TagHighlightPrivate['ProjectName'] = name
+			break
 		endif
 	endfor
 endfunction

File autoload/TagHighlight/ReadTypes.vim

 let s:all_ft_methods = ['Extension', 'Syntax', 'FileType']
 
 function! TagHighlight#ReadTypes#ReadTypesByOption()
+	let file = expand('<afile>')
+	if len(file) == 0
+		let file = expand('%')
+	endif
+	call TagHighlight#Projects#LoadProjectOptions(file)
 	call TagHighlight#Option#LoadOptionFileIfPresent()
+
 	let ft_methods = TagHighlight#Option#GetOption('LanguageDetectionMethods')
 	for method in ft_methods
 		if index(s:all_ft_methods, method) == -1
 
 	call TagHighlight#TagManager#InitialiseBufferTags()
 
-	call TagHighlight#Option#LoadOptionFileIfPresent()
-
 	let file = expand('<afile>')
 	if len(file) == 0
 		let file = expand('%')
 	endif
 
 	call TagHighlight#Projects#LoadProjectOptions(file)
+	call TagHighlight#Option#LoadOptionFileIfPresent()
 
 	if len(a:suffix) == 0
 		return
 	let b:TagHighlightLoadedLibraries = []
 	
 	let type_files = TagHighlight#ReadTypes#FindTypeFiles(a:suffix)
+	let source_dir = TagHighlight#Option#GetOption('SourceDir')
 	for fname in type_files
 		call TagHLDebug("Loading type highlighter file " . fname, 'Information')
 		let types_path = fnamemodify(fname, ':p:h')
 		let old_dir = getcwd()
 
-		exe 'cd' types_path
+		if source_dir =~ "None"
+			exe 'cd' types_path
+		else
+			exe 'cd' source_dir
+		endif
 		let b:TagHighlightPrivate['NormalisedPath'] = substitute(
 					\ fnamemodify(fullname, ':.'),
 					\ '\\', '/', 'g')
 	endfor
 
 	if TagHighlight#Option#GetOption('SetWorkingDir') == 1
-		for entry in b:TagHighlightLoadedLibraries
-			if entry['Name'] == 'Local'
-				let lcdpath = fnamemodify(entry['Path'], ':h')
-				call TagHLDebug("Setting local working directory to " . lcdpath, "Information")
-				exe 'lcd' lcdpath
-				break
-			endif
-		endfor
+		if source_dir =~ "None"
+			for entry in b:TagHighlightLoadedLibraries
+				if entry['Name'] == 'Local'
+					let lcdpath = fnamemodify(entry['Path'], ':h')
+					call TagHLDebug("Setting local working directory to " . lcdpath, "Information")
+					exe 'lcd' lcdpath
+					break
+				endif
+			endfor
+		else
+			exe 'lcd' source_dir
+		endif
 	endif
 
 	let reload_colours = TagHighlight#Option#GetOption('ReloadColourScheme')

File doc/TagHighlight.txt

 		Projects                         Link:|TagHL-Projects|
 			Project-specific configuration.
 
+		ProjectRepository                Link:|TagHL-ProjectRepository|
+			Store tags and types highlighters in central repository.
+
+		UseProjectRepository             Link:|TagHL-UseProjectRepository|
+			Enable storing of tags and types files in central repository.
+
 	Customisation:
 
 		PreReadHooks                     Link:|TagHL-PreReadHooks|
 		Option Type: Dictionary
 		Default: {}
 
+	ProjectRepository                    *TagHL-ProjectRepository*
+		If the option |TagHL-UseProjectRepository| is set to True or 1 and
+		this option is set to a directory in your file system, then all code
+		that is part of one of the projects documented in the |TagHL-Projects|
+		option will use a separate repository for storing tags, types
+		highlighter files, |taghl_config.txt| files and cscope databases (as
+		applicable).  This offers the possibility of keeping your project
+		folder empty of these files.  As an example, consider this
+		configuration file:
+>
+			UseProjectRepository:True
+			ProjectRepository:/home/al/.taghl
+			Projects:
+				DevProj1:/home/al/dev_project1
+				DevProj2:
+					SourceDir:/home/al/projects/dev_proj_2
+					IncludeSynMatches:True
+					EnableCscope:True
+<
+		In this case, when you run |:UpdateTypesFile|, the tags and
+		types highlighter files for DevProj1 will be stored in (and read from)
+		/home/al/.taghl/DevProj1/.  The tags, types highlighter files and
+		cscope database will be store in /home/al/.taghl/DevProj2/.
+
+		Option Type: String
+		Default: None (no project repository)
+
 	PythonVariantPriority                *TagHL-PythonVariantPriority*
 		The python part of |TagHighlight| can be run in a number of ways,
 		depending on your system configuration.  For most users, this should
 		Option Type: String
 		Default: "types"
 
+	UseProjectRepository                 |TagHL-UseProjectRepository|
+		This option enables the use of the projects repository.  For
+		information on this, please see |TagHL-ProjectRepository|.
+
+		Option Type: Boolean
+		Default: False
+
 	UserLibraries                        *TagHL-UserLibraries*
 		If you have some libraries that are used by your code, but which are
 		not kept with your code, it is possible to highlight keywords used in
 	  Brodsky for producing the scripts that generate these libraries).
 	* Added SetWorkingDir option to allow control of the working directory for
 	  a buffer with tags highlighted.
+	* Added the ability to store types and tags etc in a central repository
+	  rather than with the code itself (thanks to Alexey Radkov for the
+	  suggestion and for TagManager plugin that shows how it's done!)
 	
 	Bug fixes:
 	

File plugin/TagHighlight/data/options.txt

 	Default:False
 	Help:Only generate cscope database if one already exists
 
+ProjectRepository:
+	Type:string
+	Default:None
+	Help:Central repository in which to store tags and types highlighter.
+
+UseProjectRepository:
+	Type:bool
+	Default:False
+	Help:Enable storing of tags and types files in central repository.
+
 ##########################
 # Python script options: #
 ##########################