Commits

abudden committed c8e3a72

Implemented recursion limit when searching (fixes #214).

Comments (0)

Files changed (6)

autoload/TagHighlight/Find.vim

 "	TypesFileDirModePriority:As tag file
 "	ConfigFileDirModePriority:As tag file
 "	DefaultDirModeSearchWildcard:'' (look for tags file) or something specific (*.uvopt)?
+"	MaxDirSearchLevels: (integer)
 "
 " Explicit Locations:
 "
 
 function! s:ScanUp(dir, wildcards)
 	let result = {}
+	let max_levels = TagHighlight#Option#GetOption('MaxDirSearchLevels')
+	let levels = 0
 	let new_dir = a:dir
 	let dir = ''
 	let found = 0
+
+	call TagHLDebug("Searching up from " . a:dir . " for " . string(a:wildcards), 'Information')
+
+	" new_dir != dir check looks for the root directory
 	while new_dir != dir
 		let dir = new_dir
+		let new_dir = fnamemodify(dir, ':h')
 		for wildcard in a:wildcards
 			if len(glob(dir . '/' . wildcard)) > 0
+				call TagHLDebug("Found match: " . dir, "Information")
 				let result['Directory'] = dir
 				let found = 1
 				break
 		if found
 			break
 		endif
-		let new_dir = fnamemodify(dir, ':h')
+
+		" Check for recursion limit
+		let levels += 1
+		if (max_levels > 0) && (levels >= max_levels)
+			call TagHLDebug("Hit recursion limit", "Information")
+			break
+		endif
 	endwhile
+	if new_dir == dir
+		" Must have reached root directory
+		call TagHLDebug("Reached root directory and stopped", "Information")
+	endif
 	return result
 endfunction

autoload/TagHighlight/Option.vim

 		else
 			let result = eval(opt)
 		endif
+	elseif option['Type'] == 'int'
+		let result = str2nr(opt)
 	endif
 	return result
 endfunction

autoload/TagHighlight/RunPythonScript.vim

 				elseif option['Type'] == 'string'
 					let handled_options += [option['VimOptionMap']]
 					exe PY pyoption '= r"""'.a:options[option['VimOptionMap']].'"""'
+				elseif option['Type'] == 'int'
+					let handled_options += [option['VimOptionMap']]
+					exe PY pyoption '= ' . a:options[option['VimOptionMap']]
 				elseif option['Type'] == 'list'
 					let handled_options += [option['VimOptionMap']]
 					exe PY pyoption '= []'
 					else
 						let args += [switch, a:options[option['VimOptionMap']]]
 					endif
+				elseif option['Type'] == 'int'
+					if as_one == 1
+						let args += [switch . '=' . a:options[option['VimOptionMap']]]
+					else
+						let args += [switch, a:options[option['VimOptionMap']]]
+					endif
 				elseif option['Type'] == 'list'
 					for entry in a:options[option['VimOptionMap']]
 						if as_one == 1

doc/TagHighlight.txt

 		DefaultDirModePriority           Link:|TagHL-DefaultDirModePriority|
 		   Which directories to search by default.
 
+		MaxDirSearchLevels               Link:|TagHL-MaxDirSearchLevels|
+		   How far up the directory tree to search.
+
 	Location and name of Project Configuration File:
 
 		ProjectConfigFileDirModePriority Link:|TagHL-ProjectConfigFileDirModePriority|
 				wildcards match, it will try the parent directory and then
 				keep trying one level higher until it either finds a match or
 				reaches the top level directory (at which point the next
-				dir mode will be tried if no match is found).
+				dir mode will be tried if no match is found).  If you wish to
+				stop it searching all the way to the top level directory, you
+				can limit the number of levels with |TagHL-MaxDirSearchLevels|.
 
 			UpFromCurrent:
 				This works in the same way as UpFromFile, except that it
 		Option Type: List
 		Default: [] (check all supported languages)
 
+	MaxDirSearchLevels                   *TagHL-MaxDirSearchLevels*
+		When searching for a directory in which to store or from which to read
+		the project config, tags or types highlighter files, there are two
+		modes (UpFromFile and UpFromCurrent) that can be used to start in a
+		particular directory and try every directory above that one until the
+		file is found.  If there is a need to limit the number of directories
+		that will be tried (mainly likely if there is a deeply nested
+		directory structure and Vim seems a little slow), this option can be
+		used.  If set to 0 (the default), it will keep going until it reaches
+		the root directory.  If the option is set to 1, it will only check the
+		current directory; if 2 it will check the current directory and the
+		parent directory etc.
+
+		For more information, see |TagHL-DefaultDirModePriority|.
+
+		Option Type: Integer
+		Default: 0
+
 	ParsingSkipList                      *TagHL-ParsingSkipList*
 		If you're editing a lot of files and for most you want tag highlight
 		to run but one or two you don't, put the filenames of the ones for
 ==============================================================================
 7. TagHighlight History                *TagHighlight-history*               {{{1
 
+2.0.12: 3rd August 2011    : Added option to limit number of directories to
+							 search up through when looking for configuration
+							 or existing tags file.
+
 2.0.11: 2nd August 2011    : Added some example configurations to the
                              documentation.
 

plugin/TagHighlight/data/options.txt

 	Default:Explicit,UpFromFile,CurrentDirectory
 	Help:List of methods (in order) to use when searching for tags/types etc
 
+max_dir_search_levels:
+	VimOptionMap:MaxDirSearchLevels
+	Type:int
+	Default:0
+	Help:How far up to search in UpFromFile or UpFromCurrent mode
+
 config_file_name:
 	VimOptionMap:ProjectConfigFileName
 	Type:string

plugin/TagHighlight/module/cmd.py

                     help=AllOptions[dest]['Help'])
         else:
             optparse_type='string'
-            if AllOptions[dest]['Type'] == 'string':
+            if AllOptions[dest]['Type'] in ['string', 'int']:
                 action='store'
             elif AllOptions[dest]['Type'] == 'list':
                 action='append'