Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Vim :make with quickfix ends up creating a new file when error is in header

I've got a setup with Vim where I can compile my C/C++ code using :make and compilation errors are automatically shown in a quickfix window using the following lines (from the Vim wiki) in my ./vimrc:

" Automatically open, but do not go to (if there are errors) the quickfix /
" location list window, or close it when is has become empty. 
"
" Note: Must allow nesting of autocmds to enable any customizations for quickfix
" buffers. 
" Note: Normally, :cwindow jumps to the quickfix window if the command opens it
" (but not if it's already open). However, as part of the autocmd, this doesn't
" seem to happen. 
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost    l* nested lwindow

Now this setup works well if there is an error in a .cpp file, as the output from make is correctly parsed:

$ make
g++    -c -o IsingMain.o IsingMain.cpp
g++    -c -o LatticeModel.o LatticeModel.cpp
LatticeModel.cpp: In member function ‘void LatticeModel::initialiseSystem()’:
LatticeModel.cpp:18:25: error: ‘sirand’ was not declared in this scope

i.e. vim correctly switches to LatticeModel.cpp.


However if the error is in the header file, the make output is misinterpreted, and vim switches/creates a new buffer (for the following example make output) with name "In file included from IsingMain.cpp", clearly erroneously assuming that this is the file with the error (in fact the error is in LatticeModel.h):

$ make
g++    -c -o IsingMain.o IsingMain.cpp
In file included from IsingMain.cpp:2:0:
LatticeModel.h:31:5: error: ‘Zvoid’ does not name a type

Running make from the commandline works perfectly well, it's just an issue with quickfix misreading it's output. Any help greatly appreciated, let me know if any part of this is confusing. Thanks

EDIT: It seems to be something to do with with an incorrect errorformat (as described in this thread.)

EDIT 2: Temporary fix found by ignoring the make output line that starts with "In file included from" using this technique.

like image 663
Hemmer Avatar asked Jul 19 '11 12:07

Hemmer


1 Answers

While I have still not found a proper solution, the workaround suggested here: http://groups.google.com/group/vim_dev/msg/ed4f258f5b4b9749 seems to work for the time being.

set errorformat^=%-GIn\ file\ included\ %.%# 

EDIT: see also Vim tries to jump to nonexistent file after :make

like image 97
Hemmer Avatar answered Nov 15 '22 07:11

Hemmer