latex mode

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-04-01 23:14:58 +00:00
parent d2fca5279c
commit c8768bf7cb
6 changed files with 74 additions and 7 deletions

View File

@ -113,7 +113,7 @@ class Application(object):
'dir', 'elisp', 'hex', 'html', 'java', 'javascript', 'lisp',
'make', 'mini', 'mutt', 'nasm', 'ocaml', 'perl', 'python',
'replace', 'rst', 'scheme', 'search', 'sh', 'sql', 'tt',
'text', 'text2', 'which', 'xml', 'cheetah', 'colortext')
'text', 'text2', 'which', 'xml', 'cheetah', 'colortext', 'latex')
for name in names:
exec("import mode.%s; mode.%s.install(self)" % (name, name))

View File

@ -611,7 +611,7 @@ class PathListBuffer(DirBuffer):
btype = 'pathlist'
def __init__(self, name, paths, nl='\n'):
Buffer.__init__(self, nl)
self.paths = paths
self.paths = list(paths)
self.path = os.getcwd()
self._name = name
def path_exists(self):

7
lex.py
View File

@ -181,7 +181,7 @@ class RegionRule(Rule):
while len(args) > 1:
grammar = args.pop(0)
pattern = args.pop(0)
assert hasattr(grammar, 'rules'), repr(grammar)
#assert hasattr(grammar, 'rules'), repr(grammar)
assert type(pattern) == type(''), repr(pattern)
self.pairs.append((grammar, pattern))
if len(args) == 1:
@ -238,7 +238,12 @@ class RegionRule(Rule):
del lexer.mode.gstack[fqname]
else:
mode = lexer.mode
# XYZ
#grammar = self.pairs[i][0]
if self.pairs[i][0] is not None:
grammar = self.pairs[i][0]
else:
grammar = lexer.grammar
lexer.mstack.append(mode)
if self.pairs[i][1]:

View File

@ -453,6 +453,7 @@ class GetIndentionLevel(Method):
# commenting
class CommentRegion(Method):
'''Prepend a comment to every line in the current buffer'''
commentc = '#'
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
if cursor < w.mark:
@ -465,9 +466,10 @@ class CommentRegion(Method):
w.input_line = "Empty kill region"
return
for y in range(p1.y, p2.y):
w.buffer.insert_string(Point(0, y), "#")
w.buffer.insert_string(Point(0, y), self.commentc)
class UncommentRegion(Method):
'''Remove a comment from every line in the current buffer'''
commentc = '#'
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
if cursor < w.mark:
@ -480,7 +482,7 @@ class UncommentRegion(Method):
w.input_line = "Empty kill region"
return
for y in range(p1.y, p2.y):
if w.buffer.lines[y].startswith("#"):
if w.buffer.lines[y].startswith(self.commentc):
w.buffer.delete(Point(0, y), Point(1, y))
# wrapping/justifying/etc

View File

@ -95,7 +95,7 @@ class DirGrep(Method):
def _execute(self, w, **vargs):
cmd = 'grep -rEl %r %r' % (vargs['pattern'], w.buffer.path)
(status, output) = commands.getstatusoutput(cmd)
paths = output.split('\n')
paths = [x for x in output.split('\n') if x]
bufname = '*%s*' % self.name.title()
b = buffer.PathListBuffer(bufname, paths)
b.modename = 'dir'

60
mode/latex.py Normal file
View File

@ -0,0 +1,60 @@
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'}'),
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