import color, mode2, method, mode_text from lex3 import Grammar, PatternRule class MuttGrammar(Grammar): rules = [ PatternRule(name=r'header', pattern=r'^(?:From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To|Delivered-To|Date):'), PatternRule(name=r'quoteb', pattern=r'^ *(?:(?: *>){3})*(?: *>){2}.*$'), PatternRule(name=r'quotea', pattern=r'^ *(?:(?: *>){3})*(?: *>){1}.*$'), PatternRule(name=r'quotec', pattern=r'^ *(?:(?: *>){3})*(?: *>){3}.*$'), PatternRule(name=r'email', pattern=r'(?:^|(?<=[ :]))@\n ]+@(?:[^<>@\.\n ]+\.)*[^<>@\.\n ]+>?'), PatternRule(name=r'url', pattern=r'(?:^|(?<= ))(?:http|https|ftp|sftp|file|smtp|smtps|torrent|news|jabber|irc|telnet)://(?:[^\.\n ]+\.)*[^\.\n ]+'), mode_text.ContinuedRule(), mode_text.WordRule(), PatternRule(name=r'punct', pattern=r'[^a-zA-Z0-9_]'), PatternRule(name=r'stuff', pattern=r'[a-zA-Z0-9_]+'), ] class Mutt(mode2.Fundamental): grammar = MuttGrammar() def __init__(self, w): mode2.Fundamental.__init__(self, w) self.add_action_and_bindings(mode_text.LearnWord(), ('C-c l',)) self.add_action_and_bindings(MuttWrapParagraph(), ('M-q',)) self.add_action_and_bindings(MuttInsertSpace(), ('SPACE',)) self.colors = { 'header': color.build('green', 'default', 'bold'), 'email': color.build('cyan', 'default', 'bold'), 'url': color.build('cyan', 'default', 'bold'), 'quotea': color.build('yellow', 'default', 'bold'), 'quoteb': color.build('cyan', 'default', 'bold'), 'quotec': color.build('magenta', 'default', 'bold'), 'misspelled': color.build('red', 'default'), 'cont.start': color.build('default', 'default'), 'cont.end': color.build('default', 'default'), 'word': color.build('default', 'default'), 'punct': color.build('default', 'default'), 'stuff': color.build('default', 'default'), } def name(self): return "Mutt" class MuttWrapLine(method.WrapLine): limit = 72 class MuttWrapParagraph(method.WrapParagraph): wrapper = MuttWrapLine class MuttInsertSpace(mode_text.TextInsertSpace): limit = 72 wrapper = MuttWrapParagraph