Sublime Forum

How to change enumeration variables color without modifying all variables

#1

Hi everyone,
I’m trying to change the color of the enumerator variables without changing all the other variables.

This is how it looks right now:
[]

This is how it looks afther I change the foreground color of the variable scope:
https://i.imgur.com/z3RZq0R.png (Can’t upload more than one image)

Expected result:
https://i.imgur.com/CvcNQJr.png (Can’t upload more than one image)

Is there any way I can achieve that ?
I’m using ayu theme if that helps.

Thanks!

0 Likes

#2

Not possible, there is no way for ST to identify the second COLOR_GREEN as an enum: parsing is static, based on regular expression, so when looking at a word on the right side of an assignment, it can be anything.
You can highlight them differently in the declaration by adding meta.enum to the scope, but it won’t affect their color elsewhere in the code.

What could be done is modifying the syntax to assign a special scope to all caps words, but this would work only for a given coding style

1 Like

#3

Hi Clams, thank you for your response, BTW, how can I assign a special scope to all caps words like you say ?
Thanks!

0 Likes

#4

Save the following in a my_c++.sublime-syntax in your package user directory:

%YAML 1.2
---
name: My C++
scope: source.c++
contexts:
  main:
    - match: ""
      push: "Packages/C++/C++.sublime-syntax"
      with_prototype:
      - match: '\b[A-Z_]+\b'
        scope: variable.other.constant.c++

And rename the scope to whatever you want, and then select this new syntax for your C++ file.

2 Likes

Color on define var in c