Commits

abudden  committed 134a5f9

Added support for loading of specified libraries (fixes #6).

  • Participants
  • Parent commits 1f2ad83

Comments (0)

Files changed (3)

File autoload/TagHighlight/Libraries.vim

 	endfor
 endfunction
 
+function! TagHighlight#Libraries#FindUserLibraries()
+	" Open any explicitly configured libraries
+	let user_library_dir = TagHighlight#Option#GetOption('UserLibraryDir')
+	let user_libraries = TagHighlight#Option#GetOption('UserLibraries')
+
+	let libraries_to_load = []
+
+	for library in user_libraries
+		" If it looks like an absolute path, just load it
+		if (library[1] == ':' || library['0'] == '/') && filereadable(library)
+			let libraries_to_load +=
+						\ [{
+						\     'Name': 'User Library',
+						\     'Filename': fnamemodify(library, ':t'),
+						\     'Path': fnamemodify(library, '%:p'),
+						\ }]
+		" Otherwise, try appending to the library dir
+		elseif filereadable(user_library_dir . '/' . library)
+			let library_path = user_library_dir . '/' . library
+			let libraries_to_load +=
+						\ [{
+						\     'Name': 'User Library',
+						\     'Filename': fnamemodify(library_path, ':t'),
+						\     'Path': fnamemodify(library_path, '%:p'),
+						\ }]
+		else
+			echomsg "Cannot load user library " . library
+		endif
+	endfor
+	return libraries_to_load
+endfunction
+
 function! TagHighlight#Libraries#FindLibraryFiles(suffix)
 	" Should only actually read the libraries once
 	call TagHighlight#Libraries#LoadLibraries()
 
 	let libraries_to_load = []
+	let forced_standard_libraries = TagHighlight#Option#GetOption('ForcedStandardLibraries')
 
 	for library in values(g:TagHighlightPrivate['Libraries'])
 		let load = 0
 		if index(library['TypesSuffixes'], a:suffix) != -1
 			" Suffix is in the list of acceptable ones
-			if library['CheckMode'] == 'Always'
+			if index(forced_standard_libraries, library['LibraryName']) != -1
+				"echomsg "Library(".library['LibraryName']."): Forced"
+				let load = 1
+			elseif library['CheckMode'] == 'Always'
 				"echomsg "Library(".library['LibraryName']."): Always"
 				let load = 1
 			elseif library['CheckMode'] == 'MatchStart'

File autoload/TagHighlight/ReadTypes.vim

 					\ }]
 	endfor
 
+	" Load user libraries
+	let user_library_files = TagHighlight#Libraries#FindUserLibraries()
+	for lib in user_library_files
+		exe 'so' lib['Path']
+		let b:TagHighlightLoadedLibraries += [lib]
+	endfor
+
 	" Now load any libraries that are relevant
 	let library_files = TagHighlight#Libraries#FindLibraryFiles(a:suffix)
 	for lib in library_files

File plugin/TagHighlight/data/options.txt

 	Default:{'PreUpdate': [], 'PostUpdate': [], 'PreRead': [], 'PostRead': []}
 	Help:Hooks dictionary (each entry is a list of strings containing functions to call; read functions take current file name and types suffix as parameters).
 
+forced_standard_libraries:
+	VimOptionMap:ForcedStandardLibraries
+	Type:list
+	Default:[]
+	Help:List of standard libraries which we should load regardless of whether the matchers match (as long as suffix is correct).
+
+user_libraries:
+	VimOptionMap:UserLibraries
+	Type:list
+	Default:[]
+	Help:List of user libraries to load (either relative to UserLibraryDir or absolute).
+
+user_library_dir:
+	VimOptionMap:UserLibraryDir
+	Type:string
+	Default:.
+	Help:Location of user libraries that are specified with relative paths.
+
 ##########################
 # Python script options: #
 ##########################