From 2536af15e0453dd25fe5caeb2a027204502cd7f4 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Thu, 20 Aug 2009 00:29:04 -0400 Subject: [PATCH] better default highlighting; much better C highlighting --HG-- branch : pmacs2 --- application.py | 92 ++++++++++++++++++++++++++++++++++---------------- color.py | 2 ++ mode/c.py | 85 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 129 insertions(+), 50 deletions(-) diff --git a/application.py b/application.py index 779dac7..f161c89 100755 --- a/application.py +++ b/application.py @@ -49,39 +49,73 @@ class Application(object): self.error_timestamp = None self.need_draw = True 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 self.cached_colors = {} self.token_colors = { - 'spaces': ('default', 'default'), - 'eol': ('default', 'default'), - 'comment': ('red', 'default', 'bold'), - 'comment.start': ('red', 'default', 'bold'), - 'comment.data': ('red', 'default', 'bold'), - 'comment.null': ('red', 'default', 'bold'), - 'comment.end': ('red', 'default', 'bold'), - 'continuation': ('red', 'default', 'bold'), - 'escaped': ('magenta', 'default', 'bold'), - 'string.start': ('green', 'default', 'bold'), - 'string.data': ('green', 'default', 'bold'), - 'string.null': ('green', 'default', 'bold'), - 'string.hex': ('magenta', 'default', 'bold'), - 'string.octal': ('magenta', 'default', 'bold'), - 'string.escaped': ('magenta', 'default', 'bold'), - 'string.end': ('green', 'default', 'bold'), - 'char': ('green', 'default', 'bold'), - 'integer': ('default', 'default', 'bold'), - 'float': ('default', 'default', 'bold'), - 'number': ('default', 'default', 'bold'), - 'label': ('magenta', 'default', 'bold'), - 'keyword': ('cyan', 'default', 'bold'), - 'reserved': ('cyan', 'default', 'bold'), - 'function': ('blue', 'default', 'bold'), - 'builtin': ('magenta', 'default', 'bold'), - 'method': ('cyan', 'default', 'bold'), - 'bareword': ('default', 'default', 'bold'), - 'delimiter': ('default', 'default'), - 'operator': ('default', 'default'), + 'spaces': default, + 'eol': default, + 'comment': hi_red, + 'comment.start': hi_red, + 'comment.data': hi_red, + 'comment.null': hi_red, + 'comment.end': hi_red, + 'continuation': hi_red, + 'escaped': hi_magenta, + 'string.start': lo_green, + 'string.data': hi_green, + 'string.null': hi_green, + 'string.hex': hi_magenta, + 'string.octal': hi_magenta, + 'string.escaped': hi_magenta, + 'string.end': lo_green, + 'char': hi_green, + #'integer': ('white533', 'default'), + #'float': ('white533', 'default'), + #'number': ('white533', 'default'), + 'integer': default, + 'float': default, + 'number': default, + 'label': hi_magenta, + 'keyword': hi_cyan, + 'reserved': hi_cyan, + 'function': hi_blue, + 'builtin': hi_magenta, + 'method': hi_cyan, + 'bareword': default, + 'delimiter': default, + 'operator': default, } self.default_color = ('default', 'default',) diff --git a/color.py b/color.py index 80609a2..c2b75a3 100644 --- a/color.py +++ b/color.py @@ -35,6 +35,8 @@ def iter256(): for r in range(0, 6): for g 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' elif r >= b and b - g > 1: name = 'magenta' diff --git a/mode/c.py b/mode/c.py index adcdde4..c4023a7 100644 --- a/mode/c.py +++ b/mode/c.py @@ -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.operator", r"!(?!=)|\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="), - PatternRule('c.operator', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"), + PatternRule('c.operator', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&&|&|\*|\|\||\||/|\^|==|//|~|!=|%"), 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|$)', 'c.macro.start', 'spaces', 'c.header', 'c.macro.end'), PatternRule('c.identifier', word), @@ -163,6 +166,37 @@ class CMake(Exec): else: 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): name = 'C' extensions = ['.c', '.h', '.cpp'] @@ -177,25 +211,34 @@ class C(Fundamental): commentc = '//' colors = { - #'c.identifier': ('yellow', 'default', 'bold'), - 'macrocomment.start': ('red', 'default', 'bold'), - 'macrocomment.null': ('red', 'default', 'bold'), - 'macrocomment.end': ('red', 'default', 'bold'), - 'macro': ('blue', 'default', 'bold'), - 'macro.start': ('blue', 'default', 'bold'), - 'macro.name': ('yellow', 'default', 'bold'), - 'macro.null': ('magenta', 'default', 'bold'), - 'macro.continued': ('red', 'default', 'bold'), - 'macro.delimiter': ('default', 'default', 'bold'), - 'macro.concat': ('yellow', 'default', 'bold'), - 'macro.quoted': ('yellow', 'default', 'bold'), - 'include': ('blue', 'default', 'bold'), - 'header': ('green', 'default', 'bold'), - 'type': ('cyan', 'default', 'bold'), - 'constant': ('yellow', 'default', 'bold'), - 'error.start': ('blue', 'default', 'bold'), - 'error.data': ('green', 'default', 'bold'), - 'error.null': ('green', 'default', 'bold'), + 'c.comment': hi_red, + 'c.comment.start': hi_red, + 'c.comment.data': hi_red, + 'c.comment.end': hi_red, + 'c.macrocomment.start': hi_red, + 'c.macrocomment.null': hi_red, + 'c.macrocomment.end': hi_red, + + 'c.macro': hi_blue, + 'c.macro.start': hi_blue, + 'c.macro.name': hi_orange, + 'c.macro.null': hi_magenta, + 'c.macro.concat': hi_yellow, + 'c.macro.quoted': hi_green, + 'c.error.start': hi_blue, + 'c.error.data': hi_green, + + 'c.char.start': lo_green, + '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 = { 'c.syntax-cmd': "gcc -x c -fsyntax-only %(path)s",