2007-06-23 22:49:13 -04:00
|
|
|
import color, mode2, method, mode_text
|
|
|
|
from lex2 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):'),
|
2007-07-13 08:30:47 -04:00
|
|
|
PatternRule(name=r'quoteb', pattern=r'^ *(?:(?: *>){3})*(?: *>){2}.*$'),
|
|
|
|
PatternRule(name=r'quotea', pattern=r'^ *(?:(?: *>){3})*(?: *>){1}.*$'),
|
|
|
|
PatternRule(name=r'quotec', pattern=r'^ *(?:(?: *>){3})*(?: *>){3}.*$'),
|
2007-06-23 22:49:13 -04:00
|
|
|
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()
|
2007-03-06 10:05:38 -05:00
|
|
|
def __init__(self, w):
|
2007-06-23 22:49:13 -04:00
|
|
|
mode2.Fundamental.__init__(self, w)
|
2007-03-06 10:05:38 -05:00
|
|
|
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 = {
|
2007-06-23 22:49:13 -04:00
|
|
|
'header': color.build('green', 'default', 'bold'),
|
|
|
|
'email': color.build('cyan', 'default', 'bold'),
|
|
|
|
'url': color.build('cyan', 'default', 'bold'),
|
2007-07-13 08:30:47 -04:00
|
|
|
'quotea': color.build('yellow', 'default', 'bold'),
|
|
|
|
'quoteb': color.build('cyan', 'default', 'bold'),
|
|
|
|
'quotec': color.build('magenta', 'default', 'bold'),
|
2007-06-23 22:49:13 -04:00
|
|
|
'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'),
|
2007-03-06 10:05:38 -05:00
|
|
|
}
|
|
|
|
def name(self):
|
|
|
|
return "Mutt"
|
|
|
|
|
|
|
|
class MuttWrapLine(method.WrapLine):
|
|
|
|
limit = 72
|
|
|
|
|
|
|
|
class MuttWrapParagraph(method.WrapParagraph):
|
|
|
|
wrapper = MuttWrapLine
|
|
|
|
|
|
|
|
class MuttInsertSpace(mode_text.TextInsertSpace):
|
2007-06-23 22:49:13 -04:00
|
|
|
limit = 72
|
2007-03-06 10:05:38 -05:00
|
|
|
wrapper = MuttWrapParagraph
|