I would like to have a quick way to check the syntax of the current Perl file. Suppose we have following incorrect file:
#!/usr/bin/perl sub aaa { dfgdf dfgdfg if ) {} sub bbb { } When we run perl -c ./test.pl from terminal we get:
syntax error at ./test.pl line 5, near "if ) " Missing right curly or square bracket at ./test.pl line 7, at end of line ./test.pl had compilation errors. Ideally, I would like to have quickfix window to be shown if errors are present:
syntax error near "if ) " <- points to ./test.pl line 5 Missing right curly or square bracket at end of line <- points to ./test.pl line 7 I created the following function:
function! CheckPerlSyntax() let mp = &makeprg let ef = &errorformat let exeFile = expand("%:t") setlocal makeprg=perl\ -c\ % set efm=%m\ at\%f\ line\ %l make " copen let &makeprg = mp let &errorformat = ef endfunc The algorithm was:
- Change
makecommand to runperl -c current-file - Parse the error messages
- Populate quickfix list from the
- Show the quickfix window
What I got so far:
- "perl -c" really runs, but I see the terminal output, is it possible to run it silently? I tried
silent - The parsing is incorrect, I can't jump to the line from the list.
- Will it be wise to set make program and errorformat for all the perl files as autocommand and not set and reset it in this function?
- Is it possible to populate the local list and not the global quickfix list?
perl -cshould work out of the box and you can configure whether to use quickfix or loclist.:help compiler-perl.