Tip #473: "compiler" for perl
tip karma |
Rating 18/9, Viewed by 2585
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
May 13, 2003 22:17 |
|
complexity: |
|
basic |
author: |
|
Chris Forkin http://www.forkin.com/ |
|
as of Vim: |
|
5.7 |
At on stage I was writing a lot of perl scripts/modules with Vim and found it useful to be able
to run the perl syntax-checker (perl -c) from within Vim via the "make" function. To be able
to do this you'll need to add the following Module (VimCompile.pm) to your @INC
---------------<cut here>---------------
#!/usr/bin/perl -w
#$Id: VimCompile.pm,v 1.2 2002/02/16 01:07:03 forkin Exp $
# reformat "perl -c" syntax-check error-/warning-messages for Vim
package VimCompile;
use strict;
sub _die {
my ($msg)=@_;
$msg=~s/^((.* at )((.*) line )([0-9]+)(\.|, near .*))$/$4:$5: $1/mg;
die qq/$msg/;
}
sub _warn {
my ($msg)=@_;
$msg=~s/^((.* at )((.*) line )([0-9]+)(\.|, near .*))$/$4:$5: $1/mg;
warn qq/$msg/;
}
$SIG{'__DIE__'}=\&_die;
$SIG{'__WARN__'}=\&_warn;
# return OK
1;
__END__
------------<cut here>---------------
This Module will reformat the warnings/errors so that Vim can parse them (to allow you to
jump to the location/source-code of the error). You will also need to deposit the following
(perl.vim) in your ~/.vim/runtime/compiler directory.
------------<cut here>---------------
" Vim compiler file
" Compiler: perl (output of "die" massaged)
" Maintainer: Chris Forkin, [email protected]
if exists("current_compiler")
finish
endif
let current_compiler = "perl"
" A workable errorformat for "perl -c"
setlocal errorformat=%f:%l:\ %m
" default make
setlocal makeprg=perl\ -MVimCompile\ -c\ %
------------<cut here>---------------
<< Handy option flag toggler |
have . restore the cursor position a la emacs in viper mode >>
Additional Notes
Anonymous,
May 14, 2003 23:58
|
:h errorformat-perl
or have a look at $VIMRUNTIME/tools/efm_perl.pl
to use quickfix mode with perl scripts.
Thomas
|
Anonymous,
December 5, 2006 13:59
|
What's the way setting such lines
#$Id: VimCompile.pm,v 1.2 2002/02/16 01:07:03 forkin Exp $
# reformat "perl -c" syntax-check error-/warning-messages for Vim
automatically when saving a file?
thx
|
|