better default highlighting; much better C highlighting

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-08-20 00:29:04 -04:00
parent 9840cb4806
commit 2536af15e0
3 changed files with 129 additions and 50 deletions

View File

@ -50,38 +50,72 @@ class Application(object):
self.need_draw = True self.need_draw = True
self.input = keyinput.Handler() self.input = keyinput.Handler()
# white is for delimiters, operators, numbers
default = ('default', 'default')
# magenta is for keywords/builtins, translation, globs
lo_magenta = ('magenta202', 'default')
hi_magenta = ('magenta505', 'default')
# red is for comments, pods, endblocks
lo_red = ('red300', 'default')
hi_red = ('red511', 'default')
# orange are for arrays and hashes
hi_orange = ('yellow531', 'default')
lo_orange = ('yellow520', 'default')
# yellow is for scalars and prototypes
hi_yellow = ('yellow551', 'default')
lo_yellow = ('yellow330', 'default')
# green is for strings and hash keys
lo_green = ('green030', 'default')
hi_green = ('green050', 'default')
# cyan is for quotes, evals, regexes, subs
lo_cyan = ('cyan033', 'default')
hi_cyan = ('cyan155', 'default')
# blue is unused
lo_blue = ('blue113', 'default')
hi_blue = ('blue225', 'default')
# let's prepopulate some default token colors # let's prepopulate some default token colors
self.cached_colors = {} self.cached_colors = {}
self.token_colors = { self.token_colors = {
'spaces': ('default', 'default'), 'spaces': default,
'eol': ('default', 'default'), 'eol': default,
'comment': ('red', 'default', 'bold'), 'comment': hi_red,
'comment.start': ('red', 'default', 'bold'), 'comment.start': hi_red,
'comment.data': ('red', 'default', 'bold'), 'comment.data': hi_red,
'comment.null': ('red', 'default', 'bold'), 'comment.null': hi_red,
'comment.end': ('red', 'default', 'bold'), 'comment.end': hi_red,
'continuation': ('red', 'default', 'bold'), 'continuation': hi_red,
'escaped': ('magenta', 'default', 'bold'), 'escaped': hi_magenta,
'string.start': ('green', 'default', 'bold'), 'string.start': lo_green,
'string.data': ('green', 'default', 'bold'), 'string.data': hi_green,
'string.null': ('green', 'default', 'bold'), 'string.null': hi_green,
'string.hex': ('magenta', 'default', 'bold'), 'string.hex': hi_magenta,
'string.octal': ('magenta', 'default', 'bold'), 'string.octal': hi_magenta,
'string.escaped': ('magenta', 'default', 'bold'), 'string.escaped': hi_magenta,
'string.end': ('green', 'default', 'bold'), 'string.end': lo_green,
'char': ('green', 'default', 'bold'), 'char': hi_green,
'integer': ('default', 'default', 'bold'), #'integer': ('white533', 'default'),
'float': ('default', 'default', 'bold'), #'float': ('white533', 'default'),
'number': ('default', 'default', 'bold'), #'number': ('white533', 'default'),
'label': ('magenta', 'default', 'bold'), 'integer': default,
'keyword': ('cyan', 'default', 'bold'), 'float': default,
'reserved': ('cyan', 'default', 'bold'), 'number': default,
'function': ('blue', 'default', 'bold'), 'label': hi_magenta,
'builtin': ('magenta', 'default', 'bold'), 'keyword': hi_cyan,
'method': ('cyan', 'default', 'bold'), 'reserved': hi_cyan,
'bareword': ('default', 'default', 'bold'), 'function': hi_blue,
'delimiter': ('default', 'default'), 'builtin': hi_magenta,
'operator': ('default', 'default'), 'method': hi_cyan,
'bareword': default,
'delimiter': default,
'operator': default,
} }
self.default_color = ('default', 'default',) self.default_color = ('default', 'default',)

View File

@ -35,6 +35,8 @@ def iter256():
for r in range(0, 6): for r in range(0, 6):
for g in range(0, 6): for g in range(0, 6):
for b in range(0, 6): for b in range(0, 6):
#if r >= 3 and g >= 3 and b >= 3: name = 'white'
#elif r >= g and g > b: name = 'yellow'
if r >= g and g > b: name = 'yellow' if r >= g and g > b: name = 'yellow'
elif r >= b and b - g > 1: name = 'magenta' elif r >= b and b - g > 1: name = 'magenta'

View File

@ -77,9 +77,12 @@ class CGrammar(Grammar):
PatternRule("c.integer", r"(?:0(?![x0-9])|-?[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"), PatternRule("c.integer", r"(?:0(?![x0-9])|-?[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
PatternRule("c.operator", r"!(?!=)|\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="), PatternRule("c.operator", r"!(?!=)|\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule('c.operator', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"), PatternRule('c.operator', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&&|&|\*|\|\||\||/|\^|==|//|~|!=|%"),
RegionRule('c.macrocomment', '#if +(?:0|NULL|FALSE)', Grammar, '#endif'), RegionRule('c.macrocomment', '#if +(?:0|NULL|FALSE)', Grammar, '#endif'),
PatternRule('c.char', r"'.'|'\\.'|'\\[0-7]{3}'"), PatternMatchRule('', r"(')(.)(')", 'c.char.start', 'c.char.data', 'c.char.end'),
PatternMatchRule('', r"(')(\\.)(')", 'c.char.start', 'c.char.escaped', 'c.char.end'),
PatternMatchRule('', r"(')(\\[0-7]{3})(')", 'c.char.start', 'c.char.octal', 'c.char.end'),
#PatternRule('c.char', r"'.'|'\\.'|'\\[0-7]{3}'"),
PatternMatchRule('x', r'(# *include)( +)(.+)(\n|$)', PatternMatchRule('x', r'(# *include)( +)(.+)(\n|$)',
'c.macro.start', 'spaces', 'c.header', 'c.macro.end'), 'c.macro.start', 'spaces', 'c.header', 'c.macro.end'),
PatternRule('c.identifier', word), PatternRule('c.identifier', word),
@ -163,6 +166,37 @@ class CMake(Exec):
else: else:
self._doit(w, w.buffer.path, cmd, cmdname='c-make') self._doit(w, w.buffer.path, cmd, cmdname='c-make')
# white is for delimiters, operators, numbers
default = ('default', 'default')
# magenta is for keywords/builtins
lo_magenta = ('magenta202', 'default')
hi_magenta = ('magenta505', 'default')
# red is for comments
lo_red = ('red300', 'default')
hi_red = ('red511', 'default')
# orange are for arrays and hashes
hi_orange = ('yellow531', 'default')
lo_orange = ('yellow520', 'default')
# yellow is for scalars and prototypes
hi_yellow = ('yellow551', 'default')
lo_yellow = ('yellow330', 'default')
# green is for strings and characters
lo_green = ('green030', 'default')
hi_green = ('green050', 'default')
# cyan is for quotes, evals, regexes, subs
lo_cyan = ('cyan033', 'default')
hi_cyan = ('cyan155', 'default')
# blue is unused
lo_blue = ('blue113', 'default')
hi_blue = ('blue225', 'default')
class C(Fundamental): class C(Fundamental):
name = 'C' name = 'C'
extensions = ['.c', '.h', '.cpp'] extensions = ['.c', '.h', '.cpp']
@ -177,25 +211,34 @@ class C(Fundamental):
commentc = '//' commentc = '//'
colors = { colors = {
#'c.identifier': ('yellow', 'default', 'bold'), 'c.comment': hi_red,
'macrocomment.start': ('red', 'default', 'bold'), 'c.comment.start': hi_red,
'macrocomment.null': ('red', 'default', 'bold'), 'c.comment.data': hi_red,
'macrocomment.end': ('red', 'default', 'bold'), 'c.comment.end': hi_red,
'macro': ('blue', 'default', 'bold'), 'c.macrocomment.start': hi_red,
'macro.start': ('blue', 'default', 'bold'), 'c.macrocomment.null': hi_red,
'macro.name': ('yellow', 'default', 'bold'), 'c.macrocomment.end': hi_red,
'macro.null': ('magenta', 'default', 'bold'),
'macro.continued': ('red', 'default', 'bold'), 'c.macro': hi_blue,
'macro.delimiter': ('default', 'default', 'bold'), 'c.macro.start': hi_blue,
'macro.concat': ('yellow', 'default', 'bold'), 'c.macro.name': hi_orange,
'macro.quoted': ('yellow', 'default', 'bold'), 'c.macro.null': hi_magenta,
'include': ('blue', 'default', 'bold'), 'c.macro.concat': hi_yellow,
'header': ('green', 'default', 'bold'), 'c.macro.quoted': hi_green,
'type': ('cyan', 'default', 'bold'), 'c.error.start': hi_blue,
'constant': ('yellow', 'default', 'bold'), 'c.error.data': hi_green,
'error.start': ('blue', 'default', 'bold'),
'error.data': ('green', 'default', 'bold'), 'c.char.start': lo_green,
'error.null': ('green', 'default', 'bold'), 'c.char.end': lo_green,
'c.char.data': hi_green,
'c.char.escaped': hi_magenta,
'c.char.octal': hi_magenta,
'c.type': hi_cyan,
'c.include': hi_blue,
'c.header': lo_orange,
'c.constant': hi_orange,
} }
config = { config = {
'c.syntax-cmd': "gcc -x c -fsyntax-only %(path)s", 'c.syntax-cmd': "gcc -x c -fsyntax-only %(path)s",