From f73acd9fe1e55f6f0cbb2b9c461364bcc8e6f1e0 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 28 Dec 2019 22:03:10 -0600 Subject: [PATCH 01/55] Add and use options for definining the breakpoint sign --- plugin/pudb.vim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 9623de3..f2d2e7a 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -15,7 +15,22 @@ if !has("pythonx") finish endif -sign define PudbBreakPoint text=Ø) texthl=error +if !exists('g:pudb_breakpoint_sign') + let g:pudb_breakpoint_sign = '>>' +endif + +if !exists('g:pudb_breakpoint_highlight') + let g:pudb_breakpoint_highlight = 'error' +endif + +if !exists('g:pudb_breakpoint_priority') + let g:pudb_breakpoint_priority = 100 +endif + +call sign_define('PudbBreakPoint', { + \ 'text': g:pudb_breakpoint_sign, + \ 'texthl': g:pudb_breakpoint_highlight + \ }) let s:first_sign_id = 10000 let s:next_sign_id = s:first_sign_id From a05ac236f95cec381c4fa702f94ea3be085595aa Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 28 Dec 2019 22:06:57 -0600 Subject: [PATCH 02/55] Add documentation to README about new sign options --- README.rst | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 0c83916..62ae608 100644 --- a/README.rst +++ b/README.rst @@ -24,8 +24,20 @@ For easy access, you can bind it to the F8 key. .. _vim-pathogen: https://github.com/tpope/vim-pathogen#readme -Know problems +Configuration ============= -Currently, the list of breakpoints is not reloaded automatically. +The text of the sign can be defined with ``g:pudb_breakpoint_sign`` (default +'>>'): + + ``let g:pudb_breakpoint_sign = '>>'`` + +The highlight group of the sign in the sign colum can be defined with +``g:pudb_breakpoint_highlight`` (default 'error'): + + ``let g:pudb_breakpoint_highlight = 'error'`` + +Known problems +============= +Currently, the list of breakpoints is not reloaded automatically. There is also room for speed optimisations. From a6500488725acce451343f001bd384fcb7052686 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 28 Dec 2019 22:11:21 -0600 Subject: [PATCH 03/55] Define a user-accessible command for updating breakpoints --- plugin/pudb.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index f2d2e7a..84ad90a 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -39,8 +39,6 @@ augroup pudb autocmd BufReadPost *.py call s:UpdateBreakPoints() augroup end -command! TogglePudbBreakPoint call s:ToggleBreakPoint() - function! s:UpdateBreakPoints() " first remove existing signs @@ -103,3 +101,6 @@ vim.command('call s:UpdateBreakPoints()') EOF endfunction +command! TogglePudbBreakPoint call s:ToggleBreakPoint() +command! UpdatePudbBreakPoints call s:UpdateBreakPoints() + From 78a8ac3fa12bb73f2b103b7c7ab595e455f1d98d Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 28 Dec 2019 22:46:18 -0600 Subject: [PATCH 04/55] Use a sign group to avoid interfering with other plugins --- plugin/pudb.vim | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 84ad90a..8f6f98a 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -32,25 +32,16 @@ call sign_define('PudbBreakPoint', { \ 'texthl': g:pudb_breakpoint_highlight \ }) -let s:first_sign_id = 10000 -let s:next_sign_id = s:first_sign_id - augroup pudb autocmd BufReadPost *.py call s:UpdateBreakPoints() augroup end +let s:pudb_sign_group = 'pudb_sign_group' + function! s:UpdateBreakPoints() " 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 = [] - +call sign_unplace(s:pudb_sign_group) pythonx << EOF import vim @@ -60,16 +51,15 @@ from pudb import NUM_VERSION filename = vim.eval('expand("%:p")') args = () if NUM_VERSION >= (2013, 1) else (None,) -bps = load_breakpoints(*args) +bps = [bp[:2] for bp in load_breakpoints(*args)] -for bp in bps: - if bp[0] != filename: +for bp_file, bp_lnum in bps: + if bp_file != 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") + opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_breakpoint_priority']) + vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' + '' % (vim.eval('s:pudb_sign_group'), filename, opts)) EOF endfunction @@ -82,16 +72,16 @@ from pudb import NUM_VERSION from bdb import Breakpoint args = () if NUM_VERSION >= (2013, 1) else (None,) -bps = [bp[:2] for bp in load_breakpoints(*args)] +bps = {tuple(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)) + bps.remove(bp) else: - bps.append(bp) + bps.add(bp) bp_list = [Breakpoint(bp[0], bp[1]) for bp in bps] @@ -103,4 +93,3 @@ endfunction command! TogglePudbBreakPoint call s:ToggleBreakPoint() command! UpdatePudbBreakPoints call s:UpdateBreakPoints() - From 55e5c177d72ae0efa447a7d96273f5286e857ad8 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 28 Dec 2019 23:00:06 -0600 Subject: [PATCH 05/55] Use a different sign group for each file --- plugin/pudb.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 8f6f98a..551d17d 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -36,12 +36,12 @@ augroup pudb autocmd BufReadPost *.py call s:UpdateBreakPoints() augroup end -let s:pudb_sign_group = 'pudb_sign_group' +let s:pudb_sign_group = 'pudb_sign_group_' function! s:UpdateBreakPoints() " first remove existing signs -call sign_unplace(s:pudb_sign_group) +call sign_unplace(s:pudb_sign_group .. expand('%:p')) pythonx << EOF import vim @@ -59,7 +59,7 @@ for bp_file, bp_lnum in bps: opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_breakpoint_priority']) vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' - '' % (vim.eval('s:pudb_sign_group'), filename, opts)) + '' % (vim.eval('s:pudb_sign_group .. expand("%:p")'), filename, opts)) EOF endfunction From 0a512828f60040f96d8ad1c9f56ced92af1bd9e2 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 28 Dec 2019 23:06:42 -0600 Subject: [PATCH 06/55] Update README with sign priority option --- README.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 62ae608..98bb3f3 100644 --- a/README.rst +++ b/README.rst @@ -27,15 +27,19 @@ For easy access, you can bind it to the F8 key. Configuration ============= The text of the sign can be defined with ``g:pudb_breakpoint_sign`` (default -'>>'): +``'>>'``): ``let g:pudb_breakpoint_sign = '>>'`` The highlight group of the sign in the sign colum can be defined with -``g:pudb_breakpoint_highlight`` (default 'error'): +``g:pudb_breakpoint_highlight`` (default ``'error'``): ``let g:pudb_breakpoint_highlight = 'error'`` +The priority of the breakpoint signs can be defined with +``g:pudb_breakpoint_priority`` (default ``100``): + + ``let g:pudb_breakpoint_priority = 100`` Known problems ============= Currently, the list of breakpoints is not reloaded automatically. From cdf4f1930f646af4b2312be4352bcc8a6e0a733b Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 28 Dec 2019 23:09:06 -0600 Subject: [PATCH 07/55] Update README with update command --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 98bb3f3..2e5751b 100644 --- a/README.rst +++ b/README.rst @@ -21,6 +21,9 @@ For easy access, you can bind it to the F8 key. ``nnoremap :TogglePudbBreakPoint`` ``inoremap :TogglePudbBreakPointa`` + +In case the breakpoints get out of sync after a debugging session, there is also a command +``:UpdatePudbBreakPoints`` which refreshes the breakpoint signs. .. _vim-pathogen: https://github.com/tpope/vim-pathogen#readme From 9e52bc19ae256cd4278dabcab4c0adf639a994be Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 29 Dec 2019 19:09:56 -0600 Subject: [PATCH 08/55] Improve support for lazy loading Done by updating breakpoints immediately if in a python file when sourced --- plugin/pudb.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 551d17d..f68ad2f 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -93,3 +93,7 @@ endfunction command! TogglePudbBreakPoint call s:ToggleBreakPoint() command! UpdatePudbBreakPoints call s:UpdateBreakPoints() + +if &filetype == 'python' + call s:UpdateBreakPoints() +endif From 4a0805a8d2bb3558a00b71f4326d7dfe0cb6252b Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 29 Dec 2019 19:33:30 -0600 Subject: [PATCH 09/55] Preserve conditions when toggling breakpoints Just because we don't interact with conditions (yet) doesn't mean we should abolish them --- plugin/pudb.vim | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index f68ad2f..581472a 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -49,11 +49,9 @@ 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 = [bp[:2] for bp in load_breakpoints(*args)] -for bp_file, bp_lnum in bps: +for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): if bp_file != filename: continue @@ -72,20 +70,19 @@ from pudb import NUM_VERSION from bdb import Breakpoint args = () if NUM_VERSION >= (2013, 1) else (None,) -bps = {tuple(bp[:2]) for bp in load_breakpoints(*args)} +bps = {(bp.file, bp.line): bp + for bp in map(lambda args: Breakpoint(*args), load_breakpoints(*args))} filename = vim.eval('expand("%:p")') row, col = vim.current.window.cursor -bp = (filename, row) -if bp in bps: - bps.remove(bp) +bp_key = (filename, row) +if bp_key in bps: + bps.pop(bp_key) else: - bps.add(bp) - -bp_list = [Breakpoint(bp[0], bp[1]) for bp in bps] + bps[bp_key] = Breakpoint(filename, row) -save_breakpoints(bp_list) +save_breakpoints(bps.values()) vim.command('call s:UpdateBreakPoints()') EOF From f9ef362f7930333fcb45d63799082122582acad3 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 29 Dec 2019 19:37:11 -0600 Subject: [PATCH 10/55] Don't re-evaluate the filename --- plugin/pudb.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 581472a..e4536e2 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -57,7 +57,7 @@ for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_breakpoint_priority']) vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' - '' % (vim.eval('s:pudb_sign_group .. expand("%:p")'), filename, opts)) + '' % (vim.eval('s:pudb_sign_group .. "%s"' % filename), filename, opts)) EOF endfunction From 5a5a4313ca51cdd85239a1dce1cbdc45b558faab Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 1 Jan 2020 12:15:03 -0600 Subject: [PATCH 11/55] Add a command to clear all breakpoints --- plugin/pudb.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index e4536e2..4837c66 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -88,8 +88,18 @@ vim.command('call s:UpdateBreakPoints()') EOF endfunction +function! s:ClearAllBreakPoints() +pythonx << EOF +from pudb.settings import save_breakpoints +save_breakpoints([]) +EOF + +call s:UpdateBreakPoints() +endfunction + command! TogglePudbBreakPoint call s:ToggleBreakPoint() command! UpdatePudbBreakPoints call s:UpdateBreakPoints() +command! ClearAllPudbBreakPoints call s:ClearAllBreakPoints() if &filetype == 'python' call s:UpdateBreakPoints() From 6042a7bd1b11c42fbd5f3c1bb0d0aba0f29b5974 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 1 Jan 2020 12:35:00 -0600 Subject: [PATCH 12/55] Support editing breakpoint conditions --- plugin/pudb.vim | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 4837c66..e4b6364 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -2,8 +2,6 @@ " Author: Christophe Simonis " Description: Manage pudb breakpoints directly into vim " Last Modified: March 02, 2018 -" -" TODO: handle conditions in breakpoints (at least do not loose them when saving breakpoints) if exists('g:loaded_pudb_plugin') || &cp finish @@ -83,9 +81,42 @@ else: bps[bp_key] = Breakpoint(filename, row) save_breakpoints(bps.values()) +EOF + +call s:UpdateBreakPoints() +endfunction + +function! s:EditBreakPoint() +pythonx << EOF +import vim +from pudb.settings import load_breakpoints, save_breakpoints +from pudb import NUM_VERSION +from bdb import Breakpoint + +args = () if NUM_VERSION >= (2013, 1) else (None,) +bps = {(bp.file, bp.line): bp + for bp in map(lambda args: Breakpoint(*args), load_breakpoints(*args))} + +filename = vim.eval('expand("%:p")') +row, col = vim.current.window.cursor + +bp_key = (filename, row) +if bp_key not in bps: + bps[bp_key] = Breakpoint(filename, row) +bp = bps[bp_key] + +old_cond = '' if bp.cond is None else bp.cond +vim.command('echo "Current condition: %s"' % old_cond) +vim.command('echohl Question') +vim.eval('inputsave()') +bp.cond = vim.eval('input("New Condition: ", "%s")' % old_cond) +vim.eval('inputrestore()') +vim.command('echohl None') -vim.command('call s:UpdateBreakPoints()') +save_breakpoints(bps.values()) EOF + +call s:UpdateBreakPoints() endfunction function! s:ClearAllBreakPoints() @@ -100,6 +131,7 @@ endfunction command! TogglePudbBreakPoint call s:ToggleBreakPoint() command! UpdatePudbBreakPoints call s:UpdateBreakPoints() command! ClearAllPudbBreakPoints call s:ClearAllBreakPoints() +command! EditPudbBreakPoint call s:EditBreakPoint() if &filetype == 'python' call s:UpdateBreakPoints() From b27057d698dd015fa5c0b68637ec9475440bf3f2 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 1 Mar 2020 23:06:20 -0600 Subject: [PATCH 13/55] BREAKING CHANGE! Rename commands, add 'PudbListBreakpoints' command --- plugin/pudb.vim | 61 +++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index e4b6364..4900953 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -1,7 +1,7 @@ " File: pudb.vim -" Author: Christophe Simonis +" Author: Christophe Simonis, Michael van der Kamp " Description: Manage pudb breakpoints directly into vim -" Last Modified: March 02, 2018 +" Last Modified: March 01, 2020 if exists('g:loaded_pudb_plugin') || &cp finish @@ -31,12 +31,12 @@ call sign_define('PudbBreakPoint', { \ }) augroup pudb - autocmd BufReadPost *.py call s:UpdateBreakPoints() + autocmd BufReadPost *.py call s:UpdateBreakpoints() augroup end let s:pudb_sign_group = 'pudb_sign_group_' -function! s:UpdateBreakPoints() +function! s:UpdateBreakpoints() " first remove existing signs call sign_unplace(s:pudb_sign_group .. expand('%:p')) @@ -46,21 +46,21 @@ 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,) for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): - if bp_file != filename: + try: + opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_breakpoint_priority']) + vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' + '' % (vim.eval('s:pudb_sign_group .. "%s"' % bp_file), bp_file, opts)) + except vim.error: + # Buffer for the given file isn't loaded. continue - - opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_breakpoint_priority']) - vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' - '' % (vim.eval('s:pudb_sign_group .. "%s"' % filename), filename, opts)) EOF endfunction -function! s:ToggleBreakPoint() +function! s:ToggleBreakpoint() pythonx << EOF import vim from pudb.settings import load_breakpoints, save_breakpoints @@ -69,7 +69,7 @@ from bdb import Breakpoint args = () if NUM_VERSION >= (2013, 1) else (None,) bps = {(bp.file, bp.line): bp - for bp in map(lambda args: Breakpoint(*args), load_breakpoints(*args))} + for bp in map(lambda values: Breakpoint(*values), load_breakpoints(*args))} filename = vim.eval('expand("%:p")') row, col = vim.current.window.cursor @@ -83,7 +83,7 @@ else: save_breakpoints(bps.values()) EOF -call s:UpdateBreakPoints() +call s:UpdateBreakpoints() endfunction function! s:EditBreakPoint() @@ -95,7 +95,7 @@ from bdb import Breakpoint args = () if NUM_VERSION >= (2013, 1) else (None,) bps = {(bp.file, bp.line): bp - for bp in map(lambda args: Breakpoint(*args), load_breakpoints(*args))} + for bp in map(lambda values: Breakpoint(*values), load_breakpoints(*args))} filename = vim.eval('expand("%:p")') row, col = vim.current.window.cursor @@ -116,23 +116,40 @@ vim.command('echohl None') save_breakpoints(bps.values()) EOF -call s:UpdateBreakPoints() +call s:UpdateBreakpoints() endfunction -function! s:ClearAllBreakPoints() +function! s:ClearAllBreakpoints() pythonx << EOF from pudb.settings import save_breakpoints save_breakpoints([]) EOF -call s:UpdateBreakPoints() +call s:UpdateBreakpoints() +endfunction + +function! s:ListBreakpoints() +pythonx << EOF +import vim +from pudb.settings import load_breakpoints +from pudb import NUM_VERSION + +vim.command('echomsg "Listing all pudb breakpoints:"') + +args = () if NUM_VERSION >= (2013, 1) else (None,) +for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): + vim.command('echomsg "%s:%d:%s"' % ( + bp_file, bp_lnum, '' if not bool(cond) else ' %s' % cond + )) +EOF endfunction -command! TogglePudbBreakPoint call s:ToggleBreakPoint() -command! UpdatePudbBreakPoints call s:UpdateBreakPoints() -command! ClearAllPudbBreakPoints call s:ClearAllBreakPoints() -command! EditPudbBreakPoint call s:EditBreakPoint() +command! PudbToggleBreakpoint call s:ToggleBreakpoint() +command! PudbUpdateBreakpoints call s:UpdateBreakpoints() +command! PudbClearAllBreakpoints call s:ClearAllBreakpoints() +command! PudbEditBreakpoint call s:EditBreakPoint() +command! PudbListBreakpoints call s:ListBreakpoints() if &filetype == 'python' - call s:UpdateBreakPoints() + call s:UpdateBreakpoints() endif From d7615898b998b195fe4980afc95bfb9dc1253947 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 1 Jan 2020 14:56:20 -0600 Subject: [PATCH 14/55] Update README with edit and clear commands --- README.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 2e5751b..a78b7df 100644 --- a/README.rst +++ b/README.rst @@ -1,22 +1,22 @@ vim-pudb ======== -simple plugin allowing you to manage pudb breakpoint directly into vim. +Simple plugin allowing you to manage pudb breakpoints directly from vim. -This plugin need vim to be compiled with +python +This plugin needs vim to be compiled with +python or +python3 Installation ============ +The recommended way of installing is to use `vim-pathogen`_ or `vim-plug`_ -The recommended way of installing is to use `vim-pathogen`_ - +.. _vim-pathogen: https://github.com/tpope/vim-pathogen#readme +.. _vim-plug: https://github.com/junegunn/vim-plug How to use ========== To add/remove a breakpoint, you just need to call the command ``:TogglePudbBreakPoint`` -For easy access, you can bind it to the F8 key. - +For easy access, use a mapping: ``nnoremap :TogglePudbBreakPoint`` @@ -25,7 +25,10 @@ For easy access, you can bind it to the F8 key. In case the breakpoints get out of sync after a debugging session, there is also a command ``:UpdatePudbBreakPoints`` which refreshes the breakpoint signs. -.. _vim-pathogen: https://github.com/tpope/vim-pathogen#readme +To edit the condition of a breakpoint on the current line, use the command +``:EditPudbBreakPoint`` + +To clear all pudb breakpoints, use the command ``:ClearAllPudbBreakPoints`` Configuration ============= From a40f35f8a32edd5c3a7bf23a2811acddd8cc45d9 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 7 Mar 2020 22:18:29 -0600 Subject: [PATCH 15/55] BREAKING CHANGE: Remove '[Bb]reakpoint' from the commands and options Seems redundant- the whole point of the plugin is to manage breakpoints. You know what you're in for when you start typing "Pudb..." --- .gitignore | 2 + README.rst | 99 ++++++++++++++++++++++++++++++----------- plugin/pudb.vim | 115 ++++++++++++++++++++++++++++++++++-------------- 3 files changed, 156 insertions(+), 60 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..12e546f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tags +*.sw[op] diff --git a/README.rst b/README.rst index a78b7df..e6030a2 100644 --- a/README.rst +++ b/README.rst @@ -1,53 +1,100 @@ vim-pudb ======== -Simple plugin allowing you to manage pudb breakpoints directly from vim. +A simple plugin allowing you to manage pudb breakpoints directly from vim. + +Forked from `vim-pudb`_ + +.. _vim-pudb: https://github.com/KangOl/vim-pudb -This plugin needs vim to be compiled with +python or +python3 Installation ============ -The recommended way of installing is to use `vim-pathogen`_ or `vim-plug`_ + +Similar to any other vim plugin, use your preferred method. If you're new, check +out `vim-pathogen`_ or `vim-plug`_ or ``:help packages`` .. _vim-pathogen: https://github.com/tpope/vim-pathogen#readme .. _vim-plug: https://github.com/junegunn/vim-plug -How to use -========== -To add/remove a breakpoint, you just need to call the command ``:TogglePudbBreakPoint`` -For easy access, use a mapping: +Requirements +------------ + +This plugin needs vim to be compiled with ``+python`` or ``+python3`` as well as +``+signs`` and is intended for vim 8.2 or later, though I'm not sure exactly +which patch is the earliest that is supported. + +You will also need to have `pudb`_ installed, obviously. + +.. _pudb: https://pypi.org/project/pudb/ - ``nnoremap :TogglePudbBreakPoint`` - ``inoremap :TogglePudbBreakPointa`` - -In case the breakpoints get out of sync after a debugging session, there is also a command -``:UpdatePudbBreakPoints`` which refreshes the breakpoint signs. +Commands +======== + +``:PudbToggle`` + Add / remove a breakpoint at the current line. + +``:PudbEdit`` + Edit the condition of a breakpoint on the current line. Creates a + breakpoint if one doesn't already exist. -To edit the condition of a breakpoint on the current line, use the command -``:EditPudbBreakPoint`` +``:PudbClearAll`` + Remove all breakpoints from every file. + +``:PudbList`` + Show a list of the full file paths, line numbers, and conditions of all + breakpoints. + +``:PudbUpdate`` + Sometimes the breakpoint signs can get out of date. The above commands will + all trigger an update, but this command lets you trigger an update without + doing anything else. + + +Mappings +======== + +There are no mappings set up by default, so you don't have to worry about +conflicts with other plugins. Here's what I use: + +:: + + nnoremap bc :PudbClearAll + nnoremap be :PudbEdit + nnoremap bl :PudbList + nnoremap bp :PudbToggle + nnoremap bu :PudbUpdate -To clear all pudb breakpoints, use the command ``:ClearAllPudbBreakPoints`` Configuration ============= -The text of the sign can be defined with ``g:pudb_breakpoint_sign`` (default -``'>>'``): - ``let g:pudb_breakpoint_sign = '>>'`` +The text of the sign can be defined with ``g:pudb_sign`` (default ``'B>'``): + + ``let g:pudb_sign = 'B>'`` The highlight group of the sign in the sign colum can be defined with -``g:pudb_breakpoint_highlight`` (default ``'error'``): +``g:pudb_highlight`` (default ``'error'``): - ``let g:pudb_breakpoint_highlight = 'error'`` + ``let g:pudb_highlight = 'error'`` + +The priority of the breakpoint signs can be defined with ``g:pudb_priority`` +(default ``100``): + + ``let g:pudb_priority = 100`` + +This plugin uses sign groups. You can change the name of the sign group using +``g:pudb_sign_group`` (default ``_pudb_sign_group_``): + + ``let g:pudb_sign_group = '_pudb_sign_group_'`` -The priority of the breakpoint signs can be defined with -``g:pudb_breakpoint_priority`` (default ``100``): - ``let g:pudb_breakpoint_priority = 100`` Known problems -============= -Currently, the list of breakpoints is not reloaded automatically. +============== -There is also room for speed optimisations. +- Currently, the list of breakpoints is not reloaded automatically. Signs are + only updated when a python buffer is first read, or when one of the above + commands is called. +- There may be room for speed optimisations. diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 4900953..2b64efe 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -1,7 +1,8 @@ " File: pudb.vim " Author: Christophe Simonis, Michael van der Kamp -" Description: Manage pudb breakpoints directly into vim -" Last Modified: March 01, 2020 +" Description: Manage pudb breakpoints directly from vim +" Last Modified: March 07, 2020 + if exists('g:loaded_pudb_plugin') || &cp finish @@ -9,37 +10,49 @@ endif let g:loaded_pudb_plugin = 1 if !has("pythonx") - echo "Error: Required vim compiled with +python and/or +python3" + echoerr "vim-pudb requires vim compiled with +python and/or +python3" + finish +endif + +if !has("signs") + echoerr "vim-pudb requires vim compiled with +signs" finish endif -if !exists('g:pudb_breakpoint_sign') - let g:pudb_breakpoint_sign = '>>' + +" +" Load options and set defaults +" +if !exists('g:pudb_sign') + let g:pudb_sign = 'B>' +endif + +if !exists('g:pudb_highlight') + let g:pudb_highlight = 'error' endif -if !exists('g:pudb_breakpoint_highlight') - let g:pudb_breakpoint_highlight = 'error' +if !exists('g:pudb_priority') + let g:pudb_priority = 100 endif -if !exists('g:pudb_breakpoint_priority') - let g:pudb_breakpoint_priority = 100 +if !exists('g:pudb_sign_group') + let g:pudb_sign_group = '_pudb_sign_group_' endif call sign_define('PudbBreakPoint', { - \ 'text': g:pudb_breakpoint_sign, - \ 'texthl': g:pudb_breakpoint_highlight + \ 'text': g:pudb_sign, + \ 'texthl': g:pudb_highlight \ }) -augroup pudb - autocmd BufReadPost *.py call s:UpdateBreakpoints() -augroup end - -let s:pudb_sign_group = 'pudb_sign_group_' -function! s:UpdateBreakpoints() +" +" Loads the pudb breakpoint file and Updates the breakpoint signs for all +" breakpoints in all buffers. +" +function! s:Update() -" first remove existing signs -call sign_unplace(s:pudb_sign_group .. expand('%:p')) + " first remove existing signs + call sign_unplace(g:pudb_sign_group) pythonx << EOF import vim @@ -50,9 +63,9 @@ args = () if NUM_VERSION >= (2013, 1) else (None,) for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): try: - opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_breakpoint_priority']) + opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_priority']) vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' - '' % (vim.eval('s:pudb_sign_group .. "%s"' % bp_file), bp_file, opts)) + '' % (vim.eval('g:pudb_sign_group'), bp_file, opts)) except vim.error: # Buffer for the given file isn't loaded. continue @@ -60,7 +73,12 @@ EOF endfunction -function! s:ToggleBreakpoint() + +" +" Toggles a breakpoint on the current line. +" +function! s:Toggle() + pythonx << EOF import vim from pudb.settings import load_breakpoints, save_breakpoints @@ -83,10 +101,16 @@ else: save_breakpoints(bps.values()) EOF -call s:UpdateBreakpoints() + call s:Update() endfunction -function! s:EditBreakPoint() + +" +" Edit the condition of a breakpoint on the current line. +" If no such breakpoint exists, creates one. +" +function! s:Edit() + pythonx << EOF import vim from pudb.settings import load_breakpoints, save_breakpoints @@ -116,19 +140,31 @@ vim.command('echohl None') save_breakpoints(bps.values()) EOF -call s:UpdateBreakpoints() + call s:Update() endfunction -function! s:ClearAllBreakpoints() + +" +" Clears all pudb breakpoints from all files. +" +function! s:ClearAll() + pythonx << EOF from pudb.settings import save_breakpoints save_breakpoints([]) EOF -call s:UpdateBreakpoints() + call s:Update() endfunction -function! s:ListBreakpoints() + +" +" Prints a list of all the breakpoints in all files. +" Shows the full file path, line number, and condition of each breakpoint. +" +function! s:List() + call s:Update() + pythonx << EOF import vim from pudb.settings import load_breakpoints @@ -142,14 +178,25 @@ for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): bp_file, bp_lnum, '' if not bool(cond) else ' %s' % cond )) EOF + endfunction -command! PudbToggleBreakpoint call s:ToggleBreakpoint() -command! PudbUpdateBreakpoints call s:UpdateBreakpoints() -command! PudbClearAllBreakpoints call s:ClearAllBreakpoints() -command! PudbEditBreakpoint call s:EditBreakPoint() -command! PudbListBreakpoints call s:ListBreakpoints() +" Define ex commands for all the above functions so they are user-accessible. +command! PudbClearAll call s:ClearAll() +command! PudbEdit call s:Edit() +command! PudbList call s:List() +command! PudbToggle call s:Toggle() +command! PudbUpdate call s:Update() + + +" If we were loaded lazily, update immediately. if &filetype == 'python' - call s:UpdateBreakpoints() + call s:Update() endif + + +" Also update when the file is first read. +augroup pudb + autocmd BufReadPost *.py call s:Update() +augroup end From a388d1e5d71e0c0fc855b1bbb570dffc7350cea5 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 7 Mar 2020 22:31:42 -0600 Subject: [PATCH 16/55] Add "which breakpoint file" problem to list of known issues --- README.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index e6030a2..33be808 100644 --- a/README.rst +++ b/README.rst @@ -73,22 +73,22 @@ Configuration The text of the sign can be defined with ``g:pudb_sign`` (default ``'B>'``): - ``let g:pudb_sign = 'B>'`` +``let g:pudb_sign = 'B>'`` The highlight group of the sign in the sign colum can be defined with ``g:pudb_highlight`` (default ``'error'``): - ``let g:pudb_highlight = 'error'`` +``let g:pudb_highlight = 'error'`` The priority of the breakpoint signs can be defined with ``g:pudb_priority`` (default ``100``): - ``let g:pudb_priority = 100`` +``let g:pudb_priority = 100`` This plugin uses sign groups. You can change the name of the sign group using ``g:pudb_sign_group`` (default ``_pudb_sign_group_``): - ``let g:pudb_sign_group = '_pudb_sign_group_'`` +``let g:pudb_sign_group = '_pudb_sign_group_'`` Known problems @@ -98,3 +98,4 @@ Known problems only updated when a python buffer is first read, or when one of the above commands is called. - There may be room for speed optimisations. +- There is currently no way to specify which breakpoint file to use. From 512ba39c438006fa04ec2ec78ced1b08ebd01596 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 21 Mar 2020 00:01:48 -0600 Subject: [PATCH 17/55] Add ability to load breakpoints into the quickfix list --- README.rst | 6 ++++++ plugin/pudb.vim | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/README.rst b/README.rst index 33be808..dd5176a 100644 --- a/README.rst +++ b/README.rst @@ -47,6 +47,11 @@ Commands Show a list of the full file paths, line numbers, and conditions of all breakpoints. +``:PudbQfList`` + Load all breakpoints into the quickfix list. Does not jump to the first + entry. Breakpoints into buffers that are not loaded will be in the list, but + with the text ''. + ``:PudbUpdate`` Sometimes the breakpoint signs can get out of date. The above commands will all trigger an update, but this command lets you trigger an update without @@ -64,6 +69,7 @@ conflicts with other plugins. Here's what I use: nnoremap bc :PudbClearAll nnoremap be :PudbEdit nnoremap bl :PudbList + nnoremap bq :PudbQfList nnoremap bp :PudbToggle nnoremap bu :PudbUpdate diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 2b64efe..b5d4d48 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -182,10 +182,37 @@ EOF endfunction +" +" Populate the quickfix list with the breakpoint locations. +" +function! s:QuickfixList() + call s:Update() + +pythonx << EOF +import vim +from pudb.settings import load_breakpoints +from pudb import NUM_VERSION + +qflist = [] +args = () if NUM_VERSION >= (2013, 1) else (None,) +for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): + try: + line = vim.eval('getbufline(bufname("%s"), %s)' % (bp_file, bp_lnum))[0] + except LookupError: + line = '' + qflist.append(':'.join(map(str, [bp_file, bp_lnum, line]))) + +vim.command('cgetexpr %s' % (qflist)) +EOF + +endfunction + + " Define ex commands for all the above functions so they are user-accessible. command! PudbClearAll call s:ClearAll() command! PudbEdit call s:Edit() command! PudbList call s:List() +command! PudbQfList call s:QuickfixList() command! PudbToggle call s:Toggle() command! PudbUpdate call s:Update() From 499985be81cd41fa2198362ad2d2cf706bb7afa5 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 22 Mar 2020 14:20:21 -0600 Subject: [PATCH 18/55] Use get() and vim.vars for option lookup --- plugin/pudb.vim | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index b5d4d48..804691e 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -23,24 +23,13 @@ endif " " Load options and set defaults " -if !exists('g:pudb_sign') - let g:pudb_sign = 'B>' -endif - -if !exists('g:pudb_highlight') - let g:pudb_highlight = 'error' -endif - -if !exists('g:pudb_priority') - let g:pudb_priority = 100 -endif - -if !exists('g:pudb_sign_group') - let g:pudb_sign_group = '_pudb_sign_group_' -endif +let g:pudb_sign = get(g:, 'pudb_sign', 'B>') +let g:pudb_highlight = get(g:, 'pudb_highlight', 'error') +let g:pudb_priority = get(g:, 'pudb_priority', 100) +let g:pudb_sign_group = get(g:, 'pudb_sign_group', 'pudb_sign_group') call sign_define('PudbBreakPoint', { - \ 'text': g:pudb_sign, + \ 'text': g:pudb_sign, \ 'texthl': g:pudb_highlight \ }) @@ -65,7 +54,7 @@ for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): try: opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_priority']) vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' - '' % (vim.eval('g:pudb_sign_group'), bp_file, opts)) + '' % (vim.vars['pudb_sign_group'], bp_file, opts)) except vim.error: # Buffer for the given file isn't loaded. continue From 79a0b25086207dc7d4324d538df679c4065e1760 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 22 Mar 2020 15:29:30 -0600 Subject: [PATCH 19/55] Add help documentation, complete with tags, for use by vim's help system --- doc/tags | 19 ++++++ doc/vim-pudb.txt | 153 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 doc/tags create mode 100644 doc/vim-pudb.txt diff --git a/doc/tags b/doc/tags new file mode 100644 index 0000000..ea15d10 --- /dev/null +++ b/doc/tags @@ -0,0 +1,19 @@ +vim-pudb vim-pudb.txt /*vim-pudb* +vim-pudb-:PudbClearAll vim-pudb.txt /*vim-pudb-:PudbClearAll* +vim-pudb-:PudbEdit vim-pudb.txt /*vim-pudb-:PudbEdit* +vim-pudb-:PudbList vim-pudb.txt /*vim-pudb-:PudbList* +vim-pudb-:PudbQfList vim-pudb.txt /*vim-pudb-:PudbQfList* +vim-pudb-:PudbToggle vim-pudb.txt /*vim-pudb-:PudbToggle* +vim-pudb-:PudbUpdate vim-pudb.txt /*vim-pudb-:PudbUpdate* +vim-pudb-commands vim-pudb.txt /*vim-pudb-commands* +vim-pudb-configuration vim-pudb.txt /*vim-pudb-configuration* +vim-pudb-contents vim-pudb.txt /*vim-pudb-contents* +vim-pudb-highlight vim-pudb.txt /*vim-pudb-highlight* +vim-pudb-installation vim-pudb.txt /*vim-pudb-installation* +vim-pudb-introduction vim-pudb.txt /*vim-pudb-introduction* +vim-pudb-known-problems vim-pudb.txt /*vim-pudb-known-problems* +vim-pudb-priority vim-pudb.txt /*vim-pudb-priority* +vim-pudb-requirements vim-pudb.txt /*vim-pudb-requirements* +vim-pudb-sign vim-pudb.txt /*vim-pudb-sign* +vim-pudb-sign-group vim-pudb.txt /*vim-pudb-sign-group* +vim-pudb.txt vim-pudb.txt /*vim-pudb.txt* diff --git a/doc/vim-pudb.txt b/doc/vim-pudb.txt new file mode 100644 index 0000000..1a8425b --- /dev/null +++ b/doc/vim-pudb.txt @@ -0,0 +1,153 @@ +*vim-pudb.txt* Manage pudb breakpoints directly from vim + +Author: Michael van der Kamp +License: Same terms as vim itself (see |license|) + +Forked from vim-pudb: https://github.com/KangOl/vim-pudb + + +============================================================================== +CONTENTS *vim-pudb-contents* *vim-pudb* + + 1. Introduction ........................... |vim-pudb-introduction| + 2. Installation ........................... |vim-pudb-installation| + 3. Requirements ........................... |vim-pudb-requirements| + 4. Commands ............................... |vim-pudb-commands| + 4.1 PudbToggle ........................ |vim-pudb-:PudbToggle| + 4.2 PudbEdit .......................... |vim-pudb-:PudbEdit| + 4.3 PudbClearAll ...................... |vim-pudb-:PudbClearAll| + 4.4 PudbList .......................... |vim-pudb-:PudbList| + 4.5 PudbQfList ........................ |vim-pudb-:PudbQfList| + 4.6 PudbUpdate ........................ |vim-pudb-:PudbUpdate| + 5. Configuration .......................... |vim-pudb-configuration| + 6. Known problems ......................... |vim-pudb-known-problems| + + +============================================================================== +INTRODUCTION *vim-pudb-introduction* + +This plugin allows you to: + + * Toggle pudb breakpoints + * Edit and view pudb breakpoints + * List pudb breakpoints + * Load pudb breakpoints into the quickfix list + +There are no mappings set up by default, so you don't have to worry about +conflicts with other plugins. Here are some recommended mappings though, +to add to your `.vimrc` file: +> + nnoremap bc :PudbClearAll + nnoremap be :PudbEdit + nnoremap bl :PudbList + nnoremap bq :PudbQfList + nnoremap bp :PudbToggle + nnoremap bu :PudbUpdate +< + +============================================================================== +INSTALLATION *vim-pudb-installation* + +Similar to any other vim plugin, use your preferred method. If you're new, +check out: + + packages: |packages| + vim-pathogen: https://github.com/tpope/vim-pathogen#readme + vim-plug: https://github.com/junegunn/vim-plug + + +============================================================================== +REQUIREMENTS *vim-pudb-requirements* + +This plugin needs vim to be compiled with `+python` or `+python3` as well as +`+signs` and is intended for vim 8.2 or later. + +You will also need to have `pudb` installed: https://pypi.org/project/pudb/ + + +============================================================================== +COMMANDS *vim-pudb-commands* + +------------------------------------------------------------------------------ + *vim-pudb-:PudbToggle* +:PudbToggle + Add / remove a breakpoint at the current line. + +------------------------------------------------------------------------------ + *vim-pudb-:PudbEdit* +:PudbEdit + Edit the condition of a breakpoint on the current line. Creates a + breakpoint if one doesn't already exist. + +------------------------------------------------------------------------------ + *vim-pudb-:PudbClearAll* +:PudbClearAll + Remove all breakpoints from every file. + +------------------------------------------------------------------------------ + *vim-pudb-:PudbList* +:PudbList + Show a list of the full file paths, line numbers, and conditions of all + breakpoints. + +------------------------------------------------------------------------------ + *vim-pudb-:PudbQfList* +:PudbQfList + Load all breakpoints into the quickfix list. Does not jump to the first + entry. Breakpoints into buffers that are not loaded will be in the list, + but with the text ''. + +------------------------------------------------------------------------------ + *vim-pudb-:PudbUpdate* +:PudbUpdate + Sometimes the breakpoint signs can get out of date. The above commands + will all trigger an update, but this command lets you trigger an update + without doing anything else. + + +============================================================================== +CONFIGURATION *vim-pudb-configuration* + +------------------------------------------------------------------------------ + *vim-pudb-sign* +The text of the sign can be defined with `g:pudb_sign`: + + `let g:pudb_sign = 'B>'` + +Default: `'B>'` + +------------------------------------------------------------------------------ + *vim-pudb-sign-group* +This plugin uses sign groups. You can change the name of the sign group using +`g:pudb_sign_group`: + + `let g:pudb_sign_group = 'pudb_sign_group'` + +Default: `'pudb_sign_group'` + +------------------------------------------------------------------------------ + *vim-pudb-highlight* +The highlight group of the sign in the sign colum can be defined with +`g:pudb_highlight`: + + `let g:pudb_highlight = 'error'` + +Default: `'error'` + +------------------------------------------------------------------------------ + *vim-pudb-priority* +The priority of the breakpoint signs can be defined with `g:pudb_priority`: + + `let g:pudb_priority = 100` + +Default: `100` + + +============================================================================== +KNOWN PROBLEMS *vim-pudb-known-problems* + +- Currently, the list of breakpoints is not reloaded automatically. Signs are + only updated when a python buffer is first read, or when one of the above + commands is called. +- There may be room for speed optimisations. +- There is currently no way to specify which breakpoint file to use. From eac9811e092166b720172a0dff6ca53bc0327d6d Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Fri, 27 Mar 2020 21:46:12 -0600 Subject: [PATCH 20/55] Add location and generalized list variants of PudbQfList --- README.rst | 14 +++++++++++++- doc/vim-pudb.txt | 20 +++++++++++++++++++- plugin/pudb.vim | 31 +++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index dd5176a..bbf5462 100644 --- a/README.rst +++ b/README.rst @@ -47,10 +47,22 @@ Commands Show a list of the full file paths, line numbers, and conditions of all breakpoints. +``:PudbLocList`` + Load all breakpoints into the location list. Does not jump to the first + entry. Breakpoints into buffers that are not loaded will be in the list, but + with the text ''. Lines containing only whitespace + will appear with the text '' + ``:PudbQfList`` Load all breakpoints into the quickfix list. Does not jump to the first entry. Breakpoints into buffers that are not loaded will be in the list, but - with the text ''. + with the text ''. Lines containing only whitespace + will appear with the text '' + +``:PudbPopulateList `` + Supply a list of all breakpoints, in quickfix format, to the Ex command + given by . This is a generic form of PudbLocList and PudbQfList, + allowing you to customise the operation for any precise need you may have. ``:PudbUpdate`` Sometimes the breakpoint signs can get out of date. The above commands will diff --git a/doc/vim-pudb.txt b/doc/vim-pudb.txt index 1a8425b..9bf2141 100644 --- a/doc/vim-pudb.txt +++ b/doc/vim-pudb.txt @@ -17,7 +17,9 @@ CONTENTS *vim-pudb-contents* *vim-pudb* 4.2 PudbEdit .......................... |vim-pudb-:PudbEdit| 4.3 PudbClearAll ...................... |vim-pudb-:PudbClearAll| 4.4 PudbList .......................... |vim-pudb-:PudbList| + 4.4 PudbLocList ....................... |vim-pudb-:PudbLocList| 4.5 PudbQfList ........................ |vim-pudb-:PudbQfList| + 4.5 PudbPopulateList .................. |vim-pudb-:PudbPopulateList| 4.6 PudbUpdate ........................ |vim-pudb-:PudbUpdate| 5. Configuration .......................... |vim-pudb-configuration| 6. Known problems ......................... |vim-pudb-known-problems| @@ -90,12 +92,28 @@ COMMANDS *vim-pudb-commands* Show a list of the full file paths, line numbers, and conditions of all breakpoints. +------------------------------------------------------------------------------ + *vim-pudb-:PudbLocList* +:PudbLocList + Load all breakpoints into the location list. Does not jump to the first + entry. Breakpoints into buffers that are not loaded will be in the list, + but with the text ''. Lines containing only whitespace + will appear with the text '' + ------------------------------------------------------------------------------ *vim-pudb-:PudbQfList* :PudbQfList Load all breakpoints into the quickfix list. Does not jump to the first entry. Breakpoints into buffers that are not loaded will be in the list, - but with the text ''. + but with the text ''. Lines containing only whitespace + will appear with the text '' + +------------------------------------------------------------------------------ + *vim-pudb-:PudbPopulateList* +:PudbPopulateList + Supply a list of all breakpoints, in quickfix format, to the Ex command + given by . This is a generic form of PudbLocList and PudbQfList, + allowing you to customise the operation for any precise need you may have. ------------------------------------------------------------------------------ *vim-pudb-:PudbUpdate* diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 804691e..fbdd487 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -172,10 +172,10 @@ endfunction " -" Populate the quickfix list with the breakpoint locations. +" Calls the given vim command with a list of the breakpoints as strings in +" quickfix format. " -function! s:QuickfixList() - call s:Update() +function! s:PopulateList(list_command) pythonx << EOF import vim @@ -187,24 +187,47 @@ args = () if NUM_VERSION >= (2013, 1) else (None,) for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): try: line = vim.eval('getbufline(bufname("%s"), %s)' % (bp_file, bp_lnum))[0] + if not line: + line = '' except LookupError: line = '' qflist.append(':'.join(map(str, [bp_file, bp_lnum, line]))) -vim.command('cgetexpr %s' % (qflist)) +vim.command('%s %s' % (vim.eval('a:list_command'), qflist)) EOF endfunction +" +" Populate the quickfix list with the breakpoint locations. +" +function! s:QuickfixList() + call s:Update() + call s:PopulateList('cgetexpr') +endfunction + + +" +" Populate the location list with the breakpoint locations. +" +function! s:LocationList() + call s:Update() + call s:PopulateList('lgetexpr') +endfunction + + " Define ex commands for all the above functions so they are user-accessible. command! PudbClearAll call s:ClearAll() command! PudbEdit call s:Edit() command! PudbList call s:List() +command! PudbLocList call s:LocationList() command! PudbQfList call s:QuickfixList() command! PudbToggle call s:Toggle() command! PudbUpdate call s:Update() +command! -nargs=1 -complete=command PudbPopulateList call s:Update() call s:PopulateList("") + " If we were loaded lazily, update immediately. if &filetype == 'python' From 73cbfb2d6e4ff17127e7b3377ee6864053954d70 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 29 Mar 2020 22:26:45 -0600 Subject: [PATCH 21/55] Fix breakpoints loaded into QF list on an empty line --- plugin/pudb.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index fbdd487..3ea2252 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -187,7 +187,7 @@ args = () if NUM_VERSION >= (2013, 1) else (None,) for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): try: line = vim.eval('getbufline(bufname("%s"), %s)' % (bp_file, bp_lnum))[0] - if not line: + if line.strip() == '': line = '' except LookupError: line = '' From aff5bbd38416dfaff61c8019a1de9012a0af5cdd Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 29 Mar 2020 22:42:58 -0600 Subject: [PATCH 22/55] Fix inaccurate sign group default in README --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index bbf5462..dff57b9 100644 --- a/README.rst +++ b/README.rst @@ -104,9 +104,9 @@ The priority of the breakpoint signs can be defined with ``g:pudb_priority`` ``let g:pudb_priority = 100`` This plugin uses sign groups. You can change the name of the sign group using -``g:pudb_sign_group`` (default ``_pudb_sign_group_``): +``g:pudb_sign_group`` (default ``pudb_sign_group``): -``let g:pudb_sign_group = '_pudb_sign_group_'`` +``let g:pudb_sign_group = 'pudb_sign_group'`` Known problems From 5345274557ebff1d6d73d7e0f2ea277364232907 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 29 Mar 2020 23:11:50 -0600 Subject: [PATCH 23/55] Fix signs not getting removed --- plugin/pudb.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 3ea2252..9626ba7 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -53,8 +53,10 @@ args = () if NUM_VERSION >= (2013, 1) else (None,) for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): try: opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_priority']) + + # Critical to use vim.eval here instead of vim.vars[] to get sign group vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' - '' % (vim.vars['pudb_sign_group'], bp_file, opts)) + '' % (vim.eval('g:pudb_sign_group'), bp_file, opts)) except vim.error: # Buffer for the given file isn't loaded. continue From e4cf96ccf142ecf4ed8717bef53e29cda392c6bf Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 11 Jul 2020 19:44:43 -0600 Subject: [PATCH 24/55] Complete rename to "vim-pudb-and-jam" --- README.rst | 17 +++++++++-------- doc/{vim-pudb.txt => vim-pudb-and-jam.txt} | 6 +++++- 2 files changed, 14 insertions(+), 9 deletions(-) rename doc/{vim-pudb.txt => vim-pudb-and-jam.txt} (95%) diff --git a/README.rst b/README.rst index dff57b9..7bcd47d 100644 --- a/README.rst +++ b/README.rst @@ -1,9 +1,10 @@ -vim-pudb -======== +vim-pudb-and-jam +================ A simple plugin allowing you to manage pudb breakpoints directly from vim. - -Forked from `vim-pudb`_ +Forked from `vim-pudb`_ and given some jammy features such as setting and +editing equations, improved persistence of breakpoints, and the ability to list +active breakpoints either as a printed message or in a quickfix list. .. _vim-pudb: https://github.com/KangOl/vim-pudb @@ -12,10 +13,10 @@ Installation ============ Similar to any other vim plugin, use your preferred method. If you're new, check -out `vim-pathogen`_ or `vim-plug`_ or ``:help packages`` - -.. _vim-pathogen: https://github.com/tpope/vim-pathogen#readme -.. _vim-plug: https://github.com/junegunn/vim-plug +out +`vim-pathogen `_ or +`vim-plug `_ or +`:help packages `_ Requirements diff --git a/doc/vim-pudb.txt b/doc/vim-pudb-and-jam.txt similarity index 95% rename from doc/vim-pudb.txt rename to doc/vim-pudb-and-jam.txt index 9bf2141..8160e15 100644 --- a/doc/vim-pudb.txt +++ b/doc/vim-pudb-and-jam.txt @@ -1,4 +1,4 @@ -*vim-pudb.txt* Manage pudb breakpoints directly from vim +*vim-pudb-and-jam.txt* Manage pudb breakpoints directly from vim Author: Michael van der Kamp License: Same terms as vim itself (see |license|) @@ -22,6 +22,10 @@ CONTENTS *vim-pudb-contents* *vim-pudb* 4.5 PudbPopulateList .................. |vim-pudb-:PudbPopulateList| 4.6 PudbUpdate ........................ |vim-pudb-:PudbUpdate| 5. Configuration .......................... |vim-pudb-configuration| + 5.1 vim-pudb-sign ..................... |vim-pudb-sign| + 5.2 vim-pudb-sign-group ............... |vim-pudb-sign-group| + 5.3 vim-pudb-highlight ................ |vim-pudb-highlight| + 5.4 vim-pudb-priority ................. |vim-pudb-priority| 6. Known problems ......................... |vim-pudb-known-problems| From 06e79e9f1aab94b706ed26f6ece120c90cbd85f6 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 11 Jul 2020 19:46:59 -0600 Subject: [PATCH 25/55] And vim-pudb-and-jam tag to help docs --- doc/vim-pudb-and-jam.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/vim-pudb-and-jam.txt b/doc/vim-pudb-and-jam.txt index 8160e15..04b853f 100644 --- a/doc/vim-pudb-and-jam.txt +++ b/doc/vim-pudb-and-jam.txt @@ -8,6 +8,7 @@ Forked from vim-pudb: https://github.com/KangOl/vim-pudb ============================================================================== CONTENTS *vim-pudb-contents* *vim-pudb* + *vim-pudb-and-jam* 1. Introduction ........................... |vim-pudb-introduction| 2. Installation ........................... |vim-pudb-installation| From 15c8b5c1b72d5deb9733793f965a4580f55bf23b Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 12 Jul 2020 21:04:23 -0600 Subject: [PATCH 26/55] Update README.rst Fix some wording in the introductory paragraph. --- README.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 7bcd47d..aebafc6 100644 --- a/README.rst +++ b/README.rst @@ -3,8 +3,9 @@ vim-pudb-and-jam A simple plugin allowing you to manage pudb breakpoints directly from vim. Forked from `vim-pudb`_ and given some jammy features such as setting and -editing equations, improved persistence of breakpoints, and the ability to list -active breakpoints either as a printed message or in a quickfix list. +editing breakpoint conditions, customization options, improved persistence +of breakpoints, and the ability to list active breakpoints either as a +printed message or in a quickfix list. .. _vim-pudb: https://github.com/KangOl/vim-pudb From d6be4922800bfdd340e765752880c01525531f61 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 7 Feb 2021 13:27:20 -0600 Subject: [PATCH 27/55] Update python's linecache when a python file is written This fixes an annoying bug where your ability to set breakpoints would be based entirely on whether or not there was an executable line at the place you want the breakpoint when you first opened the file for editing. --- plugin/pudb.vim | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 9626ba7..6020847 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -219,6 +219,18 @@ function! s:LocationList() endfunction +" +" Clear the python line cache for the given file if it has changed +" +function! s:ClearLineCache(filename) +pythonx << EOF +import linecache +import vim +linecache.checkcache(vim.eval('a:filename')) +EOF +endfunction + + " Define ex commands for all the above functions so they are user-accessible. command! PudbClearAll call s:ClearAll() command! PudbEdit call s:Edit() @@ -237,7 +249,11 @@ if &filetype == 'python' endif -" Also update when the file is first read. augroup pudb + " Also update when the file is first read. autocmd BufReadPost *.py call s:Update() + + " Force a linecache update after writes so the breakpoints can be parsed + " correctly. + autocmd BufWritePost *.py call s:ClearLineCache(expand('%:p')) augroup end From 76f25a25ed17bf40fb544f3da631a2e802111aee Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 7 Feb 2021 13:29:05 -0600 Subject: [PATCH 28/55] Update helptags --- doc/tags | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/doc/tags b/doc/tags index ea15d10..8bae5ed 100644 --- a/doc/tags +++ b/doc/tags @@ -1,19 +1,22 @@ -vim-pudb vim-pudb.txt /*vim-pudb* -vim-pudb-:PudbClearAll vim-pudb.txt /*vim-pudb-:PudbClearAll* -vim-pudb-:PudbEdit vim-pudb.txt /*vim-pudb-:PudbEdit* -vim-pudb-:PudbList vim-pudb.txt /*vim-pudb-:PudbList* -vim-pudb-:PudbQfList vim-pudb.txt /*vim-pudb-:PudbQfList* -vim-pudb-:PudbToggle vim-pudb.txt /*vim-pudb-:PudbToggle* -vim-pudb-:PudbUpdate vim-pudb.txt /*vim-pudb-:PudbUpdate* -vim-pudb-commands vim-pudb.txt /*vim-pudb-commands* -vim-pudb-configuration vim-pudb.txt /*vim-pudb-configuration* -vim-pudb-contents vim-pudb.txt /*vim-pudb-contents* -vim-pudb-highlight vim-pudb.txt /*vim-pudb-highlight* -vim-pudb-installation vim-pudb.txt /*vim-pudb-installation* -vim-pudb-introduction vim-pudb.txt /*vim-pudb-introduction* -vim-pudb-known-problems vim-pudb.txt /*vim-pudb-known-problems* -vim-pudb-priority vim-pudb.txt /*vim-pudb-priority* -vim-pudb-requirements vim-pudb.txt /*vim-pudb-requirements* -vim-pudb-sign vim-pudb.txt /*vim-pudb-sign* -vim-pudb-sign-group vim-pudb.txt /*vim-pudb-sign-group* -vim-pudb.txt vim-pudb.txt /*vim-pudb.txt* +vim-pudb vim-pudb-and-jam.txt /*vim-pudb* +vim-pudb-:PudbClearAll vim-pudb-and-jam.txt /*vim-pudb-:PudbClearAll* +vim-pudb-:PudbEdit vim-pudb-and-jam.txt /*vim-pudb-:PudbEdit* +vim-pudb-:PudbList vim-pudb-and-jam.txt /*vim-pudb-:PudbList* +vim-pudb-:PudbLocList vim-pudb-and-jam.txt /*vim-pudb-:PudbLocList* +vim-pudb-:PudbPopulateList vim-pudb-and-jam.txt /*vim-pudb-:PudbPopulateList* +vim-pudb-:PudbQfList vim-pudb-and-jam.txt /*vim-pudb-:PudbQfList* +vim-pudb-:PudbToggle vim-pudb-and-jam.txt /*vim-pudb-:PudbToggle* +vim-pudb-:PudbUpdate vim-pudb-and-jam.txt /*vim-pudb-:PudbUpdate* +vim-pudb-and-jam vim-pudb-and-jam.txt /*vim-pudb-and-jam* +vim-pudb-and-jam.txt vim-pudb-and-jam.txt /*vim-pudb-and-jam.txt* +vim-pudb-commands vim-pudb-and-jam.txt /*vim-pudb-commands* +vim-pudb-configuration vim-pudb-and-jam.txt /*vim-pudb-configuration* +vim-pudb-contents vim-pudb-and-jam.txt /*vim-pudb-contents* +vim-pudb-highlight vim-pudb-and-jam.txt /*vim-pudb-highlight* +vim-pudb-installation vim-pudb-and-jam.txt /*vim-pudb-installation* +vim-pudb-introduction vim-pudb-and-jam.txt /*vim-pudb-introduction* +vim-pudb-known-problems vim-pudb-and-jam.txt /*vim-pudb-known-problems* +vim-pudb-priority vim-pudb-and-jam.txt /*vim-pudb-priority* +vim-pudb-requirements vim-pudb-and-jam.txt /*vim-pudb-requirements* +vim-pudb-sign vim-pudb-and-jam.txt /*vim-pudb-sign* +vim-pudb-sign-group vim-pudb-and-jam.txt /*vim-pudb-sign-group* From 53874e75c8a58c1f39bd06eb615ef0258de6aefe Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Mon, 12 Apr 2021 19:40:11 -0600 Subject: [PATCH 29/55] Move all python code into rtp pythonx module --- plugin/pudb.vim | 249 +++++----------------------------------- pythonx/pudb_and_jam.py | 139 ++++++++++++++++++++++ 2 files changed, 169 insertions(+), 219 deletions(-) create mode 100644 pythonx/pudb_and_jam.py diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 6020847..9b82c0f 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -1,28 +1,27 @@ " File: pudb.vim " Author: Christophe Simonis, Michael van der Kamp " Description: Manage pudb breakpoints directly from vim -" Last Modified: March 07, 2020 -if exists('g:loaded_pudb_plugin') || &cp +if exists('g:loaded_pudb_plugin') || &compatible finish endif let g:loaded_pudb_plugin = 1 -if !has("pythonx") - echoerr "vim-pudb requires vim compiled with +python and/or +python3" +if !has('pythonx') + echoerr 'vim-pudb requires vim compiled with +python and/or +python3' finish endif -if !has("signs") - echoerr "vim-pudb requires vim compiled with +signs" +if !has('signs') + echoerr 'vim-pudb requires vim compiled with +signs' finish endif -" +"" " Load options and set defaults -" +"" let g:pudb_sign = get(g:, 'pudb_sign', 'B>') let g:pudb_highlight = get(g:, 'pudb_highlight', 'error') let g:pudb_priority = get(g:, 'pudb_priority', 100) @@ -34,226 +33,38 @@ call sign_define('PudbBreakPoint', { \ }) -" -" Loads the pudb breakpoint file and Updates the breakpoint signs for all -" breakpoints in all buffers. -" -function! s:Update() - - " first remove existing signs - call sign_unplace(g:pudb_sign_group) - -pythonx << EOF -import vim -from pudb.settings import load_breakpoints -from pudb import NUM_VERSION - -args = () if NUM_VERSION >= (2013, 1) else (None,) - -for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): - try: - opts = '{"lnum": %d, "priority": %d}' % (bp_lnum, vim.vars['pudb_priority']) - - # Critical to use vim.eval here instead of vim.vars[] to get sign group - vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' - '' % (vim.eval('g:pudb_sign_group'), bp_file, opts)) - except vim.error: - # Buffer for the given file isn't loaded. - continue -EOF - -endfunction - - -" -" Toggles a breakpoint on the current line. -" -function! s:Toggle() - -pythonx << EOF -import vim -from pudb.settings import load_breakpoints, save_breakpoints -from pudb import NUM_VERSION -from bdb import Breakpoint - -args = () if NUM_VERSION >= (2013, 1) else (None,) -bps = {(bp.file, bp.line): bp - for bp in map(lambda values: Breakpoint(*values), load_breakpoints(*args))} - -filename = vim.eval('expand("%:p")') -row, col = vim.current.window.cursor - -bp_key = (filename, row) -if bp_key in bps: - bps.pop(bp_key) -else: - bps[bp_key] = Breakpoint(filename, row) - -save_breakpoints(bps.values()) -EOF - - call s:Update() -endfunction - - -" -" Edit the condition of a breakpoint on the current line. -" If no such breakpoint exists, creates one. -" -function! s:Edit() - -pythonx << EOF -import vim -from pudb.settings import load_breakpoints, save_breakpoints -from pudb import NUM_VERSION -from bdb import Breakpoint - -args = () if NUM_VERSION >= (2013, 1) else (None,) -bps = {(bp.file, bp.line): bp - for bp in map(lambda values: Breakpoint(*values), load_breakpoints(*args))} - -filename = vim.eval('expand("%:p")') -row, col = vim.current.window.cursor - -bp_key = (filename, row) -if bp_key not in bps: - bps[bp_key] = Breakpoint(filename, row) -bp = bps[bp_key] - -old_cond = '' if bp.cond is None else bp.cond -vim.command('echo "Current condition: %s"' % old_cond) -vim.command('echohl Question') -vim.eval('inputsave()') -bp.cond = vim.eval('input("New Condition: ", "%s")' % old_cond) -vim.eval('inputrestore()') -vim.command('echohl None') - -save_breakpoints(bps.values()) -EOF - - call s:Update() -endfunction - - -" -" Clears all pudb breakpoints from all files. -" -function! s:ClearAll() - -pythonx << EOF -from pudb.settings import save_breakpoints -save_breakpoints([]) -EOF - - call s:Update() -endfunction - - -" -" Prints a list of all the breakpoints in all files. -" Shows the full file path, line number, and condition of each breakpoint. -" -function! s:List() - call s:Update() - -pythonx << EOF -import vim -from pudb.settings import load_breakpoints -from pudb import NUM_VERSION - -vim.command('echomsg "Listing all pudb breakpoints:"') - -args = () if NUM_VERSION >= (2013, 1) else (None,) -for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): - vim.command('echomsg "%s:%d:%s"' % ( - bp_file, bp_lnum, '' if not bool(cond) else ' %s' % cond - )) -EOF - -endfunction - - -" -" Calls the given vim command with a list of the breakpoints as strings in -" quickfix format. -" -function! s:PopulateList(list_command) - -pythonx << EOF -import vim -from pudb.settings import load_breakpoints -from pudb import NUM_VERSION - -qflist = [] -args = () if NUM_VERSION >= (2013, 1) else (None,) -for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*args): - try: - line = vim.eval('getbufline(bufname("%s"), %s)' % (bp_file, bp_lnum))[0] - if line.strip() == '': - line = '' - except LookupError: - line = '' - qflist.append(':'.join(map(str, [bp_file, bp_lnum, line]))) - -vim.command('%s %s' % (vim.eval('a:list_command'), qflist)) -EOF - -endfunction - - -" -" Populate the quickfix list with the breakpoint locations. -" -function! s:QuickfixList() - call s:Update() - call s:PopulateList('cgetexpr') -endfunction - - -" -" Populate the location list with the breakpoint locations. -" -function! s:LocationList() - call s:Update() - call s:PopulateList('lgetexpr') -endfunction - - -" -" Clear the python line cache for the given file if it has changed -" -function! s:ClearLineCache(filename) -pythonx << EOF -import linecache -import vim -linecache.checkcache(vim.eval('a:filename')) -EOF -endfunction - +"" +" Everything is defined in a python module on the runtimepath! +"" +pyx import pudb_and_jam +"" " Define ex commands for all the above functions so they are user-accessible. -command! PudbClearAll call s:ClearAll() -command! PudbEdit call s:Edit() -command! PudbList call s:List() -command! PudbLocList call s:LocationList() -command! PudbQfList call s:QuickfixList() -command! PudbToggle call s:Toggle() -command! PudbUpdate call s:Update() - -command! -nargs=1 -complete=command PudbPopulateList call s:Update() call s:PopulateList("") - - +"" +command! PudbClearAll pyx pudb_and_jam.clearAll() +command! PudbEdit pyx pudb_and_jam.edit() +command! PudbList pyx pudb_and_jam.list() +command! PudbLocList pyx pudb_and_jam.locationList() +command! PudbQfList pyx pudb_and_jam.quickfixList() +command! PudbToggle pyx pudb_and_jam.toggle() +command! PudbUpdate pyx pudb_and_jam.update() +command! -nargs=1 -complete=command PudbPopulateList + \ pyx pudb_and_jam.populateList("") + + +"" " If we were loaded lazily, update immediately. -if &filetype == 'python' - call s:Update() +"" +if &filetype ==? 'python' + pyx pudb_and_jam.update() endif augroup pudb " Also update when the file is first read. - autocmd BufReadPost *.py call s:Update() + autocmd BufReadPost *.py PudbUpdate " Force a linecache update after writes so the breakpoints can be parsed " correctly. - autocmd BufWritePost *.py call s:ClearLineCache(expand('%:p')) + autocmd BufWritePost *.py pyx pudb_and_jam.clearLineCache() augroup end diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py new file mode 100644 index 0000000..9ca5681 --- /dev/null +++ b/pythonx/pudb_and_jam.py @@ -0,0 +1,139 @@ +# vim: tw=79 +import linecache +import vim + +from bdb import Breakpoint +from pudb.settings import load_breakpoints, save_breakpoints +from pudb import NUM_VERSION + +LOAD_ARGS = () if NUM_VERSION >= (2013, 1) else (None,) + + +def update(): + vim.command('call sign_unplace(g:pudb_sign_group)') + for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*LOAD_ARGS): + try: + opts = ('{"lnum": %d, "priority": %d}' + % (bp_lnum, vim.vars['pudb_priority'])) + + # Critical to use vim.eval here instead of vim.vars[] to get sign + # group, since vim.vars[] will render the string as + # "b'pudb_sign_group'" instead of "pudb_sign_group" + vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' + '' % (vim.eval('g:pudb_sign_group'), bp_file, opts)) + except vim.error: + # Buffer for the given file isn't loaded. + continue + + +def toggle(): + """ + Toggles a breakpoint on the current line. + """ + bps = {(bp.file, bp.line): bp + for bp in map(lambda values: Breakpoint(*values), + load_breakpoints(*LOAD_ARGS))} + + filename = vim.eval('expand("%:p")') + row, col = vim.current.window.cursor + + bp_key = (filename, row) + if bp_key in bps: + bps.pop(bp_key) + else: + bps[bp_key] = Breakpoint(filename, row) + + save_breakpoints(bps.values()) + update() + + +def edit(): + """ + Edit the condition of a breakpoint on the current line. + If no such breakpoint exists, creates one. + """ + bps = {(bp.file, bp.line): bp + for bp in map(lambda values: Breakpoint(*values), + load_breakpoints(*LOAD_ARGS))} + + filename = vim.eval('expand("%:p")') + row, col = vim.current.window.cursor + + bp_key = (filename, row) + if bp_key not in bps: + bps[bp_key] = Breakpoint(filename, row) + bp = bps[bp_key] + + old_cond = '' if bp.cond is None else bp.cond + vim.command('echo "Current condition: %s"' % old_cond) + vim.command('echohl Question') + vim.eval('inputsave()') + bp.cond = vim.eval('input("New Condition: ", "%s")' % old_cond) + vim.eval('inputrestore()') + vim.command('echohl None') + + save_breakpoints(bps.values()) + update() + + +def clearAll(): + """ + Clears all pudb breakpoints from all files. + """ + save_breakpoints([]) + update() + + +def list(): + """ + Prints a list of all the breakpoints in all files. + Shows the full file path, line number, and condition of each breakpoint. + """ + update() + vim.command('echomsg "Listing all pudb breakpoints:"') + for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*LOAD_ARGS): + vim.command('echomsg "%s:%d:%s"' % ( + bp_file, bp_lnum, '' if not bool(cond) else ' %s' % cond + )) + + +def populateList(list_command): + """ + Calls the given vim command with a list of the breakpoints as strings in + quickfix format. + """ + update() + qflist = [] + for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*LOAD_ARGS): + try: + line = vim.eval('getbufline(bufname("%s"), %s)' + % (bp_file, bp_lnum))[0] + if line.strip() == '': + line = '' + except LookupError: + line = '' + qflist.append(':'.join(map(str, [bp_file, bp_lnum, line]))) + vim.command('%s %s' % (list_command, qflist)) + + +def quickfixList(): + """ + Populate the quickfix list with the breakpoint locations. + """ + populateList('cgetexpr') + + +def locationList(): + """ + Populate the location list with the breakpoint locations. + """ + populateList('lgetexpr') + + +def clearLineCache(): + """ + Clear the python line cache for the given file if it has changed + """ + filename = vim.eval('expand("%:p")') + linecache.checkcache(filename) + update() From c97af55b4e89a91ffd1019bb70b7086766d8258b Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 15:58:59 -0600 Subject: [PATCH 30/55] Fix incorrect text in quickfix/location lists If a buffer was not loaded, the line numbers were often being looked up in some other loaded buffer, usually the current one, giving the wrong line text in the populated list. The problem was a redundant call to bufname(). --- pythonx/pudb_and_jam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 9ca5681..25ade28 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -106,7 +106,7 @@ def populateList(list_command): qflist = [] for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*LOAD_ARGS): try: - line = vim.eval('getbufline(bufname("%s"), %s)' + line = vim.eval('getbufline("%s", %s)' % (bp_file, bp_lnum))[0] if line.strip() == '': line = '' From 6c79900c9620a4b70a5ca0c69bb2eb6c5d17b95c Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 16:01:05 -0600 Subject: [PATCH 31/55] Add __pychache__ to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 12e546f..436e46b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ tags *.sw[op] +__pycache__ From 38e03d77f42dcc585c49051d6dccc880c0dd7591 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:30:57 -0600 Subject: [PATCH 32/55] Rename list() -> list_breakpoints() Not sure why I did that... --- plugin/pudb.vim | 2 +- pythonx/pudb_and_jam.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 9b82c0f..579cbf5 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -43,7 +43,7 @@ pyx import pudb_and_jam "" command! PudbClearAll pyx pudb_and_jam.clearAll() command! PudbEdit pyx pudb_and_jam.edit() -command! PudbList pyx pudb_and_jam.list() +command! PudbList pyx pudb_and_jam.list_breakpoints() command! PudbLocList pyx pudb_and_jam.locationList() command! PudbQfList pyx pudb_and_jam.quickfixList() command! PudbToggle pyx pudb_and_jam.toggle() diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 25ade28..a3cf3e1 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -84,7 +84,7 @@ def clearAll(): update() -def list(): +def list_breakpoints(): """ Prints a list of all the breakpoints in all files. Shows the full file path, line number, and condition of each breakpoint. From 4dcf0612745e1fff25e8fc383b6178ff412fd4ac Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:33:54 -0600 Subject: [PATCH 33/55] Import checkcache directly --- pythonx/pudb_and_jam.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index a3cf3e1..9e44628 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -1,8 +1,8 @@ # vim: tw=79 -import linecache import vim from bdb import Breakpoint +from linecache import checkcache from pudb.settings import load_breakpoints, save_breakpoints from pudb import NUM_VERSION @@ -135,5 +135,5 @@ def clearLineCache(): Clear the python line cache for the given file if it has changed """ filename = vim.eval('expand("%:p")') - linecache.checkcache(filename) + checkcache(filename) update() From c182da7e198cd29134a7fe0f195dae8de37b1b95 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:37:35 -0600 Subject: [PATCH 34/55] Extract a breakpoints generator --- pythonx/pudb_and_jam.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 9e44628..72b742a 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -2,6 +2,7 @@ import vim from bdb import Breakpoint +from itertools import starmap from linecache import checkcache from pudb.settings import load_breakpoints, save_breakpoints from pudb import NUM_VERSION @@ -9,18 +10,26 @@ LOAD_ARGS = () if NUM_VERSION >= (2013, 1) else (None,) +def breakpoints(): + """ + :return: An iterator over the saved breakpoints. + :rtype: starmap(Breakpoint) + """ + return starmap(Breakpoint, load_breakpoints(*LOAD_ARGS)) + + def update(): vim.command('call sign_unplace(g:pudb_sign_group)') - for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*LOAD_ARGS): + for bp in breakpoints(): try: opts = ('{"lnum": %d, "priority": %d}' - % (bp_lnum, vim.vars['pudb_priority'])) + % (bp.line, vim.vars['pudb_priority'])) # Critical to use vim.eval here instead of vim.vars[] to get sign # group, since vim.vars[] will render the string as # "b'pudb_sign_group'" instead of "pudb_sign_group" vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' - '' % (vim.eval('g:pudb_sign_group'), bp_file, opts)) + '' % (vim.eval('g:pudb_sign_group'), bp.file, opts)) except vim.error: # Buffer for the given file isn't loaded. continue @@ -31,8 +40,7 @@ def toggle(): Toggles a breakpoint on the current line. """ bps = {(bp.file, bp.line): bp - for bp in map(lambda values: Breakpoint(*values), - load_breakpoints(*LOAD_ARGS))} + for bp in breakpoints()} filename = vim.eval('expand("%:p")') row, col = vim.current.window.cursor @@ -53,8 +61,7 @@ def edit(): If no such breakpoint exists, creates one. """ bps = {(bp.file, bp.line): bp - for bp in map(lambda values: Breakpoint(*values), - load_breakpoints(*LOAD_ARGS))} + for bp in breakpoints()} filename = vim.eval('expand("%:p")') row, col = vim.current.window.cursor @@ -91,9 +98,9 @@ def list_breakpoints(): """ update() vim.command('echomsg "Listing all pudb breakpoints:"') - for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*LOAD_ARGS): + for bp in breakpoints(): vim.command('echomsg "%s:%d:%s"' % ( - bp_file, bp_lnum, '' if not bool(cond) else ' %s' % cond + bp.file, bp.line, '' if not bool(bp.cond) else ' %s' % bp.cond )) @@ -104,15 +111,15 @@ def populateList(list_command): """ update() qflist = [] - for bp_file, bp_lnum, temp, cond, funcname in load_breakpoints(*LOAD_ARGS): + for bp in breakpoints(): try: line = vim.eval('getbufline("%s", %s)' - % (bp_file, bp_lnum))[0] + % (bp.file, bp.line))[0] if line.strip() == '': line = '' except LookupError: line = '' - qflist.append(':'.join(map(str, [bp_file, bp_lnum, line]))) + qflist.append(':'.join(map(str, [bp.file, bp.line, line]))) vim.command('%s %s' % (list_command, qflist)) From 8e8eb0873d46ce2d7ff35e20d63ebf72607d648a Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:38:47 -0600 Subject: [PATCH 35/55] Extract a breakpoint_dict function --- pythonx/pudb_and_jam.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 72b742a..272f5fb 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -18,6 +18,14 @@ def breakpoints(): return starmap(Breakpoint, load_breakpoints(*LOAD_ARGS)) +def breakpoint_dict(): + """ + :return: The saved breakpoints, as a dict with (filename, line number) keys + :rtype: dict(tuple(str, int), Breakpoint) + """ + return {(bp.file, bp.line): bp for bp in breakpoints()} + + def update(): vim.command('call sign_unplace(g:pudb_sign_group)') for bp in breakpoints(): @@ -39,8 +47,7 @@ def toggle(): """ Toggles a breakpoint on the current line. """ - bps = {(bp.file, bp.line): bp - for bp in breakpoints()} + bps = breakpoint_dict() filename = vim.eval('expand("%:p")') row, col = vim.current.window.cursor @@ -60,8 +67,7 @@ def edit(): Edit the condition of a breakpoint on the current line. If no such breakpoint exists, creates one. """ - bps = {(bp.file, bp.line): bp - for bp in breakpoints()} + bps = breakpoint_dict() filename = vim.eval('expand("%:p")') row, col = vim.current.window.cursor From 5ae71bd44b2a21db93b944d925a54d46d2ef084e Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:39:30 -0600 Subject: [PATCH 36/55] Extract a "current position" function --- pythonx/pudb_and_jam.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 272f5fb..51e992c 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -43,20 +43,28 @@ def update(): continue +def current_position(): + """ + :return: a filename, line number pair, to be used as a key for a + breakpoint. + :rtype: tuple(str, int) + """ + filename = vim.eval('expand("%:p")') + row, _ = vim.current.window.cursor + return (filename, row) + + def toggle(): """ Toggles a breakpoint on the current line. """ bps = breakpoint_dict() + bp_key = current_position() - filename = vim.eval('expand("%:p")') - row, col = vim.current.window.cursor - - bp_key = (filename, row) if bp_key in bps: bps.pop(bp_key) else: - bps[bp_key] = Breakpoint(filename, row) + bps[bp_key] = Breakpoint(*bp_key) save_breakpoints(bps.values()) update() @@ -68,13 +76,10 @@ def edit(): If no such breakpoint exists, creates one. """ bps = breakpoint_dict() + bp_key = current_position() - filename = vim.eval('expand("%:p")') - row, col = vim.current.window.cursor - - bp_key = (filename, row) if bp_key not in bps: - bps[bp_key] = Breakpoint(filename, row) + bps[bp_key] = Breakpoint(*bp_key) bp = bps[bp_key] old_cond = '' if bp.cond is None else bp.cond From 99759c1c958fa6ccf8b667434e7c11e8fd62ae74 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:40:04 -0600 Subject: [PATCH 37/55] Extract a function for iterating breakpoints as strings --- pythonx/pudb_and_jam.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 51e992c..1bf7634 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -26,6 +26,21 @@ def breakpoint_dict(): return {(bp.file, bp.line): bp for bp in breakpoints()} +def breakpoint_strings(): + """ + :return: An generator over the saved breakpoints as strings in the format: + "filename:linenr:condition" + :rtype: generator(str) + """ + return ( + '{file}:{line:d}:{cond}'.format( + file=bp.file, + line=bp.line, + cond=bp.cond if bp.cond else ' ') + for bp in breakpoints() + ) + + def update(): vim.command('call sign_unplace(g:pudb_sign_group)') for bp in breakpoints(): @@ -109,10 +124,8 @@ def list_breakpoints(): """ update() vim.command('echomsg "Listing all pudb breakpoints:"') - for bp in breakpoints(): - vim.command('echomsg "%s:%d:%s"' % ( - bp.file, bp.line, '' if not bool(bp.cond) else ' %s' % bp.cond - )) + for bp_string in breakpoint_strings(): + vim.command('echomsg "%s"' % bp_string) def populateList(list_command): From 50fc61ee38bdeb9a8216e2cc6fac4267a556ac33 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:40:37 -0600 Subject: [PATCH 38/55] Show the condition in the quickfix list Instead of the line of code --- pythonx/pudb_and_jam.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 1bf7634..f6a909e 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -26,7 +26,7 @@ def breakpoint_dict(): return {(bp.file, bp.line): bp for bp in breakpoints()} -def breakpoint_strings(): +def breakpoint_strings(empty_cond_str=''): """ :return: An generator over the saved breakpoints as strings in the format: "filename:linenr:condition" @@ -36,7 +36,7 @@ def breakpoint_strings(): '{file}:{line:d}:{cond}'.format( file=bp.file, line=bp.line, - cond=bp.cond if bp.cond else ' ') + cond=bp.cond if bp.cond else empty_cond_str) for bp in breakpoints() ) @@ -134,17 +134,8 @@ def populateList(list_command): quickfix format. """ update() - qflist = [] - for bp in breakpoints(): - try: - line = vim.eval('getbufline("%s", %s)' - % (bp.file, bp.line))[0] - if line.strip() == '': - line = '' - except LookupError: - line = '' - qflist.append(':'.join(map(str, [bp.file, bp.line, line]))) - vim.command('%s %s' % (list_command, qflist)) + bps = list(breakpoint_strings()) + vim.command('%s %s' % (list_command, bps)) def quickfixList(): From 0194ee7532c62653700e5309e87e25ec58c02ef1 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:49:35 -0600 Subject: [PATCH 39/55] Update docs - Signs update on save - List commands don't try to figure out the line of code --- doc/vim-pudb-and-jam.txt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/doc/vim-pudb-and-jam.txt b/doc/vim-pudb-and-jam.txt index 04b853f..8171715 100644 --- a/doc/vim-pudb-and-jam.txt +++ b/doc/vim-pudb-and-jam.txt @@ -101,17 +101,13 @@ COMMANDS *vim-pudb-commands* *vim-pudb-:PudbLocList* :PudbLocList Load all breakpoints into the location list. Does not jump to the first - entry. Breakpoints into buffers that are not loaded will be in the list, - but with the text ''. Lines containing only whitespace - will appear with the text '' + entry. ------------------------------------------------------------------------------ *vim-pudb-:PudbQfList* :PudbQfList Load all breakpoints into the quickfix list. Does not jump to the first - entry. Breakpoints into buffers that are not loaded will be in the list, - but with the text ''. Lines containing only whitespace - will appear with the text '' + entry. ------------------------------------------------------------------------------ *vim-pudb-:PudbPopulateList* @@ -127,6 +123,9 @@ COMMANDS *vim-pudb-commands* will all trigger an update, but this command lets you trigger an update without doing anything else. + NOTE: There should no longer be any need to call this command. Breakpoint + signs are updated whenever you save the buffer. + ============================================================================== CONFIGURATION *vim-pudb-configuration* @@ -150,7 +149,7 @@ Default: `'pudb_sign_group'` ------------------------------------------------------------------------------ *vim-pudb-highlight* -The highlight group of the sign in the sign colum can be defined with +The highlight group of the sign in the sign column can be defined with `g:pudb_highlight`: `let g:pudb_highlight = 'error'` @@ -169,8 +168,5 @@ Default: `100` ============================================================================== KNOWN PROBLEMS *vim-pudb-known-problems* -- Currently, the list of breakpoints is not reloaded automatically. Signs are - only updated when a python buffer is first read, or when one of the above - commands is called. - There may be room for speed optimisations. - There is currently no way to specify which breakpoint file to use. From 82ca1a694f18a844cdf7990d0ebf6bba90ad843a Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:52:18 -0600 Subject: [PATCH 40/55] Update README to align with docs --- README.rst | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index aebafc6..728426f 100644 --- a/README.rst +++ b/README.rst @@ -51,15 +51,11 @@ Commands ``:PudbLocList`` Load all breakpoints into the location list. Does not jump to the first - entry. Breakpoints into buffers that are not loaded will be in the list, but - with the text ''. Lines containing only whitespace - will appear with the text '' + entry. ``:PudbQfList`` Load all breakpoints into the quickfix list. Does not jump to the first - entry. Breakpoints into buffers that are not loaded will be in the list, but - with the text ''. Lines containing only whitespace - will appear with the text '' + entry. ``:PudbPopulateList `` Supply a list of all breakpoints, in quickfix format, to the Ex command @@ -71,6 +67,9 @@ Commands all trigger an update, but this command lets you trigger an update without doing anything else. + NOTE: There should no longer be any need to call this command. Breakpoint + signs are updated whenever you save the buffer. + Mappings ======== @@ -114,8 +113,5 @@ This plugin uses sign groups. You can change the name of the sign group using Known problems ============== -- Currently, the list of breakpoints is not reloaded automatically. Signs are - only updated when a python buffer is first read, or when one of the above - commands is called. - There may be room for speed optimisations. - There is currently no way to specify which breakpoint file to use. From adb49c32d8f53587354274454794b91bb1e5c72f Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sat, 24 Apr 2021 18:52:44 -0600 Subject: [PATCH 41/55] Fix typo in README --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 728426f..9e67bc0 100644 --- a/README.rst +++ b/README.rst @@ -94,7 +94,7 @@ The text of the sign can be defined with ``g:pudb_sign`` (default ``'B>'``): ``let g:pudb_sign = 'B>'`` -The highlight group of the sign in the sign colum can be defined with +The highlight group of the sign in the sign column can be defined with ``g:pudb_highlight`` (default ``'error'``): ``let g:pudb_highlight = 'error'`` From 35b776374b1944a5ab591c8b530ce14c4c415c65 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Tue, 27 Apr 2021 21:13:15 -0600 Subject: [PATCH 42/55] Use consistent naming style in python module --- plugin/pudb.vim | 18 +++++++++--------- pythonx/pudb_and_jam.py | 32 ++++++++++++++++---------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 579cbf5..437286b 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -41,22 +41,22 @@ pyx import pudb_and_jam "" " Define ex commands for all the above functions so they are user-accessible. "" -command! PudbClearAll pyx pudb_and_jam.clearAll() -command! PudbEdit pyx pudb_and_jam.edit() +command! PudbClearAll pyx pudb_and_jam.clear_all_breakpoints() +command! PudbEdit pyx pudb_and_jam.edit_breakpoint() command! PudbList pyx pudb_and_jam.list_breakpoints() -command! PudbLocList pyx pudb_and_jam.locationList() -command! PudbQfList pyx pudb_and_jam.quickfixList() -command! PudbToggle pyx pudb_and_jam.toggle() -command! PudbUpdate pyx pudb_and_jam.update() +command! PudbLocList pyx pudb_and_jam.location_list() +command! PudbQfList pyx pudb_and_jam.quickfix_list() +command! PudbToggle pyx pudb_and_jam.toggle_breakpoint() +command! PudbUpdate pyx pudb_and_jam.update_breakpoints() command! -nargs=1 -complete=command PudbPopulateList - \ pyx pudb_and_jam.populateList("") + \ pyx pudb_and_jam.populate_list("") "" " If we were loaded lazily, update immediately. "" if &filetype ==? 'python' - pyx pudb_and_jam.update() + pyx pudb_and_jam.update_breakpoints() endif @@ -66,5 +66,5 @@ augroup pudb " Force a linecache update after writes so the breakpoints can be parsed " correctly. - autocmd BufWritePost *.py pyx pudb_and_jam.clearLineCache() + autocmd BufWritePost *.py pyx pudb_and_jam.clear_linecache() augroup end diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index f6a909e..3004064 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -41,7 +41,7 @@ def breakpoint_strings(empty_cond_str=''): ) -def update(): +def update_breakpoints(): vim.command('call sign_unplace(g:pudb_sign_group)') for bp in breakpoints(): try: @@ -69,7 +69,7 @@ def current_position(): return (filename, row) -def toggle(): +def toggle_breakpoint(): """ Toggles a breakpoint on the current line. """ @@ -82,10 +82,10 @@ def toggle(): bps[bp_key] = Breakpoint(*bp_key) save_breakpoints(bps.values()) - update() + update_breakpoints() -def edit(): +def edit_breakpoint(): """ Edit the condition of a breakpoint on the current line. If no such breakpoint exists, creates one. @@ -106,15 +106,15 @@ def edit(): vim.command('echohl None') save_breakpoints(bps.values()) - update() + update_breakpoints() -def clearAll(): +def clear_all_breakpoints(): """ Clears all pudb breakpoints from all files. """ save_breakpoints([]) - update() + update_breakpoints() def list_breakpoints(): @@ -122,40 +122,40 @@ def list_breakpoints(): Prints a list of all the breakpoints in all files. Shows the full file path, line number, and condition of each breakpoint. """ - update() + update_breakpoints() vim.command('echomsg "Listing all pudb breakpoints:"') for bp_string in breakpoint_strings(): vim.command('echomsg "%s"' % bp_string) -def populateList(list_command): +def populate_list(list_command): """ Calls the given vim command with a list of the breakpoints as strings in quickfix format. """ - update() + update_breakpoints() bps = list(breakpoint_strings()) vim.command('%s %s' % (list_command, bps)) -def quickfixList(): +def quickfix_list(): """ Populate the quickfix list with the breakpoint locations. """ - populateList('cgetexpr') + populate_list('cgetexpr') -def locationList(): +def location_list(): """ Populate the location list with the breakpoint locations. """ - populateList('lgetexpr') + populate_list('lgetexpr') -def clearLineCache(): +def clear_linecache(): """ Clear the python line cache for the given file if it has changed """ filename = vim.eval('expand("%:p")') checkcache(filename) - update() + update_breakpoints() From 3a0a680374fe2bc8581e8e0657e73d4476eb582a Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Tue, 27 Apr 2021 21:22:27 -0600 Subject: [PATCH 43/55] Make better use of the vim module --- pythonx/pudb_and_jam.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 3004064..21ff447 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -42,7 +42,7 @@ def breakpoint_strings(empty_cond_str=''): def update_breakpoints(): - vim.command('call sign_unplace(g:pudb_sign_group)') + vim.eval('sign_unplace(g:pudb_sign_group)') for bp in breakpoints(): try: opts = ('{"lnum": %d, "priority": %d}' @@ -64,7 +64,7 @@ def current_position(): breakpoint. :rtype: tuple(str, int) """ - filename = vim.eval('expand("%:p")') + filename = vim.current.buffer.name row, _ = vim.current.window.cursor return (filename, row) @@ -156,6 +156,6 @@ def clear_linecache(): """ Clear the python line cache for the given file if it has changed """ - filename = vim.eval('expand("%:p")') + filename = vim.current.buffer.name checkcache(filename) update_breakpoints() From b99be9906dd689e68c301b971a56a53ff54f9fd1 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 22 Sep 2021 22:00:34 -0600 Subject: [PATCH 44/55] Call setqflist to avoid conflicts with 'errorformat' --- pythonx/pudb_and_jam.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 21ff447..ad939fa 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -138,18 +138,41 @@ def populate_list(list_command): vim.command('%s %s' % (list_command, bps)) +def quickfix_list_arg(): + """ + :return: The list of dicts to provide as the first argument to setqflist() + :rtype: list[dict] + """ + return [ + { + 'filename': bp.file, + 'lnum': bp.line, + 'text': bp.cond if bp.cond else '', + } + for bp in breakpoints() + ] + + def quickfix_list(): """ Populate the quickfix list with the breakpoint locations. """ - populate_list('cgetexpr') + setqflist = vim.Function('setqflist') + entries = quickfix_list_arg() + setqflist(entries) + height = min(10, len(entries)) + vim.command('cwindow {}'.format(height)) def location_list(): """ Populate the location list with the breakpoint locations. """ - populate_list('lgetexpr') + setloclist = vim.Function('setloclist') + entries = quickfix_list_arg() + setloclist(entries) + height = min(10, len(entries)) + vim.command('cwindow {}'.format(height)) def clear_linecache(): From d4671cd9c6aa26655e93a7792e3ce447e0bcd661 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 22 Sep 2021 22:03:38 -0600 Subject: [PATCH 45/55] Rename edit_breakpoint() -> edit_condition() --- plugin/pudb.vim | 2 +- pythonx/pudb_and_jam.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 437286b..dfb5697 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -42,7 +42,7 @@ pyx import pudb_and_jam " Define ex commands for all the above functions so they are user-accessible. "" command! PudbClearAll pyx pudb_and_jam.clear_all_breakpoints() -command! PudbEdit pyx pudb_and_jam.edit_breakpoint() +command! PudbEdit pyx pudb_and_jam.edit_condition() command! PudbList pyx pudb_and_jam.list_breakpoints() command! PudbLocList pyx pudb_and_jam.location_list() command! PudbQfList pyx pudb_and_jam.quickfix_list() diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index ad939fa..c2d0469 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -85,7 +85,7 @@ def toggle_breakpoint(): update_breakpoints() -def edit_breakpoint(): +def edit_condition(): """ Edit the condition of a breakpoint on the current line. If no such breakpoint exists, creates one. From 6b475cb370b4ebd892e28212865c59ecf04aa9c3 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 22 Sep 2021 22:04:46 -0600 Subject: [PATCH 46/55] Add support for moving breakpoints --- plugin/pudb.vim | 1 + pythonx/pudb_and_jam.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index dfb5697..275bfbb 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -43,6 +43,7 @@ pyx import pudb_and_jam "" command! PudbClearAll pyx pudb_and_jam.clear_all_breakpoints() command! PudbEdit pyx pudb_and_jam.edit_condition() +command! PudbMove pyx pudb_and_jam.move_breakpoint() command! PudbList pyx pudb_and_jam.list_breakpoints() command! PudbLocList pyx pudb_and_jam.location_list() command! PudbQfList pyx pudb_and_jam.quickfix_list() diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index c2d0469..77ffcda 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -109,6 +109,36 @@ def edit_condition(): update_breakpoints() +def move_breakpoint(): + """ + Move the breakpoint to a different line, preserving the condition. + """ + bps = breakpoint_dict() + bp_key = current_position() + + if bp_key not in bps: + vim.command('echo "No breakpoint at current position"') + return + + bp = bps[bp_key] + old_line = bp.line + vim.command('echo "Current line: {}"'.format(old_line)) + vim.command('echohl Question') + vim.eval('inputsave()') + new_line = (vim.eval('input("New line: ", "{}")'.format(old_line))) + vim.eval('inputrestore()') + vim.command('echohl None') + + try: + bp.line = int(new_line) + except ValueError: + vim.command('echo "Invalid line number: {}"'.format(new_line)) + return + + save_breakpoints(bps.values()) + update_breakpoints() + + def clear_all_breakpoints(): """ Clears all pudb breakpoints from all files. From 4dc70d06dd43c639dc29d1897f62105b03b9f1e0 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 22 Sep 2021 22:06:09 -0600 Subject: [PATCH 47/55] Add support for editing the breakpoint file directly --- plugin/pudb.vim | 1 + pythonx/pudb_and_jam.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 275bfbb..542a0ef 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -42,6 +42,7 @@ pyx import pudb_and_jam " Define ex commands for all the above functions so they are user-accessible. "" command! PudbClearAll pyx pudb_and_jam.clear_all_breakpoints() +command! PudbEditFile pyx pudb_and_jam.edit_breakpoint_file() command! PudbEdit pyx pudb_and_jam.edit_condition() command! PudbMove pyx pudb_and_jam.move_breakpoint() command! PudbList pyx pudb_and_jam.list_breakpoints() diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 77ffcda..7889de7 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -4,7 +4,8 @@ from bdb import Breakpoint from itertools import starmap from linecache import checkcache -from pudb.settings import load_breakpoints, save_breakpoints +from pudb.settings import ( + load_breakpoints, save_breakpoints, get_breakpoints_file_name) from pudb import NUM_VERSION LOAD_ARGS = () if NUM_VERSION >= (2013, 1) else (None,) @@ -139,6 +140,13 @@ def move_breakpoint(): update_breakpoints() +def edit_breakpoint_file(): + """ + Open the breakpoint file in a buffer for direct editing. + """ + vim.command('edit {}'.format(get_breakpoints_file_name())) + + def clear_all_breakpoints(): """ Clears all pudb breakpoints from all files. From 43fa1ecad3dbe44c6da2a59e3463454e637b5e84 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 22 Sep 2021 22:07:19 -0600 Subject: [PATCH 48/55] Fix numbering in help ToC --- doc/vim-pudb-and-jam.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/vim-pudb-and-jam.txt b/doc/vim-pudb-and-jam.txt index 8171715..be81b2a 100644 --- a/doc/vim-pudb-and-jam.txt +++ b/doc/vim-pudb-and-jam.txt @@ -18,10 +18,10 @@ CONTENTS *vim-pudb-contents* *vim-pudb* 4.2 PudbEdit .......................... |vim-pudb-:PudbEdit| 4.3 PudbClearAll ...................... |vim-pudb-:PudbClearAll| 4.4 PudbList .......................... |vim-pudb-:PudbList| - 4.4 PudbLocList ....................... |vim-pudb-:PudbLocList| - 4.5 PudbQfList ........................ |vim-pudb-:PudbQfList| - 4.5 PudbPopulateList .................. |vim-pudb-:PudbPopulateList| - 4.6 PudbUpdate ........................ |vim-pudb-:PudbUpdate| + 4.5 PudbLocList ....................... |vim-pudb-:PudbLocList| + 4.6 PudbQfList ........................ |vim-pudb-:PudbQfList| + 4.7 PudbPopulateList .................. |vim-pudb-:PudbPopulateList| + 4.8 PudbUpdate ........................ |vim-pudb-:PudbUpdate| 5. Configuration .......................... |vim-pudb-configuration| 5.1 vim-pudb-sign ..................... |vim-pudb-sign| 5.2 vim-pudb-sign-group ............... |vim-pudb-sign-group| From f60031422e2af2d780b841b8c66c0767edb005c4 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 22 Sep 2021 22:11:00 -0600 Subject: [PATCH 49/55] Document PudbMove --- doc/vim-pudb-and-jam.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/vim-pudb-and-jam.txt b/doc/vim-pudb-and-jam.txt index be81b2a..a3053f9 100644 --- a/doc/vim-pudb-and-jam.txt +++ b/doc/vim-pudb-and-jam.txt @@ -16,6 +16,7 @@ CONTENTS *vim-pudb-contents* *vim-pudb* 4. Commands ............................... |vim-pudb-commands| 4.1 PudbToggle ........................ |vim-pudb-:PudbToggle| 4.2 PudbEdit .......................... |vim-pudb-:PudbEdit| + 4.2 PudbMove .......................... |vim-pudb-:PudbMove| 4.3 PudbClearAll ...................... |vim-pudb-:PudbClearAll| 4.4 PudbList .......................... |vim-pudb-:PudbList| 4.5 PudbLocList ....................... |vim-pudb-:PudbLocList| @@ -46,6 +47,7 @@ to add to your `.vimrc` file: > nnoremap bc :PudbClearAll nnoremap be :PudbEdit + nnoremap bm :PudbMove nnoremap bl :PudbList nnoremap bq :PudbQfList nnoremap bp :PudbToggle @@ -86,6 +88,11 @@ COMMANDS *vim-pudb-commands* Edit the condition of a breakpoint on the current line. Creates a breakpoint if one doesn't already exist. +------------------------------------------------------------------------------ + *vim-pudb-:PudbMove* +:PudbMove + Move the location of a breakpoint on the current line. + ------------------------------------------------------------------------------ *vim-pudb-:PudbClearAll* :PudbClearAll From 766bb16c846d30ec8a998ec2be56414bb1282c71 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Wed, 22 Sep 2021 22:14:09 -0600 Subject: [PATCH 50/55] Document PudbEditFile --- doc/vim-pudb-and-jam.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/vim-pudb-and-jam.txt b/doc/vim-pudb-and-jam.txt index a3053f9..8fccf50 100644 --- a/doc/vim-pudb-and-jam.txt +++ b/doc/vim-pudb-and-jam.txt @@ -23,6 +23,7 @@ CONTENTS *vim-pudb-contents* *vim-pudb* 4.6 PudbQfList ........................ |vim-pudb-:PudbQfList| 4.7 PudbPopulateList .................. |vim-pudb-:PudbPopulateList| 4.8 PudbUpdate ........................ |vim-pudb-:PudbUpdate| + 4.8 PudbEditFile ...................... |vim-pudb-:PudbEditFile| 5. Configuration .......................... |vim-pudb-configuration| 5.1 vim-pudb-sign ..................... |vim-pudb-sign| 5.2 vim-pudb-sign-group ............... |vim-pudb-sign-group| @@ -133,6 +134,12 @@ COMMANDS *vim-pudb-commands* NOTE: There should no longer be any need to call this command. Breakpoint signs are updated whenever you save the buffer. +------------------------------------------------------------------------------ + *vim-pudb-:PudbEditFile* +:PudbEditFile + Open the breakpoint file for editing in the current window. Breakpoint + signs will not be maintained when saving direct changes to the file. + ============================================================================== CONFIGURATION *vim-pudb-configuration* From e993f5e51770cf62f1d7b50b38cc918569189fde Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Thu, 30 Dec 2021 23:23:27 -0600 Subject: [PATCH 51/55] Use str.format --- pythonx/pudb_and_jam.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/pythonx/pudb_and_jam.py b/pythonx/pudb_and_jam.py index 7889de7..ae5bcf6 100644 --- a/pythonx/pudb_and_jam.py +++ b/pythonx/pudb_and_jam.py @@ -29,7 +29,7 @@ def breakpoint_dict(): def breakpoint_strings(empty_cond_str=''): """ - :return: An generator over the saved breakpoints as strings in the format: + :return: A generator over the saved breakpoints as strings in the format: "filename:linenr:condition" :rtype: generator(str) """ @@ -46,14 +46,21 @@ def update_breakpoints(): vim.eval('sign_unplace(g:pudb_sign_group)') for bp in breakpoints(): try: - opts = ('{"lnum": %d, "priority": %d}' - % (bp.line, vim.vars['pudb_priority'])) + options = '{{"lnum": {line:d}, "priority": {prio:d}}}'.format( + line=bp.line, + prio=vim.vars['pudb_priority'], + ) # Critical to use vim.eval here instead of vim.vars[] to get sign # group, since vim.vars[] will render the string as # "b'pudb_sign_group'" instead of "pudb_sign_group" - vim.eval('sign_place(0, "%s", "PudbBreakPoint", "%s", %s)' - '' % (vim.eval('g:pudb_sign_group'), bp.file, opts)) + vim.eval( + 'sign_place(0, "{group}", "PudbBreakPoint", "{file}", {opts})' + .format( + group=vim.eval('g:pudb_sign_group'), + file=bp.file, + opts=options, + )) except vim.error: # Buffer for the given file isn't loaded. continue @@ -99,10 +106,10 @@ def edit_condition(): bp = bps[bp_key] old_cond = '' if bp.cond is None else bp.cond - vim.command('echo "Current condition: %s"' % old_cond) + vim.command('echo "Current condition: {}"'.format(old_cond)) vim.command('echohl Question') vim.eval('inputsave()') - bp.cond = vim.eval('input("New Condition: ", "%s")' % old_cond) + bp.cond = vim.eval('input("New Condition: ", "{}")'.format(old_cond)) vim.eval('inputrestore()') vim.command('echohl None') @@ -163,7 +170,7 @@ def list_breakpoints(): update_breakpoints() vim.command('echomsg "Listing all pudb breakpoints:"') for bp_string in breakpoint_strings(): - vim.command('echomsg "%s"' % bp_string) + vim.command('echomsg "{}"'.format(bp_string)) def populate_list(list_command): @@ -173,7 +180,10 @@ def populate_list(list_command): """ update_breakpoints() bps = list(breakpoint_strings()) - vim.command('%s %s' % (list_command, bps)) + vim.command('{command} {breakpoints}'.format( + command=list_command, + breakpoints=bps, + )) def quickfix_list_arg(): From 8aacebdb4b7254e9e3c37d7e68b6f7389cf9052b Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 9 Jan 2022 15:19:32 -0600 Subject: [PATCH 52/55] Clear old autocmds before redefining --- plugin/pudb.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 542a0ef..6f2008d 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -63,7 +63,9 @@ endif augroup pudb - " Also update when the file is first read. + autocmd! + + " Update when the file is first read. autocmd BufReadPost *.py PudbUpdate " Force a linecache update after writes so the breakpoints can be parsed From f929ec0f4bb76894be493d209a373eab327c7b44 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Sun, 20 Mar 2022 23:03:16 -0600 Subject: [PATCH 53/55] Handle missing pudb installation more gracefully --- plugin/pudb.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 6f2008d..8ee5c86 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -36,7 +36,12 @@ call sign_define('PudbBreakPoint', { "" " Everything is defined in a python module on the runtimepath! "" -pyx import pudb_and_jam +try + pyx import pudb_and_jam +catch + echoerr 'vim-pudb-and-jam requires pudb to be installed' + finish +endtry "" " Define ex commands for all the above functions so they are user-accessible. From 027dfb235e213b5b266016a4652d3d0714df5272 Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Tue, 28 Jun 2022 10:35:07 -0700 Subject: [PATCH 54/55] Ignore the doc/tags file --- .gitignore | 1 + doc/tags | 22 ---------------------- 2 files changed, 1 insertion(+), 22 deletions(-) delete mode 100644 doc/tags diff --git a/.gitignore b/.gitignore index 436e46b..769fa1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ tags *.sw[op] __pycache__ +doc/tags diff --git a/doc/tags b/doc/tags deleted file mode 100644 index 8bae5ed..0000000 --- a/doc/tags +++ /dev/null @@ -1,22 +0,0 @@ -vim-pudb vim-pudb-and-jam.txt /*vim-pudb* -vim-pudb-:PudbClearAll vim-pudb-and-jam.txt /*vim-pudb-:PudbClearAll* -vim-pudb-:PudbEdit vim-pudb-and-jam.txt /*vim-pudb-:PudbEdit* -vim-pudb-:PudbList vim-pudb-and-jam.txt /*vim-pudb-:PudbList* -vim-pudb-:PudbLocList vim-pudb-and-jam.txt /*vim-pudb-:PudbLocList* -vim-pudb-:PudbPopulateList vim-pudb-and-jam.txt /*vim-pudb-:PudbPopulateList* -vim-pudb-:PudbQfList vim-pudb-and-jam.txt /*vim-pudb-:PudbQfList* -vim-pudb-:PudbToggle vim-pudb-and-jam.txt /*vim-pudb-:PudbToggle* -vim-pudb-:PudbUpdate vim-pudb-and-jam.txt /*vim-pudb-:PudbUpdate* -vim-pudb-and-jam vim-pudb-and-jam.txt /*vim-pudb-and-jam* -vim-pudb-and-jam.txt vim-pudb-and-jam.txt /*vim-pudb-and-jam.txt* -vim-pudb-commands vim-pudb-and-jam.txt /*vim-pudb-commands* -vim-pudb-configuration vim-pudb-and-jam.txt /*vim-pudb-configuration* -vim-pudb-contents vim-pudb-and-jam.txt /*vim-pudb-contents* -vim-pudb-highlight vim-pudb-and-jam.txt /*vim-pudb-highlight* -vim-pudb-installation vim-pudb-and-jam.txt /*vim-pudb-installation* -vim-pudb-introduction vim-pudb-and-jam.txt /*vim-pudb-introduction* -vim-pudb-known-problems vim-pudb-and-jam.txt /*vim-pudb-known-problems* -vim-pudb-priority vim-pudb-and-jam.txt /*vim-pudb-priority* -vim-pudb-requirements vim-pudb-and-jam.txt /*vim-pudb-requirements* -vim-pudb-sign vim-pudb-and-jam.txt /*vim-pudb-sign* -vim-pudb-sign-group vim-pudb-and-jam.txt /*vim-pudb-sign-group* From 11faaa03469748c3d2f4c20744c2d4020012c32a Mon Sep 17 00:00:00 2001 From: Michael van der Kamp Date: Tue, 28 Jun 2022 11:25:59 -0700 Subject: [PATCH 55/55] Fail more gracefully if pudb not available --- plugin/pudb.vim | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/plugin/pudb.vim b/plugin/pudb.vim index 8ee5c86..7d0956a 100644 --- a/plugin/pudb.vim +++ b/plugin/pudb.vim @@ -8,13 +8,19 @@ if exists('g:loaded_pudb_plugin') || &compatible endif let g:loaded_pudb_plugin = 1 +function! s:EchoError(msg) abort + echohl Error + echo a:msg + echohl None +endfunction + if !has('pythonx') - echoerr 'vim-pudb requires vim compiled with +python and/or +python3' + call s:EchoError('vim-pudb requires vim compiled with +python and/or +python3') finish endif if !has('signs') - echoerr 'vim-pudb requires vim compiled with +signs' + call s:EchoError('vim-pudb requires vim compiled with +signs') finish endif @@ -39,10 +45,14 @@ call sign_define('PudbBreakPoint', { try pyx import pudb_and_jam catch - echoerr 'vim-pudb-and-jam requires pudb to be installed' - finish + let s:import_failed = v:true endtry +if get(s:, 'import_failed', v:false) + call s:EchoError('vim-pudb-and-jam requires pudb to be installed') + finish +endif + "" " Define ex commands for all the above functions so they are user-accessible. ""