parent
d2fca5279c
commit
c8768bf7cb
|
@ -113,7 +113,7 @@ class Application(object):
|
||||||
'dir', 'elisp', 'hex', 'html', 'java', 'javascript', 'lisp',
|
'dir', 'elisp', 'hex', 'html', 'java', 'javascript', 'lisp',
|
||||||
'make', 'mini', 'mutt', 'nasm', 'ocaml', 'perl', 'python',
|
'make', 'mini', 'mutt', 'nasm', 'ocaml', 'perl', 'python',
|
||||||
'replace', 'rst', 'scheme', 'search', 'sh', 'sql', 'tt',
|
'replace', 'rst', 'scheme', 'search', 'sh', 'sql', 'tt',
|
||||||
'text', 'text2', 'which', 'xml', 'cheetah', 'colortext')
|
'text', 'text2', 'which', 'xml', 'cheetah', 'colortext', 'latex')
|
||||||
for name in names:
|
for name in names:
|
||||||
exec("import mode.%s; mode.%s.install(self)" % (name, name))
|
exec("import mode.%s; mode.%s.install(self)" % (name, name))
|
||||||
|
|
||||||
|
|
|
@ -611,7 +611,7 @@ class PathListBuffer(DirBuffer):
|
||||||
btype = 'pathlist'
|
btype = 'pathlist'
|
||||||
def __init__(self, name, paths, nl='\n'):
|
def __init__(self, name, paths, nl='\n'):
|
||||||
Buffer.__init__(self, nl)
|
Buffer.__init__(self, nl)
|
||||||
self.paths = paths
|
self.paths = list(paths)
|
||||||
self.path = os.getcwd()
|
self.path = os.getcwd()
|
||||||
self._name = name
|
self._name = name
|
||||||
def path_exists(self):
|
def path_exists(self):
|
||||||
|
|
7
lex.py
7
lex.py
|
@ -181,7 +181,7 @@ class RegionRule(Rule):
|
||||||
while len(args) > 1:
|
while len(args) > 1:
|
||||||
grammar = args.pop(0)
|
grammar = args.pop(0)
|
||||||
pattern = 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)
|
assert type(pattern) == type(''), repr(pattern)
|
||||||
self.pairs.append((grammar, pattern))
|
self.pairs.append((grammar, pattern))
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
|
@ -238,7 +238,12 @@ class RegionRule(Rule):
|
||||||
del lexer.mode.gstack[fqname]
|
del lexer.mode.gstack[fqname]
|
||||||
else:
|
else:
|
||||||
mode = lexer.mode
|
mode = lexer.mode
|
||||||
|
# XYZ
|
||||||
|
#grammar = self.pairs[i][0]
|
||||||
|
if self.pairs[i][0] is not None:
|
||||||
grammar = self.pairs[i][0]
|
grammar = self.pairs[i][0]
|
||||||
|
else:
|
||||||
|
grammar = lexer.grammar
|
||||||
lexer.mstack.append(mode)
|
lexer.mstack.append(mode)
|
||||||
|
|
||||||
if self.pairs[i][1]:
|
if self.pairs[i][1]:
|
||||||
|
|
|
@ -453,6 +453,7 @@ class GetIndentionLevel(Method):
|
||||||
# commenting
|
# commenting
|
||||||
class CommentRegion(Method):
|
class CommentRegion(Method):
|
||||||
'''Prepend a comment to every line in the current buffer'''
|
'''Prepend a comment to every line in the current buffer'''
|
||||||
|
commentc = '#'
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
cursor = w.logical_cursor()
|
cursor = w.logical_cursor()
|
||||||
if cursor < w.mark:
|
if cursor < w.mark:
|
||||||
|
@ -465,9 +466,10 @@ class CommentRegion(Method):
|
||||||
w.input_line = "Empty kill region"
|
w.input_line = "Empty kill region"
|
||||||
return
|
return
|
||||||
for y in range(p1.y, p2.y):
|
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):
|
class UncommentRegion(Method):
|
||||||
'''Remove a comment from every line in the current buffer'''
|
'''Remove a comment from every line in the current buffer'''
|
||||||
|
commentc = '#'
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
cursor = w.logical_cursor()
|
cursor = w.logical_cursor()
|
||||||
if cursor < w.mark:
|
if cursor < w.mark:
|
||||||
|
@ -480,7 +482,7 @@ class UncommentRegion(Method):
|
||||||
w.input_line = "Empty kill region"
|
w.input_line = "Empty kill region"
|
||||||
return
|
return
|
||||||
for y in range(p1.y, p2.y):
|
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))
|
w.buffer.delete(Point(0, y), Point(1, y))
|
||||||
|
|
||||||
# wrapping/justifying/etc
|
# wrapping/justifying/etc
|
||||||
|
|
|
@ -95,7 +95,7 @@ class DirGrep(Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
cmd = 'grep -rEl %r %r' % (vargs['pattern'], w.buffer.path)
|
cmd = 'grep -rEl %r %r' % (vargs['pattern'], w.buffer.path)
|
||||||
(status, output) = commands.getstatusoutput(cmd)
|
(status, output) = commands.getstatusoutput(cmd)
|
||||||
paths = output.split('\n')
|
paths = [x for x in output.split('\n') if x]
|
||||||
bufname = '*%s*' % self.name.title()
|
bufname = '*%s*' % self.name.title()
|
||||||
b = buffer.PathListBuffer(bufname, paths)
|
b = buffer.PathListBuffer(bufname, paths)
|
||||||
b.modename = 'dir'
|
b.modename = 'dir'
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue