From a73303bcaeae5b0cd6650b03a4892147eec6a6b2 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Tue, 12 Sep 2017 14:34:50 +0200 Subject: [PATCH 1/2] Add neovim support, atomize python code Fix rel path issue Fix rel path issue part 2 --- plugin/pudb.vim | 82 +++++++++++------------------------------------- plugin/toggle.py | 35 +++++++++++++++++++++ plugin/update.py | 25 +++++++++++++++ 3 files changed, 78 insertions(+), 64 deletions(-) create mode 100644 plugin/toggle.py create mode 100644 plugin/update.py diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 4117e90..5182a80 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-12 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..c530ba0 --- /dev/null +++ b/plugin/toggle.py @@ -0,0 +1,35 @@ +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 + + +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") From bc7f0df4a0b71f587dd757219892139e812235ef Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Wed, 13 Sep 2017 08:42:25 +0200 Subject: [PATCH 2/2] Add cond attribute to BP --- plugin/pudb.vim | 2 +- plugin/toggle.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 5182a80..a3167c2 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -1,7 +1,7 @@ " File: pudb.vim " Author: Christophe Simonis " Description: Manage pudb breakpoints directly into (neo)vim -" Last Modified: 2017-09-12 +" Last Modified: 2017-09-13 if exists('g:loaded_pudb_plugin') || &cp finish diff --git a/plugin/toggle.py b/plugin/toggle.py index c530ba0..ee3b83b 100644 --- a/plugin/toggle.py +++ b/plugin/toggle.py @@ -26,6 +26,9 @@ 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]