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.
This commit is contained in:
parent
9611e0b462
commit
ba23bed340
|
@ -67,30 +67,41 @@ class OutputWindow(EditorWindow):
|
||||||
# x, y = self.event.x, self.event.y
|
# x, y = self.event.x, self.event.y
|
||||||
# self.text.mark_set("insert", "@%d,%d" % (x, y))
|
# self.text.mark_set("insert", "@%d,%d" % (x, y))
|
||||||
line = self.text.get("insert linestart", "insert lineend")
|
line = self.text.get("insert linestart", "insert lineend")
|
||||||
|
result = self._file_line_helper(line)
|
||||||
|
if not result:
|
||||||
|
# Try the previous line. This is handy e.g. in tracebacks,
|
||||||
|
# where you tend to right-click on the displayed source line
|
||||||
|
line = self.text.get("insert -1line linestart",
|
||||||
|
"insert -1line lineend")
|
||||||
|
result = self._file_line_helper(line)
|
||||||
|
if not result:
|
||||||
|
tkMessageBox.showerror(
|
||||||
|
"No special line",
|
||||||
|
"The line you point at doesn't look like "
|
||||||
|
"a valid file name followed by a line number.",
|
||||||
|
master=self.text)
|
||||||
|
return
|
||||||
|
filename, lineno = result
|
||||||
|
edit = self.flist.open(filename)
|
||||||
|
edit.gotoline(lineno)
|
||||||
|
|
||||||
|
def _file_line_helper(self, line):
|
||||||
for prog in self.file_line_progs:
|
for prog in self.file_line_progs:
|
||||||
m = prog.search(line)
|
m = prog.search(line)
|
||||||
if m:
|
if m:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
tkMessageBox.showerror("No special line",
|
return None
|
||||||
"The line you point at doesn't look like "
|
|
||||||
"a file name followed by a line number.",
|
|
||||||
master=self.text)
|
|
||||||
return
|
|
||||||
filename, lineno = m.group(1, 2)
|
filename, lineno = m.group(1, 2)
|
||||||
try:
|
try:
|
||||||
f = open(filename, "r")
|
f = open(filename, "r")
|
||||||
f.close()
|
f.close()
|
||||||
except IOError, msg:
|
except IOError:
|
||||||
self.text.bell()
|
return None
|
||||||
return
|
|
||||||
edit = self.flist.open(filename)
|
|
||||||
try:
|
try:
|
||||||
lineno = int(lineno)
|
return filename, int(lineno)
|
||||||
except ValueError, msg:
|
except TypeError:
|
||||||
self.text.bell()
|
return None
|
||||||
return
|
|
||||||
edit.gotoline(lineno)
|
|
||||||
|
|
||||||
# These classes are currently not used but might come in handy
|
# These classes are currently not used but might come in handy
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue