pmacs3/mode/latex.py

60 lines
2.3 KiB
Python
Raw Normal View History

2008-04-01 19:14:58 -04:00
import color, mode
from lex import Grammar, PatternRule, RegionRule
from method import Method, CommentRegion, UncommentRegion
class LatexGrammar(Grammar):
rules = [
PatternRule(r'comment', r'\%.*$'),
PatternRule(r'latex_control', r'\\[a-zA-Z]+'),
RegionRule(r'latex_argument', r'{', None, r'}'),
2008-04-01 22:58:07 -04:00
RegionRule(r'latex_string', r"`", None, r"'"),
2008-04-01 19:14:58 -04:00
RegionRule(r'latex_string', r"``", None, r"''"),
PatternRule(r'latex_escaped', r'\\.'),
PatternRule(r'latex_special', r'[{}$^_%~#&]'),
]
class Latex(mode.Fundamental):
modename = 'Latex'
extensions = ['.latex', '.tex']
grammar = LatexGrammar
colors = {
'latex_control': ('blue', 'default', 'bold'),
'latex_argument.null': ('cyan', 'default', 'bold'),
'latex_string.start': ('green', 'default', 'bold'),
'latex_string.null': ('green', 'default', 'bold'),
'latex_string.end': ('green', 'default', 'bold'),
'latex_escaped': ('magenta', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('wrap-paragraph', ('M-q',))
self.add_action_and_bindings(LatexCommentRegion(), ('C-c #', "C-c \%"))
self.add_action_and_bindings(LatexUncommentRegion(), ('C-u C-c #', "C-u C-c \%"))
self.add_action_and_bindings(LatexInsertSquotes(), ("M-'",))
self.add_action_and_bindings(LatexInsertDquotes(), ('M-"',))
self.add_action_and_bindings(LatexInsertBraces(), ('M-{',))
class LatexCommentRegion(CommentRegion):
commentc = '%'
class LatexUncommentRegion(UncommentRegion):
commentc = '%'
class LatexInsertSquotes(Method):
'''Insert a pair of LaTeX-style single-quotes into the buffer'''
def _execute(self, w, **vargs):
w.insert_string_at_cursor("`'")
w.backward()
class LatexInsertDquotes(Method):
'''Insert a pair of LaTeX-style double-quotes into the buffer'''
def _execute(self, w, **vargs):
w.insert_string_at_cursor("``''")
w.backward()
w.backward()
class LatexInsertBraces(Method):
'''Insert a pair of curly braces into the buffer'''
def _execute(self, w, **vargs):
w.insert_string_at_cursor("{}")
w.backward()
install = Latex.install