Skip to content

Support vim compiled with +python3 (e.g. Ubuntu 17.04) #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions plugin/load_breakpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Usage: load_breakpoints.py <filename>

Print breakpoints in <filename>

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)
50 changes: 19 additions & 31 deletions plugin/pudb.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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("<sfile>:p:h")

augroup pudb
autocmd BufReadPost *.py call s:UpdateBreakPoints()
augroup end
Expand All @@ -38,54 +40,40 @@ 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

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
Expand Down
41 changes: 41 additions & 0 deletions plugin/set_breakpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Usage: set_breakpoint.py <filename> <lineno>

Set a breakpoint in <filename> at <lineno>

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)