6

To work with pascal files, my .vimrc contains this code:

"" Work with pascal files
augroup make_pascal
  autocmd!
  autocmd FileType pascal :compiler fpc
  autocmd FileType pascal :set makeprg=clear;\ fpc\ %
augroup END

To demonstrate the issue I am experiencing see this easy hello-world-like demonstration code written in pascal which intentionally contains an error:

program EasyExample (output);

begin
  writeln ('Correct line.');
  thisWillCauseAnError;
end.

When I run :make on this file with my Vim cursor in any line that does not contain the error, everything works fine: the external fpc compiler gets called and aborts compilation due to an error. After pressing ENTER I get back to my source code and the cursor is in the line that contains the error, and the error message is displayed at the bottom.

But when I run :make on this file with my Vim cursor in the line that does contain the error, an additional step is added (and I would like to remove it): After the compilation abortion pressing ENTER does not get me back to my source code, but instead a new "window" (is that the quickfix list?) is shown with the following text at the bottom:

(5 of 8): Error: Identifier not found "thisWillCauseAnError"

Press ENTER or type command to continue

After pressing ENTER again I see my source code again, the cursor in the line that contains the error, and the error message is displayed at the bottom.

Question

How do I get rid of that additional "window" that appears, so that the behaviour when running :make is always the same (i.e. press ENTER once to see my source code with highlighted error)?

  • @saginaw: :silent! make | redraw! | cw is a great solution and is what I will use. Please post it as an answer (so that you get reputation and the vi/Vim site stats on Area51 get better) and I will happily accept it. It would be great if you could also mention a way how I could delete the .o file automatically after compilation, as the autocmd in my answer that deletes the object file does not work with the :silent! make | redraw! | cw command: the quickfix list is empty and does not contain errors. – cbaumhardt Feb 28 '16 at 23:00
  • Sorry I removed my comments because I thought they didn't solve your issue, but I'm glad if they helped you a little! I'm not comfortable writing an answer because I can't reproduce what you're experiencing on my machine, and I don't know how compilation or Pascal works. To remove automatically the .o file, maybe you could look at :h autocmd-events and see if there's an event which corresponds to a compilation. Maybe QuickFixCmdPre or QuickFixCmdPost? That would give something like autocmd QuickFixCmdPost * !rm\ -f\ %:r.o I didn't try it so it may not work as expected. – saginaw Feb 28 '16 at 23:18
  • Sorry again, I read your comment too quickly. You say the quickfix list is empty so the events I mentioned won't work. Maybe ShellCmdPost then? You could also install a fire-once autocmd (the autocmd is installed and removed as soon as the command is executed) inside a function and call the latter from a mapping ,c or a custom command :CP: vpaste.net/0t1i4 – saginaw Feb 28 '16 at 23:34
  • The previous code won't work because I mixed a shell and Vim command on the same line. Maybe this will work, but I'm not really sure: vpaste.net/DhNQG – saginaw Feb 28 '16 at 23:46
  • @saginaw: I have a working solution now, thanks again for your help :) – cbaumhardt Feb 29 '16 at 1:29
2

saginaw pointed out in a now deleted comment that running :silent! make | redraw! | cw instead of :make solves my problem. If I run it the program compiles, and if there is an error the QuickFix list is opened on the bottom and the line with the error highlighted.

I expanded his solution further to deal with something else:

Whenever the free pascal compiler fpc is run on a file example.pas, it produces an executable example as well as an object file example.o, which can be deleted as I don't need it.

The final solution in my .vimrc is:

"" Work with pascal files
augroup make_pascal
  autocmd!
  autocmd FileType pascal :compiler fpc
  autocmd FileType pascal :set makeprg=clear;fpc\ %
  autocmd FileType pascal nnoremap <buffer> <leader>c
      \ :w <bar> silent! make <bar> redraw! <bar> cw <bar>
      \ exe "silent! !rm -f %:r.o" <bar> redraw! <CR>
augroup END

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.