diff --git a/plugin/load_breakpoints.py b/plugin/load_breakpoints.py new file mode 100644 index 0000000..472dbd9 --- /dev/null +++ b/plugin/load_breakpoints.py @@ -0,0 +1,31 @@ +""" +Usage: load_breakpoints.py + +Print breakpoints in + +Example usage: + + $ ./load_breakpoints.py foo.py + 3 + 50 + 57 + +""" + +import sys + +try: + from pudb.settings import load_breakpoints + from pudb import NUM_VERSION +except ImportError: + exit(-1) + +args = () if NUM_VERSION >= (2013, 1) else (None,) +bps = load_breakpoints(*args) + +filename = sys.argv[1] + +bps = [bp[1] for bp in bps if bp[0] == filename] + +for bp in bps: + print(bp) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 4117e90..0e95e62 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -9,8 +9,8 @@ if exists('g:loaded_pudb_plugin') || &cp endif let g:loaded_pudb_plugin = 1 -if !has("python") - echo "Error: Required vim compiled with +python" +if !has("python3") + echo "Error: Required vim compiled with +python3" finish endif @@ -19,6 +19,8 @@ sign define PudbBreakPoint text=Ø) texthl=error let s:first_sign_id = 10000 let s:next_sign_id = s:first_sign_id +let s:plugin_dir = expand(":p:h") + augroup pudb autocmd BufReadPost *.py call s:UpdateBreakPoints() augroup end @@ -38,22 +40,23 @@ endfor let b:pudb_sign_ids = [] -python << EOF +python3 << EOF import vim -from pudb.settings import load_breakpoints -from pudb import NUM_VERSION +import os +import subprocess +import shutil filename = vim.eval('expand("%:p")') -args = () if NUM_VERSION >= (2013, 1) else (None,) -bps = load_breakpoints(*args) +scriptname = os.path.join(vim.eval('s:plugin_dir'), 'load_breakpoints.py') +python_path = shutil.which('python') or shutil.which('python3') +bps = subprocess.Popen([python_path, scriptname, filename], stdout=subprocess.PIPE) -for bp in bps: - if bp[0] != filename: - continue +for bp in bps.stdout: + bp = int(bp.strip()) 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.command("sign place %s line=%s name=PudbBreakPoint file=%s" % (sign_id, bp, filename)) vim.eval("add(b:pudb_sign_ids, s:next_sign_id)") vim.command("let s:next_sign_id += 1") EOF @@ -61,31 +64,16 @@ EOF endfunction function! s:ToggleBreakPoint() -python << EOF +python3 << 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) +scriptname = os.path.join(vim.eval('s:plugin_dir'), 'set_breakpoint.py') +python_path = shutil.which('python') or shutil.which('python3') +proc = subprocess.Popen([python_path, scriptname, filename, str(row)]) +proc.wait() vim.command('call s:UpdateBreakPoints()') EOF diff --git a/plugin/set_breakpoint.py b/plugin/set_breakpoint.py new file mode 100644 index 0000000..230f0e4 --- /dev/null +++ b/plugin/set_breakpoint.py @@ -0,0 +1,41 @@ +""" +Usage: set_breakpoint.py + +Set a breakpoint in at + +Example usage: + + $ ./load_breakpoints.py foo.py + 12 + $ ./set_breakpoint.py foo.py 11 + $ ./load_breakpoints.py foo.py + 12 + 11 +""" + +import sys + +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 = sys.argv[1] +row = int(sys.argv[2]) + +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 + self.cond = None + +bp_list = [BP(bp[0], bp[1]) for bp in bps] + +save_breakpoints(bp_list)