Merge remote-tracking branch 'eharmon/master'

Conflicts:
	syntax_checkers/efm_perl.pl
This commit is contained in:
Martin Grenfell 2012-06-17 10:20:05 +01:00
commit 1e94b98705
2 changed files with 40 additions and 17 deletions

View File

@ -4,6 +4,7 @@
# with the quickfix mode of Vim
#
# Copyright (©) 2001 by Jörg Ziefle <joerg.ziefle@gmx.de>
# Copyright (c) 2012 Eric Harmon <http://eharmon.net>
# You may use and distribute this software under the same terms as Perl itself.
#
# Usage: put one of the two configurations below in your ~/.vimrc (without the
@ -13,25 +14,27 @@
# Program is run interactively with 'perl -w':
#
# set makeprg=$HOME/bin/vimparse.pl\ %\ $*
# set errorformat=%f:%l:%m
# set errorformat=%t:%f:%l:%m
#
# Program is only compiled with 'perl -wc':
#
# set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $*
# set errorformat=%f:%l:%m
# set errorformat=%t:%f:%l:%m
#
# Usage:
# vimparse.pl [-c] [-f <errorfile>] <programfile> [programargs]
# vimparse.pl [-c] [-w] [-f <errorfile>] <programfile> [programargs]
#
# -c compile only, don't run (perl -wc)
# -w output warnings as warnings instead of errors (slightly slower)
# -f write errors to <errorfile>
#
# Example usages:
# * From the command line:
# vimparse.pl program.pl
#
# vimparse.pl -c -f errorfile program.pl
# vimparse.pl -c -w -f errorfile program.pl
# Then run vim -q errorfile to edit the errors with Vim.
# This uses the custom errorformat: %t:%f:%l:%m.
#
# * From Vim:
# Edit in Vim (and save, if you don't have autowrite on), then
@ -39,6 +42,9 @@
# to error check.
#
# Version history:
# 0.3 (05/31/2012):
# * Added support for the seperate display of warnings
# * Switched output format to %t:%f:%l:%m to support error levels
# 0.2 (04/12/2001):
# * First public version (sent to Bram)
# * -c command line option for compiling only
@ -64,11 +70,11 @@
use strict;
use Getopt::Std;
use vars qw/$opt_c $opt_f $opt_h/; # needed for Getopt in combination with use strict 'vars'
use vars qw/$opt_c $opt_w $opt_f $opt_h/; # needed for Getopt in combination with use strict 'vars'
use constant VERSION => 0.2;
getopts('cf:h');
getopts('cwf:h');
&usage if $opt_h; # not necessarily needed, but good for further extension
@ -86,20 +92,33 @@ my $handle = (defined $opt_f ? \*FILE : \*STDOUT);
(my $file = shift) or &usage; # display usage if no filename is supplied
my $args = (@ARGV ? ' ' . join ' ', @ARGV : '');
my @lines = `perl @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`;
my @error_lines = `perl @{[defined $opt_c ? '-c ' : '' ]} @{[defined $opt_w ? '-X ' : '-w ']} "$file$args" 2>&1`;
my @lines = map { "E:$_" } @error_lines;
my @warn_lines;
if(defined($opt_w)) {
@warn_lines = `perl @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`;
}
# Any new errors must be warnings
foreach my $line (@warn_lines) {
if(!grep { $_ eq $line } @error_lines) {
push(@lines, "W:$line");
}
}
my $errors = 0;
foreach my $line (@lines) {
chomp($line);
my ($file, $lineno, $message, $rest);
my ($file, $lineno, $message, $rest, $severity);
if ($line =~ /^(.*)\sat\s(.*)\sline\s(\d+)(.*)$/) {
($message, $file, $lineno, $rest) = ($1, $2, $3, $4);
($severity, $message, $file, $lineno, $rest) = ($1, $2, $3, $4, $5);
$errors++;
$message .= $rest if ($rest =~ s/^,//);
print $handle "$file:$lineno:$message\n";
print $handle "$severity:$file:$lineno:$message\n";
} else { next };
@ -129,9 +148,10 @@ sub usage {
(local $0 = $0) =~ s/^.*\/([^\/]+)$/$1/; # remove path from name of program
print<<EOT;
Usage:
$0 [-c] [-f <errorfile>] <programfile> [programargs]
$0 [-c] [-w] [-f <errorfile>] <programfile> [programargs]
-c compile only, don't run (executes 'perl -wc')
-c compile only, don't run (executes 'perl -c')
-w output warnings as warnings instead of errors (slightly slower)
-f write errors to <errorfile>
Examples:
@ -139,8 +159,9 @@ Examples:
$0 program.pl
Displays output on STDOUT.
$0 -c -f errorfile program.pl
$0 -c -w -f errorfile program.pl
Then run 'vim -q errorfile' to edit the errors with Vim.
This uses the custom errorformat: %t:%f:%l:%m.
* In Vim:
Edit in Vim (and save, if you don't have autowrite on), then

View File

@ -1,7 +1,8 @@
"============================================================================
"File: perl.vim
"Description: Syntax checking plugin for syntastic.vim
"Maintainer: Anthony Carapetis <anthony.carapetis at gmail dot com>
"Maintainer: Anthony Carapetis <anthony.carapetis at gmail dot com>,
" Eric Harmon <http://eharmon.net>
"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
@ -19,11 +20,12 @@ if !executable("perl")
finish
endif
let s:checker = 'perl ' . shellescape(expand('<sfile>:p:h') . '/efm_perl.pl') . ' -c'
"remove '-w' switch to change all warnings to errors
let s:checker = 'perl ' . shellescape(expand('<sfile>:p:h') . '/efm_perl.pl') . ' -c -w'
function! SyntaxCheckers_perl_GetLocList()
let makeprg = s:checker . ' ' . shellescape(expand('%'))
let errorformat = '%f:%l:%m'
let errorformat = '%t:%f:%l:%m'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endfunction