Permalink
Browse files

completely refactor the syntax checking

add a function call to the statusline in the vimrc that checks for the
existence of a syntax checking function for the current filetype. These
functions are defined in syntax_checkers/&ft.vim (but could be defined
anywhere really). This massively reduces duplication and is way cleaner
  • Loading branch information...
scrooloose committed Jun 28, 2009
1 parent d47587e commit a747a2b8748aa2afce8bd646e42b460d185467b9
@@ -1,59 +0,0 @@
-" ============================================================================
-" File: eruby_stl_syntax_warning.vim
-" Description: filtype plugin for eruby to add a syntax check flag to the
-" statusline
-" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
-" Last Change: 21 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_eruby_stl_syntax_warning_ftplugin") || &filetype !~ '\<eruby\>'
- finish
-endif
-let b:did_eruby_stl_syntax_warning_ftplugin = 1
-
-"bail if the user doesnt have ruby or cat installed
-if !executable("ruby") || !executable("cat")
- finish
-endif
-
-"inject the syntax warning into the statusline
-let &l:statusline = substitute(&statusline, '\(%=\)',
- \ '%#warningmsg#%{StatuslineERubySyntaxWarning()}%*\1', '')
-
-"recalculate after saving
-autocmd bufwritepost <buffer> unlet! b:statusline_eruby_syntax_warning
-
-"run the erb sections of the buffer though 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! StatuslineERubySyntaxWarning()
- if !exists("b:statusline_eruby_syntax_warning")
- let b:statusline_eruby_syntax_warning = ''
- if filereadable(expand("%"))
- let output = s:CheckSyntax(expand("%"))
- if v:shell_error != 0
- let b:statusline_eruby_syntax_warning =
- \ '[syntax:'. s:ExtractErrorLine(output) . ']'
- endif
- endif
- endif
- return b:statusline_eruby_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*\): syntax error,.*', '\1', '')
-endfunction
-
-"run the erb sections of the given file through ruby -c and return the result
-function! s:CheckSyntax(filename)
- return system('cat '. a:filename . ' | ruby -e "require \"erb\"; puts ERB.new(ARGF.read, nil, \"-\").src" | ruby -c')
-endfunction
@@ -1,55 +0,0 @@
-" ============================================================================
-" File: haml_stl_syntax_warning.vim
-" Description: filtype plugin for haml to add a syntax check flag to the
-" statusline
-" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
-" Last Change: 21 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_haml_stl_syntax_warning_ftplugin")
- finish
-endif
-let b:did_haml_stl_syntax_warning_ftplugin = 1
-
-"bail if the user doesnt have the haml binary installed
-if !executable("haml")
- finish
-endif
-
-"inject the syntax warning into the statusline
-let &l:statusline = substitute(&statusline, '\(%=\)',
- \ '%#warningmsg#%{StatuslineHamlSyntaxWarning()}%*\1', '')
-
-"recalculate after saving
-autocmd bufwritepost <buffer> unlet! b:statusline_haml_syntax_warning
-
-"run the buffer through haml -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! StatuslineHamlSyntaxWarning()
- if !exists("b:statusline_haml_syntax_warning")
- let b:statusline_haml_syntax_warning = ''
- if filereadable(expand("%"))
- let output = system("haml -c " . expand("%"))
- if v:shell_error != 0
- let b:statusline_haml_syntax_warning =
- \ '[syntax:'. s:ExtractErrorLine(output) . ']'
- endif
- endif
- endif
- return b:statusline_haml_syntax_warning
-endfunction
-
-"extract the line num of the first syntax error for the given output
-"from 'haml -c'
-function! s:ExtractErrorLine(error_msg)
- return substitute(a:error_msg, '^Syntax error on line \(\d*\):.*', '\1', '')
-endfunction
@@ -1,75 +0,0 @@
-" ============================================================================
-" File: php_syntax_checking.vim
-" Description: Filtype plugin for php to provide syntax checking hacks
-" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
-" Last Change: 23 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_php_syntax_checking_ftplugin")
- finish
-endif
-let b:did_php_syntax_checking_ftplugin = 1
-
-"bail if the user doesnt have php installed
-if !executable("php")
- finish
-endif
-
-"inject the syntax warning into the statusline
-let &l:statusline = substitute(&statusline, '\(%=\)',
- \ '%#warningmsg#%{StatuslinePhpSyntaxWarning()}%*\1', '')
-
-"recalculate after saving
-autocmd bufwritepost <buffer> unlet! b:statusline_php_syntax_warning
-
-"run the buffer through php -l
-"
-"return '' if no syntax errors detected
-"return '[syntax:xxx]' if errors are detected, where xxx is the line num of
-"the first error
-function! StatuslinePhpSyntaxWarning()
- if !exists("b:statusline_php_syntax_warning")
- let b:statusline_php_syntax_warning = ''
- if filereadable(expand("%"))
- let output = system("php -l " . expand("%"))
- if v:shell_error != 0
- let b:statusline_php_syntax_warning =
- \ '[syntax:'. s:ExtractErrorLine(output) . ']'
- endif
- endif
- endif
- return b:statusline_php_syntax_warning
-endfunction
-
-"extract the line num of the first syntax error for the given output
-"from 'php -l'
-function! s:ExtractErrorLine(error_msg)
- return substitute(a:error_msg, '\_.\{-}on line \(\d*\)\_.*', '\1', '')
-endfunction
-
-"if syntax errors are found in the current buffer, show them in the quickfix
-"window
-function! s:ShowSyntaxErrors()
- let old_errorformat = &l:errorformat
- setl errorformat=Parse\ error:\ syntax\ error\\,\ %m\ in\ %f\ on\ line\ %l,%-G%.%#
-
- let old_makeprg = &l:makeprg
- setl makeprg=php\ -l\ %
-
- silent make
- redraw!
-
- let &l:makeprg = old_makeprg
- let &l:errorformat = old_errorformat
-
- if !empty(getqflist())
- copen
- endif
-endfunction
-
-command! -nargs=0 -buffer SyntaxErrors call s:ShowSyntaxErrors()
@@ -1,69 +0,0 @@
-" ============================================================================
-" File: ruby_syntax_checking.vim
-" Description: Filetype plugin for ruby that provides syntax checking hacks
-" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
-" Last Change: 23 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_syntax_checking_ftplugin") || &filetype !~ '\<ruby\>'
- finish
-endif
-let b:did_ruby_syntax_checking_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 <buffer> 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
-
-"if syntax errors are found in the current buffer, show them in the quickfix
-"window
-function! s:ShowSyntaxErrors()
- let old_makeprg = &l:makeprg
- setl makeprg=ruby\ -c\ %
- silent make
- redraw!
- let &l:makeprg = old_makeprg
-
- if !empty(getqflist())
- copen
- endif
-endfunction
-
-command! -nargs=0 -buffer SyntaxErrors call s:ShowSyntaxErrors()
@@ -1,55 +0,0 @@
-" ============================================================================
-" File: sass_stl_syntax_warning.vim
-" Description: filtype plugin for sass to add a syntax check flag to the
-" statusline
-" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
-" Last Change: 21 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_sass_stl_syntax_warning_ftplugin")
- finish
-endif
-let b:did_sass_stl_syntax_warning_ftplugin = 1
-
-"bail if the user doesnt have the sass binary installed
-if !executable("sass")
- finish
-endif
-
-"inject the syntax warning into the statusline
-let &l:statusline = substitute(&statusline, '\(%=\)',
- \ '%#warningmsg#%{StatuslineSassSyntaxWarning()}%*\1', '')
-
-"recalculate after saving
-autocmd bufwritepost <buffer> unlet! b:statusline_sass_syntax_warning
-
-"run the buffer through sass -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! StatuslineSassSyntaxWarning()
- if !exists("b:statusline_sass_syntax_warning")
- let b:statusline_sass_syntax_warning = ''
- if filereadable(expand("%"))
- let output = system("sass -c " . expand("%"))
- if v:shell_error != 0
- let b:statusline_sass_syntax_warning =
- \ '[syntax:'. s:ExtractErrorLine(output) . ']'
- endif
- endif
- endif
- return b:statusline_sass_syntax_warning
-endfunction
-
-"extract the line num of the first syntax error for the given output
-"from 'sass -c'
-function! s:ExtractErrorLine(error_msg)
- return substitute(a:error_msg, '^Syntax error on line \(\d*\):.*', '\1', '')
-endfunction
View
@@ -0,0 +1,29 @@
+if exists("loaded_eruby_syntax_checker")
+ finish
+endif
+let loaded_eruby_syntax_checker = 1
+
+"bail if the user doesnt have ruby or cat installed
+if !executable("ruby") || !executable("cat")
+ finish
+endif
+
+"run the erb sections of the buffer though ruby -c and return the line num of
+"the first error, or 0 if no errors
+function! CheckSyntax_eruby()
+ let output = s:CheckSyntax(expand("%"))
+ if v:shell_error != 0
+ return s:ExtractErrorLine(output)
+ endif
+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*\): syntax error,.*', '\1', '')
+endfunction
+
+"run the erb sections of the given file through ruby -c and return the result
+function! s:CheckSyntax(filename)
+ return system('cat '. a:filename . ' | ruby -e "require \"erb\"; puts ERB.new(ARGF.read, nil, \"-\").src" | ruby -c')
+endfunction
View
@@ -0,0 +1,24 @@
+if exists("loaded_haml_syntax_checker")
+ finish
+endif
+let loaded_haml_syntax_checker = 1
+
+"bail if the user doesnt have the haml binary installed
+if !executable("haml")
+ finish
+endif
+
+"run the buffer through haml -c
+"return the line num of the first error, or 0 if no errors
+function! CheckSyntax_haml()
+ let output = system("haml -c " . expand("%"))
+ if v:shell_error != 0
+ return s:ExtractErrorLine(output)
+ endif
+endfunction
+
+"extract the line num of the first syntax error for the given output
+"from 'haml -c'
+function! s:ExtractErrorLine(error_msg)
+ return substitute(a:error_msg, '^Syntax error on line \(\d*\):.*', '\1', '')
+endfunction
View
@@ -0,0 +1,26 @@
+if exists("loaded_php_syntax_checker")
+ finish
+endif
+let loaded_php_syntax_checker = 1
+
+"bail if the user doesnt have php installed
+if !executable("php")
+ finish
+endif
+"run the buffer through php -l
+"
+"return '' if no syntax errors detected
+"return '[syntax:xxx]' if errors are detected, where xxx is the line num of
+"the first error
+function! CheckSyntax_php()
+ let output = system("php -l " . expand("%"))
+ if v:shell_error != 0
+ return s:ExtractErrorLine(output)
+ endif
+endfunction
+
+"extract the line num of the first syntax error for the given output
+"from 'php -l'
+function! s:ExtractErrorLine(error_msg)
+ return substitute(a:error_msg, '\_.\{-}on line \(\d*\)\_.*', '\1', '')
+endfunction
Oops, something went wrong.

0 comments on commit a747a2b

Please sign in to comment.