SyntaxCheck()

id:cooldaemon:20070517 を参考

autocmd BufWritePost * call SyntaxCheck()

function SyntaxCheck()
  let mp = &makeprg
  set makeprg=/usr/bin/false 
  
  if &syntax == 'perl'
    set makeprg=~/.vim/tools/efm_perl.pl\ -c\ %
  elseif &syntax == 'php'
    set makeprg=~/.vim/tools/php_checker.php\ %
  elseif &syntax == 'javascript'
    set makeprg=~/.vim/tools/js_checker.sh\ %
  elseif &syntax == 'html' || &syntax == 'xhtml'
    set makeprg=~/.vim/tools/html_checker.sh\ %
  elseif &syntax == 'css'
    set makeprg=~/bin/validate_css\ %
  elseif &syntax == 'sh'
    set makeprg=~/.vim/tools/sh_checker.pl\ %
  endif

  execute ':w'
  
  if &makeprg == '/usr/bin/false'
    return 
  endif
  
  if has('gui_running')
    execute ':silent make'
  else
    execute ':make'
  endif
  
  execute ':cw5'
  
  let &makeprg = mp
endf
#!/usr/bin/env php
<?php
$REGX_ERROR = '/^\w+ error:\s*(.+)\sin\s(.+)\son\sline\s(\d+)/';
$result = `/usr/bin/env php -l "$argv[1]" 2>&1`;
if ( preg_match( '/No syntax errors detected in/mis', $result ) ) {
    exit();
}
$lines = split( "\n", $result );
foreach ( $lines as $line ) {
    if ( preg_match( $REGX_ERROR, $line, $matches ) ) {
        $message = $matches[1];
        $file = $matches[2];
        $lineno = $matches[3];
        echo "$file:$lineno:$message\n";
    }
}
?>
  • js_checker.sh
#!/bin/sh
~/bin/jsl -nocontext -nofilelisting -nologo -nosummary -conf ~/bin/jsl.default.conf -process "$1"
  • html_checker.sh
#!/bin/sh
/opt/local/bin/tidy -quiet --gnu-emacs yes -config ~/.tidyrc "$1" 1>/dev/null
  • sh_checker.pl
#!/usr/bin/env perl
use strict;
use warnings;
my $res =`/bin/sh -x "$ARGV[0]" 2>&1`;
my @lines = split( "\n", $res );
foreach my $line ( @lines ) {
    if ( $line =~ m{(.+):\sline\s(\d+):\s(.+)}ixms )  {
        print "$1:$2:$3\n";
    }
}