2007-09-11 12:06:12 -04:00
|
|
|
import re
|
2009-04-08 10:57:25 -04:00
|
|
|
from mode import Fundamental
|
|
|
|
from method import WrapParagraph
|
|
|
|
from mode.text import ContinuedRule, WordRule, TextInsertSpace
|
2009-05-03 19:47:27 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
|
2007-07-21 11:40:53 -04:00
|
|
|
|
2009-05-03 19:47:27 -04:00
|
|
|
rules = [
|
|
|
|
PatternRule('quotec', '^ *(?:(?: *>){3})*(?: *>){3}.*$'),
|
|
|
|
PatternRule('quoteb', '^ *(?:(?: *>){3})*(?: *>){2}.*$'),
|
|
|
|
PatternRule('quotea', '^ *(?:(?: *>){3})*(?: *>){1}.*$'),
|
|
|
|
PatternRule('email', r'(?:^|(?<=[ :]))<?[^<>@\n ]+@(?:[^<>@\.\n ]+\.)*[^<>@\.\n ]+>?'),
|
|
|
|
PatternRule('url', r'(?:^|(?<= ))(?:http|https|ftp|sftp|file|smtp|smtps|torrent|news|jabber|irc|telnet)://(?:[^\.\n ]+\.)*[^\.\n ]+'),
|
|
|
|
ContinuedRule(),
|
|
|
|
WordRule(),
|
|
|
|
PatternRule('punctuation', '[^a-zA-Z0-9_]'),
|
|
|
|
PatternRule('data', '[a-zA-Z0-9_]+'),
|
|
|
|
]
|
|
|
|
|
2009-06-09 23:59:19 -04:00
|
|
|
class HeaderGrammar(Grammar):
|
|
|
|
rules = [PatternRule('header', '^[^ ].*:')] + rules
|
2009-05-03 19:47:27 -04:00
|
|
|
class BodyGrammar(Grammar): rules = rules
|
|
|
|
class MuttGrammar(Grammar):
|
|
|
|
rules = [RegionRule('mutt', '^', HeaderGrammar, '^\n$', BodyGrammar, '')]
|
2007-07-21 11:40:53 -04:00
|
|
|
|
2009-04-08 10:57:25 -04:00
|
|
|
class MuttWrapParagraph(WrapParagraph):
|
2008-04-18 23:32:08 -04:00
|
|
|
limit = 72
|
|
|
|
empty_re = re.compile('^(?: *>.*| *)$')
|
2009-04-08 10:57:25 -04:00
|
|
|
class MuttInsertSpace(TextInsertSpace):
|
2008-04-18 23:32:08 -04:00
|
|
|
wrapper = MuttWrapParagraph
|
|
|
|
|
2009-04-08 10:57:25 -04:00
|
|
|
class Mutt(Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'Mutt'
|
|
|
|
grammar = MuttGrammar()
|
|
|
|
colors = {
|
2009-05-03 19:47:27 -04:00
|
|
|
'mutt.header': ('green', 'default', 'bold'),
|
|
|
|
'mutt.email': ('cyan', 'default', 'bold'),
|
|
|
|
'mutt.url': ('cyan', 'default', 'bold'),
|
|
|
|
'mutt.quotea': ('yellow', 'default', 'bold'),
|
|
|
|
'mutt.quoteb': ('cyan', 'default', 'bold'),
|
|
|
|
'mutt.quotec': ('magenta', 'default', 'bold'),
|
|
|
|
'mutt.misspelled': ('red', 'default', 'bold'),
|
|
|
|
'mutt.cont.start': ('default', 'default'),
|
|
|
|
'mutt.cont.end': ('default', 'default'),
|
|
|
|
'mutt.word': ('default', 'default'),
|
|
|
|
'mutt.punctuation': ('default', 'default'),
|
|
|
|
'mutt.data': ('default', 'default'),
|
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,
|
|
|
|
}
|
2009-03-30 23:15:27 -04:00
|
|
|
_bindings = {
|
|
|
|
'learn-word': ('C-c l',),
|
|
|
|
'mutt-wrap-paragraph': ('M-q',),
|
|
|
|
'mutt-insert-space': ('SPACE',),
|
|
|
|
}
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Mutt.install
|