@@ -34,20 +34,58 @@ ENDPYTHON
34
34
cexpr " "
35
35
let l: traceback = []
36
36
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.
37
51
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).
40
66
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 %+.
41
69
let &efm .= ' %+C %.%#,'
42
70
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)
44
78
let &efm .= ' %-G%.%#'
45
79
46
80
python << ENDPYTHON2
81
+ # Remove any error lines containing ' <string>' . We don't need them.
82
+ # Add the rest to a Vim list .
47
83
for x in [i for i in err.splitlines () if " <string>" not in i ]:
48
84
vim .command (" call add(l:traceback, '{}')" .format (x ))
49
85
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.
51
89
cgetexpr (l: traceback )
52
90
call pymode#QuickfixOpen (0 , g: pymode_lint_hold , g: pymode_lint_maxheight , g: pymode_lint_minheight , 0 )
53
91
let &efm = l: oldefm
0 commit comments