import re from method import Method import mode _error_regexes = [ r'at (?P\S+) line (?P\d+)\.?$', #perl r'File "(?P.+?)", line (?P\d+)(?:, in \S+)?$', #python r'^(?P\S+?):(?P\d+): ', #javac/gcc r'at \S+\((?P.+?):(?P\d+)\)$', #java ] 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] path, line = m.group('file'), int(m.group('line')) if path == '-': path = w.buffer.orig_path b2 = a.open_path(path) a.switch_buffer(b2) a.methods['goto-line'].execute(b2.windows[0], lineno=line) w.set_error(errline) class Error(mode.Fundamental): name = 'Error' actions = [ErrorGotoLine] def __init__(self, w): mode.Fundamental.__init__(self, w) self.add_bindings('error-goto-line', ('C-c M-g',)) install = Error.install