Sublime Forum

Better Python syntax highlighting?

#1

The Python syntax highlighting is really great. However, there’s one aspect of it that drives me nuts. Once you do a function call of any sort - plain old function or a method call on something else - the entire chunk gets highlighted in a single color. Further, the arguments all get highlighted in a single color. This is hard to read, and also doesn’t seem consistent with the highlighting for other languages.

To explain the problem more closedly …

foo = "something"
bar

Currently foo and bar are colored with The Variable Color and "something" is in The String Color. But then if you do

foo.anything
bar()
foo(baz=qux)

Now foo, anything, bar, baz, and qux are all colored with The Too-Common Color, a third-color that kind of washes over your Python code … But shouldn’t there be a little more variation here, a little more context? i.e. at least making the stuff inside parentheses be a different color, or coloring kwarg identifiers differently (i.e. baz above), coloriung the equal signs inside of parentheses the same color as equal signs in general …

Does anybody feel the same about this, and/or know of a way to address it? Is it this way because of technical difficulty?

0 Likes

#2

You can modify your theme file to apply different colors based on scope. How fine grained the context coloring is will rely on the tmLanguage file and what scopes are applied. You can use github.com/facelessuser/ScopeHunter to find what scopes are being applied in a given region. For example, function arguments (at least in python) apply the meta.function-call.arguments scope.

[pre=#2D2D2D]cursors.add(sublime.Region(region.begin(), region.begin() + len(new_content)))
view.run_command(“split_selection_into_lines”)[/pre]

I’m no expert at the theme stuff, so I’ve just been stumbling through making these modifications. I know a couple of people are working on color scheme editors, so perhaps you want to take a look at those



0 Likes

#3

These are great tips, thanks so much.

0 Likes