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

Skip to content

Commit ba23bed

Browse files
committed
Tweak the goto file/line command (in the right button menu in PyShell
and output windows) so that it if it doesn't succeed with the line at the cursor, it tries the line before that. This is handy with tracebacks, where my natural tendency is to click in the displayed source line rather than in the file/line indicator just above it. Now I can indulge this tendency. I factored out a helper and changed the error handling so that a non-existing file is treated as if the line didn't match -- this is handy because some function calls (e.g. "foo.bar(1)") match the grep pattern.
1 parent 9611e0b commit ba23bed

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

Tools/idle/OutputWindow.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,41 @@ def goto_file_line(self, event=None):
6767
# x, y = self.event.x, self.event.y
6868
# self.text.mark_set("insert", "@%d,%d" % (x, y))
6969
line = self.text.get("insert linestart", "insert lineend")
70+
result = self._file_line_helper(line)
71+
if not result:
72+
# Try the previous line. This is handy e.g. in tracebacks,
73+
# where you tend to right-click on the displayed source line
74+
line = self.text.get("insert -1line linestart",
75+
"insert -1line lineend")
76+
result = self._file_line_helper(line)
77+
if not result:
78+
tkMessageBox.showerror(
79+
"No special line",
80+
"The line you point at doesn't look like "
81+
"a valid file name followed by a line number.",
82+
master=self.text)
83+
return
84+
filename, lineno = result
85+
edit = self.flist.open(filename)
86+
edit.gotoline(lineno)
87+
88+
def _file_line_helper(self, line):
7089
for prog in self.file_line_progs:
7190
m = prog.search(line)
7291
if m:
7392
break
7493
else:
75-
tkMessageBox.showerror("No special line",
76-
"The line you point at doesn't look like "
77-
"a file name followed by a line number.",
78-
master=self.text)
79-
return
94+
return None
8095
filename, lineno = m.group(1, 2)
8196
try:
8297
f = open(filename, "r")
8398
f.close()
84-
except IOError, msg:
85-
self.text.bell()
86-
return
87-
edit = self.flist.open(filename)
99+
except IOError:
100+
return None
88101
try:
89-
lineno = int(lineno)
90-
except ValueError, msg:
91-
self.text.bell()
92-
return
93-
edit.gotoline(lineno)
102+
return filename, int(lineno)
103+
except TypeError:
104+
return None
94105

95106
# These classes are currently not used but might come in handy
96107

0 commit comments

Comments
 (0)