2007-07-21 11:40:53 -04:00
|
|
|
import color, method, mode2, re
|
|
|
|
from lex3 import Grammar, PatternRule, RegionRule
|
|
|
|
|
|
|
|
class DiffGrammar(Grammar):
|
|
|
|
rules = [
|
2007-09-28 16:55:57 -04:00
|
|
|
PatternRule(name=r'left', pattern=r"^\-.*\n$"),
|
|
|
|
PatternRule(name=r'right', pattern=r"^\+.*\n$"),
|
|
|
|
PatternRule(name=r'metadata', pattern=r'^[A-Za-z].*\n$'),
|
|
|
|
PatternRule(name=r'seperator', pattern=r'^={67}\n$'),
|
|
|
|
PatternRule(name=r'location', pattern=r"^@@ [-+0-9a-z, ]* @@\n$"),
|
|
|
|
PatternRule(name=r'common', pattern=r"^.*\n$"),
|
2007-07-21 11:40:53 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
class Diff(mode2.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'diff'
|
2007-07-21 11:40:53 -04:00
|
|
|
grammar = DiffGrammar()
|
|
|
|
colors = {
|
|
|
|
'left': ('red', 'default', 'bold'),
|
|
|
|
'right': ('blue', 'default', 'bold'),
|
|
|
|
'seperator': ('magenta', 'default', 'bold'),
|
|
|
|
'metadata': ('magenta', 'default', 'bold'),
|
|
|
|
'location': ('magenta', 'default', 'bold'),
|
|
|
|
}
|
|
|
|
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',))
|
|
|
|
|
|
|
|
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
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Diff.install
|