branch : pmacs2
This commit is contained in:
moculus 2009-04-06 19:21:30 +00:00
parent 15adad749c
commit 1bef0247dc
4 changed files with 91 additions and 42 deletions

View File

@ -4,22 +4,39 @@ from buffer import Buffer
from buffer.data import DataBuffer
from highlight import Highlighter
color_map = {
'B': 'black',
'r': 'red',
'g': 'green',
'y': 'yellow',
'b': 'blue',
'm': 'magenta',
'c': 'cyan',
'w': 'white',
'd': 'default',
'*': 'bold',
}
reverse_map = {
'black': 'B',
'blue': 'b',
'cyan': 'c',
'default': 'd',
'green': 'g',
'magenta': 'm',
'red': 'r',
'white': 'w',
'yellow': 'y',
'bold': '*',
}
def get_cbuf_code(*args):
return '[' + ':'.join([reverse_map[x] for x in args]) + ']'
# NOTE: this highlighter will not reprocess the data given. it is intended to
# be used with read-only buffers like DataBuffer and ColorBuffer
class ColorHighlighter(Highlighter):
color_re = re.compile(r'\[([a-zA-Z0-9\*:]+)\]')
color_map = {
'B': 'black',
'r': 'red',
'g': 'green',
'y': 'yellow',
'b': 'blue',
'm': 'magenta',
'c': 'cyan',
'w': 'white',
'd': 'default',
'*': 'bold',
}
def __init__(self):
self.tokens = []
def append_token(self, y, x, s, color):
@ -47,7 +64,7 @@ class ColorHighlighter(Highlighter):
if j > i:
offset += self.append_token(y, i - offset, line[i:j], c)
fields = m.group(1).split(':')
c = [self.color_map.get(x, x) for x in fields]
c = [color_map.get(x, x) for x in fields]
offset += k - j
i = k
else:

View File

@ -2,6 +2,7 @@ import os, commands, re, tempfile
from subprocess import Popen, PIPE, STDOUT
import buffer, completer, default, dirutil, regex, util, window
import buffer.color
from point import Point
class MethodError(Exception):
@ -1104,9 +1105,39 @@ class SetModeTabWidth(Method):
app.modes[mode].tabwidth = vargs['width']
w.set_error('Default tab width set to %d' % app.modes[mode].tabwidth)
class ViewTokenColors(Method):
args = []
def _execute(self, w, **vargs):
a = w.application
keys = sorted([x for x in a.token_colors.keys()])
l = 0
for key in keys:
l = max(l, len(key))
lines = ['Color information for %d tokens:\n' % len(keys), '\n']
for key in keys:
c = buffer.color.get_cbuf_code(*a.token_colors[key])
lines.append('%s%-*s %r\n' % (c, l, key, a.token_colors[key]))
a.color_data_buffer("*Token-Colors*", ''.join(lines), switch_to=True)
class SetTokenColors(Method):
args = [arg('name', p='Token Name: ', h=''),
arg('colors', p='Colors: ', h='')]
def _execute(self, w, **vargs):
name = vargs['name']
colors = tuple([x.strip() for x in vargs['colors'].split(',')])
a = w.application
w.set_error('Noop')
if '*' in name:
nstr = name.replace('.', '\\.').replace('*', '.*')
r = re.compile(nstr)
count = 0
for name2 in a.token_colors:
if r.match(name2):
a.token_colors[name2] = colors
count += 1
msg = 'Color for %d tokens matching %s set to %r'
w.set_error(msg % (count, name, colors))
elif name in a.token_colors:
a.cached_colors = {}
a.token_colors[name] = colors
w.set_error('Color for %s set to %r' % (name, colors))

View File

@ -1,6 +1,7 @@
from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule
# this is a comment
class StringGrammar1(Grammar):
rules = [
PatternRule(r'data', r"[^\\']+"),
@ -17,17 +18,17 @@ tbbid = r'[A-Z]{2}\d{3}-\d{3}-\d{3}'
class BDSGrammar(Grammar):
rules = [
PatternRule(r'comment', r'#.*$'),
PatternRule(r'bds_section', r'section(?= *\()'),
PatternRule(r'bds_component', tbbid + r"(?= *\()"),
PatternRule(r'bds_attr_name', r"[a-z_]+(?==)"),
RegionRule(r'bds_attr_value', r"(?<=)'", StringGrammar1, r"'"),
RegionRule(r'bds_attr_value', r'(?<=)"', StringGrammar2, r'"'),
PatternRule(r'bds_num', r"-?(?:[0-9][0-9\.]*[0-9]|[0-9])"),
PatternRule(r'bds_alias', r"[a-z0-9]+(?=:" + tbbid + ")"),
PatternRule(r'bds_id', tbbid),
PatternRule(r'bds_func', r"[a-zA-Z0-9_]+(?= *\()"),
RegionRule(r'bds_string', r"'", StringGrammar1, r"'"),
RegionRule(r'bds_string', r'"', StringGrammar2, r'"'),
PatternRule(r'bds.section', r'section(?= *\()'),
PatternRule(r'bds.component', tbbid + r"(?= *\()"),
PatternRule(r'bds.attr_name', r"[a-z_]+(?==)"),
RegionRule(r'bds.attr_value', r"(?<=)'", StringGrammar1, r"'"),
RegionRule(r'bds.attr_value', r'(?<=)"', StringGrammar2, r'"'),
PatternRule(r'bds.num', r"-?(?:[0-9][0-9\.]*[0-9]|[0-9])"),
PatternRule(r'bds.alias', r"[a-z0-9]+(?=:" + tbbid + ")"),
PatternRule(r'bds.id', tbbid),
PatternRule(r'bds.func', r"[a-zA-Z0-9_]+(?= *\()"),
RegionRule(r'bds.string', r"'", StringGrammar1, r"'"),
RegionRule(r'bds.string', r'"', StringGrammar2, r'"'),
]
class BDS(Fundamental):
@ -35,20 +36,20 @@ class BDS(Fundamental):
extensions = ['.bds']
grammar = BDSGrammar
colors = {
'bds_section': ('blue', 'default', 'bold'),
'bds_component': ('magenta', 'default', 'bold'),
'bds_attr_name': ('blue', 'default', 'bold'),
'bds_attr_value.start': ('green', 'default', 'bold'),
'bds_attr_value.null': ('green', 'default', 'bold'),
'bds_attr_value.end': ('green', 'default', 'bold'),
'bds_num': ('red', 'default', 'bold'),
'bds_alias': ('magenta', 'default', 'bold'),
'bds_id': ('yellow', 'default', 'bold'),
'bds_func': ('cyan', 'default', 'bold'),
'bds_op': ('magenta', 'default', 'bold'),
'bds_string.start': ('red', 'default', 'bold'),
'bds_string.null': ('red', 'default', 'bold'),
'bds_string.end': ('red', 'default', 'bold'),
'bds.section': ('blue', 'default', 'bold'),
'bds.component': ('magenta', 'default', 'bold'),
'bds.attr_name': ('blue', 'default', 'bold'),
'bds.attr_value.start': ('green', 'default', 'bold'),
'bds.attr_value.null': ('green', 'default', 'bold'),
'bds.attr_value.end': ('green', 'default', 'bold'),
'bds.num': ('red', 'default', 'bold'),
'bds.alias': ('magenta', 'default', 'bold'),
'bds.id': ('yellow', 'default', 'bold'),
'bds.func': ('cyan', 'default', 'bold'),
'bds.op': ('magenta', 'default', 'bold'),
'bds.string.start': ('red', 'default', 'bold'),
'bds.string.null': ('red', 'default', 'bold'),
'bds.string.end': ('red', 'default', 'bold'),
}
install = BDS.install

View File

@ -40,11 +40,11 @@ class Diff3(Fundamental):
grammar = Diff3Grammar()
colors = {
'diff.part1.start': ('yellow', 'default', 'bold'),
'diff.part1.pre': ('red', 'red', 'bold'),
'diff.part1.pre': ('default', 'red', 'bold'),
'diff.part2.start': ('yellow', 'default', 'bold'),
'diff.part2.pre': ('green', 'green', 'bold'),
'diff.part2.pre': ('default', 'green', 'bold'),
'diff.part3.start': ('yellow', 'default', 'bold'),
'diff.part3.pre': ('blue', 'blue', 'bold'),
'diff.part3.pre': ('default', 'blue', 'bold'),
}
def install(*args, **kwargs):