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_TagHLOption') && (g:plugin_development_mode != 1))
16 throw "Already loaded"
21 let g:loaded_TagHLOption = 1
23 let s:log_defaults = 1
24 let g:TagHighlightOptionDefaults = {}
26 function! TagHighlight#Option#LoadOptionFileIfPresent()
27 let option_file = TagHighlight#Find#LocateFile('CONFIG', '')
29 " Check whether we've found the option file
30 if ! option_file['Exists']
31 call TagHLDebug("No project config file", "Information")
35 " Got an option file, load it in:
36 let b:TagHighlightConfigFileOptions = TagHighlight#LoadDataFile#LoadFile(option_file['FullPath'])
41 function! TagHighlight#Option#LoadOptions()
42 if has_key(g:TagHighlightPrivate, 'PluginOptions')
46 let g:TagHighlightPrivate['PluginOptions'] = []
47 let options = TagHighlight#LoadDataFile#LoadDataFile('options.txt')
49 for option_dest in keys(options)
50 if has_key(options[option_dest], 'VimOptionMap')
51 let option = deepcopy(options[option_dest])
52 let option['Destination'] = option_dest
53 let g:TagHighlightPrivate['PluginOptions'] += [option]
58 function! TagHighlight#Option#GetOption(name)
59 " Check we've loaded the options
60 call TagHighlight#Option#LoadOptions()
62 " Check this option exists
64 for option in g:TagHighlightPrivate['PluginOptions']
65 if option['VimOptionMap'] == a:name
71 throw "Unrecognised option:" .a:name
74 " Option priority (highest first):
75 " * buffer dictionary,
76 " * config file dictionary
77 " * global dictionary,
78 for var in ["g:TagHighlightSettings","b:TagHighlightConfigFileOptions","b:TagHighlightSettings"]
80 exe 'let present = has_key(' . var . ', a:name)'
82 exe 'let opt = ' . var . '[a:name]'
88 " We haven't found it, return the default
90 if a:name == "DefaultDirModePriority"
91 if TagHighlight#Option#GetOption("Recurse")
92 let opt = ["Explicit","UpFromFile","CurrentDirectory"]
94 let opt = ["FileDirectory"]
98 let opt = option['Default']
103 if option['Type'] =~ 'list'
105 if type(opt) == type('')
106 if opt == '[]' || opt == ''
109 let parsed_opt = [opt]
114 for part in parsed_opt
115 if part =~ '^OPT(\k\+)$'
116 let value_name = part[4:len(part)-2]
117 let result += [TagHighlight#Option#GetOption(value_name)]
122 elseif option['Type'] == 'bool'
123 if opt =~ 'True' || opt == 1
125 elseif opt =~ 'False' || opt == 0
128 throw "Unrecognised bool value"
130 elseif option['Type'] == 'string'
131 if opt =~ '^OPT(\k\+)$'
132 let value_name = opt[4:len(opt)-2]
133 let result = TagHighlight#Option#GetOption(value_name)
137 elseif option['Type'] == 'dict'
138 " This is a complex one: just assume it's valid Vim script
139 if type(opt) == type([])
140 " Probably a multi-entry dict that has automatically been
142 let result = eval(join(opt, ', '))
143 elseif type(opt) == type("")
144 let result = eval(opt)
148 elseif option['Type'] == 'int'
149 let result = str2nr(opt)
154 function! TagHighlight#Option#CopyOptions()
156 for var in ["g:TagHighlightSettings","b:TagHighlightConfigFileOptions","b:TagHighlightSettings"]
158 for key in keys(eval(var))
159 if type(eval(var)[key]) == type([])
160 let result[key] = eval(var)[key][:]
161 elseif type(eval(var)[key]) == type({})
162 let result[key] = deepcopy(eval(var)[key])
164 let result[key] = eval(var)[key]