pmacs3/mode/mutt.py

51 lines
2.1 KiB
Python
Raw Normal View History

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 = [
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_]+'),
]
2007-10-21 20:55:29 -04:00
class Mutt(mode.Fundamental):
2007-10-18 17:07:35 -04:00
modename = 'Mutt'
grammar = MuttGrammar()
colors = {
'mutt_header': ('green', 'default', 'bold'),
2007-07-21 11:40:53 -04:00
'email': ('cyan', 'default', 'bold'),
'url': ('cyan', 'default', 'bold'),
'quotea': ('yellow', 'default', 'bold'),
'quoteb': ('cyan', 'default', 'bold'),
'quotec': ('magenta', 'default', 'bold'),
'misspelled': ('red', 'default'),
'cont.start': ('default', 'default'),
'cont.end': ('default', 'default'),
'word': ('default', 'default'),
'punct': ('default', 'default'),
'stuff': ('default', 'default'),
}
def __init__(self, w):
2007-10-21 20:55:29 -04:00
mode.Fundamental.__init__(self, w)
2007-07-21 11:40:53 -04: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',))
class MuttWrapParagraph(method.WrapParagraph2):
limit = 72
empty_re = re.compile('^(?: *>.*| *)$')
2007-07-21 11:40:53 -04:00
class MuttInsertSpace(mode.text.TextInsertSpace):
wrapper = MuttWrapParagraph
2007-10-19 02:41:33 -04:00
install = Mutt.install