Commits

abudden committed a9ce5e3

Significant changes. Changed to use Recurse by default and got rid of non-recursive command. Changed the way run options are generated. Moved functionality of commands into function. Wildcards now only match files, not directories. Boolean options work better now ('True' == 0!). Working directory should never change now. For non-recursive mode, just use the file directory (so different DefaultDirModePriority).

  • Participants
  • Parent commits 4e61456

Comments (0)

Files changed (9)

autoload/TagHighlight/Debug.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    05/08/2011
+"   Date:    08/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 	let g:TagHighlightSettings['DebugLevel'] = 'Information'
 
 	call TagHLDebug("========================================================", "Information")
-	call TagHighlight#Generation#UpdateTypesFile(1, 0)
-	let s:SavedTabNr = tabpagenr()
-	let s:SavedWinNr = winnr()
-	tabdo windo call TagHighlight#ReadTypes#ReadTypesAutoDetect()
-	exe 'tabn' s:SavedTabNr
-	exe s:SavedWinNr . "wincmd w"
+	call TagHighlight#Generation#UpdateAndRead(0)
 
 	" Get rid of the 'stored' versions of the debug options
 	for dbg_option in debug_options

autoload/TagHighlight/Find.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    05/08/2011
+"   Date:    08/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 
 	" a:which is 'TAGS', 'TYPES', 'CONFIG'
 	let default_priority = TagHighlight#Option#GetOption('DefaultDirModePriority')
+	call TagHLDebug("Priority: " . string(default_priority), "Information")
 	let default_search_wildcards = TagHighlight#Option#GetOption('DefaultDirModeSearchWildcards')
 
 
-	let file = '<afile>'
-	if len(expand(file)) == 0
-		let file = '%'
+	let file = expand('<afile>')
+	if len(file) == 0
+		let file = expand('%')
 	endif
 
 	if a:which == 'TAGS'
 			endif
 		elseif search_mode == 'CurrentDirectory'
 			call TagHLDebug('Using current directory', 'Information')
-			let result['Directory'] = fnamemodify(file,':p:h')
+			let result['Directory'] = fnamemodify('.',':p:h')
 			let result['Filename'] = filename
 		elseif search_mode == 'FileDirectory'
 			call TagHLDebug('Using file directory', 'Information')
 				let glob_pattern .= '/'
 			endif
 			let glob_pattern .= wildcard
-			if len(glob(glob_pattern)) > 0
-				call TagHLDebug("Found match: " . dir . " (" . glob_pattern . ")", "Information")
-				let result['Directory'] = dir
-				let found = 1
-				break
+			let glob_result = split(glob(glob_pattern), "\n")
+			if len(glob_result) > 0
+				for r in glob_result
+					if filereadable(r)
+						let found = 1
+					endif
+				endfor
+				if found
+					call TagHLDebug("Found match: " . dir . " (" . glob_pattern . ")", "Information")
+					let result['Directory'] = dir
+					let found = 1
+					break
+				else
+					call TagHLDebug("Wildcard matches were not readable (directory?)", "Information")
+				endif
 			endif
 		endfor
 		if found

autoload/TagHighlight/Generation.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    05/08/2011
+"   Date:    08/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 endtry
 let g:loaded_TagHLGeneration = 1
 
-function! TagHighlight#Generation#UpdateTypesFile(recurse, skiptags)
+function! TagHighlight#Generation#UpdateTypesFile()
 	" Load the version information if we haven't already
 	call TagHighlight#Version#LoadVersionInfo()
 
 	" Debug information for configuration
 	if TagHighlight#Debug#DebugLevelIncludes('Information')
+		call TagHLDebug("Running UpdateTypesFile function at " . strftime("%Y%m%d-%H%M%S"), "Information")
+		call TagHLDebug("Current directory is " . getcwd(), "Information")
+		call TagHLDebug("Current file is " . expand('%:p'), "Information")
 		call TagHLDebug("Release Info:" . string(g:TagHighlightPrivate['PluginVersion']), "Information")
 		call TagHLDebug("Global options (g:TagHighlightSettings): " . string(g:TagHighlightSettings), "Information")
 		if exists('b:TagHighlightSettings')
 			call TagHLDebug("No buffer options set", "Information")
 		endif
 	endif
-	
+
 	" Load the option file
 	let option_file_info = TagHighlight#Option#LoadOptionFileIfPresent()
 	" Debug information for configuration
 		exe 'call' preupdate_hook . '()'
 	endfor
 	
-	" Start with a copy of the settings so that we can tweak things
-	let RunOptions = TagHighlight#Option#CopyOptions()
-	if a:recurse
-		let RunOptions['Recurse'] = 1
-	endif
-	if a:skiptags
-		let RunOptions['DoNotGenerateTags'] = 1
-	endif
-
 	" Most simple options are automatic.  The options below are
 	" handled manually.
 	
 	if ctags_option == 'None'
 		" Option not set: search for 'ctags' in the path
 		call TagHLDebug("CtagsExecutable not set, searching for 'ctags' in path", "Information")
-		let RunOptions['CtagsExeFull'] = TagHighlight#RunPythonScript#FindExeInPath('ctags')
+		let b:TagHighlightSettings['CtagsExeFull'] = TagHighlight#RunPythonScript#FindExeInPath('ctags')
 	elseif ctags_option =~ '[\\/]'
 		" Option set and includes '/' or '\': must be explicit
 		" path to named executable: just pass to mktypes
 		call TagHLDebug("CtagsExecutable set with path delimiter, using as explicit path", "Information")
-		let RunOptions['CtagsExeFull'] = ctags_option
+		let b:TagHighlightSettings['CtagsExeFull'] = ctags_option
 	else
 		" Option set but doesn't include path separator: search
 		" in the path
 		call TagHLDebug("CtagsExecutable set without path delimiter, searching in path", "Information")
-		let RunOptions['CtagsExeFull'] = TagHighlight#RunPythonScript#FindExeInPath(ctags_option)
+		let b:TagHighlightSettings['CtagsExeFull'] = TagHighlight#RunPythonScript#FindExeInPath(ctags_option)
 	endif
 
 	let tag_file_info = TagHighlight#Find#LocateFile('TAGS', '')
 	if tag_file_info['Found'] == 1
-		let RunOptions['CtagsFileLocation'] = tag_file_info['Directory']
+		let b:TagHighlightSettings['CtagsFileLocation'] = tag_file_info['Directory']
 	endif
 
 	let types_file_info = TagHighlight#Find#LocateFile('TYPES', '*')
 	if types_file_info['Found'] == 1
-		let RunOptions['TypesFileLocation'] = types_file_info['Directory']
+		let b:TagHighlightSettings['TypesFileLocation'] = types_file_info['Directory']
 	endif
 
-	if ! has_key(RunOptions, 'SourceDir')
+	if TagHighlight#Option#GetOption('SourceDir') =~ 'None'
 		" The source directory has not been set.  If a project config file was
 		" found, use that directory.  If not, but a types file was found,
 		" use that directory.  If not, but a tag file was found, use that
 		" directory.  If not, use the current directory.
 		call TagHLDebug("No source dir set", "Information")
-		if option_file_info['Found'] == 1 && option_file_info['Exists'] == 1
+		call TagHLDebug("Current directory is now " . getcwd(), "Information")
+		if ! TagHighlight#Option#GetOption('Recurse')
+			call TagHLDebug("Non-recursive mode, using file directory", "Information")
+			let file = expand('<afile>')
+			if len(file) == 0
+				let file = expand('%')
+			endif
+			call TagHLDebug("File is " . file . "(" . fnamemodify(file, ':p:h') . ")", "Information")
+			let b:TagHighlightSettings['SourceDir'] = fnamemodify(file, ':p:h')
+		elseif option_file_info['Found'] == 1 && option_file_info['Exists'] == 1
 			call TagHLDebug("Using project config file directory", "Information")
-			let RunOptions['SourceDir'] = option_file_info['Directory']
+			let b:TagHighlightSettings['SourceDir'] = option_file_info['Directory']
 		elseif types_file_info['Found'] == 1 && types_file_info['Exists'] == 1
 			call TagHLDebug("Using types file directory", "Information")
-			let RunOptions['SourceDir'] = types_file_info['Directory']
+			let b:TagHighlightSettings['SourceDir'] = types_file_info['Directory']
 		elseif tag_file_info['Found'] == 1 && tag_file_info['Exists'] == 1
 			call TagHLDebug("Using tags file directory", "Information")
-			let RunOptions['SourceDir'] = tag_file_info['Directory']
+			let b:TagHighlightSettings['SourceDir'] = tag_file_info['Directory']
 		else
 			call TagHLDebug("Using current directory", "Information")
-			let RunOptions['SourceDir'] = '.'
+			let b:TagHighlightSettings['SourceDir'] = '.'
 		endif
+	else
+		call TagHLDebug("Source dir set explicitly to " . TagHighlight#Option#GetOption("SourceDir"), "Information")
 	endif
 	
-	call TagHLDebug("Running Generator with options: " . string(RunOptions), "Information")
+	call TagHLDebug("Running generator with options:", "Information")
+	for var in ["g:TagHighlightSettings","b:TagHighlightConfigFileOptions","b:TagHighlightSettings"]
+		if exists(var)
+			call TagHLDebug(" - " . var . ": " . string(eval(var)), "Information")
+		else
+			call TagHLDebug(" - " . var . ": UNSET", "Information")
+		endif
+	endfor
+	let RunOptions = TagHighlight#Option#CopyOptions()
 	call TagHighlight#RunPythonScript#RunGenerator(RunOptions)
 
 	let postupdate_hooks = TagHighlight#Option#GetOption('PostUpdateHooks')
 		call TagHLDebug("Calling post-update hook " . postupdate_hook, "Information")
 		exe 'call' postupdate_hook . '()'
 	endfor
+
+	call TagHLDebug("UpdateTypesFile() complete, current directory is now " . getcwd(), "Information")
 endfunction
+
+function! TagHighlight#Generation#UpdateAndRead(skiptags)
+	let restore_options = 0
+	if exists('b:TagHighlightSettings')
+		let stored_options = deepcopy(b:TagHighlightSettings)
+		let restore_options = 1
+	else
+		let b:TagHighlightSettings = {}
+	endif
+
+	" Start with a copy of the settings so that we can tweak things
+	if a:skiptags
+		let b:TagHighlightSettings['DoNotGenerateTags'] = 1
+	endif
+	
+	call TagHighlight#Generation#UpdateTypesFile()
+	let SavedTabNr = tabpagenr()
+	let SavedWinNr = winnr()
+	tabdo windo call TagHighlight#ReadTypes#ReadTypesAutoDetect()
+	exe 'tabn' SavedTabNr
+	exe SavedWinNr . 'wincmd w'
+
+	unlet b:TagHighlightSettings
+	if restore_options
+		let b:TagHighlightSettings = deepcopy(stored_options)
+	endif
+endfunction

autoload/TagHighlight/Option.vim

 
 	if ! exists('opt')
 		" We haven't found it, return the default
-		let opt = option['Default']
+		" Special cases first
+		if a:name == "DefaultDirModePriority"
+			if TagHighlight#Option#GetOption("Recurse")
+				let opt = ["Explicit","UpFromFile","CurrentDirectory"]
+			else
+				let opt = ["FileDirectory"]
+			endif
+		else
+			" Normal case
+			let opt = option['Default']
+		endif
+	else
 	endif
 
-	if option['Type'] == 'list'
+	if option['Type'] =~ 'list'
 		let result = []
 		if type(opt) == type('')
 			if opt == '[]' || opt == ''
 			endif
 		endfor
 	elseif option['Type'] == 'bool'
-		if opt == 'True' || opt == 1
+		if opt =~ 'True' || opt == 1
 			let result = 1
-		elseif opt == 'False' || opt == 0
+		elseif opt =~ 'False' || opt == 0
 			let result = 0
 		else
 			throw "Unrecognised bool value"
 
 function! TagHighlight#Option#CopyOptions()
 	let result = {}
-	for key in keys(g:TagHighlightSettings)
-		if type(g:TagHighlightSettings[key]) == type([])
-			let result[key] = g:TagHighlightSettings[key][:]
-		elseif type(g:TagHighlightSettings[key]) == type({})
-			let result[key] = deepcopy(g:TagHighlightSettings[key])
-		else
-			let result[key] = g:TagHighlightSettings[key]
+	for var in ["g:TagHighlightSettings","b:TagHighlightConfigFileOptions","b:TagHighlightSettings"]
+		if exists(var)
+			for key in keys(eval(var))
+				if type(eval(var)[key]) == type([])
+					let result[key] = eval(var)[key][:]
+				elseif type(eval(var)[key]) == type({})
+					let result[key] = deepcopy(eval(var)[key])
+				else
+					let result[key] = eval(var)[key]
+				endif
+			endfor
 		endif
 	endfor
-	if exists('b:TagHighlightSettings')
-		for key in keys(b:TagHighlightSettings)
-			if type(b:TagHighlightSettings[key]) == type([])
-				let result[key] = b:TagHighlightSettings[key][:]
-			elseif type(b:TagHighlightSettings[key]) == type({})
-				let result[key] = deepcopy(b:TagHighlightSettings[key])
-			else
-				let result[key] = b:TagHighlightSettings[key]
-			endif
-		endfor
-	endif
-
 	return result
 endfunction

autoload/TagHighlight/ReadTypes.vim

 
 function! TagHighlight#ReadTypes#ReadTypesAutoDetect()
 	let extension = expand('%:e')
-	call TagHLDebug("Reading types for extension " . extension, "Information")
+	if TagHighlight#Debug#DebugLevelIncludes('Information')
+		call TagHLDebug("Reading types for extension " . extension . " at " . strftime("%Y%m%d-%H%M%S"), "Information")
+	endif
 	for key in keys(g:TagHighlightPrivate['ExtensionLookup'])
 		let regex = '^'.key.'$'
 		if extension =~ regex
 
 	call TagHighlight#Option#LoadOptionFileIfPresent()
 
-	let file = '<afile>'
-	if len(expand(file)) == 0
-		let file = '%'
+	let file = expand('<afile>')
+	if len(file) == 0
+		let file = expand('%')
 	endif
 
 	call TagHLDebug("Reading types of suffix " . a:suffix . " for file " . file, "Information")

doc/TagHighlight.txt

 	:UpdateTypesFile                 *:UpdateTypesFile*
 
 		This command creates the syntax highlighting file used to show the
-		extra colouring.  It then updates all of the open files
-		automatically.  By default, it only looks for source files in the
-		current directory.  However, see |UpdateTypesFile!| and
-		|TagHL-Recurse|.
+		extra colouring.  It then updates all of the open files automatically.
+		By default, it scans recursively into subdirectories of the top level
+		project source directory.  To find this, it looks for a file called
+		"tags" or a file called "taghl_config.txt" in the directory containing
+		the source code or any of its parents (all the way up to the root
+		directory).  If it finds one of these files, it assumes that the
+		directory containing the file also contains all of the source code.
+		If it can't find either of the files, it will use the current
+		directory.  This operation can be customised using the option
+		|TagHL-DefaultDirModePriority|.
 
-	:UpdateTypesFile!                *:UpdateTypesFile!*
-
-		This command operates in the same way as |UpdateTypesFile| except
-		that it looks for source files recursively into subdirectories.
-		It automatically excludes directories named either "docs" or
-		"Documentation".  See also |TagHL-Recurse|.
+		NOTE: Recursion is now on by default.  To turn it off, set the option
+		|TagHL-Recurse| to be 'False' or 0.  This can either be done globally
+		in |g:TagHighlightSettings| or in a file named |taghl_config.txt| in
+		the directory containing the source file.
 
 	:UpdateTypesFileOnly             *:UpdateTypesFileOnly*
 
 			if ! exists('g:TagHighlightSettings')
 				let g:TagHighlightSettings = {}
 			endif
-			let g:TagHighlightSettings['Recurse'] = 1
+			let g:TagHighlightSettings['TagFileName'] = 'tagfile'
 			let g:TagHighlightSettings['CtagsExecutable'] = 'etags.exe'
 <
 		If you want to override any existing options (or you want to be
 		lazy...) you can probably also do it this way:
 >
-			let g:TagHighlightSettings = {'Recurse': 1, 'CtagsExecutable': 'etags.exe'}
+			let g:TagHighlightSettings = {'TagFileName': 'tagfile', 'CtagsExecutable': 'etags.exe'}
 <
 	Project Options                  *taghl_config.txt*
 
 		colons used to delimit keys and values.  A simple example would
 		look like this:
 >
-			Recurse:True
 			SkipPatterns:Skip.*,AnotherPattern\d+
 			IncludeLocals:1
 			UserLibraryDir:c:/user_libraries
 
 			First time round, use |:cd| to get to the project root and run:
 >
-				:UpdateTypesFile!
+				:UpdateTypesFile
 <
 			After the first run, you can open any source file in the project,
 			with the current directory set anywhere you like; the existing
 
 	Low Complexity                                                        {{{4
 
-		Use case: User has source code configured in multiple subdirectories;
-		          rarely has the current directory set to the project root and
-		          deletes the tags and types files often and therefore wishes
-		          to fix the working directory to be the project root.  User
-		          would also like to make |TagHL-Recurse| the default, so that
-		          they can run |:UpdateTypesFile| instead of |:UpdateTypesFile!|.
-		          User project uses Qt4, so the user would like the classes
-		          etc from Qt4 (e.g. QString) to be highlighted.
+		Use case: User has source code all in one directory but has a lot of
+		          subdirectories that would take a long time to scan.  The
+		          user therefore wishes to disable recursive scanning.  User
+				  project uses Qt4, so the user would like the classes etc
+				  from Qt4 (e.g. QString) to be highlighted.
 
 		Implementation:
 			
 			Make sure that you have installed the standard libraries (see 
 			|TagHighlight-install-stdlib|).  The Qt4 library will be loaded
-			automatically.  Create a file called taghl_config.txt in the root
-			of the project.  In that file, add one line (no leading spaces):
+			automatically.  Create a file called taghl_config.txt in the
+			source directory.  In that file, add the following line (with no
+			leading whitespace).
 >
-				Recurse:True
+				Recurse:False
 <
 			No other configuration should be necessary; just run:
 >
 			Open up a new Vim and type:
 >
 				:cd /home/user/libraries/lib1
-				:UpdateTypesFile!
+				:UpdateTypesFile
 <
 			That should create a file called types_c.taghl in the library
 			directory.
 		use Vim's current working directory.
 
 		Option Type: List
-		Default: ["Explicit", "UpFromFile", "CurrentDirectory"]
+		Default:
+			If |TagHL-Recurse| is True (the default), the default is
+			["Explicit", "UpFromFile", "CurrentDirectory"].
+
+			If |TagHL-Recurse| is False, the default is ["FileDirectory"].
 
 	DefaultDirModeSearchWildcards        *TagHL-DefaultDirModeSearchWildcards*
 		This option contains the wildcards that should be checked for when
 		or UpFromCurrent dir mode).  The default is to match when either a
 		project configuration file is found or a tags file is found.
 
+		Note that the wildcard will only match against readable files, not
+		directories.
+
 		Option Type: List
 		Default: [value of TagFileName option, value of ProjectConfigFileName option]
 
 
 	Recurse                              *TagHL-Recurse*
 		If this option is set to True or 1, any call to |:UpdateTypesFile|
-		will be treated as equivalent to |:UpdateTypesFile!|: tag files (and
-		therefore the types highlighter file based on that tag file) will
-		contain tags from source code in the source directory and all
-		subdirectories of that directory.  If this option is not set, or set
-		to False or 0, only source code in the source directory will be
-		scanned.
+		will scan recursively: tag files (and therefore the types highlighter
+		file based on that tag file) will contain tags from source code in the
+		source directory and all subdirectories of that directory.  If this
+		option is not set, or set to False or 0, only source code in the
+		source directory will be scanned.
 
 		Option Type: Boolean
-		Default: False (don't recurse)
+		Default: True (recurse)
 
 	SkipPatterns                         *TagHL-SkipPatterns*
 		Any (python) regular expressions listed in this option will be matched
 ==============================================================================
 7. TagHighlight History                *TagHighlight-history*               {{{1
 
+2.0.16: 8th August 2011    : Wildcard matches are for files only, not
+                             directories (work-around for issue with tags file
+                             having same name as svn tags directory).  Extra
+                             debug regarding working directory etc.
+                             Simplified commands by moving functionality into
+                             a new function.  REMOVED non-recursive command!
+
 2.0.15: 5th August 2011    : Debug output improvements.
 
 2.0.14: 5th August 2011    : Bug fix for selection of source directory.  If

plugin/TagHighlight.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    05/08/2011
+"   Date:    08/08/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 	echoerr "Multiple plugin installs found: something has gone wrong!"
 endif
 
-" Update types & tags - called with a ! recurses
-command! -bang -bar UpdateTypesFile 
-			\ silent call TagHighlight#Generation#UpdateTypesFile(<bang>0, 0) | 
-			\ let s:SavedTabNr = tabpagenr() |
-			\ let s:SavedWinNr = winnr() |
-			\ silent tabdo windo call TagHighlight#ReadTypes#ReadTypesAutoDetect() |
-			\ silent exe 'tabn ' . s:SavedTabNr |
-			\ silent exe s:SavedWinNr . "wincmd w"
+" Update types & tags - called with a ! turns off recursion
+command! -bar UpdateTypesFile 
+			\ call TagHighlight#Generation#UpdateAndRead(0)
 
-command! -bang -bar UpdateTypesFileOnly 
-			\ silent call TagHighlight#Generation#UpdateTypesFile(<bang>0, 1) | 
-			\ let s:SavedTabNr = tabpagenr() |
-			\ let s:SavedWinNr = winnr() |
-			\ silent tabdo windo call TagHighlight#ReadTypes#ReadTypesAutoDetect() |
-			\ silent exe 'tabn ' . s:SavedTabNr |
-			\ silent exe s:SavedWinNr . "wincmd w"
+command! -bar UpdateTypesFileOnly 
+			\ call TagHighlight#Generation#UpdateAndRead(1)
 
-command! -nargs=1 UpdateTypesFileDebug call TagHighlight#Debug#DebugUpdateTypesFile(<f-args>)
+command! -nargs=1 UpdateTypesFileDebug 
+			\ call TagHighlight#Debug#DebugUpdateTypesFile(<f-args>)
 
 function! s:LoadLanguages()
 	" This loads the language data files.

plugin/TagHighlight/data/options.txt

 def_dir_mode_priority:
 	VimOptionMap:DefaultDirModePriority
 	Type:list
-	Default:Explicit,UpFromFile,CurrentDirectory
+	Default:[]
 	Help:List of methods (in order) to use when searching for tags/types etc
+	Note:Default is overridden in TagHighlight#Option#GetOption()
 
 max_dir_search_levels:
 	VimOptionMap:MaxDirSearchLevels
 	Help:Location of source files to scan
 
 recurse:
-	CommandLineSwitches:-r,-R,--recurse
+	CommandLineSwitches:--no-recurse
 	VimOptionMap:Recurse
 	Type:bool
-	Default:False
+	Default:True
 	Help:Recurse into subdirectories
  
 ctags_file:

plugin/TagHighlight/module/worker.py

 import os
 
 def RunWithOptions(options):
+    start_directory = os.getcwd()
     from .config import config, SetInitialOptions, LoadLanguages
     from .debug import Debug
 
     for language in config['language_list']:
         if language in tag_db:
             CreateTypesFile(config, language, tag_db[language])
+
+    os.chdir(start_directory)