diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 4117e90..a3167c2 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -1,16 +1,19 @@ " File: pudb.vim " Author: Christophe Simonis -" Description: Manage pudb breakpoints directly into vim -" Last Modified: December 03, 2012 -" +" Description: Manage pudb breakpoints directly into (neo)vim +" Last Modified: 2017-09-13 if exists('g:loaded_pudb_plugin') || &cp finish endif + let g:loaded_pudb_plugin = 1 +let g:plugin_path = expand(':p:h') +let s:toggle_path = g:plugin_path . '/toggle.py' +let s:update_path = g:plugin_path . '/update.py' -if !has("python") - echo "Error: Required vim compiled with +python" +if !has("python") && !has("python3") + echo "Error: Required (neo)vim compiled with +python" finish endif @@ -26,68 +29,19 @@ augroup end command! TogglePudbBreakPoint call s:ToggleBreakPoint() function! s:UpdateBreakPoints() + " first remove existing signs + if !exists("b:pudb_sign_ids") + let b:pudb_sign_ids = [] + endif -" first remove existing signs -if !exists("b:pudb_sign_ids") - let b:pudb_sign_ids = [] -endif - -for i in b:pudb_sign_ids - exec "sign unplace " . i -endfor -let b:pudb_sign_ids = [] - - -python << EOF -import vim -from pudb.settings import load_breakpoints -from pudb import NUM_VERSION - -filename = vim.eval('expand("%:p")') - -args = () if NUM_VERSION >= (2013, 1) else (None,) -bps = load_breakpoints(*args) - -for bp in bps: - if bp[0] != filename: - continue - - sign_id = vim.eval("s:next_sign_id") - vim.command("sign place %s line=%s name=PudbBreakPoint file=%s" % (sign_id, bp[1], filename)) - vim.eval("add(b:pudb_sign_ids, s:next_sign_id)") - vim.command("let s:next_sign_id += 1") -EOF + for i in b:pudb_sign_ids + exec "sign unplace " . i + endfor + let b:pudb_sign_ids = [] + execute 'pyfile ' . s:update_path endfunction function! s:ToggleBreakPoint() -python << EOF -import vim -from pudb.settings import load_breakpoints, save_breakpoints -from pudb import NUM_VERSION - -args = () if NUM_VERSION >= (2013, 1) else (None,) -bps = [bp[:2] for bp in load_breakpoints(*args)] - -filename = vim.eval('expand("%:p")') -row, col = vim.current.window.cursor - -bp = (filename, row) -if bp in bps: - bps.pop(bps.index(bp)) -else: - bps.append(bp) - -class BP(object): - def __init__(self, fn, ln): - self.file = fn - self.line = ln - -bp_list = [BP(bp[0], bp[1]) for bp in bps] - -save_breakpoints(bp_list) - -vim.command('call s:UpdateBreakPoints()') -EOF + execute 'pyfile ' . s:toggle_path endfunction - diff --git a/plugin/toggle.py b/plugin/toggle.py new file mode 100644 index 0000000..ee3b83b --- /dev/null +++ b/plugin/toggle.py @@ -0,0 +1,38 @@ +try: + import neovim + import os + sock = os.environ.get('NVIM_LISTEN_ADDRESS') + vim = neovim.attach('socket', sock) +except: + import vim + +from pudb.settings import load_breakpoints, save_breakpoints +from pudb import NUM_VERSION + +args = () if NUM_VERSION >= (2013, 1) else (None,) +bps = [bp[:2] for bp in load_breakpoints(*args)] + +filename = vim.eval('expand("%:p")') +row, col = vim.current.window.cursor + +bp = (filename, row) +if bp in bps: + bps.pop(bps.index(bp)) +else: + bps.append(bp) + + +class BP(object): + def __init__(self, fn, ln): + self.file = fn + self.line = ln + # TODO: Properly handle conditions and allow the user to create them + # from (neo)vim + self.cond = None + + +bp_list = [BP(_bp[0], _bp[1]) for _bp in bps] + +save_breakpoints(bp_list) + +vim.command('call s:UpdateBreakPoints()') diff --git a/plugin/update.py b/plugin/update.py new file mode 100644 index 0000000..ca16ee6 --- /dev/null +++ b/plugin/update.py @@ -0,0 +1,25 @@ +try: + import neovim + import os + sock = os.environ.get('NVIM_LISTEN_ADDRESS') + vim = neovim.attach('socket', sock) +except: + import vim + +from pudb.settings import load_breakpoints +from pudb import NUM_VERSION + +filename = vim.eval('expand("%:p")') + +args = () if NUM_VERSION >= (2013, 1) else (None,) +bps = load_breakpoints(*args) + +for bp in bps: + if bp[0] != filename: + continue + + sign_id = vim.eval("s:next_sign_id") + vim.command("sign place %s line=%s name=PudbBreakPoint file=%s" + % (sign_id, bp[1], filename)) + vim.eval("add(b:pudb_sign_ids, s:next_sign_id)") + vim.command("let s:next_sign_id += 1")