branch : pmacs2
This commit is contained in:
moculus 2008-03-16 15:39:17 +00:00
parent d75b3bd6a1
commit ed443b4f32
9 changed files with 90 additions and 142 deletions

View File

@ -1593,6 +1593,7 @@ class CloseBracket(CloseTag):
mytag = ']'
class GetToken(Method):
'''View type and data of the "current" token'''
def _execute(self, w, **vargs):
token = w.get_token()
if token is None:

View File

@ -86,17 +86,15 @@ class Fundamental(Handler):
lexer = None
tabber = None
colors = {}
#default_color = ('default', 'default',)
def install(cls, app):
app.setmode(cls.modename.lower(), cls, paths=cls.paths,
basenames=cls.basenames, extensions=cls.extensions,
detection=cls.detection)
for (key, val) in cls.colors.iteritems():
#key2 = '%s.%s' % (cls.modename, key)
#app.token_colors[key2] = val
if key in app.token_colors:
raise Exception, '%r conflict from %r' % (key, cls.modename)
s = 'token_colors: name %r conflict in %r' % (key, cls.modename)
raise Exception, s
else:
app.token_colors[key] = val
install = classmethod(install)

View File

@ -3,28 +3,28 @@ from lex import Grammar, PatternRule, RegionRule, PatternGroupRule
class AboutGrammar(Grammar):
rules = [
PatternRule(r'stars', r'\*+'),
PatternRule(r'equals', r'=+'),
PatternRule(r'pmacs', r'pmacs'),
PatternRule(r'author', r'Erik Osheim'),
PatternRule(r'copyright', r'\(c\) 2005-2007'),
PatternRule(r'license', r'GNU General Public License v2'),
PatternRule(r'binding', r'C-c M-h'),
PatternRule(r'command', r'\(show-bindings-buffer\)'),
PatternRule(r'about_stars', r'\*+'),
PatternRule(r'about_equals', r'=+'),
PatternRule(r'about_pmacs', r'pmacs'),
PatternRule(r'about_author', r'Erik Osheim'),
PatternRule(r'about_copyright', r'\(c\) 2005-2007'),
PatternRule(r'about_license', r'GNU General Public License v2'),
PatternRule(r'about_binding', r'C-c M-h'),
PatternRule(r'about_command', r'\(show-bindings-buffer\)'),
]
class About(mode.Fundamental):
modename = 'About'
grammar = AboutGrammar()
colors = {
'stars': ('yellow', 'default'),
'equals': ('red', 'default'),
'pmacs': ('cyan', 'default'),
'author': ('cyan', 'default'),
'copyright': ('blue', 'default'),
'license': ('cyan', 'default'),
'binding': ('cyan', 'default'),
'command': ('blue', 'default'),
'about_stars': ('yellow', 'default'),
'about_equals': ('red', 'default'),
'about_pmacs': ('cyan', 'default'),
'about_author': ('cyan', 'default'),
'about_copyright': ('blue', 'default'),
'about_license': ('cyan', 'default'),
'about_binding': ('cyan', 'default'),
'about_command': ('blue', 'default'),
}
install = About.install

View File

@ -8,16 +8,13 @@ from mode.python import StringGrammar
class MacroGrammar(Grammar):
rules = [
PatternRule('name', r'(?:(?<=#define )) *[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule(r"unop", r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"),
PatternRule(r"integer", r"-?(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
PatternRule(r"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'char', r"'.'|'\\.'|'\\[0-7]{3}'"),
PatternRule(r"continued", r"\\\n$"),
]

View File

@ -16,8 +16,8 @@ class TemplateGrammar(Grammar):
rules = [
RegionRule(r'comment', r'#\*', Grammar, r'\*#'),
PatternRule(r'comment', r'##.*\n'),
PatternRule(r'placeholder', r'\$[a-zA-Z0-9_]+'),
PatternRule(r'directive', r'#.*?[#\n]'),
PatternRule(r'cheetah_placeholder', r'\$[a-zA-Z0-9_]+'),
PatternRule(r'cheetah_directive', r'#.*?[#\n]'),
RegionRule(r'cheetah_tag', r'</?', TagGrammar, r'/?>'),
]
@ -26,22 +26,16 @@ class Template(mode.Fundamental):
extensions = ['.tmpl']
grammar = TemplateGrammar
colors = {
#'comment': ('red', 'default'),
#'comment.start': ('red', 'default'),
#'comment.null': ('red', 'default'),
#'comment.end': ('red', 'default'),
'directive': ('magenta', 'default'),
'placeholder': ('magenta', 'default'),
'cheetah_tag.start': ('default', 'default'),
'cheetah_tag.namespace': ('magenta', 'default'),
'cheetah_tag.name': ('blue', 'default'),
'cheetah_tag.attrname': ('cyan', 'default'),
'cheetah_tag.string.start': ('green', 'default'),
'cheetah_tag.string.null': ('green', 'default'),
'cheetah_tag.string.end': ('green', 'default'),
'cheetah_tag.end': ('default', 'default'),
'cheetah_directive': ('magenta', 'default'),
'cheetah_placeholder': ('magenta', 'default'),
'cheetah_tag.start': ('default', 'default'),
'cheetah_tag.namespace': ('magenta', 'default'),
'cheetah_tag.name': ('blue', 'default'),
'cheetah_tag.attrname': ('cyan', 'default'),
'cheetah_tag.string.start': ('green', 'default'),
'cheetah_tag.string.null': ('green', 'default'),
'cheetah_tag.string.end': ('green', 'default'),
'cheetah_tag.end': ('default', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -4,28 +4,19 @@ from mode.python import StringGrammar
class ConsoleGrammar(Grammar):
rules = [
PatternRule(r'mesg', r'^[A-Za-z].*$'),
PatternRule(r'input', r'^>>>.*$'),
PatternRule(r'input', r'^-->.*$'),
#PatternRule(r'output', r'^ .*$'),
RegionRule(r'py_string', r'"', StringGrammar, r'"'),
RegionRule(r'py_string', r"'", StringGrammar, r"'"),
PatternRule(r'console_mesg', r'^[A-Za-z].*$'),
PatternRule(r'console_input', r'^>>>.*$'),
PatternRule(r'console_input', r'^-->.*$'),
RegionRule(r'string', r'"', StringGrammar, r'"'),
RegionRule(r'string', r"'", StringGrammar, r"'"),
PatternRule(r'bareword', r'[a-zA-Z_][a-zA-Z0-9_]*'),
]
class Console(mode.Fundamental):
modename = 'Console'
grammar = ConsoleGrammar()
colors = {
'mesg': ('blue', 'default'),
'input': ('cyan', 'default'),
'output': ('default', 'default'),
'py_string.start': ('green', 'default'),
'py_string.octal': ('magenta', 'default'),
'py_string.escaped': ('magenta', 'default'),
'py_string.null': ('green', 'default'),
'py_string.end': ('green', 'default'),
'console_mesg': ('blue', 'default'),
'console_input': ('cyan', 'default'),
}
install = Console.install

View File

@ -21,31 +21,5 @@ class Diff(mode.Fundamental):
'metadata': ('magenta', 'default', 'bold'),
'location': ('magenta', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
#self.add_action_and_bindings(DiffNextSection(), ('M-n', 'M-D_ARROW',))
#self.add_action_and_bindings(DiffPreviousSection(), ('M-p', 'M-U_ARROW',))
class DiffNextSection(method.Method):
re = re.compile("(?:^|(?<=\n))@@ [-+0-9a-z, ]* @@(?:$|\n)")
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
i = cursor.y + 1
while i < len(w.buffer.lines):
if self.re.match(w.buffer.lines[i]):
w.goto_line(i)
return
i += 1
class DiffPreviousSection(method.Method):
re = re.compile("(?:^|(?<=\n))@@ [-+0-9a-z, ]* @@(?:$|\n)")
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
i = cursor.y - 1
while i >= 0:
if self.re.match(w.buffer.lines[i]):
w.goto_line(i)
return
i -= 1
install = Diff.install

View File

@ -6,64 +6,67 @@ from method import Method, Argument
class PermGrammar(Grammar):
rules = [
PatternRule(r'sticky', r'[tT]'),
PatternRule(r'setid', r'[sS]'),
PatternRule(r'read', r'r'),
PatternRule(r'write', r'w'),
PatternRule(r'exec', r'x'),
PatternRule(r'perm_sticky', r'[tT]'),
PatternRule(r'perm_setid', r'[sS]'),
PatternRule(r'perm_read', r'r'),
PatternRule(r'perm_write', r'w'),
PatternRule(r'perm_exec', r'x'),
]
class PathGrammar(Grammar):
rules = [
RegionRule(r'perm', r'(?<=^.)', PermGrammar, r' '),
PatternGroupRule(r'fields', r'owner', r'[^ ]+ +', r'group', r'[^ ]+ +',
r'size', r'[^ ]+ +',
r'mtime', r'[A-Za-z]{3} [ 0-9]{2} [0-9]{2}:[0-9]{2} +',
r'name', r'[^\n]*',
RegionRule(r'dir_perm', r'(?<=^.)', PermGrammar, r' '),
PatternGroupRule(
r'dir_fields',
r'dir_owner', r'[^ ]+ +',
r'dir_group', r'[^ ]+ +',
r'dir_size', r'[^ ]+ +',
r'dir_mtime', r'[A-Za-z]{3} [ 0-9]{2} [0-9]{2}:[0-9]{2} +',
r'dir_name', r'[^\n]*',
),
]
class DirGrammar(Grammar):
rules = [
RegionRule(r'file', r'^-', PathGrammar, r'\n'),
RegionRule(r'blk', r'^b', PathGrammar, r'\n'),
RegionRule(r'chr', r'^c', PathGrammar, r'\n'),
RegionRule(r'dir', r'^d', PathGrammar, r'\n'),
RegionRule(r'lnk', r'^l', PathGrammar, r'\n'),
RegionRule(r'fifo', r'^p', PathGrammar, r'\n'),
RegionRule(r'sock', r'^s', PathGrammar, r'\n'),
RegionRule(r'unk', r'^\?', PathGrammar, r'\n'),
RegionRule(r'dir_file', r'^-', PathGrammar, r'\n'),
RegionRule(r'dir_blk', r'^b', PathGrammar, r'\n'),
RegionRule(r'dir_chr', r'^c', PathGrammar, r'\n'),
RegionRule(r'dir_dir', r'^d', PathGrammar, r'\n'),
RegionRule(r'dir_lnk', r'^l', PathGrammar, r'\n'),
RegionRule(r'dir_fifo', r'^p', PathGrammar, r'\n'),
RegionRule(r'dir_sock', r'^s', PathGrammar, r'\n'),
RegionRule(r'dir_unk', r'^\?', PathGrammar, r'\n'),
]
class Dir(mode.Fundamental):
modename = 'Dir'
grammar = DirGrammar()
colors = {
'blk.start': ('cyan', 'default'),
'blk.name': ('cyan', 'default'),
'chr.start': ('yellow', 'default'),
'chr.name': ('yellow', 'default'),
'dir.start': ('blue', 'default'),
'dir.name': ('blue', 'default'),
'lnk.start': ('green', 'default'),
'lnk.name': ('green', 'default'),
'fifo.start': ('red', 'default'),
'fifo.name': ('red', 'default'),
'sock.start': ('red', 'default'),
'sock.name': ('red', 'default'),
'unk.start': ('magenta', 'default'),
'unk.name': ('magenta', 'default'),
'dir_blk.start': ('cyan', 'default'),
'dir_blk.name': ('cyan', 'default'),
'dir_chr.start': ('yellow', 'default'),
'dir_chr.name': ('yellow', 'default'),
'dir_dir.start': ('blue', 'default'),
'dir_dir.dir_name': ('blue', 'default'),
'dir_lnk.start': ('green', 'default'),
'dir_lnk.name': ('green', 'default'),
'dir_fifo.start': ('red', 'default'),
'dir_fifo.name': ('red', 'default'),
'dir_sock.start': ('red', 'default'),
'dir_sock.name': ('red', 'default'),
'dir_unk.start': ('magenta', 'default'),
'dir_unk.name': ('magenta', 'default'),
'perm.setid': ('yellow', 'default'),
'perm.sticky': ('yellow', 'default'),
'perm.read': ('magenta', 'default'),
'perm.write': ('magenta', 'default'),
'perm.exec': ('magenta', 'default'),
'dir_perm.perm_setid': ('yellow', 'default'),
'dir_perm.perm_sticky': ('yellow', 'default'),
'dir_perm.perm_read': ('magenta', 'default'),
'dir_perm.perm_write': ('magenta', 'default'),
'dir_perm.perm_exec': ('magenta', 'default'),
'owner': ('cyan', 'default'),
'group': ('cyan', 'default'),
'size': ('yellow', 'default'),
'mtime': ('green', 'default'),
'dir_owner': ('cyan', 'default'),
'dir_group': ('cyan', 'default'),
'dir_size': ('yellow', 'default'),
'dir_mtime': ('green', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -12,13 +12,13 @@ class StringGrammar(Grammar):
class ELispGrammar(Grammar):
rules = [
PatternRule(r'comment', r';.*$'),
PatternRule(r'reserved', r'(?:nil)(?![a-zA-Z0-9_])'),
PatternRule(r'elisp_reserved', r'(?:nil)(?![a-zA-Z0-9_])'),
PatternRule(r'elisp_keyword', r'(?:while|when|unless|setq|require|or|not|mapcar|list|let|lambda|if|exists|equal|defvar|defun|defalias|count|cons|cdr|car|apply|and)(?![a-zA-Z0-9_])'),
PatternRule(r'symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'type', r":[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'elisp_symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'elisp_type', r":[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'attribute', r"&[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'bareword', r"[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r"integer", r"(?<![\.0-9a-zA-Z_])(?:0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"),
PatternRule(r"integer", r"(?<![\.0-9a-zA-Z_])(?:0|-?[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"),
PatternRule(r"float", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)(?![\.0-9a-zA-Z_])"),
PatternRule(r"imaginary", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+|(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)[jJ])(?![\.0-9a-zA-Z_])"),
RegionRule(r'string', r'"', StringGrammar, r'"'),
@ -39,20 +39,10 @@ class ELisp(mode.Fundamental):
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'elisp_keyword': ('cyan', 'default'),
'reserved': ('blue', 'default'),
'symbol': ('magenta', 'default'),
'type': ('blue', 'default'),
#'string.start': ('green', 'default'),
#'string.null': ('green', 'default'),
#'string.octal': ('magenta', 'default'),
#'string.escaped': ('magenta', 'default'),
#'string.format': ('yellow', 'default'),
#'string.end': ('green', 'default'),
#'integer': ('default', 'default'),
#'float': ('default', 'default'),
#'imaginary': ('default', 'default'),
#'comment': ('red', 'default'),
'elisp_keyword': ('cyan', 'default'),
'elisp_reserved': ('blue', 'default'),
'elisp_symbol': ('magenta', 'default'),
'elisp_type': ('blue', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)