Skip to content

Commit a064c3c

Browse files
committed
Commenting the errorformat string
1 parent e1e63cc commit a064c3c

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

autoload/pymode/run.vim

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,58 @@ ENDPYTHON
3434
cexpr ""
3535
let l:traceback = []
3636
let l:oldefm = &efm
37+
38+
" The following lines set Vim's errorformat variable, to allow the
39+
" quickfix window to show Python tracebacks properly. It is much
40+
" easier to use let than set, because set requires many more
41+
" characters to be escaped. This is much easier to read and
42+
" maintain. % escapes are still needed however before any regex meta
43+
" characters. Hence \S (non-whitespace) becomes %\S etc. Note that
44+
" * becomes %#, so .* (match any character) becomes %.%# Commas must
45+
" also be escaped, with a backslash (\,). See the Vim help on
46+
" quickfix for details.
47+
"
48+
" Python errors are multi-lined. They often start with 'Traceback', so
49+
" we want to capture that (with +G) and show it in the quickfix window
50+
" because it explains the order of error messages.
3751
let &efm = '%+GTraceback%.%#,'
38-
let &efm .= '%E File "%f"\, line %l\,%m,'
39-
let &efm .= '%E File "%f"\, line %l,'
52+
53+
" The error message itself starts with a line with 'File' in it. There
54+
" are a couple of variations, and we need to process a line beginning
55+
" with whitespace followed by File, the filename in "", a line number,
56+
" and optional further text. %E here indicates the start of a multi-line
57+
" error message. The %\C at the end means that a case-sensitive search is
58+
" required.
59+
let &efm .= '%E File "%f"\, line %l\,%m%\C,'
60+
let &efm .= '%E File "%f"\, line %l%\C,'
61+
62+
" The possible continutation lines are idenitifed to Vim by %C. We deal
63+
" with these in order of most to least specific to ensure a proper
64+
" match. A pointer (^) identifies the column in which the error occurs
65+
" (but will not be entirely accurate due to indention of Python code).
4066
let &efm .= '%C%p^,'
67+
" Any text, indented by more than two spaces contain useful information.
68+
" We want this to appear in the quickfix window, hence %+.
4169
let &efm .= '%+C %.%#,'
4270
let &efm .= '%+C %.%#,'
43-
let &efm .= '%Z%m,'
71+
72+
" The last line (%Z) does not begin with any whitespace. We use a zero
73+
" width lookahead (\&) to check this. The line contains the error
74+
" message itself (%m)
75+
let &efm .= '%Z%\S%\&%m,'
76+
77+
" We can ignore any other lines (%-G)
4478
let &efm .= '%-G%.%#'
4579

4680
python << ENDPYTHON2
81+
# Remove any error lines containing '<string>'. We don't need them.
82+
# Add the rest to a Vim list.
4783
for x in [i for i in err.splitlines() if "<string>" not in i]:
4884
vim.command("call add(l:traceback, '{}')".format(x))
4985
ENDPYTHON2
50-
86+
" Now we can add the list of errors to the quickfix window, and show it. We have
87+
" to add them all at once in this way, because the errors are multi-lined and
88+
" they won't be parsed properly otherwise.
5189
cgetexpr(l:traceback)
5290
call pymode#QuickfixOpen(0, g:pymode_lint_hold, g:pymode_lint_maxheight, g:pymode_lint_minheight, 0)
5391
let &efm = l:oldefm

0 commit comments

Comments
 (0)