Vim w/Python: Make ":make" take me to the error
python, vim
Solution
This code will navigate to innermost exception.
function! s:InnermostExceptionInQFList()
let s:num = 0
for item in getqflist()
if item.lnum > 0
let s:num += 1
endif
endfor
if s:num > 0
try
silent execute(s:num . 'cnext')
catch /E553:/
" E553: No more elements
endtry
endif
silent execute('wincmd w')
endfunction
autocmd! QuickfixCmdPost * call s:InnermostExceptionInQFList()
Problem
If I have a python file like: ``` def Bar(): raise NotImplementedError def Foo(): Bar() if __name__ == '__main__': Foo() ``` And I type :make in vim, it nicely builds me a :cwindow filled with the relevant areas to move up the traceback. However, it defaults my cursor to the first frame of the call (in name == 'main'). Can I somehow change the default behaviour, so it takes me to the actual call of the exception? -- Update -- Answering Ingo's question: :makeprg/errorformat are set to default for the gentoo install. That is: ``` makeprg=python % errorformat=%A File "%f"\, line %l%.%#,%Z%[%^ ]%\@=%m ``` The stacktrace in the quickfix window looks like such: ``` main.py 1 || Traceback (most recent call last): 2 main.py|8| 3 || Foo() 4 main.py|5| 5 || Bar() 6 main.py|2| 7 || raise NotImplementedError 8 || NotImplementedError ``` Spoiled brat that I am, I'd love it if I started at the 'raise' (line 7) and could :cp 'backwards' as needed.