Vim Tips Wiki
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
Various packages are available to check source code for style compliance or to identify errors such as using a variable before a value is assigned to it. For Python code, two such packages are [http://pypi.python.org/pypi/pyflakes pyflakes] and [http://pypi.python.org/pypi/pep8 pep8]. It is convenient to configure Vim's <code>:make</code> command to invoke one of the programs and display any errors in the quickfix window. This tip shows how to run <code>:make</code> multiple times and combine the errors into one quickfix list.
+
Various packages are available to check source code for style compliance or to identify errors such as using a variable before a value is assigned to it. For Python code, two such packages are [http://pypi.python.org/pypi/pyflakes pyflakes] and [http://pypi.python.org/pypi/pep8 pep8]. It is convenient to configure Vim's <tt>:make</tt> command to invoke one of the programs and display any errors in the quickfix window. This tip shows how to run <tt>:make</tt> multiple times and combine the errors into one quickfix list.
   
After sourcing the following code, edit a Python file and type <code>:Pycheck</code> to check the code with both <code>pyflakes</code> and <code>pep8</code> (each of these needs to be installed).
+
After sourcing the following code, edit a Python file and type <tt>:Pycheck</tt> to check the code with both <tt>pyflakes</tt> and <tt>pep8</tt> (each of these needs to be installed).
 
<pre>
 
<pre>
 
" Do make with different makeprg settings.
 
" Do make with different makeprg settings.
Line 38: Line 38:
 
</pre>
 
</pre>
   
The script defines a user command (<code>Pycheck</code>) that invokes the <code>DoMake</code> function, specifying the names of the programs to be run to check the current file. Any changes to the file are saved. Each program name provided (there can be any number) is used to set the <code>'makeprg'</code> option, then <code>:make!</code> is run to invoke the program and set the quickfix list from the results. The <code>!</code> option avoids jumping to the first error, if any (later, the script jumps to the first error for the first program, if applicable), while <code>silent</code> prevents the display of normal messages that result from running <code>:make</code> in order to avoid the "Press Enter" prompt.
+
The script defines a user command (<tt>Pycheck</tt>) that invokes the <tt>DoMake</tt> function, specifying the names of the programs to be run to check the current file. Any changes to the file are saved. Each program name provided (there can be any number) is used to set the <tt>'makeprg'</tt> option, then <tt>:make!</tt> is run to invoke the program and set the quickfix list from the results. The <tt>!</tt> option avoids jumping to the first error, if any (later, the script jumps to the first error for the first program, if applicable), while <tt>silent</tt> prevents the display of normal messages that result from running <tt>:make</tt> in order to avoid the "Press Enter" prompt.
   
The quickfix list from each run of <code>:make</code> is appended to <code>qflist</code> (a variable initialised to <code>[]</code> or an empty list). When finished, <code>qflist</code> holds all quickfix messages resulting from running each of the programs. If the list is empty, the quickfix window is closed (if it was currently open from a previous run). Otherwise, the list is used to set Vim's quickfix list, and the quickfix window is opened and the first error displayed.
+
The quickfix list from each run of <tt>:make</tt> is appended to <tt>qflist</tt> (a variable initialised to <tt>[]</tt> or an empty list). When finished, <tt>qflist</tt> holds all quickfix messages resulting from running each of the programs. If the list is empty, the quickfix window is closed (if it was currently open from a previous run). Otherwise, the list is used to set Vim's quickfix list, and the quickfix window is opened and the first error displayed.
   
 
==See also==
 
==See also==
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)