mode refactors

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-02-15 17:06:35 +00:00
parent e81712afc1
commit dd780d2f7e
30 changed files with 215 additions and 284 deletions

View File

@ -492,10 +492,8 @@ class GetIndentionLevel(Method):
w.set_error('Indention level: %r' % i)
# commenting
# commenting in python
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:
@ -508,16 +506,17 @@ class CommentRegion(Method):
w.input_line = "Empty kill region"
return
commentc = w.mode.commentc or '#'
x = w.buffer.detect_indent_level(p1.y, p2.y) or 0
for y in range(p1.y, p2.y):
c = self.commentc
c = commentc
if len(w.buffer.lines[y]) < x:
c += ' ' * (x - len(w.buffer.lines[y]))
w.buffer.insert_string(Point(x, y), c)
class UncommentRegion(Method):
'''Remove a comment from every line in the current buffer'''
commentre = re.compile('^( *)(#+)')
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
if cursor < w.mark:
@ -530,9 +529,12 @@ class UncommentRegion(Method):
w.input_line = "Empty kill region"
return
commentc = w.mode.commentc or '#'
commentre = re.compile('^( *)((?:%s)+)' % commentc)
for y in range(p1.y, p2.y):
line = w.buffer.lines[y]
m = self.commentre.match(line)
m = commentre.match(line)
if not m:
continue
s1, s2 = m.groups()

View File

@ -32,11 +32,12 @@ class Handler(object):
del self.bindings[binding]
def add_binding(self, name, sequence):
if self.window is None:
return
#return
raise Exception("No window available")
elif not hasattr(self.window, 'application'):
raise Exception, "argh %r %r" % (self, self.window)
raise Exception("No application available")
elif name not in self.window.application.methods:
raise Exception, "No action called %r found" % name
raise Exception("No action called %r found" % name)
else:
self.bindings[sequence] = name
def add_bindings(self, name, sequences):
@ -89,6 +90,7 @@ class Fundamental(Handler):
context = None
colors = {}
word_letters = None
commentc = None
# config settings installed/modified by the mode
config = {}
@ -97,6 +99,7 @@ class Fundamental(Handler):
sconfig = {}
actions = []
_bindings = {}
completers = {}
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s"
@ -151,6 +154,7 @@ class Fundamental(Handler):
return
else:
app.methods[m.name] = m
for (datatype, completer) in cls.completers.iteritems():
app.set_completer(datatype, completer)
install = classmethod(install)
@ -264,6 +268,10 @@ class Fundamental(Handler):
for c in string.letters + string.digits + string.punctuation:
self.add_binding('insert-string-%s' % c, c)
# per-mode bindings
for (name, sequences) in self._bindings.iteritems():
self.add_bindings(name, sequences)
# lexing for highlighting, etc.
if self.grammar:
self.lexer = Lexer(self, self.grammar)
@ -405,7 +413,6 @@ class Fundamental(Handler):
return '%d%s' % (b.indentlvl, t)
def _get_mark(self):
w = self.window
return '(%d,%d)' % (w.first.y + 1, w.first.x + 1),
if w.mark:
return '(%d,%d)' % (w.mark.y + 1, w.mark.x + 1)
else:

View File

@ -135,6 +135,12 @@ class Awk(mode.Fundamental):
modename = 'awk'
extensions = ['.awk']
grammar = AwkGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
config = {'awk.cmd-opts': ""}
actions = [AwkFilterFile, AwkFilterBuffer, AwkFilterInput]
colors = {
'awk_global': ('yellow', 'default', 'bold'),
'awk_function': ('magenta', 'default', 'bold'),
@ -145,7 +151,9 @@ class Awk(mode.Fundamental):
'awk_regex.data': ('cyan', 'default', 'bold'),
'awk_regex.end': ('cyan', 'default', 'bold'),
}
config = {'awk.cmd-opts': ""}
actions = [AwkFilterFile, AwkFilterBuffer, AwkFilterInput]
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = Awk.install

View File

@ -137,6 +137,10 @@ class C(mode.Fundamental):
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
actions = [CCheckSyntax, CMake]
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"
commentc = '//'
colors = {
'macrocomment.start': ('red', 'default', 'bold'),
'macrocomment.null': ('red', 'default', 'bold'),
@ -170,9 +174,14 @@ class C(mode.Fundamental):
lconfig = {
'ignore-suffix': ['.o'],
}
actions = [CCheckSyntax, CMake]
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
'c-check-syntax': ('C-c s',),
'c-make': ('C-c C-c',),
}
def get_status_names(self):
names = mode.Fundamental.get_status_names(self)
@ -180,14 +189,6 @@ class C(mode.Fundamental):
names['func'] = self.get_line_function(c.y)
return names
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_bindings('c-check-syntax', ('C-c s',))
self.add_bindings('c-make', ('C-c C-c',))
def get_functions(self):
return {}
def get_function_names(self):

View File

@ -36,6 +36,7 @@ class Template(mode.Fundamental):
modename = 'Cheetah'
extensions = ['.tmpl']
grammar = TemplateGrammar
commentc = '##'
colors = {
'cheetah_directive': ('magenta', 'default', 'bold'),
'cheetah_placeholder': ('magenta', 'default', 'bold'),
@ -48,10 +49,10 @@ class Template(mode.Fundamental):
'cheetah_tag.string.end': ('green', 'default', 'bold'),
'cheetah_tag.end': ('default', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = Template.install

View File

@ -2,23 +2,7 @@ import color, mode
from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar1, StringGrammar2, PythonGrammar
#class ConsoleGrammar(Grammar):
# rules = [
# RegionRule(r'string', r'"', StringGrammar2, r'"'),
# RegionRule(r'string', r"'", StringGrammar1, r"'"),
# RegionRule(r'console_input', r'^(?:>>>|-->)', PythonGrammar, '\n$'),
# PatternRule(r'console_mesg', r'^[A-Za-z].*$'),
# PatternRule(r'console_reserved', r'True|False|None'),
# PatternRule(r'console_bareword', r'[a-zA-Z_][a-zA-Z0-9_]*'),
# ]
class Console(mode.Fundamental):
modename = 'Console'
# grammar = ConsoleGrammar()
# colors = {
# 'console_mesg': ('red', 'default', 'bold'),
# 'console_input.start': ('red', 'default', 'bold'),
# 'console_reserved': ('magenta', 'default', 'bold'),
# 'console_bareword': ('default', 'default', 'bold'),
# }
install = Console.install

View File

@ -5,7 +5,6 @@ from mode.python import PythonGrammar
from point import Point
PAD = ' '
LIMIT = 79
class ConsoleExec(method.Method):
def _execute(self, w, **vargs):
@ -57,12 +56,7 @@ class ConsoleExec(method.Method):
t = sys.exc_traceback
output = str(e) + traceback.format_exc()
limit = 1000
for w2 in b.windows:
limit = min(w.width, limit)
if limit == 1000:
limit = LIMIT
limit -= len(PAD)
limit = min([w.width for w in b.windows]) - len(PAD)
if output:
newlines = []
@ -224,6 +218,18 @@ class ConsoleMini(mode.Fundamental):
actions = [ConsoleExec, ConsoleClear, ConsoleCancel, ConsoleHistoryPrev,
ConsoleHistoryNext, ConsoleTab,
ConsolePageUp, ConsolePageDown, ConsoleGotoBeginning, ConsoleGotoEnd]
_bindings = {
'console-exec': ('RETURN',),
'console-clear': ('C-l',),
'console-cancel': ('C-]', 'C-g'),
'console-history-prev': ('C-p', 'UP'),
'console-history-next': ('C-n', 'DOWN'),
'console-tab': ('TAB',),
'console-page-up': ('M-v',),
'console-page-down': ('C-v',),
'console-goto-beginning': ('M-<',),
'console-goto-end': ('M->',),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.globals = dict(w.application.globals())
@ -231,15 +237,5 @@ class ConsoleMini(mode.Fundamental):
self.saved_input = ""
self.history = ['']
self.hindex = 0
self.add_bindings('console-exec', ('RETURN',))
self.add_bindings('console-clear', ('C-l',))
self.add_bindings('console-cancel', ('C-]', 'C-g'))
self.add_bindings('console-history-prev', ('C-p', 'UP'))
self.add_bindings('console-history-next', ('C-n', 'DOWN'))
self.add_bindings('console-tab', ('TAB',))
self.add_bindings('console-page-up', ('M-v',))
self.add_bindings('console-page-down', ('C-v',))
self.add_bindings('console-goto-beginning', ('M-<',))
self.add_bindings('console-goto-end', ('M->',))
install = ConsoleMini.install

View File

@ -80,10 +80,10 @@ class CSS(mode.Fundamental):
'css_keyword.escaped': ('magenta', 'default', 'bold'),
'css_keyword.end': ('default', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = CSS.install

View File

@ -2,7 +2,7 @@ import commands, os.path, string, sys, traceback
import color, completer, default, mode, method, regex, tab
from point import Point
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
from mode.lisp import LispTabber, LispCommentRegion, LispUncommentRegion
from mode.lisp import LispTabber
class StringGrammar(Grammar):
rules = [
@ -35,6 +35,7 @@ class ELisp(mode.Fundamental):
extensions = ['.el']
tabbercls = LispTabber
grammar = ELispGrammar
commentc = ';'
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
@ -45,12 +46,12 @@ class ELisp(mode.Fundamental):
'elisp_symbol': ('magenta', 'default', 'bold'),
'elisp_type': ('blue', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_bindings('lisp-comment-region', ('C-c #',))
self.add_bindings('lisp-uncomment-region', ('C-u C-C #',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
'lisp-comment-region': ('C-c #',),
'lisp-uncomment-region': ('C-u C-C #',),
}
install = ELisp.install

View File

@ -82,6 +82,7 @@ class Erlang(mode.Fundamental):
tabwidth = 4
tabbercls = ErlangTabber
grammar = ErlangGrammar
commentc = '%'
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
@ -100,10 +101,10 @@ class Erlang(mode.Fundamental):
'erl_atom.null': ('magenta', 'default', 'bold'),
'erl_atom.end': ('magenta', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = Erlang.install

View File

@ -32,6 +32,7 @@ class Haskell(mode.Fundamental):
modename = 'Haskell'
extensions = ['.hs']
tabwidth = 4
commentc = '--'
#tabbercls = mode.lisp.LispTabber
grammar = HaskellGrammar
#opentokens = ('delimiter',)
@ -51,10 +52,5 @@ class Haskell(mode.Fundamental):
'hs_string.gap.null': ('red', 'default', 'bold'),
'hs_string.gap.end': ('red', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
#self.add_bindings('close-paren', (')',))
#self.add_bindings('close-brace', ('}',))
#self.add_bindings('close-bracket', (']',))
install = Haskell.install

View File

@ -99,13 +99,12 @@ class HTML(mode.Fundamental):
colors['style.%s' % _name] = _colorbase[_name]
colors['tag.%s' % _name] = _colorbase[_name]
actions = [HtmlViewPage, HtmlValidatePage, HtmlCheckSpelling]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_bindings('xml-create-tag', ('M-t',))
self.url = None
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
'xml-create-tag': ('M-t',),
}
url = None
install = HTML.install

View File

@ -121,6 +121,7 @@ class Java(mode.Fundamental):
extensions = ['.java']
tabbercls = JavaTabber2
grammar = JavaGrammar
commentc = '//'
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)

View File

@ -91,6 +91,7 @@ class Javascript(mode.Fundamental):
extensions = ['.js']
grammar = JavascriptGrammar
tabbercls = JavascriptTabber2
commentc = '//'
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
@ -106,10 +107,10 @@ class Javascript(mode.Fundamental):
'js_regex.escaped': ('magenta', 'default', 'bold'),
'js_regex.end': ('cyan', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = Javascript.install

View File

@ -78,10 +78,10 @@ class LatexViewPdf(LatexBuildPdf):
pdfpath = self._modpath(w, '.pdf')
os.execvp(viewcmd, (viewcmd, pdfpath))
class LatexCommentRegion(method.CommentRegion):
commentc = '%'
class LatexUncommentRegion(method.UncommentRegion):
commentc = '%'
#class LatexCommentRegion(method.CommentRegion):
# commentc = '%'
#class LatexUncommentRegion(method.UncommentRegion):
# commentc = '%'
class LatexInsertSquotes(method.Method):
'''Insert a pair of LaTeX-style single-quotes into the buffer'''
@ -116,6 +116,7 @@ class LatexCheckSpelling(method.Method):
class Latex(mode.Fundamental):
modename = 'Latex'
extensions = ['.latex', '.tex']
commentc = '%'
grammar = LatexGrammar
colors = {
'latex_wrapper': ('magenta', 'default', 'bold'),
@ -133,21 +134,19 @@ class Latex(mode.Fundamental):
'latex.pdfbuildcmd': 'pdflatex',
'latex.pdfviewcmd': 'evince',
}
actions = [LatexCommentRegion, LatexUncommentRegion, LatexInsertSquotes,
actions = [LatexInsertSquotes,
LatexInsertDquotes, LatexInsertBraces, LatexBuild,
LatexInsertSpace, LatexBuildPdf, LatexViewPdf,
LatexCheckSpelling]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('wrap-paragraph', ('M-q',))
self.add_bindings('latex-comment-region', ('C-c #', "C-c \%"))
self.add_bindings('latex-uncomment-region', ('C-u C-c #', "C-u C-c \%"))
self.add_bindings('latex-insert-squotes', ("M-'",))
self.add_bindings('latex-insert-dquotes', ('M-"',))
self.add_bindings('latex-insert-braces', ('M-{',))
self.add_bindings('latex-build', ("C-c C-c", 'C-c B'))
self.add_bindings('latex-insert-space', ('SPACE',))
self.add_bindings('latex-build-pdf', ("C-c C-p",))
self.add_bindings('latex-view-pdf', ('C-c C-v',))
_bindings = {
'wrap-paragraph': ('M-q',),
'latex-insert-squotes': ("M-'",),
'latex-insert-dquotes': ('M-"',),
'latex-insert-braces': ('M-{',),
'latex-build': ("C-c C-c", 'C-c B'),
'latex-insert-space': ('SPACE',),
'latex-build-pdf': ("C-c C-p",),
'latex-view-pdf': ('C-c C-v',),
}
install = Latex.install

View File

@ -14,11 +14,6 @@ class LispGrammar(Grammar):
PatternRule(r'eol', r'\n'),
]
class LispCommentRegion(CommentRegion):
commentc = ';'
class LispUncommentRegion(UncommentRegion):
commentc = ';'
class LispTabber(tab.StackTabber):
wsre = regex.whitespace
wst = ('spaces', 'null', 'eol',)
@ -49,14 +44,11 @@ class Lisp(mode.Fundamental):
opentags = {'(': ')'}
closetokens = ('delimiter',)
closetags = {')': '('}
actions = [LispCommentRegion, LispUncommentRegion]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_bindings('lisp-comment-region', ('C-c #',))
self.add_bindings('lisp-uncomment-region', ('C-u C-C #',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
commentc = ';'
install = Lisp.install

View File

@ -42,17 +42,18 @@ class Lua(mode.Fundamental):
extensions = ['.lua']
#tabbercls = mode.lisp.LispTabber
grammar = LuaGrammar
commentc = '--'
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {}
actions = [LuaCheckSyntax]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_bindings('lua-check-syntax', ('C-c s',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
'lua-check-syntax': ('C-c s',),
}
install = Lua.install

View File

@ -36,6 +36,7 @@ class Make(mode.Fundamental):
modename = 'Make'
basenames = ['Makefile']
grammar = MakeGrammar
commentc = '#'
savetabs = True
colors = {
'targets.start': ('cyan', 'default', 'bold'),

View File

@ -25,11 +25,11 @@ class NasmGrammar(Grammar):
PatternRule(r'comment', r';.*$'),
]
class Nasm(mode.Fundamental):
modename = 'nasm'
extensions = ['.s']
grammar = NasmGrammar
commentc = ';'
colors = {
'nasm_keyword': ('cyan', 'default', 'bold'),
'macros': ('blue', 'default', 'bold'),

View File

@ -67,10 +67,10 @@ class Ocaml(mode.Fundamental):
'ocaml_string.escaped': ('magenta', 'default', 'bold'),
'ocaml_string.end': ('green', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = Ocaml.install

View File

@ -619,6 +619,7 @@ class Perl(mode.Fundamental):
detection = ['perl']
tabbercls = PerlTabber2
grammar = PerlGrammar
commentc = '#'
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)

View File

@ -3,7 +3,7 @@ from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar
#from mode.c import CTabber
class JavaGrammar(Grammar):
class PHPGrammar(Grammar):
rules = [
#PatternRule(r'import', r'(?<=import ) *[a-zA-Z0-9_.*]+'),
#PatternRule(r'package', r'(?<=package ) *[a-zA-Z0-9_.*]+'),
@ -19,19 +19,19 @@ class JavaGrammar(Grammar):
PatternRule(r'php_constants', r'PHP_VERSION|PHP_OS|DEFAULT_INCLUDE_PATH|PEAR_INSTALL_DIR|PEAR_EXTENSION_DIR|PHP_EXTENSION_DIR|PHP_BINDIR|PHP_LIBDIR|PHP_DATADIR|PHP_SYSCONFDIR|PHP_LOCALSTATEDIR|PHP_CONFIG_FILE_PATH|PHP_OUTPUT_HANDLER_START|PHP_OUTPUT_HANDLER_CONT|PHP_OUTPUT_HANDLER_END|E_ERROR|E_WARNING|E_PARSE|E_NOTICE|E_CORE_ERROR|E_CORE_WARNING|E_COMPILE_ERROR|E_COMPILE_WARNING|E_USER_ERROR|E_USER_WARNING|E_USER_NOTICE|E_ALL'),
PatternRule(r'keyword', r"(?:abstract|assert|boolean|break|byte|case|catch|char|class|continue|default|double|do|else|extends|finally|final|float|for|if|implements|import|instanceof|interface|int|long|native|new|package|private|protected|public|return|short|static|switch|super|synchronized|threadsafe|throws|throw|transient|try|void|while)(?![a-zA-Z_])"),
PatternRule(r'java_label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
PatternRule(r'php_label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
PatternRule(r'java_builtin', r"(?:null|true|false|this)"),
PatternRule(r'php_builtin', r"(?:null|true|false|this)"),
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"),
PatternRule(r"unop", r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"),
PatternRule(r"java_integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
PatternRule(r"java_float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
PatternRule(r"php_integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
PatternRule(r"php_float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
RegionRule(r'string', '"', StringGrammar, '"'),
PatternRule(r'java_char', r"'.'|'\\.'|'\\[0-7]{3}'"),
PatternRule(r'php_char', r"'.'|'\\.'|'\\[0-7]{3}'"),
PatternRule(r"eol", r"\n$"),
]
@ -160,11 +160,12 @@ class JavaGrammar(Grammar):
# self._opt_append('cont', currlvl + w)
# return currlvl
class Java(mode.Fundamental):
modename = 'Java'
extensions = ['.java']
class PHP(mode.Fundamental):
modename = 'PHP'
extensions = ['.php']
#tabbercls = JavaTabber
grammar = JavaGrammar
grammar = PHPGrammar
commentc = '#'
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
@ -174,11 +175,11 @@ class Java(mode.Fundamental):
'doccomment.end': ('red', 'default', 'bold'),
'doccomment.null': ('red', 'default', 'bold'),
'import': ('blue', 'default', 'bold'),
'java_label': ('magenta', 'default', 'bold'),
'java_builtin': ('magenta', 'default', 'bold'),
'java_char': ('green', 'default', 'bold'),
'java_integer': ('green', 'default', 'bold'),
'java_float': ('green', 'default', 'bold'),
'php_label': ('magenta', 'default', 'bold'),
'php_builtin': ('magenta', 'default', 'bold'),
'php_char': ('green', 'default', 'bold'),
'php_integer': ('green', 'default', 'bold'),
'php_float': ('green', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
@ -186,4 +187,4 @@ class Java(mode.Fundamental):
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
install = Java.install
install = PHP.install

View File

@ -402,54 +402,6 @@ class PythonBrmFindReferences(method.Method):
else:
w.set_error('%d references found' % n)
# commenting in python
class PythonCommentRegion(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:
p1 = cursor
p2 = w.mark
elif w.mark < cursor:
p1 = w.mark
p2 = cursor
else:
w.input_line = "Empty kill region"
return
x = w.buffer.detect_indent_level(p1.y, p2.y)
for y in range(p1.y, p2.y):
c = self.commentc
if len(w.buffer.lines[y]) < x:
c += ' ' * (x - len(w.buffer.lines[y]))
w.buffer.insert_string(Point(x, y), c)
class PythonUncommentRegion(Method):
'''Remove a comment from every line in the current buffer'''
commentre = re.compile('^( *)(#+)')
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
if cursor < w.mark:
p1 = cursor
p2 = w.mark
elif w.mark < cursor:
p1 = w.mark
p2 = cursor
else:
w.input_line = "Empty kill region"
return
x = w.buffer.detect_indent_level(p1.y, p2.y)
for y in range(p1.y, p2.y):
line = w.buffer.lines[y]
m = self.commentre.match(line)
if not m:
continue
s1, s2 = m.groups()
x1, x2 = len(s1), len(s1) + len(s2)
w.buffer.delete(Point(x1, y), Point(x2, y))
class PythonNameCompleter(completer.Completer):
def _get_dict(self, w):
return w.buffer.method.old_window.mode.context.get_names()
@ -586,6 +538,7 @@ class Python(mode.Fundamental):
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
commentc = '#'
colors = {
'python_keyword': ('cyan', 'default', 'bold'),
'python_reserved': ('magenta', 'default', 'bold'),
@ -605,8 +558,7 @@ class Python(mode.Fundamental):
lconfig = {
'ignore-suffix': ['.pyc', '.pyo'],
}
actions = [PythonCommentRegion, PythonUncommentRegion,
PythonInitNames, PythonListNames, PythonGotoName,
actions = [PythonInitNames, PythonListNames, PythonGotoName,
PythonGotoFunction, PythonGotoClass, PythonCheckSyntax,
PythonDictCleanup, PythonSemanticComplete, PythonBrmFindReferences,
PythonInsertTripleSquotes, PythonInsertTripleDquotes]

View File

@ -102,9 +102,9 @@ class RST(mode.Fundamental):
config = {
'rst.margin': 75,
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('rst-insert-space', ('SPACE',))
self.add_bindings('rst-wrap-paragraph', ('M-q',))
_bindings = {
'rst-insert-space': ('SPACE',),
'rst-wrap-paragraph': ('M-q',),
}
install = RST.install

View File

@ -43,6 +43,7 @@ class Scheme(mode.Fundamental):
tabwidth = 2
tabbercls = mode.lisp.LispTabber
grammar = SchemeGrammar
commentc = ';'
opentokens = ('delimiter',)
opentags = {'(': ')'}
closetokens = ('delimiter',)
@ -54,13 +55,11 @@ class Scheme(mode.Fundamental):
'scheme_number': ('default', 'default', 'bold'),
}
actions = [SchemeCheckSyntax]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_bindings('scheme-check-syntax', ('C-c s',))
self.add_bindings('lisp-comment-region', ('C-c #',))
self.add_bindings('lisp-uncomment-region', ('C-u C-C #',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
'scheme-check-syntax': ('C-c s',),
}
install = Scheme.install

View File

@ -209,8 +209,8 @@ class Sh(mode.Fundamental):
'neval.end': ('yellow', 'default', 'bold'),
}
actions = [ShCheckSyntax]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('sh-check-syntax', ('C-c s',))
_bindings = {
'sh-check-syntax': ('C-c s',),
}
install = Sh.install

View File

@ -1,7 +1,6 @@
import mode, tab
from lex import Grammar, PatternRule, NocasePatternRule, RegionRule, NocaseRegionRule
from mode.python import StringGrammar1, StringGrammar2
from method import CommentRegion, UncommentRegion
class BitStringGrammar(Grammar):
rules = [PatternRule(r'data', r'[01]+')]
@ -60,23 +59,9 @@ sql_rules = [
PlPgSqlGrammar.rules = base_rules + sql_rules + end_rules
#class FunctionGrammar(Grammar):
# rules = base_rules + [
# PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*(?=\()'),
# NocasePatternRule(r'sql_keyword', r'(?:as|returns|language)'),
# sql_type_rule,
# NocasePatternRule(r'language', r'(?<=language ) *[a-zA-Z_][a-zA-Z0-9_]+'),
# RegionRule(r'definition', "'", PlPgSqlGrammar, "'(?!')"),
# ] + end_rules
class SqlGrammar(Grammar):
rules = base_rules + function_rules + sql_rules + end_rules
class SqlCommentRegion(CommentRegion):
commentc = '--'
class SqlUncommentRegion(UncommentRegion):
commentc = '--'
class SqlTabber(tab.StackTabber):
wst = ('null', 'eol',)
def is_base(self, y):
@ -126,12 +111,11 @@ class Sql(mode.Fundamental):
extensions = ['.sql']
grammar = SqlGrammar
tabbercls = SqlTabber
commentc = '--'
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
actions = [SqlCommentRegion, SqlUncommentRegion]
colors = {
'sql_operator': ('yellow', 'default', 'bold'),
'attribute': ('magenta', 'default', 'bold'),
@ -145,7 +129,6 @@ class Sql(mode.Fundamental):
'sql_quoted.end': ('yellow', 'default', 'bold'),
'sql_variable': ('yellow', 'default', 'bold'),
'sql_bareword': ('default', 'default', 'bold'),
'function.start': ('cyan', 'default', 'bold'),
'function.data': ('default', 'default', 'bold'),
'function.null': ('default', 'default', 'bold'),
@ -159,12 +142,12 @@ class Sql(mode.Fundamental):
'function.definition.null': ('magenta', 'default', 'bold'),
'function.definition.end': ('magenta', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.add_bindings('sql-comment-region', ('C-c #',))
self.add_bindings('sql-uncomment-region', ('C-u C-c #',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
'sql-comment-region': ('C-c #',),
'sql-uncomment-region': ('C-u C-c #',),
}
install = Sql.install

View File

@ -52,10 +52,9 @@ class Template(mode.Fundamental):
'tt_tag.string.end': ('green', 'default', 'bold'),
'tt_tag.end': ('default', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = Template.install

View File

@ -77,8 +77,7 @@ class XML(mode.Fundamental):
'xml_entity': ('magenta', 'default', 'bold'),
}
actions = [XmlValidate, XmlCreateTag]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('xml-create-tag', ('M-t',))
_bindings = {
'xml-create-tag': ('M-t',),
}
install = XML.install

View File

@ -2,6 +2,7 @@ import color, mode, tab
from lex import Grammar, PatternRule, RegionRule
from mode.c import C, CGrammar, CTabber2
# ugh
_rules = list(CGrammar.rules)
_rules.insert(0, PatternRule(r"yacc_directive", r"^%[a-zA-Z_]+"))
_rules.insert(1, PatternRule(r"yacc_section", r"%%"))
@ -10,6 +11,7 @@ _rules.insert(3, PatternRule(r"yacc_production", r"^[a-z_]+:"))
_rules.insert(4, PatternRule(r"yacc_var", r"\$[0-9\$]"))
_rules.insert(5, PatternRule(r"yacc_empty", r"^ +\n$"))
# TODO: don't think we need this anymore
class TrueDict(dict):
def __contains__(self, k): return True
def __getitem__(self, k): return True
@ -23,10 +25,14 @@ class YaccGrammar(CGrammar):
rules = _rules
class YaccTabber(CTabber2):
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'},
'yacc_delimiter': {'%{': '%}'}}
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['},
'yacc_delimiter': {'%}': '%{'}}
open_tokens = {
'delimiter': {'{': '}', '(': ')', '[': ']'},
'yacc_delimiter': {'%{': '%}'},
}
close_tokens = {
'delimiter': {'}': '{', ')': '(', ']': '['},
'yacc_delimiter': {'%}': '%{'},
}
control_tokens = {'yacc_production': TrueDict()}
scope_tokens = {}
end_at_eof = False