From 0f3a1bf450b32e94e2fb0175535ce9c3b3318ed1 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Sun, 23 Feb 2014 10:22:37 +0200 Subject: [PATCH] Cleanup. Enforce sane loading order. Group global initialization. Minor logging fixes. New option: g:syntastic_bash_hack. --- autoload/syntastic/c.vim | 4 +- autoload/syntastic/log.vim | 56 ++++-------- autoload/syntastic/postprocess.vim | 4 +- autoload/syntastic/util.vim | 5 +- plugin/syntastic.vim | 138 +++++++++++++---------------- plugin/syntastic/autoloclist.vim | 6 +- plugin/syntastic/balloons.vim | 6 +- plugin/syntastic/checker.vim | 2 +- plugin/syntastic/cursor.vim | 6 +- plugin/syntastic/highlighting.vim | 6 +- plugin/syntastic/loclist.vim | 2 +- plugin/syntastic/modemap.vim | 2 +- plugin/syntastic/notifiers.vim | 2 +- plugin/syntastic/registry.vim | 2 +- plugin/syntastic/signs.vim | 23 +---- 15 files changed, 93 insertions(+), 171 deletions(-) diff --git a/autoload/syntastic/c.vim b/autoload/syntastic/c.vim index 82f4c704..6bdbe855 100644 --- a/autoload/syntastic/c.vim +++ b/autoload/syntastic/c.vim @@ -1,4 +1,4 @@ -if exists("g:loaded_syntastic_c_autoload") +if exists("g:loaded_syntastic_c_autoload") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_c_autoload = 1 @@ -327,4 +327,4 @@ call s:Init() let &cpo = s:save_cpo unlet s:save_cpo -" vim: set et sts=4 sw=4 fdm=marker: +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/autoload/syntastic/log.vim b/autoload/syntastic/log.vim index 99698533..afc63476 100644 --- a/autoload/syntastic/log.vim +++ b/autoload/syntastic/log.vim @@ -1,4 +1,4 @@ -if exists("g:loaded_syntastic_log_autoload") +if exists("g:loaded_syntastic_log_autoload") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_log_autoload = 1 @@ -6,36 +6,6 @@ let g:loaded_syntastic_log_autoload = 1 let s:save_cpo = &cpo set cpo&vim -if !exists("g:syntastic_debug") - let g:syntastic_debug = 0 -endif - -let s:global_options = [ - \ 'syntastic_aggregate_errors', - \ 'syntastic_always_populate_loc_list', - \ 'syntastic_auto_jump', - \ 'syntastic_auto_loc_list', - \ 'syntastic_check_on_open', - \ 'syntastic_check_on_wq', - \ 'syntastic_debug', - \ 'syntastic_echo_current_error', - \ 'syntastic_enable_balloons', - \ 'syntastic_enable_highlighting', - \ 'syntastic_enable_signs', - \ 'syntastic_error_symbol', - \ 'syntastic_filetype_map', - \ 'syntastic_full_redraws', - \ 'syntastic_id_checkers', - \ 'syntastic_ignore_files', - \ 'syntastic_loc_list_height', - \ 'syntastic_mode_map', - \ 'syntastic_quiet_messages', - \ 'syntastic_reuse_loc_lists', - \ 'syntastic_stl_format', - \ 'syntastic_style_error_symbol', - \ 'syntastic_style_warning_symbol', - \ 'syntastic_warning_symbol' ] - let s:deprecation_notices_issued = [] " Public functions {{{1 @@ -94,10 +64,10 @@ function! syntastic#log#debugShowOptions(level, names) let leader = s:logTimestamp() call s:logRedirect(1) - let vlist = type(a:names) == type("") ? [a:names] : a:names + let vlist = copy(type(a:names) == type("") ? [a:names] : a:names) if !empty(vlist) - let vals = map(copy(vlist), "'&' . v:val . ' = ' . strtrans(string(eval('&' . v:val)))") - echomsg leader . join(vals, ', ') + call map(vlist, "'&' . v:val . ' = ' . strtrans(string(eval('&' . v:val)))") + echomsg leader . join(vlist, ', ') endif call s:logRedirect(0) endfunction @@ -112,7 +82,10 @@ function! syntastic#log#debugShowVariables(level, names) let vlist = type(a:names) == type("") ? [a:names] : a:names for name in vlist - echomsg leader . s:formatVariable(name) + let msg = s:formatVariable(name) + if msg != '' + echomsg leader . msg + endif endfor call s:logRedirect(0) @@ -123,7 +96,7 @@ function! syntastic#log#debugDump(level) return endif - call syntastic#log#debugShowVariables(a:level, s:global_options) + call syntastic#log#debugShowVariables( a:level, sort(keys(g:syntastic_defaults)) ) endfunction " Private functions {{{1 @@ -166,11 +139,11 @@ let s:logTimestamp = function(has('reltime') ? 's:logTimestamp_smart' : 's:logTi function! s:formatVariable(name) let vals = [] - if exists('g:' . a:name) - call add(vals, 'g:' . a:name . ' = ' . strtrans(string(g:{a:name}))) + if exists('g:syntastic_' . a:name) + call add(vals, 'g:syntastic_' . a:name . ' = ' . strtrans(string(g:syntastic_{a:name}))) endif - if exists('b:' . a:name) - call add(vals, 'b:' . a:name . ' = ' . strtrans(string(b:{a:name}))) + if exists('b:syntastic_' . a:name) + call add(vals, 'b:syntastic_' . a:name . ' = ' . strtrans(string(b:syntastic_{a:name}))) endif return join(vals, ', ') @@ -178,4 +151,5 @@ endfunction let &cpo = s:save_cpo unlet s:save_cpo -" vim: set et sts=4 sw=4 fdm=marker: + +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/autoload/syntastic/postprocess.vim b/autoload/syntastic/postprocess.vim index 877bb507..04ff731e 100644 --- a/autoload/syntastic/postprocess.vim +++ b/autoload/syntastic/postprocess.vim @@ -1,4 +1,4 @@ -if exists("g:loaded_syntastic_postprocess_autoload") +if exists("g:loaded_syntastic_postprocess_autoload") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_postprocess_autoload = 1 @@ -64,4 +64,4 @@ endfunction let &cpo = s:save_cpo unlet s:save_cpo -" vim: set et sts=4 sw=4: +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/autoload/syntastic/util.vim b/autoload/syntastic/util.vim index 1ab837a1..17557fc4 100644 --- a/autoload/syntastic/util.vim +++ b/autoload/syntastic/util.vim @@ -1,4 +1,4 @@ -if exists('g:loaded_syntastic_util_autoload') +if exists('g:loaded_syntastic_util_autoload') || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_util_autoload = 1 @@ -248,4 +248,5 @@ endfunction let &cpo = s:save_cpo unlet s:save_cpo -" vim: set et sts=4 sw=4 fdm=marker: + +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index d9ba5fee..a39652c8 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -19,8 +19,6 @@ if has('reltime') let g:syntastic_start = reltime() endif -runtime! plugin/syntastic/*.vim - let s:running_windows = syntastic#util#isRunningWindows() for s:feature in ['autocmd', 'eval', 'modify_fname', 'quickfix', 'user_commands'] @@ -39,59 +37,38 @@ if !s:running_windows && executable('uname') endtry endif -if !exists("g:syntastic_always_populate_loc_list") - let g:syntastic_always_populate_loc_list = 0 -endif +let g:syntastic_defaults = { + \ 'aggregate_errors': 0, + \ 'always_populate_loc_list': 0, + \ 'auto_jump': 0, + \ 'auto_loc_list': 2, + \ 'bash_hack': 1, + \ 'check_on_open': 0, + \ 'check_on_wq': 1, + \ 'debug': 0, + \ 'echo_current_error': 1, + \ 'enable_balloons': 1, + \ 'enable_highlighting': 1, + \ 'enable_signs': 1, + \ 'error_symbol': '>>', + \ 'filetype_map': {}, + \ 'full_redraws': !(has('gui_running') || has('gui_macvim')), + \ 'id_checkers': 1, + \ 'ignore_files': [], + \ 'loc_list_height': 10, + \ 'quiet_messages': {}, + \ 'reuse_loc_lists': (v:version >= 704), + \ 'stl_format': '[Syntax: line:%F (%t)]', + \ 'style_error_symbol': 'S>', + \ 'style_warning_symbol': 'S>', + \ 'warning_symbol': '>>', + \ } -if !exists("g:syntastic_auto_jump") - let g:syntastic_auto_jump = 0 -endif - -if !exists("g:syntastic_quiet_messages") - let g:syntastic_quiet_messages = {} -endif - -if !exists("g:syntastic_stl_format") - let g:syntastic_stl_format = '[Syntax: line:%F (%t)]' -endif - -if !exists("g:syntastic_check_on_open") - let g:syntastic_check_on_open = 0 -endif - -if !exists("g:syntastic_check_on_wq") - let g:syntastic_check_on_wq = 1 -endif - -if !exists("g:syntastic_aggregate_errors") - let g:syntastic_aggregate_errors = 0 -endif - -if !exists("g:syntastic_id_checkers") - let g:syntastic_id_checkers = 1 -endif - -if !exists("g:syntastic_loc_list_height") - let g:syntastic_loc_list_height = 10 -endif - -if !exists("g:syntastic_ignore_files") - let g:syntastic_ignore_files = [] -endif - -if !exists("g:syntastic_filetype_map") - let g:syntastic_filetype_map = {} -endif - -if !exists("g:syntastic_full_redraws") - let g:syntastic_full_redraws = !(has('gui_running') || has('gui_macvim')) -endif - -" TODO: not documented -if !exists("g:syntastic_reuse_loc_lists") - " a relevant bug has been fixed in one of the pre-releases of Vim 7.4 - let g:syntastic_reuse_loc_lists = (v:version >= 704) -endif +for s:key in keys(g:syntastic_defaults) + if !exists('g:syntastic_' . s:key) + let g:syntastic_{s:key} = g:syntastic_defaults[s:key] + endif +endfor if exists("g:syntastic_quiet_warnings") call syntastic#log#deprecationWarn("variable g:syntastic_quiet_warnings is deprecated, please use let g:syntastic_quiet_messages = {'level': 'warnings'} instead") @@ -119,6 +96,8 @@ if v:version > 703 || (v:version == 703 && has('patch446')) call add(s:debug_dump_options, 'shellxescape') endif +runtime! plugin/syntastic/*.vim + " debug constants let g:SyntasticDebugTrace = 1 @@ -296,13 +275,14 @@ function! s:CacheErrors(checkers) call syntastic#log#debugShowOptions(g:SyntasticDebugTrace, s:debug_dump_options) call syntastic#log#debugDump(g:SyntasticDebugVariables) - call syntastic#log#debugShowVariables(g:SyntasticDebugTrace, 'syntastic_aggregate_errors') + call syntastic#log#debugShowVariables(g:SyntasticDebugTrace, 'aggregate_errors') call syntastic#log#debug(g:SyntasticDebugTrace, 'getcwd() = ' . getcwd()) let filetypes = s:ResolveFiletypes() let aggregate_errors = syntastic#util#var('aggregate_errors') let decorate_errors = (aggregate_errors || len(filetypes) > 1) && syntastic#util#var('id_checkers') + let clist = [] for ft in filetypes let clist = s:registry.getCheckers(ft, a:checkers) @@ -372,16 +352,6 @@ function! s:ShowLocList() call g:SyntasticLoclist.current().show() endfunction -"the script changes &shellredir and &shell to stop the screen flicking when -"shelling out to syntax checkers. Not all OSs support the hacks though -function! s:OSSupportsShellredirHack() - return !s:running_windows && executable('/bin/bash') && (s:uname() !~ "FreeBSD") && (s:uname() !~ "OpenBSD") -endfunction - -function! s:IsRedrawRequiredAfterMake() - return !s:running_windows && (s:uname() =~ "FreeBSD" || s:uname() =~ "OpenBSD") -endfunction - function! s:IgnoreFile(filename) let fname = fnamemodify(a:filename, ':p') for pattern in g:syntastic_ignore_files @@ -442,12 +412,7 @@ function! SyntasticMake(options) let old_lc_messages = $LC_MESSAGES let old_lc_all = $LC_ALL - if s:OSSupportsShellredirHack() - "this is a hack to stop the screen needing to be ':redraw'n when - "when :lmake is run. Otherwise the screen flickers annoyingly - let &shellredir = '&>' - let &shell = '/bin/bash' - endif + call s:bashHack() if has_key(a:options, 'errorformat') let &errorformat = a:options['errorformat'] @@ -483,7 +448,7 @@ function! SyntasticMake(options) let &shellredir = old_shellredir let &shell = old_shell - if s:IsRedrawRequiredAfterMake() + if !s:running_windows && (s:uname() =~ "FreeBSD" || s:uname() =~ "OpenBSD") call syntastic#util#redraw(g:syntastic_full_redraws) endif @@ -494,12 +459,12 @@ function! SyntasticMake(options) endif if has_key(a:options, 'defaults') - call SyntasticAddToErrors(errors, a:options['defaults']) + call s:addToErrors(errors, a:options['defaults']) endif " Add subtype info if present. if has_key(a:options, 'subtype') - call SyntasticAddToErrors(errors, { 'subtype': a:options['subtype'] }) + call s:addToErrors(errors, { 'subtype': a:options['subtype'] }) endif if has_key(a:options, 'postprocess') && !empty(a:options['postprocess']) @@ -512,8 +477,8 @@ function! SyntasticMake(options) return errors endfunction -"take a list of errors and add default values to them from a:options -function! SyntasticAddToErrors(errors, options) +" Take a list of errors and add default values to them from a:options +function! s:addToErrors(errors, options) for err in a:errors for key in keys(a:options) if !has_key(err, key) || empty(err[key]) @@ -525,4 +490,23 @@ function! SyntasticAddToErrors(errors, options) return a:errors endfunction -" vim: set et sts=4 sw=4: +" The script changes &shellredir and &shell to stop the screen flicking when +" shelling out to syntax checkers. Not all OSs support the hacks though. +function! s:bashHack() + if !exists('s:bash') + if !s:running_windows && (s:uname() !~# "FreeBSD") && (s:uname() !~# "OpenBSD") + let s:bash = + \ executable('/usr/local/bin/bash') ? '/usr/local/bin/bash' : + \ executable('/bin/bash') ? '/bin/bash' : '' + else + let s:bash = '' + endif + endif + + if g:syntastic_bash_hack && s:bash != '' + let &shell = s:bash + let &shellredir = '&>' + endif +endfunction + +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/plugin/syntastic/autoloclist.vim b/plugin/syntastic/autoloclist.vim index f0038e11..3e6de2d8 100644 --- a/plugin/syntastic/autoloclist.vim +++ b/plugin/syntastic/autoloclist.vim @@ -1,12 +1,8 @@ -if exists("g:loaded_syntastic_notifier_autoloclist") +if exists("g:loaded_syntastic_notifier_autoloclist") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_notifier_autoloclist = 1 -if !exists("g:syntastic_auto_loc_list") - let g:syntastic_auto_loc_list = 2 -endif - let g:SyntasticAutoloclistNotifier = {} " Public methods {{{1 diff --git a/plugin/syntastic/balloons.vim b/plugin/syntastic/balloons.vim index 184a0528..38b88ecb 100644 --- a/plugin/syntastic/balloons.vim +++ b/plugin/syntastic/balloons.vim @@ -1,12 +1,8 @@ -if exists("g:loaded_syntastic_notifier_balloons") +if exists("g:loaded_syntastic_notifier_balloons") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_notifier_balloons = 1 -if !exists("g:syntastic_enable_balloons") - let g:syntastic_enable_balloons = 1 -endif - if !has('balloon_eval') let g:syntastic_enable_balloons = 0 endif diff --git a/plugin/syntastic/checker.vim b/plugin/syntastic/checker.vim index 94cbdb03..148d406c 100644 --- a/plugin/syntastic/checker.vim +++ b/plugin/syntastic/checker.vim @@ -1,4 +1,4 @@ -if exists("g:loaded_syntastic_checker") +if exists("g:loaded_syntastic_checker") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_checker = 1 diff --git a/plugin/syntastic/cursor.vim b/plugin/syntastic/cursor.vim index 5e24ae14..c5f8c1d5 100644 --- a/plugin/syntastic/cursor.vim +++ b/plugin/syntastic/cursor.vim @@ -1,12 +1,8 @@ -if exists("g:loaded_syntastic_notifier_cursor") +if exists("g:loaded_syntastic_notifier_cursor") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_notifier_cursor = 1 -if !exists('g:syntastic_echo_current_error') - let g:syntastic_echo_current_error = 1 -endif - let g:SyntasticCursorNotifier = {} " Public methods {{{1 diff --git a/plugin/syntastic/highlighting.vim b/plugin/syntastic/highlighting.vim index 80d31f19..98f6e147 100644 --- a/plugin/syntastic/highlighting.vim +++ b/plugin/syntastic/highlighting.vim @@ -1,4 +1,4 @@ -if exists("g:loaded_syntastic_notifier_highlighting") +if exists("g:loaded_syntastic_notifier_highlighting") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_notifier_highlighting = 1 @@ -6,10 +6,6 @@ let g:loaded_syntastic_notifier_highlighting = 1 " Highlighting requires getmatches introduced in 7.1.040 let s:has_highlighting = v:version > 701 || (v:version == 701 && has('patch040')) -if !exists("g:syntastic_enable_highlighting") - let g:syntastic_enable_highlighting = 1 -endif - let g:SyntasticHighlightingNotifier = {} let s:setup_done = 0 diff --git a/plugin/syntastic/loclist.vim b/plugin/syntastic/loclist.vim index 052501c4..570ba382 100644 --- a/plugin/syntastic/loclist.vim +++ b/plugin/syntastic/loclist.vim @@ -1,4 +1,4 @@ -if exists("g:loaded_syntastic_loclist") +if exists("g:loaded_syntastic_loclist") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_loclist = 1 diff --git a/plugin/syntastic/modemap.vim b/plugin/syntastic/modemap.vim index 9b04235c..a0e43293 100644 --- a/plugin/syntastic/modemap.vim +++ b/plugin/syntastic/modemap.vim @@ -1,4 +1,4 @@ -if exists("g:loaded_syntastic_modemap") +if exists("g:loaded_syntastic_modemap") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_modemap = 1 diff --git a/plugin/syntastic/notifiers.vim b/plugin/syntastic/notifiers.vim index 58f3448a..0dcc82cf 100644 --- a/plugin/syntastic/notifiers.vim +++ b/plugin/syntastic/notifiers.vim @@ -1,4 +1,4 @@ -if exists("g:loaded_syntastic_notifiers") +if exists("g:loaded_syntastic_notifiers") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_notifiers = 1 diff --git a/plugin/syntastic/registry.vim b/plugin/syntastic/registry.vim index 7621b374..64c72286 100644 --- a/plugin/syntastic/registry.vim +++ b/plugin/syntastic/registry.vim @@ -1,4 +1,4 @@ -if exists("g:loaded_syntastic_registry") +if exists("g:loaded_syntastic_registry") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_registry = 1 diff --git a/plugin/syntastic/signs.vim b/plugin/syntastic/signs.vim index 3b1e7522..487634af 100644 --- a/plugin/syntastic/signs.vim +++ b/plugin/syntastic/signs.vim @@ -1,29 +1,8 @@ -if exists("g:loaded_syntastic_notifier_signs") +if exists("g:loaded_syntastic_notifier_signs") || !exists("g:loaded_syntastic_plugin") finish endif let g:loaded_syntastic_notifier_signs = 1 -if !exists("g:syntastic_enable_signs") - let g:syntastic_enable_signs = 1 -endif - -if !exists("g:syntastic_error_symbol") - let g:syntastic_error_symbol = '>>' -endif - -if !exists("g:syntastic_warning_symbol") - let g:syntastic_warning_symbol = '>>' -endif - -if !exists("g:syntastic_style_error_symbol") - let g:syntastic_style_error_symbol = 'S>' -endif - -if !exists("g:syntastic_style_warning_symbol") - let g:syntastic_style_warning_symbol = 'S>' -endif - - " start counting sign ids at 5000, start here to hopefully avoid conflicting " with any other code that places signs (not sure if this precaution is " actually needed)