2009-07-10 21:39:39 -04:00
|
|
|
"============================================================================
|
|
|
|
"File: syntastic.vim
|
|
|
|
"Description: vim plugin for on the fly syntax checking
|
2009-12-16 05:02:36 -05:00
|
|
|
"Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
|
2012-02-16 12:11:03 -05:00
|
|
|
"Version: 2.3.0
|
|
|
|
"Last Change: 16 Feb, 2012
|
2009-07-10 21:39:39 -04:00
|
|
|
"License: This program is free software. It comes without any warranty,
|
|
|
|
" to the extent permitted by applicable law. You can redistribute
|
|
|
|
" it and/or modify it under the terms of the Do What The Fuck You
|
|
|
|
" Want To Public License, Version 2, as published by Sam Hocevar.
|
|
|
|
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
|
|
"
|
|
|
|
"============================================================================
|
|
|
|
|
2009-07-10 19:09:52 -04:00
|
|
|
if exists("g:loaded_syntastic_plugin")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_syntastic_plugin = 1
|
|
|
|
|
2012-05-08 08:31:20 -04:00
|
|
|
let s:running_windows = has("win16") || has("win32")
|
2009-07-10 19:09:52 -04:00
|
|
|
|
2011-12-07 08:16:11 -05:00
|
|
|
if !exists("g:syntastic_enable_signs")
|
2011-12-09 07:56:41 -05:00
|
|
|
let g:syntastic_enable_signs = 1
|
|
|
|
endif
|
2012-07-09 07:09:30 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2011-12-09 07:56:41 -05:00
|
|
|
if !has('signs')
|
|
|
|
let g:syntastic_enable_signs = 0
|
2009-07-10 21:47:17 -04:00
|
|
|
endif
|
|
|
|
|
2011-12-07 08:26:19 -05:00
|
|
|
if !exists("g:syntastic_enable_balloons")
|
2011-12-09 07:56:41 -05:00
|
|
|
let g:syntastic_enable_balloons = 1
|
|
|
|
endif
|
|
|
|
if !has('balloon_eval')
|
|
|
|
let g:syntastic_enable_balloons = 0
|
2011-05-02 19:21:16 -04:00
|
|
|
endif
|
|
|
|
|
2011-12-08 17:23:51 -05:00
|
|
|
if !exists("g:syntastic_enable_highlighting")
|
|
|
|
let g:syntastic_enable_highlighting = 1
|
|
|
|
endif
|
|
|
|
|
2012-10-01 10:10:53 -04:00
|
|
|
" highlighting requires getmatches introduced in 7.1.040
|
2012-11-17 15:15:45 -05:00
|
|
|
if v:version < 701 || (v:version == 701 && !has('patch040'))
|
|
|
|
let g:syntastic_enable_highlighting = 0
|
2012-10-01 10:10:53 -04:00
|
|
|
endif
|
|
|
|
|
2011-12-09 20:15:24 -05:00
|
|
|
if !exists("g:syntastic_echo_current_error")
|
|
|
|
let g:syntastic_echo_current_error = 1
|
|
|
|
endif
|
|
|
|
|
2009-07-13 07:12:18 -04:00
|
|
|
if !exists("g:syntastic_auto_loc_list")
|
2011-11-30 14:56:27 -05:00
|
|
|
let g:syntastic_auto_loc_list = 2
|
2009-07-13 05:38:50 -04:00
|
|
|
endif
|
|
|
|
|
2011-01-04 17:27:47 -05:00
|
|
|
if !exists("g:syntastic_auto_jump")
|
|
|
|
let syntastic_auto_jump=0
|
|
|
|
endif
|
|
|
|
|
2009-07-19 22:59:54 -04:00
|
|
|
if !exists("g:syntastic_quiet_warnings")
|
|
|
|
let g:syntastic_quiet_warnings = 0
|
|
|
|
endif
|
|
|
|
|
2011-02-19 02:10:20 -05:00
|
|
|
if !exists("g:syntastic_stl_format")
|
|
|
|
let g:syntastic_stl_format = '[Syntax: line:%F (%t)]'
|
|
|
|
endif
|
|
|
|
|
2011-11-28 18:44:40 -05:00
|
|
|
if !exists("g:syntastic_mode_map")
|
2011-11-29 03:44:09 -05:00
|
|
|
let g:syntastic_mode_map = {}
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !has_key(g:syntastic_mode_map, "mode")
|
|
|
|
let g:syntastic_mode_map['mode'] = 'active'
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !has_key(g:syntastic_mode_map, "active_filetypes")
|
|
|
|
let g:syntastic_mode_map['active_filetypes'] = []
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !has_key(g:syntastic_mode_map, "passive_filetypes")
|
|
|
|
let g:syntastic_mode_map['passive_filetypes'] = []
|
2011-11-28 18:44:40 -05:00
|
|
|
endif
|
|
|
|
|
2011-12-24 04:44:01 -05:00
|
|
|
if !exists("g:syntastic_check_on_open")
|
|
|
|
let g:syntastic_check_on_open = 0
|
|
|
|
endif
|
|
|
|
|
2012-02-10 12:56:32 -05:00
|
|
|
if !exists("g:syntastic_loc_list_height")
|
|
|
|
let g:syntastic_loc_list_height = 10
|
|
|
|
endif
|
|
|
|
|
2011-12-09 18:49:21 -05:00
|
|
|
command! SyntasticToggleMode call s:ToggleMode()
|
|
|
|
command! SyntasticCheck call s:UpdateErrors(0) <bar> redraw!
|
2011-12-02 04:36:11 -05:00
|
|
|
command! Errors call s:ShowLocList()
|
2011-11-28 18:44:40 -05:00
|
|
|
|
2011-12-09 19:18:28 -05:00
|
|
|
highlight link SyntasticError SpellBad
|
|
|
|
highlight link SyntasticWarning SpellCap
|
|
|
|
|
2011-12-09 20:15:24 -05:00
|
|
|
augroup syntastic
|
|
|
|
if g:syntastic_echo_current_error
|
|
|
|
autocmd cursormoved * call s:EchoCurrentError()
|
|
|
|
endif
|
2011-12-09 20:18:20 -05:00
|
|
|
|
2011-12-24 04:44:01 -05:00
|
|
|
autocmd BufReadPost * if g:syntastic_check_on_open | call s:UpdateErrors(1) | endif
|
2011-12-23 19:33:07 -05:00
|
|
|
autocmd BufWritePost * call s:UpdateErrors(1)
|
2011-12-23 18:46:39 -05:00
|
|
|
|
2011-12-16 07:30:56 -05:00
|
|
|
autocmd BufWinEnter * if empty(&bt) | call s:AutoToggleLocList() | endif
|
2011-12-17 14:08:07 -05:00
|
|
|
autocmd BufWinLeave * if empty(&bt) | lclose | endif
|
2011-12-09 20:15:24 -05:00
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
2009-07-11 20:13:06 -04:00
|
|
|
"refresh and redraw all the error info for this buf when saving or reading
|
2011-11-28 18:44:40 -05:00
|
|
|
function! s:UpdateErrors(auto_invoked)
|
2011-12-16 11:28:06 -05:00
|
|
|
if !empty(&buftype)
|
2011-01-11 17:33:29 -05:00
|
|
|
return
|
|
|
|
endif
|
2011-11-28 18:44:40 -05:00
|
|
|
|
|
|
|
if !a:auto_invoked || s:ModeMapAllowsAutoChecking()
|
|
|
|
call s:CacheErrors()
|
|
|
|
end
|
2009-07-10 21:47:17 -04:00
|
|
|
|
2012-08-25 01:41:05 -04:00
|
|
|
call setloclist(0, s:LocList())
|
2011-12-23 08:56:49 -05:00
|
|
|
|
2011-12-02 04:53:49 -05:00
|
|
|
if g:syntastic_enable_balloons
|
|
|
|
call s:RefreshBalloons()
|
2011-05-02 19:21:16 -04:00
|
|
|
endif
|
|
|
|
|
2009-07-10 21:47:17 -04:00
|
|
|
if g:syntastic_enable_signs
|
2009-07-13 21:46:56 -04:00
|
|
|
call s:RefreshSigns()
|
2009-07-10 21:47:17 -04:00
|
|
|
endif
|
2009-07-13 05:38:50 -04:00
|
|
|
|
2012-10-01 10:10:53 -04:00
|
|
|
if g:syntastic_enable_highlighting
|
2012-09-27 08:44:23 -04:00
|
|
|
call s:HighlightErrors()
|
2012-03-02 05:05:15 -05:00
|
|
|
endif
|
|
|
|
|
2011-12-23 08:56:49 -05:00
|
|
|
if g:syntastic_auto_jump && s:BufHasErrorsOrWarningsToDisplay()
|
|
|
|
silent! ll
|
|
|
|
endif
|
|
|
|
|
2011-12-16 07:30:56 -05:00
|
|
|
call s:AutoToggleLocList()
|
|
|
|
endfunction
|
|
|
|
|
2011-12-23 08:56:49 -05:00
|
|
|
"automatically open/close the location list window depending on the users
|
|
|
|
"config and buffer error state
|
2011-12-24 06:05:51 -05:00
|
|
|
function! s:AutoToggleLocList()
|
2011-01-04 17:26:17 -05:00
|
|
|
if s:BufHasErrorsOrWarningsToDisplay()
|
2011-12-23 08:56:49 -05:00
|
|
|
if g:syntastic_auto_loc_list == 1
|
|
|
|
call s:ShowLocList()
|
2011-01-04 17:27:47 -05:00
|
|
|
endif
|
2011-12-23 08:56:49 -05:00
|
|
|
else
|
|
|
|
if g:syntastic_auto_loc_list > 0
|
2011-01-04 17:26:17 -05:00
|
|
|
|
2011-12-17 14:08:07 -05:00
|
|
|
"TODO: this will close the loc list window if one was opened by
|
|
|
|
"something other than syntastic
|
|
|
|
lclose
|
2009-07-13 07:12:18 -04:00
|
|
|
endif
|
2009-07-13 05:38:50 -04:00
|
|
|
endif
|
2009-07-10 19:09:52 -04:00
|
|
|
endfunction
|
|
|
|
|
2011-12-16 11:48:26 -05:00
|
|
|
"lazy init the loc list for the current buffer
|
|
|
|
function! s:LocList()
|
|
|
|
if !exists("b:syntastic_loclist")
|
|
|
|
let b:syntastic_loclist = []
|
|
|
|
endif
|
|
|
|
return b:syntastic_loclist
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"clear the loc list for the buffer
|
2012-02-18 10:54:22 -05:00
|
|
|
function! s:ClearCache()
|
2011-12-16 11:48:26 -05:00
|
|
|
let b:syntastic_loclist = []
|
2012-02-18 10:54:22 -05:00
|
|
|
unlet! b:syntastic_errors
|
|
|
|
unlet! b:syntastic_warnings
|
2011-12-16 11:48:26 -05:00
|
|
|
endfunction
|
2011-12-16 08:28:49 -05:00
|
|
|
|
2009-07-10 19:55:51 -04:00
|
|
|
"detect and cache all syntax errors in this buffer
|
|
|
|
"
|
2009-07-13 07:12:18 -04:00
|
|
|
"depends on a function called SyntaxCheckers_{&ft}_GetLocList() existing
|
2009-07-10 19:55:51 -04:00
|
|
|
"elsewhere
|
2011-11-28 18:44:40 -05:00
|
|
|
function! s:CacheErrors()
|
2012-02-18 10:54:22 -05:00
|
|
|
call s:ClearCache()
|
2009-07-10 19:09:52 -04:00
|
|
|
|
2009-09-20 06:45:06 -04:00
|
|
|
if filereadable(expand("%"))
|
2011-12-13 18:28:11 -05:00
|
|
|
|
|
|
|
"sub - for _ in filetypes otherwise we cant name syntax checker
|
|
|
|
"functions legally for filetypes like "gentoo-metadata"
|
2011-12-21 18:52:58 -05:00
|
|
|
let fts = substitute(&ft, '-', '_', 'g')
|
|
|
|
for ft in split(fts, '\.')
|
2012-09-06 04:08:52 -04:00
|
|
|
if SyntasticCheckable(ft)
|
2011-12-21 18:52:58 -05:00
|
|
|
let errors = SyntaxCheckers_{ft}_GetLocList()
|
2012-03-26 16:43:56 -04:00
|
|
|
"keep only lines that effectively match an error/warning
|
|
|
|
let errors = s:FilterLocList({'valid': 1}, errors)
|
2011-12-21 18:52:58 -05:00
|
|
|
"make errors have type "E" by default
|
|
|
|
call SyntasticAddToErrors(errors, {'type': 'E'})
|
|
|
|
call extend(s:LocList(), errors)
|
|
|
|
endif
|
|
|
|
endfor
|
2009-09-20 06:45:06 -04:00
|
|
|
endif
|
2009-07-10 19:09:52 -04:00
|
|
|
endfunction
|
|
|
|
|
2011-11-28 18:44:40 -05:00
|
|
|
"toggle the g:syntastic_mode_map['mode']
|
|
|
|
function! s:ToggleMode()
|
|
|
|
if g:syntastic_mode_map['mode'] == "active"
|
|
|
|
let g:syntastic_mode_map['mode'] = "passive"
|
|
|
|
else
|
|
|
|
let g:syntastic_mode_map['mode'] = "active"
|
|
|
|
endif
|
|
|
|
|
2012-02-18 10:54:22 -05:00
|
|
|
call s:ClearCache()
|
2011-12-15 08:42:42 -05:00
|
|
|
call s:UpdateErrors(1)
|
|
|
|
|
2011-11-28 18:44:40 -05:00
|
|
|
echo "Syntastic: " . g:syntastic_mode_map['mode'] . " mode enabled"
|
|
|
|
endfunction
|
|
|
|
|
2011-12-21 18:52:58 -05:00
|
|
|
"check the current filetypes against g:syntastic_mode_map to determine whether
|
2011-11-28 18:44:40 -05:00
|
|
|
"active mode syntax checking should be done
|
|
|
|
function! s:ModeMapAllowsAutoChecking()
|
2011-12-21 19:10:13 -05:00
|
|
|
let fts = split(&ft, '\.')
|
2011-12-21 18:52:58 -05:00
|
|
|
|
2011-12-21 19:10:13 -05:00
|
|
|
if g:syntastic_mode_map['mode'] == 'passive'
|
2011-12-21 18:52:58 -05:00
|
|
|
"check at least one filetype is active
|
2011-12-21 19:10:13 -05:00
|
|
|
let actives = g:syntastic_mode_map["active_filetypes"]
|
|
|
|
return !empty(filter(fts, 'index(actives, v:val) != -1'))
|
2011-11-28 18:44:40 -05:00
|
|
|
else
|
2011-12-21 18:52:58 -05:00
|
|
|
"check no filetypes are passive
|
2011-12-21 19:10:13 -05:00
|
|
|
let passives = g:syntastic_mode_map["passive_filetypes"]
|
|
|
|
return empty(filter(fts, 'index(passives, v:val) != -1'))
|
2011-11-28 18:44:40 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2009-07-19 22:59:54 -04:00
|
|
|
function! s:BufHasErrorsOrWarningsToDisplay()
|
2012-08-10 03:23:46 -04:00
|
|
|
if empty(s:LocList())
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
return len(s:Errors()) || !g:syntastic_quiet_warnings
|
2009-07-16 23:51:48 -04:00
|
|
|
endfunction
|
|
|
|
|
2011-12-15 17:31:19 -05:00
|
|
|
function! s:Errors()
|
2012-02-18 10:54:22 -05:00
|
|
|
if !exists("b:syntastic_errors")
|
|
|
|
let b:syntastic_errors = s:FilterLocList({'type': "E"})
|
|
|
|
endif
|
|
|
|
return b:syntastic_errors
|
2011-02-19 02:10:20 -05:00
|
|
|
endfunction
|
|
|
|
|
2011-12-15 17:31:19 -05:00
|
|
|
function! s:Warnings()
|
2012-02-18 10:54:22 -05:00
|
|
|
if !exists("b:syntastic_warnings")
|
|
|
|
let b:syntastic_warnings = s:FilterLocList({'type': "W"})
|
|
|
|
endif
|
|
|
|
return b:syntastic_warnings
|
2011-02-19 02:10:20 -05:00
|
|
|
endfunction
|
|
|
|
|
2011-12-16 11:57:06 -05:00
|
|
|
"Filter a loc list (defaults to s:LocList()) by a:filters
|
2011-12-15 17:52:35 -05:00
|
|
|
"e.g.
|
2011-12-16 11:57:06 -05:00
|
|
|
" s:FilterLocList({'bufnr': 10, 'type': 'e'})
|
2011-12-15 17:52:35 -05:00
|
|
|
"
|
2011-12-16 11:57:06 -05:00
|
|
|
"would return all errors in s:LocList() for buffer 10.
|
2011-12-15 17:52:35 -05:00
|
|
|
"
|
|
|
|
"Note that all comparisons are done with ==?
|
2011-12-16 11:57:06 -05:00
|
|
|
function! s:FilterLocList(filters, ...)
|
|
|
|
let llist = a:0 ? a:1 : s:LocList()
|
|
|
|
|
2012-02-18 10:36:44 -05:00
|
|
|
let rv = []
|
|
|
|
|
2011-12-16 11:57:06 -05:00
|
|
|
for error in llist
|
2012-02-18 10:36:44 -05:00
|
|
|
|
|
|
|
let passes_filters = 1
|
2011-12-15 17:52:35 -05:00
|
|
|
for key in keys(a:filters)
|
2012-02-18 10:36:44 -05:00
|
|
|
if error[key] !=? a:filters[key]
|
|
|
|
let passes_filters = 0
|
|
|
|
break
|
2011-12-15 17:52:35 -05:00
|
|
|
endif
|
|
|
|
endfor
|
2012-02-18 10:36:44 -05:00
|
|
|
|
|
|
|
if passes_filters
|
|
|
|
call add(rv, error)
|
|
|
|
endif
|
2011-12-15 17:52:35 -05:00
|
|
|
endfor
|
|
|
|
return rv
|
|
|
|
endfunction
|
|
|
|
|
2009-09-13 02:41:47 -04:00
|
|
|
if g:syntastic_enable_signs
|
2012-02-08 08:26:55 -05:00
|
|
|
"define the signs used to display syntax and style errors/warns
|
2012-07-09 07:09:30 -04:00
|
|
|
exe 'sign define SyntasticError text='.g:syntastic_error_symbol.' texthl=error'
|
|
|
|
exe 'sign define SyntasticWarning text='.g:syntastic_warning_symbol.' texthl=todo'
|
|
|
|
exe 'sign define SyntasticStyleError text='.g:syntastic_style_error_symbol.' texthl=error'
|
|
|
|
exe 'sign define SyntasticStyleWarning text='.g:syntastic_style_warning_symbol.' texthl=todo'
|
2009-09-13 02:41:47 -04:00
|
|
|
endif
|
2009-07-10 19:55:51 -04:00
|
|
|
|
|
|
|
"start counting sign ids at 5000, start here to hopefully avoid conflicting
|
2009-07-13 07:13:22 -04:00
|
|
|
"with any other code that places signs (not sure if this precaution is
|
2009-07-10 19:55:51 -04:00
|
|
|
"actually needed)
|
2009-07-10 19:09:52 -04:00
|
|
|
let s:first_sign_id = 5000
|
|
|
|
let s:next_sign_id = s:first_sign_id
|
|
|
|
|
2009-07-13 22:10:47 -04:00
|
|
|
"place signs by all syntax errs in the buffer
|
2011-12-15 17:31:19 -05:00
|
|
|
function! s:SignErrors()
|
2009-07-19 22:59:54 -04:00
|
|
|
if s:BufHasErrorsOrWarningsToDisplay()
|
2010-09-10 05:20:04 -04:00
|
|
|
|
2011-12-16 11:57:06 -05:00
|
|
|
let errors = s:FilterLocList({'bufnr': bufnr('')})
|
2011-12-15 17:52:35 -05:00
|
|
|
for i in errors
|
2012-01-27 14:43:48 -05:00
|
|
|
let sign_severity = 'Error'
|
|
|
|
let sign_subtype = ''
|
|
|
|
if has_key(i,'subtype')
|
|
|
|
let sign_subtype = i['subtype']
|
2009-07-13 22:10:47 -04:00
|
|
|
endif
|
2012-01-27 14:43:48 -05:00
|
|
|
if i['type'] ==? 'w'
|
|
|
|
let sign_severity = 'Warning'
|
|
|
|
endif
|
|
|
|
let sign_type = 'Syntastic' . sign_subtype . sign_severity
|
2009-07-13 22:10:47 -04:00
|
|
|
|
2011-12-15 17:52:35 -05:00
|
|
|
if !s:WarningMasksError(i, errors)
|
|
|
|
exec "sign place ". s:next_sign_id ." line=". i['lnum'] ." name=". sign_type ." file=". expand("%:p")
|
|
|
|
call add(s:BufSignIds(), s:next_sign_id)
|
|
|
|
let s:next_sign_id += 1
|
|
|
|
endif
|
2009-07-10 19:09:52 -04:00
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-12-15 17:52:35 -05:00
|
|
|
"return true if the given error item is a warning that, if signed, would
|
|
|
|
"potentially mask an error if displayed at the same time
|
|
|
|
function! s:WarningMasksError(error, llist)
|
|
|
|
if a:error['type'] !=? 'w'
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2011-12-16 11:57:06 -05:00
|
|
|
return len(s:FilterLocList({ 'type': "E", 'lnum': a:error['lnum'] }, a:llist)) > 0
|
2011-12-15 17:52:35 -05:00
|
|
|
endfunction
|
|
|
|
|
2009-07-13 21:46:56 -04:00
|
|
|
"remove the signs with the given ids from this buffer
|
|
|
|
function! s:RemoveSigns(ids)
|
|
|
|
for i in a:ids
|
2009-07-10 19:09:52 -04:00
|
|
|
exec "sign unplace " . i
|
2009-07-13 21:46:56 -04:00
|
|
|
call remove(s:BufSignIds(), index(s:BufSignIds(), i))
|
2009-07-10 19:09:52 -04:00
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2009-07-10 19:55:51 -04:00
|
|
|
"get all the ids of the SyntaxError signs in the buffer
|
2009-07-10 19:09:52 -04:00
|
|
|
function! s:BufSignIds()
|
|
|
|
if !exists("b:syntastic_sign_ids")
|
|
|
|
let b:syntastic_sign_ids = []
|
|
|
|
endif
|
|
|
|
return b:syntastic_sign_ids
|
|
|
|
endfunction
|
|
|
|
|
2009-07-13 21:46:56 -04:00
|
|
|
"update the error signs
|
|
|
|
function! s:RefreshSigns()
|
|
|
|
let old_signs = copy(s:BufSignIds())
|
|
|
|
call s:SignErrors()
|
|
|
|
call s:RemoveSigns(old_signs)
|
|
|
|
let s:first_sign_id = s:next_sign_id
|
|
|
|
endfunction
|
|
|
|
|
2009-07-13 07:12:18 -04:00
|
|
|
"display the cached errors for this buf in the location list
|
|
|
|
function! s:ShowLocList()
|
2011-12-16 11:48:26 -05:00
|
|
|
if !empty(s:LocList())
|
2012-07-24 07:21:29 -04:00
|
|
|
call setloclist(0, s:LocList())
|
2009-09-13 20:39:27 -04:00
|
|
|
let num = winnr()
|
2012-02-10 12:56:32 -05:00
|
|
|
exec "lopen " . g:syntastic_loc_list_height
|
2009-09-13 20:39:27 -04:00
|
|
|
if num != winnr()
|
|
|
|
wincmd p
|
|
|
|
endif
|
2009-07-10 19:09:52 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2012-03-02 05:05:15 -05:00
|
|
|
"highlight the current errors using matchadd()
|
|
|
|
"
|
|
|
|
"The function `Syntastic_{&ft}_GetHighlightRegex` is used to get the regex to
|
|
|
|
"highlight errors that do not have a 'col' key (and hence cant be done
|
|
|
|
"automatically). This function must take one arg (an error item) and return a
|
|
|
|
"regex to match that item in the buffer.
|
|
|
|
"
|
|
|
|
"If the 'force_highlight_callback' key is set for an error item, then invoke
|
|
|
|
"the callback even if it can be highlighted automatically.
|
2012-09-27 08:44:23 -04:00
|
|
|
function! s:HighlightErrors()
|
2012-03-02 05:05:15 -05:00
|
|
|
call s:ClearErrorHighlights()
|
|
|
|
|
|
|
|
let fts = substitute(&ft, '-', '_', 'g')
|
|
|
|
for ft in split(fts, '\.')
|
|
|
|
|
|
|
|
for item in s:LocList()
|
|
|
|
|
|
|
|
let force_callback = has_key(item, 'force_highlight_callback') && item['force_highlight_callback']
|
|
|
|
|
|
|
|
let group = item['type'] == 'E' ? 'SyntasticError' : 'SyntasticWarning'
|
2012-03-20 17:41:33 -04:00
|
|
|
if get( item, 'col' ) && !force_callback
|
2012-03-02 05:05:15 -05:00
|
|
|
let lastcol = col([item['lnum'], '$'])
|
|
|
|
let lcol = min([lastcol, item['col']])
|
|
|
|
call matchadd(group, '\%'.item['lnum'].'l\%'.lcol.'c')
|
|
|
|
else
|
|
|
|
|
|
|
|
if exists("*SyntaxCheckers_". ft ."_GetHighlightRegex")
|
|
|
|
let term = SyntaxCheckers_{ft}_GetHighlightRegex(item)
|
|
|
|
if len(term) > 0
|
|
|
|
call matchadd(group, '\%' . item['lnum'] . 'l' . term)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2011-12-08 15:34:11 -05:00
|
|
|
"remove all error highlights from the window
|
2011-11-30 14:23:31 -05:00
|
|
|
function! s:ClearErrorHighlights()
|
2011-12-09 19:18:28 -05:00
|
|
|
for match in getmatches()
|
|
|
|
if stridx(match['group'], 'Syntastic') == 0
|
|
|
|
call matchdelete(match['id'])
|
|
|
|
endif
|
2011-11-30 14:23:31 -05:00
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2011-12-08 15:34:11 -05:00
|
|
|
"set up error ballons for the current set of errors
|
|
|
|
function! s:RefreshBalloons()
|
|
|
|
let b:syntastic_balloons = {}
|
2011-12-09 08:31:10 -05:00
|
|
|
if s:BufHasErrorsOrWarningsToDisplay()
|
2011-12-16 11:48:26 -05:00
|
|
|
for i in s:LocList()
|
2011-12-08 15:34:11 -05:00
|
|
|
let b:syntastic_balloons[i['lnum']] = i['text']
|
|
|
|
endfor
|
|
|
|
set beval bexpr=SyntasticErrorBalloonExpr()
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-12-09 20:15:24 -05:00
|
|
|
"print as much of a:msg as possible without "Press Enter" prompt appearing
|
|
|
|
function! s:WideMsg(msg)
|
|
|
|
let old_ruler = &ruler
|
|
|
|
let old_showcmd = &showcmd
|
|
|
|
|
2012-10-25 20:01:31 -04:00
|
|
|
"convert tabs to spaces so that the tabs count towards the window width
|
|
|
|
"as the proper amount of characters
|
2012-10-25 17:20:07 -04:00
|
|
|
let msg = substitute(a:msg, "\t", repeat(" ", &tabstop), "g")
|
|
|
|
let msg = strpart(msg, 0, winwidth(0)-1)
|
2011-12-11 04:26:55 -05:00
|
|
|
|
|
|
|
"This is here because it is possible for some error messages to begin with
|
|
|
|
"\n which will cause a "press enter" prompt. I have noticed this in the
|
|
|
|
"javascript:jshint checker and have been unable to figure out why it
|
|
|
|
"happens
|
|
|
|
let msg = substitute(msg, "\n", "", "g")
|
|
|
|
|
2011-12-09 20:15:24 -05:00
|
|
|
set noruler noshowcmd
|
|
|
|
redraw
|
2011-12-11 04:26:55 -05:00
|
|
|
|
|
|
|
echo msg
|
2011-12-09 20:15:24 -05:00
|
|
|
|
|
|
|
let &ruler=old_ruler
|
|
|
|
let &showcmd=old_showcmd
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"echo out the first error we find for the current line in the cmd window
|
|
|
|
function! s:EchoCurrentError()
|
|
|
|
"If we have an error or warning at the current line, show it
|
2011-12-16 11:57:06 -05:00
|
|
|
let errors = s:FilterLocList({'lnum': line("."), "type": 'e'})
|
|
|
|
let warnings = s:FilterLocList({'lnum': line("."), "type": 'w'})
|
2011-12-15 18:08:39 -05:00
|
|
|
|
|
|
|
let b:syntastic_echoing_error = len(errors) || len(warnings)
|
|
|
|
if len(errors)
|
|
|
|
return s:WideMsg(errors[0]['text'])
|
|
|
|
endif
|
|
|
|
if len(warnings)
|
|
|
|
return s:WideMsg(warnings[0]['text'])
|
|
|
|
endif
|
2011-12-09 20:15:24 -05:00
|
|
|
|
|
|
|
"Otherwise, clear the status line
|
2011-12-19 18:02:50 -05:00
|
|
|
if b:syntastic_echoing_error
|
2011-12-11 04:32:36 -05:00
|
|
|
echo
|
2011-12-19 18:02:50 -05:00
|
|
|
let b:syntastic_echoing_error = 0
|
2011-12-11 04:32:36 -05:00
|
|
|
endif
|
2011-12-09 20:15:24 -05:00
|
|
|
endfunction
|
|
|
|
|
2012-02-06 12:46:08 -05:00
|
|
|
"load the chosen checker for the current filetype - useful for filetypes like
|
|
|
|
"javascript that have more than one syntax checker
|
2012-03-21 05:42:11 -04:00
|
|
|
function! s:LoadChecker(checker, ft)
|
|
|
|
exec "runtime syntax_checkers/" . a:ft . "/" . a:checker . ".vim"
|
2012-02-06 12:46:08 -05:00
|
|
|
endfunction
|
|
|
|
|
2012-07-01 17:48:54 -04:00
|
|
|
"the script changes &shellpipe and &shell to stop the screen flicking when
|
|
|
|
"shelling out to syntax checkers. Not all OSs support the hacks though
|
|
|
|
function! s:OSSupportsShellpipeHack()
|
2012-10-23 18:02:00 -04:00
|
|
|
return !s:running_windows && (s:uname() !~ "FreeBSD") && (s:uname() !~ "OpenBSD")
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:IsRedrawRequiredAfterMake()
|
|
|
|
return !s:running_windows && (s:uname() =~ "FreeBSD" || s:uname() =~ "OpenBSD")
|
2012-07-01 17:48:54 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-09-24 13:53:15 -04:00
|
|
|
function! s:uname()
|
|
|
|
if !exists('s:uname')
|
|
|
|
let s:uname = system('uname')
|
|
|
|
endif
|
|
|
|
return s:uname
|
|
|
|
endfunction
|
|
|
|
|
2012-09-17 19:41:36 -04:00
|
|
|
"check if a syntax checker exists for the given filetype - and attempt to
|
|
|
|
"load one
|
|
|
|
function! SyntasticCheckable(ft)
|
|
|
|
if !exists("g:loaded_" . a:ft . "_syntax_checker")
|
|
|
|
exec "runtime syntax_checkers/" . a:ft . ".vim"
|
|
|
|
endif
|
|
|
|
|
|
|
|
return exists("*SyntaxCheckers_". a:ft ."_GetLocList")
|
|
|
|
endfunction
|
|
|
|
|
2012-09-22 14:51:12 -04:00
|
|
|
"the args must be arrays of the form [major, minor, macro]
|
|
|
|
function SyntasticIsVersionAtLeast(installed, required)
|
|
|
|
if a:installed[0] != a:required[0]
|
|
|
|
return a:installed[0] > a:required[0]
|
|
|
|
endif
|
|
|
|
|
|
|
|
if a:installed[1] != a:required[1]
|
|
|
|
return a:installed[1] > a:required[1]
|
|
|
|
endif
|
|
|
|
|
|
|
|
return a:installed[2] >= a:required[2]
|
|
|
|
endfunction
|
|
|
|
|
2011-02-19 02:10:20 -05:00
|
|
|
"return a string representing the state of buffer according to
|
|
|
|
"g:syntastic_stl_format
|
2009-07-10 19:55:51 -04:00
|
|
|
"
|
|
|
|
"return '' if no errors are cached for the buffer
|
|
|
|
function! SyntasticStatuslineFlag()
|
2009-07-19 22:59:54 -04:00
|
|
|
if s:BufHasErrorsOrWarningsToDisplay()
|
2011-02-19 02:10:20 -05:00
|
|
|
let errors = s:Errors()
|
|
|
|
let warnings = s:Warnings()
|
2009-07-19 22:59:54 -04:00
|
|
|
|
2012-02-18 10:38:27 -05:00
|
|
|
let num_errors = len(errors)
|
|
|
|
let num_warnings = len(warnings)
|
|
|
|
|
2011-02-19 02:10:20 -05:00
|
|
|
let output = g:syntastic_stl_format
|
2009-07-19 22:59:54 -04:00
|
|
|
|
2011-02-19 02:10:20 -05:00
|
|
|
"hide stuff wrapped in %E(...) unless there are errors
|
2012-02-18 10:38:27 -05:00
|
|
|
let output = substitute(output, '\C%E{\([^}]*\)}', num_errors ? '\1' : '' , 'g')
|
2009-07-19 22:59:54 -04:00
|
|
|
|
2011-02-19 02:10:20 -05:00
|
|
|
"hide stuff wrapped in %W(...) unless there are warnings
|
2012-02-18 10:38:27 -05:00
|
|
|
let output = substitute(output, '\C%W{\([^}]*\)}', num_warnings ? '\1' : '' , 'g')
|
2009-07-19 22:59:54 -04:00
|
|
|
|
2011-02-19 02:10:20 -05:00
|
|
|
"hide stuff wrapped in %B(...) unless there are both errors and warnings
|
2012-02-18 10:38:27 -05:00
|
|
|
let output = substitute(output, '\C%B{\([^}]*\)}', (num_warnings && num_errors) ? '\1' : '' , 'g')
|
2011-02-19 02:10:20 -05:00
|
|
|
|
|
|
|
"sub in the total errors/warnings/both
|
2012-02-18 10:38:27 -05:00
|
|
|
let output = substitute(output, '\C%w', num_warnings, 'g')
|
|
|
|
let output = substitute(output, '\C%e', num_errors, 'g')
|
2011-12-16 11:48:26 -05:00
|
|
|
let output = substitute(output, '\C%t', len(s:LocList()), 'g')
|
2011-02-19 02:10:20 -05:00
|
|
|
|
|
|
|
"first error/warning line num
|
2011-12-16 11:48:26 -05:00
|
|
|
let output = substitute(output, '\C%F', s:LocList()[0]['lnum'], 'g')
|
2011-02-19 02:10:20 -05:00
|
|
|
|
|
|
|
"first error line num
|
2012-02-18 10:38:27 -05:00
|
|
|
let output = substitute(output, '\C%fe', num_errors ? errors[0]['lnum'] : '', 'g')
|
2009-07-19 22:59:54 -04:00
|
|
|
|
2011-02-19 02:10:20 -05:00
|
|
|
"first warning line num
|
2012-02-18 10:38:27 -05:00
|
|
|
let output = substitute(output, '\C%fw', num_warnings ? warnings[0]['lnum'] : '', 'g')
|
2009-07-19 22:59:54 -04:00
|
|
|
|
2011-02-19 02:10:20 -05:00
|
|
|
return output
|
2009-07-10 19:09:52 -04:00
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endfunction
|
2009-07-10 19:55:51 -04:00
|
|
|
|
2009-07-15 05:28:44 -04:00
|
|
|
"A wrapper for the :lmake command. Sets up the make environment according to
|
|
|
|
"the options given, runs make, resets the environment, returns the location
|
|
|
|
"list
|
|
|
|
"
|
|
|
|
"a:options can contain the following keys:
|
|
|
|
" 'makeprg'
|
|
|
|
" 'errorformat'
|
|
|
|
"
|
|
|
|
"The corresponding options are set for the duration of the function call. They
|
|
|
|
"are set with :let, so dont escape spaces.
|
2011-12-09 08:44:54 -05:00
|
|
|
"
|
|
|
|
"a:options may also contain:
|
|
|
|
" 'defaults' - a dict containing default values for the returned errors
|
2012-02-08 08:26:55 -05:00
|
|
|
" 'subtype' - all errors will be assigned the given subtype
|
2009-07-15 05:28:44 -04:00
|
|
|
function! SyntasticMake(options)
|
2009-07-29 00:07:04 -04:00
|
|
|
let old_loclist = getloclist(0)
|
2012-04-08 02:19:05 -04:00
|
|
|
let old_makeprg = &l:makeprg
|
2009-07-15 05:28:44 -04:00
|
|
|
let old_shellpipe = &shellpipe
|
2011-02-17 15:53:53 -05:00
|
|
|
let old_shell = &shell
|
2012-04-08 02:19:05 -04:00
|
|
|
let old_errorformat = &l:errorformat
|
2009-07-15 05:28:44 -04:00
|
|
|
|
2012-07-01 17:48:54 -04:00
|
|
|
if s:OSSupportsShellpipeHack()
|
2009-07-15 05:28:44 -04:00
|
|
|
"this is a hack to stop the screen needing to be ':redraw'n when
|
|
|
|
"when :lmake is run. Otherwise the screen flickers annoyingly
|
|
|
|
let &shellpipe='&>'
|
2011-02-17 15:53:53 -05:00
|
|
|
let &shell = '/bin/bash'
|
2009-07-15 05:28:44 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(a:options, 'makeprg')
|
2012-04-08 02:19:05 -04:00
|
|
|
let &l:makeprg = a:options['makeprg']
|
2009-07-15 05:28:44 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(a:options, 'errorformat')
|
2012-04-08 02:19:05 -04:00
|
|
|
let &l:errorformat = a:options['errorformat']
|
2009-07-15 05:28:44 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
silent lmake!
|
|
|
|
let errors = getloclist(0)
|
|
|
|
|
2009-07-29 00:07:04 -04:00
|
|
|
call setloclist(0, old_loclist)
|
2012-04-08 02:19:05 -04:00
|
|
|
let &l:makeprg = old_makeprg
|
|
|
|
let &l:errorformat = old_errorformat
|
2009-07-15 05:28:44 -04:00
|
|
|
let &shellpipe=old_shellpipe
|
2011-02-17 16:02:31 -05:00
|
|
|
let &shell=old_shell
|
2011-02-17 15:53:53 -05:00
|
|
|
|
2012-10-23 18:02:00 -04:00
|
|
|
if s:IsRedrawRequiredAfterMake()
|
2011-09-19 16:10:53 -04:00
|
|
|
redraw!
|
|
|
|
endif
|
|
|
|
|
2011-12-09 08:44:54 -05:00
|
|
|
if has_key(a:options, 'defaults')
|
|
|
|
call SyntasticAddToErrors(errors, a:options['defaults'])
|
|
|
|
endif
|
|
|
|
|
2012-02-08 08:25:11 -05:00
|
|
|
" Add subtype info if present.
|
|
|
|
if has_key(a:options, 'subtype')
|
|
|
|
call SyntasticAddToErrors(errors, {'subtype': a:options['subtype']})
|
|
|
|
endif
|
|
|
|
|
2009-07-15 05:28:44 -04:00
|
|
|
return errors
|
|
|
|
endfunction
|
|
|
|
|
2011-12-08 15:34:11 -05:00
|
|
|
"get the error balloon for the current mouse position
|
2011-11-30 14:23:31 -05:00
|
|
|
function! SyntasticErrorBalloonExpr()
|
2011-12-08 15:34:11 -05:00
|
|
|
if !exists('b:syntastic_balloons')
|
|
|
|
return ''
|
|
|
|
endif
|
2011-11-30 14:23:31 -05:00
|
|
|
return get(b:syntastic_balloons, v:beval_lnum, '')
|
|
|
|
endfunction
|
|
|
|
|
2011-12-09 08:44:54 -05:00
|
|
|
"take a list of errors and add default values to them from a:options
|
|
|
|
function! SyntasticAddToErrors(errors, options)
|
|
|
|
for i in range(0, len(a:errors)-1)
|
|
|
|
for key in keys(a:options)
|
2012-01-27 14:43:48 -05:00
|
|
|
if !has_key(a:errors[i], key) || empty(a:errors[i][key])
|
2011-12-09 08:44:54 -05:00
|
|
|
let a:errors[i][key] = a:options[key]
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
return a:errors
|
|
|
|
endfunction
|
|
|
|
|
2012-02-06 12:46:08 -05:00
|
|
|
"take a list of syntax checkers for the current filetype and load the right
|
|
|
|
"one based on the global settings and checker executable availabity
|
|
|
|
"
|
|
|
|
"a:checkers should be a list of syntax checker names. These names are assumed
|
|
|
|
"to be the names of the vim syntax checker files that should be sourced, as
|
|
|
|
"well as the names of the actual syntax checker executables. The checkers
|
|
|
|
"should be listed in order of default preference.
|
|
|
|
"
|
2012-03-21 05:42:11 -04:00
|
|
|
"a:ft should be the filetype for the checkers being loaded
|
|
|
|
"
|
|
|
|
"if a option called 'g:syntastic_{a:ft}_checker' exists then attempt to
|
2012-02-06 12:46:08 -05:00
|
|
|
"load the checker that it points to
|
2012-03-21 05:42:11 -04:00
|
|
|
function! SyntasticLoadChecker(checkers, ft)
|
|
|
|
let opt_name = "g:syntastic_" . a:ft . "_checker"
|
2012-02-06 12:46:08 -05:00
|
|
|
|
|
|
|
if exists(opt_name)
|
|
|
|
let opt_val = {opt_name}
|
2012-05-07 15:23:43 -04:00
|
|
|
if index(a:checkers, opt_val) != -1
|
2012-03-21 05:42:11 -04:00
|
|
|
call s:LoadChecker(opt_val, a:ft)
|
2012-02-06 12:46:08 -05:00
|
|
|
else
|
|
|
|
echoerr &ft . " syntax not supported or not installed."
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
for checker in a:checkers
|
|
|
|
if executable(checker)
|
2012-03-21 05:42:11 -04:00
|
|
|
return s:LoadChecker(checker, a:ft)
|
2012-02-06 12:46:08 -05:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2009-07-10 19:55:51 -04:00
|
|
|
" vim: set et sts=4 sw=4:
|