set breakpoints in pudb directly from vim!
This commit is contained in:
@@ -21,6 +21,7 @@ Plugin 'scrooloose/nerdtree'
|
|||||||
Plugin 'tpope/vim-fugitive'
|
Plugin 'tpope/vim-fugitive'
|
||||||
Plugin 'tpope/vim-eunuch'
|
Plugin 'tpope/vim-eunuch'
|
||||||
Plugin 'majutsushi/tagbar'
|
Plugin 'majutsushi/tagbar'
|
||||||
|
Plugin 'vim-python/python-syntax'
|
||||||
" Plugin 'mattn/emmet-vim'
|
" Plugin 'mattn/emmet-vim'
|
||||||
" Plugin 'lepture/vim-jinja'
|
" Plugin 'lepture/vim-jinja'
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ call vundle#end()
|
|||||||
|
|
||||||
"Local settings
|
"Local settings
|
||||||
"{{{
|
"{{{
|
||||||
set guifont=Consolas:h12
|
" set guifont=Consolas:h12
|
||||||
|
set guifont=JetBrains\ Mono\ 12
|
||||||
colorscheme snowhite
|
colorscheme snowhite
|
||||||
"}}}
|
"}}}
|
||||||
|
|||||||
@@ -7,3 +7,8 @@ iabbrev <buffer> sex raise SystemExit
|
|||||||
iabbrev <buffer> ddf HERE = os.path.abspath(os.path.dirname(__file__))
|
iabbrev <buffer> ddf HERE = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
nnoremap <buffer> <localleader>x :term python %<cr>
|
nnoremap <buffer> <localleader>x :term python %<cr>
|
||||||
|
|
||||||
|
nnoremap <buffer> <localleader>ba :PudbAddBreakpoint<cr>
|
||||||
|
nnoremap <buffer> <localleader>bd :PudbDeleteBreakpoint<cr>
|
||||||
|
nnoremap <buffer> <localleader>bs :PudbShowBreakpoints<cr>
|
||||||
|
nnoremap <buffer> <localleader>bh :PudbHideBreakpoints<cr>
|
||||||
|
|||||||
71
plugin/pudb.vim
Normal file
71
plugin/pudb.vim
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
let s:bpfile = trim(system('python -c "import pudb.settings; print(pudb.settings.get_breakpoints_file_name())"'))
|
||||||
|
|
||||||
|
if filereadable(s:bpfile)
|
||||||
|
call sign_define("pudb_bp", { "text": "b", "texthl": "Error"})
|
||||||
|
|
||||||
|
function! BreakpointFromString(bp_string)
|
||||||
|
return split(split(a:bp_string, ' ')[1], ':')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! StringFromBreakpoint(breakpoint)
|
||||||
|
return 'b ' . a:breakpoint[0] . ':' . a:breakpoint[1]
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! LoadBreakpoints()
|
||||||
|
let breakpoints = filter(readfile(s:bpfile), 'v:val[0] == "b"')
|
||||||
|
let breakpoints = map(breakpoints, 'BreakpointFromString(v:val)')
|
||||||
|
return breakpoints
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! AddBreakpoint()
|
||||||
|
if &ft != 'python'
|
||||||
|
echoerr 'Not a Python file'
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let breakpoints = LoadBreakpoints()
|
||||||
|
let fname = expand('%:p')
|
||||||
|
let lineno = line('.')
|
||||||
|
for breakpoint in breakpoints
|
||||||
|
if fname == breakpoint[0] && lineno == breakpoint[1]
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
let bpline = 'b ' . fname . ':' . lineno
|
||||||
|
call writefile([bpline], s:bpfile, 'a')
|
||||||
|
call DrawMarkers()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! DeleteBreakpoint()
|
||||||
|
if &ft != 'python'
|
||||||
|
echoerr 'Not a Python file'
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let fname = expand('%:p')
|
||||||
|
let lineno = line('.')
|
||||||
|
let breakpoints = filter(LoadBreakpoints(),
|
||||||
|
\ 'v:val[0] != fname || v:val[1] != lineno')
|
||||||
|
call writefile(map(breakpoints, 'StringFromBreakpoint(v:val)'),
|
||||||
|
\ s:bpfile, 'w')
|
||||||
|
call DrawMarkers()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UndrawMarkers()
|
||||||
|
call sign_unplace('pudb')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! DrawMarkers()
|
||||||
|
call UndrawMarkers()
|
||||||
|
let breakpoints = LoadBreakpoints()
|
||||||
|
for breakpoint in breakpoints
|
||||||
|
if bufexists(breakpoint[0])
|
||||||
|
call sign_place(0, 'pudb', 'pudb_bp', breakpoint[0], {
|
||||||
|
\ 'lnum': str2nr(breakpoint[1])})
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
command! PudbAddBreakpoint call AddBreakpoint()
|
||||||
|
command! PudbDeleteBreakpoint call DeleteBreakpoint()
|
||||||
|
command! PudbShowBreakpoints call DrawMarkers()
|
||||||
|
command! PudbHideBreakpoints call UndrawMarkers()
|
||||||
|
endif
|
||||||
Reference in New Issue
Block a user