tab completion in pdb
I make frequent use of the python's built-in debugger, which I think is brilliant in its simplicity. However an important feature seems to be missing: bash-like tab completion similar to that provided by the rlcompleter module. By default, Pdb and other instances of Cmd complete names for commands only. However in the context of pdb, I think it is more useful to complete identifiers and keywords in its current scope than to complete names of commands (most of which have single letter abbreviations). I believe this makes pdb a far more usable introspection tool. Implementation: I've attached a patch to pdb.py (on Python 2.4.4c1). The only real difference to rlcompleter's default complete method is that because pdb changes scope as you step through a program, rlcompleter's namespace is updated to reflect the current local and global namespace. This is my first attempt at a python patch. Any suggestions or improvements are welcome. Stephen Emslie
On Fri, Jan 19, 2007, stephen emslie wrote:
I've attached a patch to pdb.py (on Python 2.4.4c1). The only real difference to rlcompleter's default complete method is that because pdb changes scope as you step through a program, rlcompleter's namespace is updated to reflect the current local and global namespace.
This is my first attempt at a python patch. Any suggestions or improvements are welcome.
Please go ahead and upload this patch to SourceForge to make sure it doesn't get lost. Thanks! -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ Help a hearing-impaired person: http://rule6.info/hearing.html
Thanks for taking a look. I've created a patch relative to pdb.py in svn and
submitted it to sourceforge here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1641544&group_id=5470&atid=305470
On 1/19/07, Aahz
On Fri, Jan 19, 2007, stephen emslie wrote:
I've attached a patch to pdb.py (on Python 2.4.4c1). The only real difference to rlcompleter's default complete method is that because pdb changes scope as you step through a program, rlcompleter's namespace is updated to reflect the current local and global namespace.
This is my first attempt at a python patch. Any suggestions or
improvements
are welcome.
Please go ahead and upload this patch to SourceForge to make sure it doesn't get lost. Thanks! -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
Help a hearing-impaired person: http://rule6.info/hearing.html
There has been some discussion about this off-list. Most of the
discussion has centered around what appropriate tab completion should
be in different cases (what should be offered in the completion
namespace and when).
pydb has been dealt with a number of these issues already (thanks
Rocky Bernstein).
I would like to continue the discussion here. Here's a quick summary:
- when a line is blank, pdb commands and valid identifiers and
keywords should be included in the namespace.
- if a line does not start with a pdb command, then it is a python
expression and can be completed by rlcompleter, with all valid
identifiers and keywords available in the namespace.
- if a line does start with a pdb command then we should decide on
the best way to complete each pdb command.
for example:
" "[complete] -> all possible commands, identifiers and keywords
"b"[complete] -> "basestring bool break buffer"
"basestring."[complete] -> "basestring.__base__
basestring.__delattr__ ... etc."
"break "[complete] -> whatever the pdb completer will offer
currently, the submitted patch only attempts to complete python
expressions with rlcompleter. I think it would be useful (and more
honest, as Rocky puts it) to offer completion for pdb commands as
well. Apart from general comments, what would be great are suggestions
on what sort of completion should follow the various pdb commands.
Stephen Emslie
On 1/22/07, stephen emslie
Thanks for taking a look. I've created a patch relative to pdb.py in svn and submitted it to sourceforge here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1641544&group_id=5470&atid=305470
On 1/19/07, Aahz < aahz@pythoncraft.com> wrote:
On Fri, Jan 19, 2007, stephen emslie wrote:
I've attached a patch to pdb.py (on Python 2.4.4c1). The only real difference to rlcompleter's default complete method is that because pdb changes scope as you step through a program, rlcompleter's namespace is updated to reflect the current local and global namespace.
This is my first attempt at a python patch. Any suggestions or improvements are welcome.
Please go ahead and upload this patch to SourceForge to make sure it doesn't get lost. Thanks! -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
Help a hearing-impaired person: http://rule6.info/hearing.html
I think its worth forwarding a cautionary snippet from Rocky that
makes a lot of sense:
On 2/4/07, R. Bernstein
The caveat though in all of these cases is that it can be difficult to get exactly what the valid completions are. For example if you know you need an number, do you really want to complete on all objects that are a numeric type plus the digits 0-9, "+", "-", and "("? And also throw in functions which return a number? So in general, I think one has to back off a bit. And there are two ways to back off: one is allowing more possible completions (e.g. any object) and another by allowing less. I've been offering less. But I think really it's dictated by what "feels" right which will no doubt be different for different people. "Feeling right" could also be determined by how long completion takes is which may vary in different situations on different computers.
Handling command completion feels more like engineering than art or science.
participants (2)
-
Aahz
-
stephen emslie