Skip to content

Commit 4ee8bcd

Browse files
committed
Update python's linecache when a python file is written
This fixes an annoying bug where your ability to set breakpoints would be based entirely on whether or not there was an executable line at the place you want the breakpoint when you first opened the file for editing.
1 parent be396ce commit 4ee8bcd

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

plugin/pudb.vim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ function! s:LocationList()
219219
endfunction
220220

221221

222+
"
223+
" Clear the python line cache for the given file if it has changed
224+
"
225+
function! s:ClearLineCache(filename)
226+
pythonx << EOF
227+
import linecache
228+
import vim
229+
linecache.checkcache(vim.eval('a:filename'))
230+
EOF
231+
endfunction
232+
233+
222234
" Define ex commands for all the above functions so they are user-accessible.
223235
command! PudbClearAll call s:ClearAll()
224236
command! PudbEdit call s:Edit()
@@ -237,7 +249,11 @@ if &filetype == 'python'
237249
endif
238250

239251

240-
" Also update when the file is first read.
241252
augroup pudb
253+
" Also update when the file is first read.
242254
autocmd BufReadPost *.py call s:Update()
255+
256+
" Force a linecache update after writes so the breakpoints can be parsed
257+
" correctly.
258+
autocmd BufWritePost *.py call s:ClearLineCache(expand('%:p'))
243259
augroup end

0 commit comments

Comments
 (0)