Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Perl in Vim with quickfix

Tags:

vim

perl

Ok, it's not about compiling exactly, but recently I discovered the :compiler command in Vim. The help is included in the quickfix documentation, and as fas as I understood I could run:

:compiler perl

To select the perl interpreter. Then, the help says:

The Perl compiler plugin doesn't actually compile, but invokes Perl's internal syntax checking feature and parses the output for possible errors so you can correct them in quick-fix mode.

But as it's unclear what should I to actually run the program. May I run :make, even without a make file? That makes sense to me, since:

echo &makeprg

Returns perl -Wc %. However…

Doing that on a bogus test program, only returns the standard errors formatting output, no quickfix window is opened. What am I missing here?

like image 889
sidyll Avatar asked Apr 25 '11 13:04

sidyll


2 Answers

Just open the quickfix window with

:copen

Navigate errors with

:crew
:cnext
:cprev

Note that a common trap with quickfixing using a non-project make (i.e. where the makeprg variable usually includes the name of the current buffer (expansion of %)), is that when the focus is on the quickfix window, issueing :make again will fail, because the quickfix buffer has no filename associated with it. Perhaps this could be fixed by supplying an artificial name for the quickfix window in e.g. the Perl compiler mode for vim?

like image 161
sehe Avatar answered Oct 15 '22 23:10

sehe


Using the following code, and F6 can run perl script and shown at quickfix.

func! checkPerlSyntax()
    let map = &makeprg
    let ef = &errorformat
    let exeFile = expand("%:t")
    setlocal makeprg=perl
    set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
    silent make %
    copen
    let &makeprg     = mp
    let &errorformat = ef
endfunc

nmap pl :!perl %<.pl<CR>
map <F6> :call checkPerlSyntax()<CR>
like image 1
Marslo Avatar answered Oct 16 '22 01:10

Marslo