import color, method, mode, lex, lex_diff, re class Diff(mode.Fundamental): def __init__(self, w): mode.Fundamental.__init__(self, w) self.grammar = lex_diff.DiffGrammar() self.lexer = lex.Lexer(self.grammar) self.add_action_and_bindings(DiffNextSection(), ('M-n', 'M-D_ARROW',)) self.add_action_and_bindings(DiffPreviousSection(), ('M-p', 'M-U_ARROW',)) self.colors = { 'left': color.build('red', 'default', 'bold'), 'right': color.build('blue', 'default', 'bold'), 'seperator': color.build('magenta', 'default', 'bold'), 'cvs metadata': color.build('magenta', 'default', 'bold'), 'svn metadata': color.build('magenta', 'default', 'bold'), 'location': color.build('magenta', 'default', 'bold'), } def name(self): return "Diff" class DiffNextSection(method.Method): re = re.compile("(?:^|(?<=\n))@@ [-+0-9a-z, ]* @@(?:$|\n)") def _execute(self, w, **vargs): cursor = w.logical_cursor() i = cursor.y + 1 while i < len(w.buffer.lines): if self.re.match(w.buffer.lines[i]): w.goto_line(i) return i += 1 class DiffPreviousSection(method.Method): re = re.compile("(?:^|(?<=\n))@@ [-+0-9a-z, ]* @@(?:$|\n)") def _execute(self, w, **vargs): cursor = w.logical_cursor() i = cursor.y - 1 while i >= 0: if self.re.match(w.buffer.lines[i]): w.goto_line(i) return i -= 1