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>
|
2011-12-01 19:27:14 -05:00
|
|
|
"Version: 2.0.0
|
|
|
|
"Last Change: 2 Dec, 2011
|
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
|
|
|
|
|
|
|
|
let s:running_windows = has("win16") || has("win32") || has("win64")
|
|
|
|
|
2011-08-16 13:46:39 -04:00
|
|
|
if !s:running_windows
|
|
|
|
let s:uname = system('uname')
|
|
|
|
endif
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
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-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
|
|
|
|
|
|
|
autocmd bufreadpost,bufwritepost * call s:UpdateErrors(1)
|
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-01-11 17:33:29 -05:00
|
|
|
if &buftype == 'quickfix'
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2011-01-04 17:26:17 -05:00
|
|
|
if s:BufHasErrorsOrWarningsToDisplay()
|
|
|
|
call setloclist(0, b:syntastic_loclist)
|
2011-01-04 17:27:47 -05:00
|
|
|
if g:syntastic_auto_jump
|
2011-11-29 03:44:51 -05:00
|
|
|
silent! ll
|
2011-01-04 17:27:47 -05:00
|
|
|
endif
|
2011-02-15 22:49:54 -05:00
|
|
|
elseif g:syntastic_auto_loc_list == 2
|
2011-02-14 16:25:33 -05:00
|
|
|
lclose
|
2011-01-04 17:26:17 -05:00
|
|
|
endif
|
|
|
|
|
2011-02-15 22:49:54 -05:00
|
|
|
if g:syntastic_auto_loc_list == 1
|
2009-07-19 22:59:54 -04:00
|
|
|
if s:BufHasErrorsOrWarningsToDisplay()
|
2009-07-13 07:12:18 -04:00
|
|
|
call s:ShowLocList()
|
|
|
|
else
|
2009-07-13 07:23:04 -04:00
|
|
|
"TODO: this will close the loc list window if one was opened by
|
|
|
|
"something other than syntastic
|
2009-07-13 07:12:18 -04:00
|
|
|
lclose
|
|
|
|
endif
|
2009-07-13 05:38:50 -04:00
|
|
|
endif
|
2009-07-10 19:09:52 -04:00
|
|
|
endfunction
|
|
|
|
|
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()
|
2009-07-13 07:12:18 -04:00
|
|
|
let b:syntastic_loclist = []
|
2009-07-10 19:09:52 -04:00
|
|
|
|
2009-09-20 06:45:06 -04:00
|
|
|
if filereadable(expand("%"))
|
|
|
|
for ft in split(&ft, '\.')
|
2011-11-28 18:44:40 -05:00
|
|
|
if s:Checkable(ft)
|
2009-09-20 06:45:06 -04:00
|
|
|
let b:syntastic_loclist = extend(b:syntastic_loclist, SyntaxCheckers_{ft}_GetLocList())
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
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
|
|
|
|
|
|
|
|
echo "Syntastic: " . g:syntastic_mode_map['mode'] . " mode enabled"
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"check the current filetypes against g:syntastic_mode_map to determine whether
|
|
|
|
"active mode syntax checking should be done
|
|
|
|
function! s:ModeMapAllowsAutoChecking()
|
|
|
|
if g:syntastic_mode_map['mode'] == 'passive'
|
|
|
|
|
|
|
|
"check at least one filetype is active
|
|
|
|
for ft in split(&ft, '\.')
|
|
|
|
if index(g:syntastic_mode_map['active_filetypes'], ft) != -1
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
|
|
|
endfor
|
|
|
|
else
|
|
|
|
|
|
|
|
"check no filetypes are passive
|
|
|
|
for ft in split(&ft, '\.')
|
|
|
|
if index(g:syntastic_mode_map['passive_filetypes'], ft) != -1
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
return 1
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2009-07-17 00:13:27 -04:00
|
|
|
"return true if there are cached errors/warnings for this buf
|
2009-07-16 23:51:48 -04:00
|
|
|
function! s:BufHasErrorsOrWarnings()
|
2009-07-13 07:12:18 -04:00
|
|
|
return exists("b:syntastic_loclist") && !empty(b:syntastic_loclist)
|
2009-07-10 19:09:52 -04:00
|
|
|
endfunction
|
|
|
|
|
2009-07-17 00:13:27 -04:00
|
|
|
"return true if there are cached errors for this buf
|
2009-07-16 23:51:48 -04:00
|
|
|
function! s:BufHasErrors()
|
2009-07-19 22:59:54 -04:00
|
|
|
return len(s:ErrorsForType('E')) > 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:BufHasErrorsOrWarningsToDisplay()
|
|
|
|
return s:BufHasErrors() || (!g:syntastic_quiet_warnings && s:BufHasErrorsOrWarnings())
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:ErrorsForType(type)
|
|
|
|
if !exists("b:syntastic_loclist")
|
|
|
|
return []
|
2009-07-16 23:51:48 -04:00
|
|
|
endif
|
2011-02-11 07:15:00 -05:00
|
|
|
return filter(copy(b:syntastic_loclist), 'v:val["type"] ==? "' . a:type . '"')
|
2009-07-16 23:51:48 -04:00
|
|
|
endfunction
|
|
|
|
|
2011-02-19 02:10:20 -05:00
|
|
|
function s:Errors()
|
|
|
|
return extend(s:ErrorsForType("E"), s:ErrorsForType(''))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function s:Warnings()
|
|
|
|
return s:ErrorsForType("W")
|
|
|
|
endfunction
|
|
|
|
|
2009-09-13 02:41:47 -04:00
|
|
|
if g:syntastic_enable_signs
|
|
|
|
"use >> to display syntax errors in the sign column
|
|
|
|
sign define SyntasticError text=>> texthl=error
|
|
|
|
sign define SyntasticWarning text=>> texthl=todo
|
|
|
|
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
|
2009-07-10 19:09:52 -04:00
|
|
|
function s:SignErrors()
|
2009-07-19 22:59:54 -04:00
|
|
|
if s:BufHasErrorsOrWarningsToDisplay()
|
2009-07-13 07:12:18 -04:00
|
|
|
for i in b:syntastic_loclist
|
2010-09-10 05:20:04 -04:00
|
|
|
if i['bufnr'] != bufnr("")
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2009-07-13 22:10:47 -04:00
|
|
|
let sign_type = 'SyntasticError'
|
|
|
|
if i['type'] == 'W'
|
|
|
|
let sign_type = 'SyntasticWarning'
|
|
|
|
endif
|
|
|
|
|
|
|
|
exec "sign place ". s:next_sign_id ." line=". i['lnum'] ." name=". sign_type ." file=". expand("%:p")
|
2009-07-10 19:09:52 -04:00
|
|
|
call add(s:BufSignIds(), s:next_sign_id)
|
|
|
|
let s:next_sign_id += 1
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
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()
|
|
|
|
if exists("b:syntastic_loclist")
|
2009-09-13 20:39:27 -04:00
|
|
|
let num = winnr()
|
2009-07-13 07:12:18 -04:00
|
|
|
lopen
|
2009-09-13 20:39:27 -04:00
|
|
|
if num != winnr()
|
|
|
|
wincmd p
|
|
|
|
endif
|
2009-07-10 19:09:52 -04:00
|
|
|
endif
|
|
|
|
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
|
|
|
"check if a syntax checker exists for the given filetype - and attempt to
|
|
|
|
"load one
|
|
|
|
function! s:Checkable(ft)
|
|
|
|
if !exists("g:loaded_" . a:ft . "_syntax_checker")
|
|
|
|
exec "runtime syntax_checkers/" . a:ft . ".vim"
|
|
|
|
endif
|
|
|
|
|
|
|
|
return exists("*SyntaxCheckers_". a:ft ."_GetLocList")
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"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-08 15:34:11 -05:00
|
|
|
for i in b:syntastic_loclist
|
|
|
|
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
|
|
|
|
|
|
|
|
set noruler noshowcmd
|
|
|
|
redraw
|
|
|
|
echo strpart(a:msg, 0, winwidth(0)-1)
|
|
|
|
|
|
|
|
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 !exists('b:syntastic_loclist')
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
"If we have an error or warning at the current line, show it
|
|
|
|
let lnum = line(".")
|
|
|
|
for i in b:syntastic_loclist
|
|
|
|
if lnum == i['lnum']
|
|
|
|
return s:WideMsg(i['text'])
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
"Otherwise, clear the status line
|
|
|
|
echo
|
|
|
|
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
|
|
|
|
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
|
|
|
|
let output = substitute(output, '\C%E{\([^}]*\)}', len(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
|
|
|
|
let output = substitute(output, '\C%W{\([^}]*\)}', len(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
|
|
|
|
let output = substitute(output, '\C%B{\([^}]*\)}', (len(warnings) && len(errors)) ? '\1' : '' , 'g')
|
|
|
|
|
|
|
|
"sub in the total errors/warnings/both
|
|
|
|
let output = substitute(output, '\C%w', len(warnings), 'g')
|
|
|
|
let output = substitute(output, '\C%e', len(errors), 'g')
|
|
|
|
let output = substitute(output, '\C%t', len(b:syntastic_loclist), 'g')
|
|
|
|
|
|
|
|
"first error/warning line num
|
|
|
|
let output = substitute(output, '\C%F', b:syntastic_loclist[0]['lnum'], 'g')
|
|
|
|
|
|
|
|
"first error line num
|
|
|
|
let output = substitute(output, '\C%fe', len(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
|
|
|
|
let output = substitute(output, '\C%fw', len(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
|
2009-07-15 05:28:44 -04:00
|
|
|
function! SyntasticMake(options)
|
2009-07-29 00:07:04 -04:00
|
|
|
let old_loclist = getloclist(0)
|
2009-07-15 05:28:44 -04:00
|
|
|
let old_makeprg = &makeprg
|
|
|
|
let old_shellpipe = &shellpipe
|
2011-02-17 15:53:53 -05:00
|
|
|
let old_shell = &shell
|
2009-07-15 05:28:44 -04:00
|
|
|
let old_errorformat = &errorformat
|
|
|
|
|
2011-08-16 13:46:39 -04:00
|
|
|
if !s:running_windows && (s:uname !~ "FreeBSD")
|
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')
|
|
|
|
let &makeprg = a:options['makeprg']
|
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(a:options, 'errorformat')
|
|
|
|
let &errorformat = a:options['errorformat']
|
|
|
|
endif
|
|
|
|
|
|
|
|
silent lmake!
|
|
|
|
let errors = getloclist(0)
|
|
|
|
|
2009-07-29 00:07:04 -04:00
|
|
|
call setloclist(0, old_loclist)
|
2009-07-15 05:28:44 -04:00
|
|
|
let &makeprg = old_makeprg
|
|
|
|
let &errorformat = old_errorformat
|
|
|
|
let &shellpipe=old_shellpipe
|
2011-02-17 16:02:31 -05:00
|
|
|
let &shell=old_shell
|
2011-02-17 15:53:53 -05:00
|
|
|
|
2011-11-28 18:38:45 -05:00
|
|
|
if !s:running_windows && s:uname =~ "FreeBSD"
|
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
|
|
|
|
|
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-08 15:34:11 -05:00
|
|
|
"highlight the list of errors (a:errors) using matchadd()
|
|
|
|
"
|
|
|
|
"a:termfunc is provided 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.
|
|
|
|
"
|
|
|
|
"an optional boolean third argument can be provided to force a:termfunc to be
|
|
|
|
"used regardless of whether a 'col' key is present for the error
|
2011-11-30 14:23:31 -05:00
|
|
|
function! SyntasticHighlightErrors(errors, termfunc, ...)
|
2011-12-08 17:23:51 -05:00
|
|
|
if !g:syntastic_enable_highlighting
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2011-11-30 14:23:31 -05:00
|
|
|
call s:ClearErrorHighlights()
|
|
|
|
|
2011-12-08 15:34:11 -05:00
|
|
|
let force_callback = a:0 && a:1
|
2011-11-30 14:23:31 -05:00
|
|
|
for item in a:errors
|
2011-12-09 19:18:28 -05:00
|
|
|
let group = item['type'] == 'E' ? 'SyntasticError' : 'SyntasticWarning'
|
2011-12-08 15:34:11 -05:00
|
|
|
if item['col'] && !force_callback
|
2011-11-30 14:23:31 -05:00
|
|
|
let lastcol = col([item['lnum'], '$'])
|
|
|
|
let lcol = min([lastcol, item['col']])
|
2011-12-09 19:18:28 -05:00
|
|
|
call matchadd(group, '\%'.item['lnum'].'l\%'.lcol.'c')
|
2011-11-30 14:23:31 -05:00
|
|
|
else
|
|
|
|
let term = a:termfunc(item)
|
|
|
|
if len(term) > 0
|
2011-12-09 19:18:28 -05:00
|
|
|
call matchadd(group, '\%' . item['lnum'] . 'l' . term)
|
2011-11-30 14:23:31 -05:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
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)
|
|
|
|
if empty(a:errors[i][key])
|
|
|
|
let a:errors[i][key] = a:options[key]
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
return a:errors
|
|
|
|
endfunction
|
|
|
|
|
2009-07-10 19:55:51 -04:00
|
|
|
" vim: set et sts=4 sw=4:
|