diff --git a/.vimrc_template b/.vimrc_template index 64bbb6e..5a73fe2 100644 --- a/.vimrc_template +++ b/.vimrc_template @@ -21,6 +21,7 @@ Plugin 'scrooloose/nerdtree' Plugin 'tpope/vim-fugitive' Plugin 'tpope/vim-eunuch' Plugin 'majutsushi/tagbar' +Plugin 'vim-python/python-syntax' " Plugin 'mattn/emmet-vim' " Plugin 'lepture/vim-jinja' @@ -37,6 +38,7 @@ call vundle#end() "Local settings "{{{ -set guifont=Consolas:h12 +" set guifont=Consolas:h12 +set guifont=JetBrains\ Mono\ 12 colorscheme snowhite "}}} diff --git a/ftplugin/python.vim b/ftplugin/python.vim index 9c25621..04dc5ed 100644 --- a/ftplugin/python.vim +++ b/ftplugin/python.vim @@ -7,3 +7,8 @@ iabbrev sex raise SystemExit iabbrev ddf HERE = os.path.abspath(os.path.dirname(__file__)) nnoremap x :term python % + +nnoremap ba :PudbAddBreakpoint +nnoremap bd :PudbDeleteBreakpoint +nnoremap bs :PudbShowBreakpoints +nnoremap bh :PudbHideBreakpoints diff --git a/plugin/pudb.vim b/plugin/pudb.vim new file mode 100644 index 0000000..5a8ab4c --- /dev/null +++ b/plugin/pudb.vim @@ -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