Search code examples
vimmakefile

Vim errorformat: hide messages with three ' * ' on it


I am using make to compile, sometimes with gcc, or clang. I have a function that change the errorformat depending on the compiler. But I still receive warnings associated with make, that I want to ignore, or at least degrade them to not warnings:

make[2]: *** [/buildpath/build.make:519: /path/test.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:36062: /path] Error 2
make: *** [Makefile:163: all] Error 2

My error format with gcc:

      \ '%-G%f:%s:,' .
      \ '%-G%f:%l: %#error: %#(Each undeclared identifier is reported only%.%#,' .
      \ '%-G%f:%l: %#error: %#for each function it appears%.%#,' .
      \ '%-GIn file included%.%#,' .
      \ '%-G %#from %f:%l\,,' .
      \ '%f:%l:%c: %trror: %m,' .
      \ '%f:%l:%c: %tarning: %m,' .
      \ '%I%f:%l:%c: note: %m,' .
      \ '%f:%l:%c: %m,' .
      \ '%f:%l: %trror: %m,' .
      \ '%f:%l: %tarning: %m,'.
      \ '%I%f:%l: note: %m,'.
      \ '%f:%l: %m'

When running it from vim I get the errors associates with gcc correctly, but still these make warnings:

make[2]: *** [/buildpath/build.make:519:/build.make|519 warning| /path/test.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2|36062 warning| /path] Error 2
make: *** [Makefile|163 warning| all] Error 2

I have tried -G %#%#%# to match the three asterisks (%# being an asterisk from :help errorformat). But I receive an error saying:

Neomake error in: function <SNR>166_nvim_exit_handler[6]..<SNR>166_exit_handler[27]..<SNR>166_RegisterJobOutput[16]..<SNR>166_ProcessJobOutput, line 55
Neomake: [2.2:2] Error during output processing for build: Vim(caddexpr):E871: (NFA regexp) Can't have a multi follow a multi !.

Solution

  • As of Vim 9.0 patch 1613, the default value of errorformat on Unix-like operating systems has been updated to ignore these messages from Make.

    These are the entries that were added (note that you would need to escape some characters in these patterns to use them in a :set command or your vimrc):

    • %-Gg%\?make[%*\d]: *** [%f:%l:%m
    • %-Gg%\?make: *** [%f:%l:%m

    The reason your attempt (something like %-G%#%#%#) did not work is because %# is used to insert a RegEx asterisk token, not an asterisk literal, and because these error format patterns must match the whole line, not just a substring.

    If anyone is on Windows, you will need to add the patterns to errorformat yourself, and if anyone is using mingw32-make instead of make, you will have to modify the patterns slightly. I did so by adding the following line to my vimrc:

    • set errorformat^=%-Gmingw32-make:\ ***\ [%f:%l:%m