2007-09-11 12:06:12 -04:00
|
|
|
import re
|
2007-10-21 20:55:29 -04:00
|
|
|
import color, mode, method
|
2007-07-21 11:40:53 -04:00
|
|
|
import mode.text
|
2007-10-21 20:52:48 -04:00
|
|
|
from lex import Grammar, PatternRule
|
2007-07-21 11:40:53 -04:00
|
|
|
|
|
|
|
class MuttGrammar(Grammar):
|
|
|
|
rules = [
|
2008-03-16 01:23:14 -04:00
|
|
|
PatternRule(name=r'mutt_header', pattern=r'^(?:From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To|Delivered-To|Date):'),
|
2007-07-21 11:40:53 -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}.*$'),
|
|
|
|
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_]+'),
|
|
|
|
]
|
|
|
|
|
2008-04-18 23:32:08 -04:00
|
|
|
class MuttWrapParagraph(method.WrapParagraph):
|
|
|
|
limit = 72
|
|
|
|
empty_re = re.compile('^(?: *>.*| *)$')
|
|
|
|
class MuttInsertSpace(mode.text.TextInsertSpace):
|
|
|
|
wrapper = MuttWrapParagraph
|
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class Mutt(mode.Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'Mutt'
|
|
|
|
grammar = MuttGrammar()
|
|
|
|
colors = {
|
2008-05-03 13:31:30 -04:00
|
|
|
'mutt_header': ('green', 'default', 'bold'),
|
|
|
|
'email': ('cyan', 'default', 'bold'),
|
|
|
|
'url': ('cyan', 'default', 'bold'),
|
|
|
|
'quotea': ('yellow', 'default', 'bold'),
|
|
|
|
'quoteb': ('cyan', 'default', 'bold'),
|
|
|
|
'quotec': ('magenta', 'default', 'bold'),
|
|
|
|
'misspelled': ('red', 'default', 'bold'),
|
|
|
|
'cont.start': ('default', 'default', 'bold'),
|
|
|
|
'cont.end': ('default', 'default', 'bold'),
|
|
|
|
'word': ('default', 'default', 'bold'),
|
|
|
|
'punct': ('default', 'default', 'bold'),
|
|
|
|
'stuff': ('default', 'default', 'bold'),
|
2007-07-21 11:40:53 -04:00
|
|
|
}
|
2008-04-19 20:25:17 -04:00
|
|
|
actions = [MuttInsertSpace, MuttWrapParagraph]
|
2008-11-24 13:49:41 -05:00
|
|
|
config = {
|
|
|
|
'mutt.margin': 72,
|
|
|
|
}
|
2007-07-21 11:40:53 -04:00
|
|
|
def __init__(self, w):
|
2007-10-21 20:55:29 -04:00
|
|
|
mode.Fundamental.__init__(self, w)
|
2008-04-18 23:32:08 -04:00
|
|
|
self.add_bindings('learn-word', ('C-c l',))
|
|
|
|
self.add_bindings('mutt-wrap-paragraph', ('M-q',))
|
|
|
|
self.add_bindings('mutt-insert-space', ('SPACE',))
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Mutt.install
|