Created
August 31, 2013 12:29
-
-
Save b108/6397904 to your computer and use it in GitHub Desktop.
PHP auto syntax check (*nix only).
Pre-writing file into /tmp directory because current dir may be remote mounted and writing can be very slow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if !exists('*PHPsynCHK') | |
function! PHPsynCHK() | |
ccl | |
let winnum = winnr() " get current window number | |
let linenum = line('.') | |
let colnum = col('.') | |
"silent execute "%!php -l -f /dev/stdin | sed 's@\\/dev\\/stdin@".bufname("%")."@g' >/tmp/vimerr; cat" | |
let tmp_file = '/tmp/vim_tmp.php' | |
silent execute "w! " . tmp_file | |
silent execute "!php -l -f '" . tmp_file . "' 2>&1 | sed 's\\#" . tmp_file . "\\#".bufname("%")."\\#g' >/tmp/vimerr" | |
set errorformat=%m\ in\ %f\ on\ line\ %l | |
silent cf /tmp/vimerr | |
cw " open the error window if it contains error | |
" return to the window with cursor set on the line of the first error (if any) | |
execute winnum . "wincmd w" | |
"silent undo | |
silent cf | |
if 1 == len(getqflist()) | |
w | |
call cursor(linenum, colnum) | |
endif | |
endfunction | |
endif | |
au! BufWriteCmd *.php call PHPsynCHK() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment