Skip to content

Add support for neovim, newest pudb and atomize python code #5

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 2 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
82 changes: 18 additions & 64 deletions plugin/pudb.vim
Original file line number Diff line number Diff line change
@@ -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('<sfile>: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")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Program will now execute correctly if (neo)vim has either +python or +python3 compilation flags

echo "Error: Required (neo)vim compiled with +python"
finish
endif

Expand All @@ -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

38 changes: 38 additions & 0 deletions plugin/toggle.py
Original file line number Diff line number Diff line change
@@ -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()')
25 changes: 25 additions & 0 deletions plugin/update.py
Original file line number Diff line number Diff line change
@@ -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")