From: Steffen Mueller Date: Sun, 31 May 2009 19:57:24 +0000 (+0200) Subject: Auto-complete lexicals in the debugger shell X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d22862789d0938361a070647ab6fe995d674f77c;p=p5sagit%2Fp5-mst-13.2.git Auto-complete lexicals in the debugger shell When typing the name of a lexical variable in the debugger shell, its name can now be tab auto-completed just like package variables. Requires PadWalker to be available. Silently skips lexicals if it's not. --- diff --git a/lib/perl5db.pl b/lib/perl5db.pl index 9162d16..b851212 100644 --- a/lib/perl5db.pl +++ b/lib/perl5db.pl @@ -8610,7 +8610,6 @@ If there's only one hit, and it's a package qualifier, and it's not equal to the =cut if ( $text =~ /^[\$@%]/ ) { # symbols (in $package + packages in main) - =pod =over 4 @@ -8634,6 +8633,32 @@ We set the prefix to the item's sigil, and trim off the sigil to get the text to $prefix = substr $text, 0, 1; $text = substr $text, 1; + my @out; + +=pod + +=item * + +We look for the lexical scope above DB::DB and auto-complete lexical variables +if PadWalker could be loaded. + +=cut + + if (not $text =~ /::/ and eval "require PadWalker; 1" and not $@ ) { + my $level = 1; + while (1) { + my @info = caller($level); + $level++; + $level = -1, last + if not @info; + last if $info[3] eq 'DB::DB'; + } + if ($level > 0) { + my $lexicals = PadWalker::peek_my($level); + push @out, grep /^\Q$prefix$text/, keys %$lexicals; + } + } + =pod =item * @@ -8642,7 +8667,7 @@ If the package is C<::> (C
), create an empty list; if it's something else, =cut - my @out = map "$prefix$_", grep /^\Q$text/, + push @out, map "$prefix$_", grep /^\Q$text/, ( grep /^_?[a-zA-Z]/, keys %$pack ), ( $pack eq '::' ? () : ( grep /::$/, keys %:: ) ); diff --git a/pod/perldebug.pod b/pod/perldebug.pod index 3ba73e8..a58e835 100644 --- a/pod/perldebug.pod +++ b/pod/perldebug.pod @@ -1066,9 +1066,9 @@ have full editing capabilities much like GNU I(3) provides. Look for these in the F directory on CPAN. These do not support normal B command-line editing, however. -A rudimentary command-line completion is also available. -Unfortunately, the names of lexical variables are not available for -completion. +A rudimentary command-line completion is also available, including +lexical variables in the current scope if the C module +is installed. Without Readline support you may see the symbols "^[[A", "^[[C", "^[[B", "^[[D"", "^H", ... when using the arrow keys and/or the backspace key.