Skip to content

Instantly share code, notes, and snippets.

@oelmekki
Created July 17, 2014 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oelmekki/aae46e5e1074f4a89a50 to your computer and use it in GitHub Desktop.
Save oelmekki/aae46e5e1074f4a89a50 to your computer and use it in GitHub Desktop.
" File: ruby_check.vim
" Author: Olivier El Mekki
" Email: olivier@el-mekki.com
" Description: ruby syntax checks the buffer
" Usage:
" :RUBYCheck - lauch the syntax check
if exists('ruby_check_plugin')
finish
endif
let ruby_check_plugin = 1
"Main function
function! s:RUBYCheck()
let l:bufname = bufname( '%' )
if ! filereadable( l:bufname ) || &modified
let l:file = s:CreateTmp()
else
let l:file = l:bufname
endif
call s:Run( l:file )
endfunction
" Create a temporary file and copy the current buffer content in it
" @return string the temporary file path
function! s:CreateTmp()
let l:file = tempname()
let l:text = getline( 0, line( '$' ) )
call writefile( l:text, l:file )
return l:file
endfunction
" Do the check and echo it
" @param string the file to check
function! s:Run( file )
echo system( 'ruby -c ' . a:file )
endfunction
command! RUBYCheck call s:RUBYCheck()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment