6da8d0ebffdd85d3a6c22aa7833e247a106a0ca8
[stack/conf/vim.git] / addons / TagHighlight / autoload / TagHighlight / Debug.vim
1 " Tag Highlighter:
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
11 "            of this software.
12
13 " ---------------------------------------------------------------------
14 try
15         if &cp || v:version < 700 || (exists('g:loaded_TagHLDebug') && (g:plugin_development_mode != 1))
16                 throw "Already loaded"
17         endif
18 catch
19         finish
20 endtry
21 let g:loaded_TagHLDebug = 1
22
23 let TagHighlight#Debug#DebugLevels = [
24                         \ "None",
25                         \ "Critical",
26                         \ "Error",
27                         \ "Warning",
28                         \ "Status",
29                         \ "Information",
30                         \ ]
31
32 function! TagHighlight#Debug#GetDebugLevel()
33         try
34                 let debug_level = TagHighlight#Option#GetOption('DebugLevel')
35         catch /Unrecognised option/
36                 " Probably loading the option file, so no debug level available
37                 " yet, so assume 'Information'
38                 let debug_level = 'Information'
39         endtry
40         let debug_num = index(g:TagHighlight#Debug#DebugLevels, debug_level)
41         if debug_num != -1
42                 return debug_num
43         else
44                 return index(g:TagHighlight#Debug#DebugLevels, 'Error')
45         endif
46 endfunction
47
48 function! TagHighlight#Debug#GetDebugLevelName()
49         let debug_level_num = TagHighlight#Debug#GetDebugLevel()
50         return g:TagHighlight#Debug#DebugLevels[debug_level_num]
51 endfunction
52
53 function! TagHighlight#Debug#DebugLevelIncludes(level)
54         let level_index = index(g:TagHighlight#Debug#DebugLevels, a:level)
55         if level_index == -1
56                 let level_index = index(g:TagHighlight#Debug#DebugLevels, 'Critical')
57         endif
58         if level_index <= TagHighlight#Debug#GetDebugLevel()
59                 return 1
60         else
61                 return 0
62         endif
63 endfunction
64
65 function! TagHighlight#Debug#DebugUpdateTypesFile(filename)
66         " Update the types file with debugging turned on
67         if a:filename ==? 'None'
68                 " Force case to be correct
69                 let debug_file = 'None'
70         else
71                 let debug_file = a:filename
72         endif
73
74         let debug_options = ["DebugFile","DebugLevel"]
75
76         " Store the old debug options
77         for dbg_option in debug_options
78                 let stored_option_name = 'Stored'.dbg_option
79                 if has_key(g:TagHighlightSettings, dbg_option)
80                         let g:TagHighlightSettings[stored_option_name] = g:TagHighlightSettings[dbg_option]
81                 else
82                         let g:TagHighlightSettings[stored_option_name] = 'None'
83                 endif
84         endfor
85
86         let g:TagHighlightSettings['DebugFile'] = debug_file
87         let g:TagHighlightSettings['DebugLevel'] = 'Information'
88
89         call TagHLDebug("========================================================", "Information")
90         redir => vim_version_info
91         silent version
92         redir END
93         call TagHLDebug("--------------------------------------------------------", "Information")
94         call TagHLDebug(vim_version_info, "Information")
95         call TagHighlight#Generation#UpdateAndRead(0)
96
97         " Get rid of the 'stored' versions of the debug options
98         for dbg_option in debug_options
99                 let stored_option_name = 'Stored'.dbg_option
100                 if g:TagHighlightSettings[stored_option_name] == 'None'
101                         unlet g:TagHighlightSettings[dbg_option]
102                 else
103                         let g:TagHighlightSettings[dbg_option] = g:TagHighlightSettings[stored_option_name]
104                 endif
105                 unlet g:TagHighlightSettings[stored_option_name]
106         endfor
107 endfunction