Commits

abudden  committed 362b1dc

Added support for pre- and post- -read and -update hooks (fixes #16).

  • Participants
  • Parent commits def54a6

Comments (0)

Files changed (5)

File autoload/TagHighlight/Generation.vim

 function! TagHighlight#Generation#UpdateTypesFile(recurse, skiptags)
 	" Initial very simple implementation
 	
+	" Call any PreUpdate hooks
+	let hooks = TagHighlight#Option#GetOption('Hooks')
+	if has_key(hooks, 'PreUpdate')
+		for preupdate_hook in hooks['PreUpdate']
+			exe 'call' preupdate_hook . '()'
+		endfor
+	endif
+	
 	" Start with a copy of the settings so that we can tweak things
 	let RunOptions = TagHighlight#Option#CopyOptions()
 	if a:recurse
 		let RunOptions['TypesFileLocation'] = types_file_info['Directory']
 	endif
 	
-	" Find the cscope path
+	call TagHighlight#RunPythonScript#RunGenerator(RunOptions)
 
-	call TagHighlight#RunPythonScript#RunGenerator(RunOptions)
+	if has_key(hooks, 'PostUpdate')
+		for postupdate_hook in hooks['PostUpdate']
+			exe 'call' postupdate_hook . '()'
+		endfor
+	endif
 endfunction

File autoload/TagHighlight/LoadDataFile.vim

 			elseif stridx(entry, ':') != -1
 				" This is key:value, so it's a simple dictionary entry
 				let parts = split(entry, ':')
+				" Rather coarse replacement of split(x,y,n)
+				if len(parts) > 2
+					let parts[1] = join(parts[1:], ':')
+				endif
 				if stridx(parts[1], ',') != -1
 					" This entry is a list
 					let result[parts[0]] = split(parts[1], ',')
 				endif
 				" Handle the entry (without the preceding tab)
 				let parts = split(entry[1:], ':')
+				" Rather coarse replacement of split(x,y,n)
+				if len(parts) > 2
+					let parts[1] = join(parts[1:], ':')
+				endif
 				if stridx(parts[1], ',') != -1
 					" This entry is a list
 					let result[top_key][parts[0]] = split(parts[1], ',')

File autoload/TagHighlight/Option.vim

 			else
 				let opt = default
 			endif
+		elseif option['Type'] == 'dict'
+			" This is a complex one: just assume it's valid Vim script
+			if type(default) == type([])
+				" Probably a multi-entry dict that has automatically been
+				" split: rejoin
+				let opt = eval(join(default, ', '))
+			else
+				let opt = eval(default)
+			endif
 		endif
 	endif
 	return opt

File autoload/TagHighlight/ReadTypes.vim

 		return
 	endif
 
+	let fullname = expand(file . ':p')
+
+	let hooks = TagHighlight#Option#GetOption('Hooks')
+	" Call Pre Read hooks (if any)
+	if has_key(hooks, 'PreRead')
+		for preread_hook in hooks['PreRead']
+			exe 'call' preread_hook . '(fullname, a:suffix)'
+		endfor
+	endif
+
 	let skiplist = TagHighlight#Option#GetOption('ParsingSkipList')
 	if len(skiplist) > 0
 		let basename = expand(file . ':p:t')
-		let fullname = expand(file . ':p')
 		if index(skiplist, basename) != -1
 			call TagHighlight#Debug#Print("Skipping file due to basename match", 'Status')
 			return
 		endfor
 	endif
 
+	" Call Post Read Hooks (if any)
+	if has_key(hooks, 'PostRead')
+		for postread_hook in hooks['PostRead']
+			exe 'call' postread_hook . '(fullname, a:suffix)'
+		endfor
+	endif
+
 	" Restore the view
 	call winrestview(savedView)
 endfunction

File plugin/TagHighlight/data/options.txt

 	Default:None
 	Help:Location of the python executable or None to search the path
 
+hooks:
+	VimOptionMap:Hooks
+	Type:dict
+	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).
+
 ##########################
 # Python script options: #
 ##########################