2008-12-03 00:15:22 -05:00
|
|
|
import re
|
|
|
|
from method import Method
|
2009-03-30 01:10:25 -04:00
|
|
|
from mode import Fundamental
|
2008-12-03 00:15:22 -05:00
|
|
|
|
|
|
|
_error_regexes = [
|
2008-12-03 19:30:01 -05:00
|
|
|
r'at (?P<file>\S+) line (?P<line>\d+)\.?$', #perl
|
2008-12-03 00:15:22 -05:00
|
|
|
r'File "(?P<file>.+?)", line (?P<line>\d+)(?:, in \S+)?$', #python
|
|
|
|
r'^(?P<file>\S+?):(?P<line>\d+): ', #javac/gcc
|
|
|
|
r'at \S+\((?P<file>.+?):(?P<line>\d+)\)$', #java
|
2009-04-26 22:13:57 -04:00
|
|
|
r'^(?P<line>\d+):', #grep
|
2008-12-03 00:15:22 -05:00
|
|
|
]
|
|
|
|
error_regexes = [re.compile(s) for s in _error_regexes]
|
|
|
|
|
|
|
|
def find_next_error(w):
|
|
|
|
b = w.buffer
|
|
|
|
x, y = w.logical_cursor().xy()
|
|
|
|
while y < len(b.lines):
|
|
|
|
for regex in error_regexes:
|
|
|
|
m = regex.search(b.lines[y], x)
|
|
|
|
if m:
|
|
|
|
return (m, y)
|
|
|
|
x = 0
|
|
|
|
y += 1
|
|
|
|
return (None, None)
|
|
|
|
|
|
|
|
class ErrorGotoLine(Method):
|
|
|
|
'''Goto the line of the file indicated'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
a = w.application
|
|
|
|
(m, y) = find_next_error(w)
|
|
|
|
if m is None:
|
|
|
|
w.set_error("nothing found")
|
|
|
|
return
|
|
|
|
errline = w.buffer.lines[y]
|
2009-04-26 22:13:57 -04:00
|
|
|
|
|
|
|
d = m.groupdict()
|
|
|
|
path = d.get('file')
|
|
|
|
line = d.get('line')
|
|
|
|
if line is None:
|
|
|
|
return
|
|
|
|
elif path is None or path == '-':
|
2008-12-03 19:30:01 -05:00
|
|
|
path = w.buffer.orig_path
|
2008-12-03 00:15:22 -05:00
|
|
|
b2 = a.open_path(path)
|
|
|
|
a.switch_buffer(b2)
|
2009-04-26 22:13:57 -04:00
|
|
|
a.methods['goto-line'].execute(b2.windows[0], lineno=int(line))
|
2008-12-03 00:15:22 -05:00
|
|
|
w.set_error(errline)
|
|
|
|
|
2009-03-30 01:10:25 -04:00
|
|
|
class Error(Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'Error'
|
2008-12-03 00:15:22 -05:00
|
|
|
actions = [ErrorGotoLine]
|
|
|
|
def __init__(self, w):
|
2009-03-30 01:10:25 -04:00
|
|
|
Fundamental.__init__(self, w)
|
2009-03-27 21:39:32 -04:00
|
|
|
self.add_bindings('error-goto-line', ('RETURN', 'C-c M-g',))
|
2008-12-03 00:15:22 -05:00
|
|
|
|
|
|
|
install = Error.install
|