From 90dce6d3e7c16a54afa87b3441f16d815674aab9 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Tue, 9 Apr 2013 00:24:54 +0300 Subject: [PATCH] Cleanup. Makes cursor a standard notifier. Adds a method enabled() to the notifiers. Adds an optional method reset() to the notifiers. --- plugin/syntastic.vim | 7 +---- plugin/syntastic/autoloclist.vim | 14 ++++----- plugin/syntastic/balloons.vim | 4 +++ plugin/syntastic/cursor.vim | 47 +++++++++++++++++++++++-------- plugin/syntastic/highlighting.vim | 12 ++++---- plugin/syntastic/notifiers.vim | 13 +++++++-- plugin/syntastic/signer.vim | 4 +++ 7 files changed, 68 insertions(+), 33 deletions(-) diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index f4f48eb9..002d20f8 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -47,7 +47,6 @@ endif let s:registry = g:SyntasticRegistry.Instance() let s:notifiers = g:SyntasticNotifiers.New() -let s:cursor_notifier = g:SyntasticNotifierCursor.New() let s:modemap = g:SyntasticModeMap.Instance() function! s:CompleteCheckerName(argLead, cmdLine, cursorPos) @@ -68,10 +67,6 @@ highlight link SyntasticError SpellBad highlight link SyntasticWarning SpellCap augroup syntastic - if g:syntastic_echo_current_error - autocmd CursorMoved * call s:cursor_notifier.refresh(s:LocList()) - endif - autocmd BufReadPost * if g:syntastic_check_on_open | call s:UpdateErrors(1) | endif autocmd BufWritePost * call s:UpdateErrors(1) @@ -117,8 +112,8 @@ endfunction "clear the loc list for the buffer function! s:ClearCache() + call s:notifiers.reset(s:LocList()) unlet! b:syntastic_loclist - call s:cursor_notifier.resetOldLine() endfunction function! s:CurrentFiletypes() diff --git a/plugin/syntastic/autoloclist.vim b/plugin/syntastic/autoloclist.vim index 38ad04e4..47908abd 100644 --- a/plugin/syntastic/autoloclist.vim +++ b/plugin/syntastic/autoloclist.vim @@ -3,14 +3,6 @@ if exists("g:loaded_syntastic_notifier_autoloclist") endif let g:loaded_syntastic_notifier_autoloclist=1 -"TODO: this var is a hack required for the Notifiers class. This is complicated -"because this notification type doesnt use the same option naming convention -"that Notifiers assumes -" -"i.e. it uses g:syntastic_auto_loc_list which has 3 possible values rather -"than just on or off -let g:syntastic_enable_autoloclist=1 - if !exists("g:syntastic_auto_loc_list") let g:syntastic_auto_loc_list = 2 endif @@ -24,6 +16,10 @@ function! g:SyntasticNotifierAutoloclist.New() return newObj endfunction +function! g:SyntasticNotifierAutoloclist.enabled() + return 1 " always enabled +endfunction + function! g:SyntasticNotifierAutoloclist.refresh(loclist) call g:SyntasticNotifierAutoloclist.AutoToggle(a:loclist) endfunction @@ -42,3 +38,5 @@ function! g:SyntasticNotifierAutoloclist.AutoToggle(loclist) endif endif endfunction + +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/plugin/syntastic/balloons.vim b/plugin/syntastic/balloons.vim index 78b1ceb6..242f4022 100644 --- a/plugin/syntastic/balloons.vim +++ b/plugin/syntastic/balloons.vim @@ -20,6 +20,10 @@ function! g:SyntasticNotifierBalloons.New() return newObj endfunction +function! g:SyntasticNotifierBalloons.enabled() + return exists('b:syntastic_enable_balloons') ? b:syntastic_enable_balloons : g:syntastic_enable_balloons +endfunction + " Update the error balloons function! g:SyntasticNotifierBalloons.refresh(loclist) let b:syntastic_balloons = {} diff --git a/plugin/syntastic/cursor.vim b/plugin/syntastic/cursor.vim index e75cf7f9..bc0f6bb2 100644 --- a/plugin/syntastic/cursor.vim +++ b/plugin/syntastic/cursor.vim @@ -3,7 +3,7 @@ if exists("g:loaded_syntastic_notifier_cursor") endif let g:loaded_syntastic_notifier_cursor=1 -if !exists("g:syntastic_echo_current_error") +if !exists('g:syntastic_echo_current_error') let g:syntastic_echo_current_error = 1 endif @@ -13,25 +13,50 @@ let g:SyntasticNotifierCursor = {} function! g:SyntasticNotifierCursor.New() let newObj = copy(self) - let newObj.oldLine = -1 + let b:oldLine = -1 return newObj endfunction +function! g:SyntasticNotifierCursor.enabled() + return exists('b:syntastic_echo_current_error') ? b:syntastic_echo_current_error : g:syntastic_echo_current_error +endfunction + function! g:SyntasticNotifierCursor.refresh(loclist) - let l = line('.') - if l == self.oldLine + if g:syntastic_echo_current_error + let b:syntastic_messages = copy(a:loclist.messages()) + autocmd syntastic CursorMoved * call g:SyntasticRefreshCursor() + else + autocmd! syntastic CursorMoved + endif +endfunction + +function! g:SyntasticNotifierCursor.reset(loclist) + let b:oldLine = -1 +endfunction + +" Private methods {{{1 + +" The following defensive nonsense is needed because of the nature of autocmd +function! g:SyntasticRefreshCursor() + if exists('b:syntastic_messages') + " file not checked return endif - let self.oldLine = l - let messages = a:loclist.messages() - if has_key(messages, l) - return syntastic#util#wideMsg(messages[l]) + if !exists('b:oldLine') + let b:oldLine = -1 + endif + let l = line('.') + if l == b:oldLine + return + endif + let b:oldLine = l + + if has_key(b:syntastic_messages, l) + return syntastic#util#wideMsg(b:syntastic_messages[l]) else echo endif endfunction -function! g:SyntasticNotifierCursor.resetOldLine() - let self.oldLine = -1 -endfunction +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/plugin/syntastic/highlighting.vim b/plugin/syntastic/highlighting.vim index 61ce5b2c..9a815e7c 100644 --- a/plugin/syntastic/highlighting.vim +++ b/plugin/syntastic/highlighting.vim @@ -1,7 +1,7 @@ if exists("g:loaded_syntastic_notifier_highlighting") finish endif -let g:loaded_syntastic_notifier_highlighting=1 +let g:loaded_syntastic_notifier_highlighting = 1 if !exists("g:syntastic_enable_highlighting") let g:syntastic_enable_highlighting = 1 @@ -21,12 +21,14 @@ function! g:SyntasticNotifierHighlighting.New() return newObj endfunction +function! g:SyntasticNotifierHighlighting.enabled() + return exists('b:syntastic_enable_highlighting') ? b:syntastic_enable_highlighting : g:syntastic_enable_highlighting +endfunction + " The function `Syntastic_{filetype}_{checker}_GetHighlightRegex` is used " to override default highlighting. This function must take one arg (an " error item) and return a regex to match that item in the buffer. function! g:SyntasticNotifierHighlighting.refresh(loclist) - call self._reset() - let fts = substitute(&ft, '-', '_', 'g') for ft in split(fts, '\.') @@ -49,10 +51,8 @@ function! g:SyntasticNotifierHighlighting.refresh(loclist) endfor endfunction -" Private functions {{{1 - " Remove all error highlights from the window -function! g:SyntasticNotifierHighlighting._reset() +function! g:SyntasticNotifierHighlighting.reset(loclist) for match in getmatches() if stridx(match['group'], 'Syntastic') == 0 call matchdelete(match['id']) diff --git a/plugin/syntastic/notifiers.vim b/plugin/syntastic/notifiers.vim index 554e4b04..a14452aa 100644 --- a/plugin/syntastic/notifiers.vim +++ b/plugin/syntastic/notifiers.vim @@ -5,7 +5,7 @@ let g:loaded_syntastic_notifiers=1 let g:SyntasticNotifiers = {} -let s:notifier_types = ['signs', 'balloons', 'highlighting', 'autoloclist'] +let s:notifier_types = ['signs', 'balloons', 'highlighting', 'cursor', 'autoloclist'] " Public methods {{{1 @@ -25,10 +25,19 @@ endfunction function! g:SyntasticNotifiers.refresh(loclist) for type in self._enabled_types - if ( exists('b:syntastic_enable_'.type) ? b:syntastic_enable_{type} : g:syntastic_enable_{type} ) + if self._notifier[type].enabled() call self._notifier[type].refresh(a:loclist) endif endfor endfunction +function! g:SyntasticNotifiers.reset(loclist) + for type in self._enabled_types + let class = substitute(type, '.*', 'SyntasticNotifier\u&', '') + if has_key(g:{class}, 'reset') + call self._notifier[type].reset(a:loclist) + endif + endfor +endfunction + " vim: set sw=4 sts=4 et fdm=marker: diff --git a/plugin/syntastic/signer.vim b/plugin/syntastic/signer.vim index 4388af5d..68295fd0 100644 --- a/plugin/syntastic/signer.vim +++ b/plugin/syntastic/signer.vim @@ -51,6 +51,10 @@ function! g:SyntasticNotifierSigns.New() return newObj endfunction +function! g:SyntasticNotifierSigns.enabled() + return exists('b:syntastic_enable_signs') ? b:syntastic_enable_signs : g:syntastic_enable_signs +endfunction + " Update the error signs function! g:SyntasticNotifierSigns.refresh(loclist) let old_signs = copy(self._bufSignIds())