pmacs3/mode/mutt.py

58 lines
2.1 KiB
Python

import re
from mode import Fundamental
from method import WrapParagraph
from mode.text import ContinuedRule, WordRule, TextInsertSpace
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
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_]+'),
]
class HeaderGrammar(Grammar): rules = [PatternRule('header', '^.+:')] + rules
class BodyGrammar(Grammar): rules = rules
class MuttGrammar(Grammar):
rules = [RegionRule('mutt', '^', HeaderGrammar, '^\n$', BodyGrammar, '')]
class MuttWrapParagraph(WrapParagraph):
limit = 72
empty_re = re.compile('^(?: *>.*| *)$')
class MuttInsertSpace(TextInsertSpace):
wrapper = MuttWrapParagraph
class Mutt(Fundamental):
name = 'Mutt'
grammar = MuttGrammar()
colors = {
'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'),
}
actions = [MuttInsertSpace, MuttWrapParagraph]
config = {
'mutt.margin': 72,
}
_bindings = {
'learn-word': ('C-c l',),
'mutt-wrap-paragraph': ('M-q',),
'mutt-insert-space': ('SPACE',),
}
install = Mutt.install