Wikia

Vim Tips Wiki

Changes: Errorformats

Edit

Back to page

(Improved cmake code)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
The <tt>errorformat</tt> (or <tt>efm</tt>) option is a comma-separated list of scanf-style format strings that are used with QuickFix to extract information like file name, line number, column number, etc, from errors and warnings generated with <tt>:make</tt>. If an error/warning message in the quickfix window matches one of your error formats, you can select it (double click in gvim, or press Enter on the line) to jump to the correct place. It also provides some simple reformatting and highlighting to standardize the display of recognized messages. {{help|'efm'}}
+
The <code>errorformat</code> (or <code>efm</code>) option is a comma-separated list of scanf-style format strings that are used with QuickFix to extract information like file name, line number, column number, etc, from errors and warnings generated with <code>:make</code>. If an error/warning message in the quickfix window matches one of your error formats, you can select it (double click in gvim, or press Enter on the line) to jump to the correct place. It also provides some simple reformatting and highlighting to standardize the display of recognized messages. {{help|'efm'}}
   
Vim comes preloaded with some good defaults. You can use the <code>set errorformat</code> command in (for instance) your [[vimrc]] file to add more for tools you use. If you use the <tt>+=</tt> operator for the assignment, it will append the text to the current value, separated with a comma, as required for the errorformat.
+
Vim comes preloaded with some good defaults. You can use the <code>set errorformat</code> command in (for instance) your [[vimrc]] file to add more for tools you use. If you use the <code>+=</code> operator for the assignment, it will append the text to the current value, separated with a comma, as required for the errorformat.
   
 
Since compilers and other programs generate messages according to their own rules, there are a multitude of error formats that could be useful. Some are listed here.
 
Since compilers and other programs generate messages according to their own rules, there are a multitude of error formats that could be useful. Some are listed here.
   
 
===flex===
 
===flex===
The free alternative to LEX, a lexical parser generator. Error messages are like: <tt>"somefile.l", line 15: rule cannot be matched</tt>.
+
The free alternative to LEX, a lexical parser generator. Error messages are like: <code>"somefile.l", line 15: rule cannot be matched</code>.
 
<pre>
 
<pre>
 
set errorformat+=%*[\"]%f%*[\"]\\,\ line\ %l:\ %m
 
set errorformat+=%*[\"]%f%*[\"]\\,\ line\ %l:\ %m
Line 33: Line 33:
   
 
===Texas Instruments cl2000 compiler===
 
===Texas Instruments cl2000 compiler===
This is the C-compiler and linker that's used for some Texas Instruments DSP microprocessors. Error format is like <tt>"file.c", line 17: some error message</tt>.
+
This is the C-compiler and linker that's used for some Texas Instruments DSP microprocessors. Error format is like <code>"file.c", line 17: some error message</code>.
 
<pre>
 
<pre>
 
set errorformat=\"%f\"\\,\ line\ %l:\ %m
 
set errorformat=\"%f\"\\,\ line\ %l:\ %m
Line 45: Line 45:
   
 
===gfortran===
 
===gfortran===
A suitable <tt>'errorformat'</tt> for gfortran is:
+
A suitable <code>'errorformat'</code> for gfortran is:
 
<pre>
 
<pre>
 
set efm=%E%f:%l.%c:,%E%f:%l:,%C,%C%p%*[0123456789^],%ZError:\ %m,%C%.%#
 
set efm=%E%f:%l.%c:,%E%f:%l:,%C,%C%p%*[0123456789^],%ZError:\ %m,%C%.%#
Line 51: Line 51:
   
 
<poem>
 
<poem>
<tt>%E%f:%l.%c:</tt>&nbsp;&nbsp; to parse "FILENAME:LINENUMBER.COLNUMBER:".
+
<code>%E%f:%l.%c:</code>&nbsp;&nbsp; to parse "FILENAME:LINENUMBER.COLNUMBER:".
<tt>%E%f:%l:</tt>&nbsp;&nbsp; to parse "FILENAME:LINENUMBER:".
+
<code>%E%f:%l:</code>&nbsp;&nbsp; to parse "FILENAME:LINENUMBER:".
<tt>%C:</tt>&nbsp;&nbsp; to pass over the empty line.
+
<code>%C:</code>&nbsp;&nbsp; to pass over the empty line.
<tt>%C%p%*[0123456789^]:</tt>&nbsp;&nbsp; to get the column number from the indicator line (" 1").
+
<code>%C%p%*[0123456789^]:</code>&nbsp;&nbsp; to get the column number from the indicator line (" 1").
<tt>%ZError:\ %m:</tt>&nbsp;&nbsp; to parse the error message ("Error: ERROR_MESSAGE").
+
<code>%ZError:\ %m:</code>&nbsp;&nbsp; to parse the error message ("Error: ERROR_MESSAGE").
<tt>%C%.%#:</tt>&nbsp;&nbsp; to pass over the source code line (and ignore it).
+
<code>%C%.%#:</code>&nbsp;&nbsp; to pass over the source code line (and ignore it).
 
</poem>
 
</poem>
   
The following allows parsing of the following message (<tt>make</tt> output):
+
The following allows parsing of the following message (<code>make</code> output):
 
<pre>
 
<pre>
 
gfortran hello-world.f90 -o hello-world.exe
 
gfortran hello-world.f90 -o hello-world.exe
Line 75: Line 75:
 
</pre>
 
</pre>
   
In Vim, <tt>:clist</tt> then shows:
+
In Vim, <code>:clist</code> then shows:
 
<pre>
 
<pre>
 
2 hello-world.f90:11 col 1 error: Unclassifiable statement at (1)
 
2 hello-world.f90:11 col 1 error: Unclassifiable statement at (1)
Line 98: Line 98:
 
===Modelsim vlog/vcom for Verilog/VHDL ===
 
===Modelsim vlog/vcom for Verilog/VHDL ===
 
A simulation tool for Verilog/VHDL. Error messages look like: <br>
 
A simulation tool for Verilog/VHDL. Error messages look like: <br>
<tt>** Error: /pathto/somefile.v(115): near \"source text\": syntax error message</tt>.
+
<code>** Error: /pathto/somefile.v(115): near \"source text\": syntax error message</code>.
 
<pre>
 
<pre>
 
set errorformat=**\ Error:\ %f(%l):\ %m
 
set errorformat=**\ Error:\ %f(%l):\ %m
Line 106: Line 106:
 
Code for the [[wikipedia:Zilog eZ80|Zilog eZ80]] microprocessor can be built from Vim after installing ZDS. Create a makefile manually or use the one generated from a ZDS project.
 
Code for the [[wikipedia:Zilog eZ80|Zilog eZ80]] microprocessor can be built from Vim after installing ZDS. Create a makefile manually or use the one generated from a ZDS project.
   
With the following in your [[vimrc]], you can use <tt>:Make</tt> to perform a <tt>:make</tt> and to open any resulting quickfix window:
+
With the following in your [[vimrc]], you can use <code>:Make</code> to perform a <code>:make</code> and to open any resulting quickfix window:
 
<pre>
 
<pre>
 
command -nargs=* Make make <args>|cwindow 3
 
command -nargs=* Make make <args>|cwindow 3
 
</pre>
 
</pre>
   
Add the following to file <tt>~/.vim/after/ftplugin/c.vim</tt> (Unix) or <tt>$HOME/vimfiles/after/ftplugin/c.vim</tt> (Windows) – you may need to create the file. Then you can press F7 to build:
+
Add the following to file <code>~/.vim/after/ftplugin/c.vim</code> (Unix) or <code>$HOME/vimfiles/after/ftplugin/c.vim</code> (Windows) – you may need to create the file. Then you can press F7 to build:
 
<pre>
 
<pre>
 
setlocal errorformat=%f\ (%l\\,%c)\ :\ ERROR\ (%n)\ %m
 
setlocal errorformat=%f\ (%l\\,%c)\ :\ ERROR\ (%n)\ %m
Line 119: Line 119:
   
 
The errorformat line contains two tab characters (shown as large whitespaces above).
 
The errorformat line contains two tab characters (shown as large whitespaces above).
:''Todo'': Should investigate use of <tt>:let errorformat=...</tt> with <tt>\t</tt> to avoid need to use literal tab characters.
+
:''Todo'': Should investigate use of <code>:let errorformat=...</code> with <code>\t</code> to avoid need to use literal tab characters.
   
 
==CMake==
 
==CMake==
Line 149: Line 149:
 
*Clean up tips in [[:Category:Compiler]].
 
*Clean up tips in [[:Category:Compiler]].
 
*Where appropriate, should merge compiler tips for a particular language into one tip.
 
*Where appropriate, should merge compiler tips for a particular language into one tip.
*Need emphasis to be on the <tt>:compiler</tt> command (don't directly mess with <tt>'efm'</tt>).
+
*Need emphasis to be on the <code>:compiler</code> command (don't directly mess with <code>'efm'</code>).
*Settings for <tt>errorformat</tt> should be in a compiler plugin rather than in vimrc. {{help|write-compiler-plugin}} {{help|compiler-select}}
+
*Settings for <code>errorformat</code> should be in a compiler plugin rather than in vimrc. {{help|write-compiler-plugin}} {{help|compiler-select}}
 
*If there is no support for a compiler, user should add a new compiler (need example of how).
 
*If there is no support for a compiler, user should add a new compiler (need example of how).
 
*Need links to a tip with info on the quickfix window.
 
*Need links to a tip with info on the quickfix window.
Line 171: Line 171:
 
*[[VimTip852|852 Make support for NEC V850 CA850 compilers]]
 
*[[VimTip852|852 Make support for NEC V850 CA850 compilers]]
   
Many existing tips have obsolete/bad advice, for example, tip 476 says to edit the <tt>$VIM/ftplugin/perl.vim</tt> file (probably means <tt>$VIMRUNTIME/ftplugin/perl.vim</tt> but you should never patch a distribution file).
+
Many existing tips have obsolete/bad advice, for example, tip 476 says to edit the <code>$VIM/ftplugin/perl.vim</code> file (probably means <code>$VIMRUNTIME/ftplugin/perl.vim</code> but you should never patch a distribution file).
   
 
----
 
----

Latest revision as of 07:55, July 11, 2012

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 1575 Printable Monobook Previous Next

created 2008 · complexity basic · author Bmearns · version 7.0


The errorformat (or efm) option is a comma-separated list of scanf-style format strings that are used with QuickFix to extract information like file name, line number, column number, etc, from errors and warnings generated with :make. If an error/warning message in the quickfix window matches one of your error formats, you can select it (double click in gvim, or press Enter on the line) to jump to the correct place. It also provides some simple reformatting and highlighting to standardize the display of recognized messages. :help 'efm'

Vim comes preloaded with some good defaults. You can use the set errorformat command in (for instance) your vimrc file to add more for tools you use. If you use the += operator for the assignment, it will append the text to the current value, separated with a comma, as required for the errorformat.

Since compilers and other programs generate messages according to their own rules, there are a multitude of error formats that could be useful. Some are listed here.

flexEdit

The free alternative to LEX, a lexical parser generator. Error messages are like: "somefile.l", line 15: rule cannot be matched.

set errorformat+=%*[\"]%f%*[\"]\\,\ line\ %l:\ %m

bisonEdit

The GNU bison parser generator (similar to YACC) generates a couple of different types of errors. They start with the file name, then a colon. If available, the linenumber comes next, followed by a dot (period) and the column number. If appropriate, a dash and then another column number (giving a column range) follows, and then a colon, space, and the error message.

set errorformat+=%f:%l.%c-%*[0-9]:\ %m
set errorformat+=%f:%l.%c:\ %m
set errorformat+=%f:\ %m

Texas Instruments cl2000 compilerEdit

This is the C-compiler and linker that's used for some Texas Instruments DSP microprocessors. Error format is like "file.c", line 17: some error message.

set errorformat=\"%f\"\\,\ line\ %l:\ %m

mingwEdit

The mingw Windows port of the gcc c-compiler/linker from the FSF.

set errorformat+=%f:%l:\ %m

gfortranEdit

A suitable 'errorformat' for gfortran is:

set efm=%E%f:%l.%c:,%E%f:%l:,%C,%C%p%*[0123456789^],%ZError:\ %m,%C%.%#

%E%f:%l.%c:   to parse "FILENAME:LINENUMBER.COLNUMBER:".
%E%f:%l:   to parse "FILENAME:LINENUMBER:".
%C:   to pass over the empty line.
%C%p%*[0123456789^]:   to get the column number from the indicator line (" 1").
%ZError:\ %m:   to parse the error message ("Error: ERROR_MESSAGE").
%C%.%#:   to pass over the source code line (and ignore it).

The following allows parsing of the following message (make output):

gfortran hello-world.f90 -o hello-world.exe
hello-world.f90:11:

sprint *, "hello", pi, x, r
1
Error: Unclassifiable statement at (1)
hello-world.f90:9.4:

r = cotan(pi/2)
   1
Error: Function 'cotan' at (1) has no IMPLICIT type
make: *** [hello-world.exe] Error 1

In Vim, :clist then shows:

2 hello-world.f90:11 col 1 error:  Unclassifiable statement at (1)
3 hello-world.f90:9 col 4 error:  Function 'cotan' at (1) has no IMPLICIT type

Where hello-world.f90 is:

program hello
implicit none

real (kind = 10), dimension(10):: r
real (kind=8):: pi

pi = atan(1.0) * 4
r = cotan(pi/2)
sprint *, "hello", pi, x, r

end program

Modelsim vlog/vcom for Verilog/VHDL Edit

A simulation tool for Verilog/VHDL. Error messages look like:
** Error: /pathto/somefile.v(115): near \"source text\": syntax error message.

set errorformat=**\ Error:\ %f(%l):\ %m

ZilogEdit

Code for the Zilog eZ80 microprocessor can be built from Vim after installing ZDS. Create a makefile manually or use the one generated from a ZDS project.

With the following in your vimrc, you can use :Make to perform a :make and to open any resulting quickfix window:

command -nargs=* Make make <args>|cwindow 3

Add the following to file ~/.vim/after/ftplugin/c.vim (Unix) or $HOME/vimfiles/after/ftplugin/c.vim (Windows) – you may need to create the file. Then you can press F7 to build:

setlocal errorformat=%f\	(%l\\,%c)\ :\	ERROR\ (%n)\ %m
setlocal makeef=\myerrs.txt
nnoremap <F7> :update<CR>:Make -f myproject_myconf.mak<CR><CR>

The errorformat line contains two tab characters (shown as large whitespaces above).

Todo: Should investigate use of :let errorformat=... with \t to avoid need to use literal tab characters.

CMakeEdit

" CMake Parser
" Call stack entries
let &efm = ' %#%f:%l %#(%m)'
" Start of multi-line error
let &efm .= ',%E' . 'CMake Error at %f:%l (message):'
" End of multi-line error
let &efm .= ',%Z' . 'Call Stack (most recent call first):'
" Continuation is message
let &efm .= ',%C' . ' %m'

See alsoEdit

ReferencesEdit

CommentsEdit

 TO DO 

  • Clean up tips in Category:Compiler.
  • Where appropriate, should merge compiler tips for a particular language into one tip.
  • Need emphasis to be on the :compiler command (don't directly mess with 'efm').
  • Settings for errorformat should be in a compiler plugin rather than in vimrc. :help write-compiler-plugin :help compiler-select
  • If there is no support for a compiler, user should add a new compiler (need example of how).
  • Need links to a tip with info on the quickfix window.

Related tips (all are in Compiler category; first four are in 'see also' above)

Many existing tips have obsolete/bad advice, for example, tip 476 says to edit the $VIM/ftplugin/perl.vim file (probably means $VIMRUNTIME/ftplugin/perl.vim but you should never patch a distribution file).


Around Wikia's network

Random Wiki