Neon-color-scheme icon indicating copy to clipboard operation
Neon-color-scheme copied to clipboard

Highlighting of keys in dictionary literals when using the official Python syntax definition

Open vaultah opened this issue 2 years ago • 7 comments

If I use the Neon color scheme (version 3.2.2) and Sublime Text's official Python syntax definition (build 4126), I get dictionary literals highlighted like this:

Screenshot from 2022-03-23 22-52-24

This looks somewhat confusing, because the only distinction between constant and non-constant parts of expressions used as keys are quotes, which are tiny and too easy to miss.

If I use Sublime Text's built-in color schemes (like Monokai), dictionary keys are highlighted as expected:

Screenshot from 2022-03-23 22-58-39

I'm not exactly sure where the problem is. FWIW I never noticed this problem while using the MagicPython syntax definition, but it's not listed as supported by Neon color scheme.

vaultah avatar Mar 23 '22 23:03 vaultah

The way it works now is that a dict key, regardless of whether it's a variable or string literal, is colored light green. A value is actually supposed to be light blue as well, for variables and string literals, but it looks like I missed defining a color for variables. I wanted to clearly differentiate between keys and values, regardless of what type of entity they are. From what you're saying, you'd like to have strings differentiated from variables, right?

Let me see if I can come up with a way to keep a visually similar, but not identical, element to all keys and all values, yet still have a difference between string literals and variables.

MattDMo avatar Mar 25 '22 15:03 MattDMo

From what you're saying, you'd like to have strings differentiated from variables, right?

Yeah, I would just want string literals and a variables in the key portion to be more easily distinguishable. I often prefer single quotes, which are even tinier than the double quotes in the example above, so variable and constant parts of dictionary keys visually blend together. Here's a real world example:

Screenshot from 2022-03-25 15-08-33

They don't have to be highlighted exactly like with other color schemes. I actually really like this color and the way it looks with bold values :)

vaultah avatar Mar 25 '22 15:03 vaultah

FWIW I want to switch from MagicPython syntax definition to the official one, but I guess MagicPython does something different in terms of scopes, causing this color scheme to highlight keys more in line with my expectations:

Screenshot from 2022-03-25 15-20-41

vaultah avatar Mar 25 '22 15:03 vaultah

OK, I see what you mean, thanks!

I've never really used MagicPython. A number of years ago the regular Python syntax was pretty bad, so in response I wrote Python Improved. Unfortunately, development on that has lagged for a couple of reasons - declining free time on my part, and fantastic improvements to the stock Python syntax after the Packages were open-sourced. It now is only missing one feature that I want - highlighting of BUG/TODO/XXX in comments. I'll probably put in a PR at some point.

MattDMo avatar Mar 25 '22 15:03 MattDMo

How does this look?

image

The key coloring is still there, but there's a muted background for string literals.

Or there's this:

image

with a more muted background.

MattDMo avatar Mar 25 '22 16:03 MattDMo

Both options are already perfectly acceptable, though I personally prefer the second (more muted) version.

Just a thought, would it look slightly better if this background was expanded to the surrounding quotes as well? Similar to the way curly braces in {placeholders} in f-strings have the same background as the enclosed part. Also, I'd say the same kind of background (but blue-ish) could be added to the string literals in the value portion as well (for symmetry).

But I can definitely live with the proposed solution, so the rest is completely up to you :P

vaultah avatar Mar 25 '22 17:03 vaultah

Or, rather, it might be better to add this background to variables and leave string literals as is -- now that I think about it, the absolute majority of dictionary literals that I see in the real world use only string literals for keys. In other words, it'd be better to keep the style that already works well in by far the most common case and add small tweaks to improve it for less common cases

vaultah avatar Mar 25 '22 22:03 vaultah