Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vaultah opened this issue Mar 23, 2022 · 7 comments

Comments

@vaultah
Copy link

vaultah commented Mar 23, 2022

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.

@MattDMo
Copy link
Owner

MattDMo commented Mar 25, 2022

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.

@vaultah
Copy link
Author

vaultah commented Mar 25, 2022

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
Copy link
Author

vaultah commented Mar 25, 2022

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

@MattDMo
Copy link
Owner

MattDMo commented Mar 25, 2022

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
Copy link
Owner

MattDMo commented Mar 25, 2022

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.

@vaultah
Copy link
Author

vaultah commented Mar 25, 2022

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
Copy link
Author

vaultah commented Mar 25, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants