Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 453f768

Browse files
committed
Longlist display code with syntax-highlighted. Close #4093
1 parent 44705ad commit 453f768

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

IPython/core/debugger.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import bdb
3030
import functools
31+
import inspect
3132
import linecache
3233
import sys
3334

@@ -513,6 +514,28 @@ def do_list(self, arg):
513514

514515
do_l = do_list
515516

517+
def getsourcelines(self, obj):
518+
lines, lineno = inspect.findsource(obj)
519+
if inspect.isframe(obj) and obj.f_globals is obj.f_locals:
520+
# must be a module frame: do not try to cut a block out of it
521+
return lines, 1
522+
elif inspect.ismodule(obj):
523+
return lines, 1
524+
return inspect.getblock(lines[lineno:]), lineno+1
525+
526+
def do_longlist(self, arg):
527+
self.lastcmd = 'longlist'
528+
filename = self.curframe.f_code.co_filename
529+
breaklist = self.get_file_breaks(filename)
530+
try:
531+
lines, lineno = self.getsourcelines(self.curframe)
532+
except OSError as err:
533+
self.error(err)
534+
return
535+
last = lineno + len(lines)
536+
self.print_list_lines(self.curframe.f_code.co_filename, lineno, last)
537+
do_ll = do_longlist
538+
516539
def do_pdef(self, arg):
517540
"""Print the call signature for any callable object.
518541

0 commit comments

Comments
 (0)