forked from adamhjk/adam-vim
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathruby_stl_syntax_warning.vim
54 lines (49 loc) · 2.09 KB
/
ruby_stl_syntax_warning.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
" ============================================================================
" File: ruby_stl_syntax_warning.vim
" Description: filtype plugin for ruby to add a syntax check flag to the
" statusline
" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
" Last Change: 22 Jun, 2009
" 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.
"
" ============================================================================
if exists("b:did_ruby_stl_syntax_warning_ftplugin") || &filetype !~ '\<ruby\>'
finish
endif
let b:did_ruby_stl_syntax_warning_ftplugin = 1
"bail if the user doesnt have ruby installed
if !executable("ruby")
finish
endif
"inject the syntax warning into the statusline
let &l:statusline = substitute(&statusline, '\(%=\)',
\ '%#warningmsg#%{StatuslineRubySyntaxWarning()}%*\1', '')
"recalculate after saving
autocmd bufwritepost * unlet! b:statusline_ruby_syntax_warning
"run the buffer through ruby -c
"
"return '' if no syntax errors detected
"return '[syntax:xxx]' if errors are detected, where xxx is the line num of
"the first error
function! StatuslineRubySyntaxWarning()
if !exists("b:statusline_ruby_syntax_warning")
let b:statusline_ruby_syntax_warning = ''
if filereadable(expand("%"))
let output = system("ruby -c " . expand("%"))
if v:shell_error != 0
let b:statusline_ruby_syntax_warning =
\ '[syntax:'. s:ExtractErrorLine(output) . ']'
endif
endif
endif
return b:statusline_ruby_syntax_warning
endfunction
"extract the line num of the first syntax error for the given output
"from 'ruby -c'
function! s:ExtractErrorLine(error_msg)
return substitute(a:error_msg, '.\{-}:\(\d*\): .*', '\1', '')
endfunction