]>
git.r.bdr.sh - rbdr/dotfiles/blob - vim/syntax_checkers/efm_perl.pl
3 # vimparse.pl - Reformats the error messages of the Perl interpreter for use
4 # with the quickfix mode of Vim
6 # Copyright (©) 2001 by Jörg Ziefle <joerg.ziefle@gmx.de>
7 # You may use and distribute this software under the same terms as Perl itself.
9 # Usage: put one of the two configurations below in your ~/.vimrc (without the
10 # description and '# ') and enjoy (be sure to adjust the paths to vimparse.pl
13 # Program is run interactively with 'perl -w':
15 # set makeprg=$HOME/bin/vimparse.pl\ %\ $*
16 # set errorformat=%f:%l:%m
18 # Program is only compiled with 'perl -wc':
20 # set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $*
21 # set errorformat=%f:%l:%m
24 # vimparse.pl [-c] [-f <errorfile>] <programfile> [programargs]
26 # -c compile only, don't run (perl -wc)
27 # -f write errors to <errorfile>
30 # * From the command line:
31 # vimparse.pl program.pl
33 # vimparse.pl -c -f errorfile program.pl
34 # Then run vim -q errorfile to edit the errors with Vim.
37 # Edit in Vim (and save, if you don't have autowrite on), then
38 # type ':mak' or ':mak args' (args being the program arguments)
43 # * First public version (sent to Bram)
44 # * -c command line option for compiling only
45 # * grammatical fix: 'There was 1 error.'
46 # * bug fix for multiple arguments
48 # * documentation (top of file, &usage)
49 # * minor code clean ups
52 # * Basic functionality
55 # * test on more systems
56 # * use portable way to determine the location of perl ('use Config')
57 # * include option that shows perldiag messages for each error
58 # * allow to pass in program by STDIN
59 # * more intuitive behaviour if no error is found (show message)
61 # Tested under SunOS 5.7 with Perl 5.6.0. Let me know if it's not working for
67 use vars qw
/$opt_c $opt_f $opt_h/; # needed for Getopt in combination with use strict 'vars'
69 use constant VERSION
=> 0.2;
73 &usage
if $opt_h; # not necessarily needed, but good for further extension
77 open FILE
, "> $opt_f" or do {
78 warn "Couldn't open $opt_f: $!. Using STDOUT instead.\n";
84 my $handle = (defined $opt_f ? \
*FILE
: \
*STDOUT
);
86 (my $file = shift) or &usage
; # display usage if no filename is supplied
87 my $args = (@ARGV ? ' ' . join ' ', @ARGV : '');
89 my @lines = `perl @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`;
92 foreach my $line (@lines) {
95 my ($file, $lineno, $message, $rest);
97 if ($line =~ /^(.*)\sat\s(.*)\sline\s(\d+)(\.|,\snear\s\".*\")$/) {
99 ($message, $file, $lineno, $rest) = ($1, $2, $3, $4);
101 $message .= $rest if ($rest =~ s/^,//);
102 print $handle "$file:$lineno:$message\n";
108 if (defined $opt_f) {
113 $msg = "There was 1 error.\n";
117 $msg = "There were $errors errors.\n";
123 unlink $opt_f unless $errors;
129 (local $0 = $0) =~ s/^.*\/([^\/]+)$/$1/; # remove path from name of program
132 $0 [-c] [-f <errorfile>] <programfile> [programargs]
134 -c compile only, don't run (executes 'perl -wc')
135 -f write errors to <errorfile>
138 * At the command line:
140 Displays output on STDOUT.
142 $0 -c -f errorfile program.pl
143 Then run 'vim -q errorfile' to edit the errors with Vim.
146 Edit in Vim (and save, if you don't have autowrite on), then
147 type ':mak' or ':mak args' (args being the program arguments)