2007-06-24 00:44:09 -04:00
|
|
|
import color, method, mode2, re
|
2007-07-15 09:44:20 -04:00
|
|
|
from lex3 import Grammar, PatternRule, RegionRule
|
2007-03-06 10:05:38 -05:00
|
|
|
|
2007-06-24 00:44:09 -04:00
|
|
|
class DiffGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(name=r'left', pattern=r"^\-.*$"),
|
|
|
|
PatternRule(name=r'right', pattern=r"^\+.*$"),
|
|
|
|
PatternRule(name=r'metadata', pattern=r'^[A-Za-z].*$'),
|
|
|
|
PatternRule(name=r'seperator', pattern=r'^={67}$'),
|
|
|
|
PatternRule(name=r'location', pattern=r"(?:^|(?<=\n))@@ [-+0-9a-z, ]* @@(?:$|\n)"),
|
|
|
|
PatternRule(name=r'common', pattern=r"(?:^|(?<=\n)).*(?:$|\n)"),
|
|
|
|
]
|
2007-03-06 10:05:38 -05:00
|
|
|
|
2007-06-24 00:44:09 -04:00
|
|
|
class Diff(mode2.Fundamental):
|
|
|
|
grammar = DiffGrammar()
|
|
|
|
def __init__(self, w):
|
|
|
|
mode2.Fundamental.__init__(self, w)
|
|
|
|
#self.add_action_and_bindings(DiffNextSection(), ('M-n', 'M-D_ARROW',))
|
|
|
|
#self.add_action_and_bindings(DiffPreviousSection(), ('M-p', 'M-U_ARROW',))
|
2007-03-06 10:05:38 -05:00
|
|
|
self.colors = {
|
|
|
|
'left': color.build('red', 'default', 'bold'),
|
|
|
|
'right': color.build('blue', 'default', 'bold'),
|
|
|
|
'seperator': color.build('magenta', 'default', 'bold'),
|
2007-06-24 00:44:09 -04:00
|
|
|
'metadata': color.build('magenta', 'default', 'bold'),
|
2007-03-06 10:05:38 -05:00
|
|
|
'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
|