2 " Author: A. S. Budden <abudden _at_ gmail _dot_ com>
3 " Copyright: Copyright (C) 2009-2011 A. S. Budden
4 " Permission is hereby granted to use and distribute this code,
5 " with or without modifications, provided that this copyright
6 " notice is copied with it. Like anything else that's free,
7 " the TagHighlight plugin is provided *as is* and comes with no
8 " warranty of any kind, either expressed or implied. By using
9 " this plugin, you agree that in no event will the copyright
10 " holder be liable for any damages resulting from the use
13 " ---------------------------------------------------------------------
15 if &cp || v:version < 700 || (exists('g:loaded_TagHighlight') && (g:plugin_development_mode != 1))
16 throw "Already loaded"
21 let g:loaded_TagHighlight = 1
23 let old_versions = globpath(&rtp, 'plugin/ctags_highlighting.vim')
24 if len(old_versions) > 0
25 echoerr "Legacy ctags highlighter found. This highlighter is"
26 \ "intended to replace ctags_highlighter. See the"
27 \ "user documentation in doc/TagHighlight.txt for"
32 if ! exists('g:TagHighlightSettings')
33 let g:TagHighlightSettings = {}
36 let g:TagHighlightPrivate = {}
38 let s:plugin_paths = split(globpath(&rtp, 'plugin/TagHighlight/TagHighlight.py'), '\n')
39 if len(s:plugin_paths) == 1
40 let g:TagHighlightPrivate['PluginPath'] = fnamemodify(s:plugin_paths[0], ':p:h')
41 elseif len(s:plugin_paths) == 0
42 echoerr "Cannot find TagHighlight.py"
44 echoerr "Multiple plugin installs found: something has gone wrong!"
48 command! -bar UpdateTypesFile
49 \ silent call TagHighlight#Generation#UpdateAndRead(0)
51 command! -bar UpdateTypesFileOnly
52 \ silent call TagHighlight#Generation#UpdateAndRead(1)
54 command! -nargs=1 UpdateTypesFileDebug
55 \ call TagHighlight#Debug#DebugUpdateTypesFile(<f-args>)
57 function! s:LoadLanguages()
58 " This loads the language data files.
59 let language_files = split(glob(g:TagHighlightPrivate['PluginPath'] . '/data/languages/*.txt'), '\n')
60 let g:TagHighlightPrivate['ExtensionLookup'] = {}
61 let g:TagHighlightPrivate['FileTypeLookup'] = {}
62 let g:TagHighlightPrivate['SyntaxLookup'] = {}
63 let g:TagHighlightPrivate['SpecialSyntaxHandlers'] = {}
64 for language_file in language_files
65 let entries = TagHighlight#LoadDataFile#LoadFile(language_file)
66 if has_key(entries, 'Suffix') && has_key(entries, 'VimExtensionMatcher')
67 \ && has_key(entries, 'VimFileTypes') && has_key(entries, 'VimSyntaxes')
68 let g:TagHighlightPrivate['ExtensionLookup'][entries['VimExtensionMatcher']] = entries['Suffix']
70 if type(entries['VimFileTypes']) == type([])
71 let ftkey = join(entries['VimFileTypes'], ",")
73 let ftkey = entries['VimFileTypes']
75 let g:TagHighlightPrivate['FileTypeLookup'][ftkey] = entries['Suffix']
77 if type(entries['VimSyntaxes']) == type([])
78 let stkey = join(entries['VimSyntaxes'], ",")
80 let stkey = entries['VimSyntaxes']
82 let g:TagHighlightPrivate['SyntaxLookup'][stkey] = entries['Suffix']
84 echoerr "Could not load language from file " . language_file
86 if has_key(entries, 'SpecialSyntaxHandlers')
87 if type(entries['SpecialSyntaxHandlers']) == type([])
88 let handlers = entries['SpecialSyntaxHandlers']
90 let handlers = [entries['SpecialSyntaxHandlers']]
92 let g:TagHighlightPrivate['SpecialSyntaxHandlers'][entries['Suffix']] = handlers
97 function! s:LoadKinds()
98 " Load the list of kinds (ignoring ctags information) into
99 " Vim. This is used to make the default links
100 let g:TagHighlightPrivate['Kinds'] = TagHighlight#LoadDataFile#LoadDataFile('kinds.txt')
101 " Use a dictionary to get all unique entries
102 let tag_names_dict = {}
103 for entry in keys(g:TagHighlightPrivate['Kinds'])
104 for key in keys(g:TagHighlightPrivate['Kinds'][entry])
105 let tag_names_dict[g:TagHighlightPrivate['Kinds'][entry][key]] = ""
108 let g:TagHighlightPrivate['AllTypes'] = sort(keys(tag_names_dict))
111 function! TagHLDebug(str, level)
112 if TagHighlight#Debug#DebugLevelIncludes(a:level)
114 let debug_file = TagHighlight#Option#GetOption('DebugFile')
115 let print_time = TagHighlight#Option#GetOption('DebugPrintTime')
116 catch /Unrecognised option/
117 " Probably haven't loaded the option definitions
118 " yet, so assume no debug log file
119 let debug_file = 'None'
121 if debug_file == 'None'
124 exe 'redir >>' debug_file
125 if print_time && exists("*strftime")
126 silent echo strftime("%H.%M.%S") . ": " . a:str
135 call s:LoadLanguages()
138 for tagname in g:TagHighlightPrivate['AllTypes']
139 let simplename = substitute(tagname, '^CTags', '', '')
140 exe 'hi default link' tagname simplename
141 " Highlight everything as a keyword by default
142 exe 'hi default link' simplename 'Keyword'
145 if ! has_key(g:TagHighlightPrivate, 'AutoCommandsLoaded')
146 let g:TagHighlightPrivate['AutoCommandsLoaded'] = 1
147 autocmd BufRead,BufNewFile * call TagHighlight#ReadTypes#ReadTypesByExtension()
148 autocmd Syntax * call TagHighlight#ReadTypes#ReadTypesBySyntax()
149 autocmd FileType * call TagHighlight#ReadTypes#ReadTypesByFileType()
151 command! ReadTypes call TagHighlight#ReadTypes#ReadTypesByOption()