atom/solarized-dark-syntax

"self." and initial variable instances do not color in python.

Closed this issue · 7 comments

zmk5 commented

For example:

self.some_variable = 0
self.some_variable.some_method()
a_variable = 0

The "self" in either of these will change colors. The initial "a_variable" instance will not change color either. I tried adding these to my stylesheet, but no method I tried could make this work. Does anyone have any ideas on making this work?

Variables currently don't have special scopes assigned to them yet, so it isn't possible to color them differently. As for self, you should be able to target that using variable.language.python (or, starting in Atom 1.8.0, variable.language.self.python).

Does that answer your question?

zmk5 commented

So I should add something like this to my stylesheet.less when 1.8 comes out?

source.python{
variable.language.self.python{
color: #example_color;
}
}

Yep, that should work. I'll leave this open though in case Solarized should highlight self by default.

zmk5 commented

Ok! Thank you so much!

In case anyone else is struggling getting this to work, I had to prepend the style code with atom-text-editor::shadow as recommended here.

atom-text-editor::shadow {
  .source.python {
    .variable.language.self.python {
      color: #268bd2;
    }
  }
}

Actually sorry, I've now seen that Atom doesn't use the Shadow DOM boundary anymore so the above code will cause deprecation warnings. I think this is the correct way to write it now:

atom-text-editor.editor {
  .syntax--source.syntax--python {
    .syntax--variable.syntax--language.syntax--self.syntax--python {
      color: #268bd2;
    }
  }
}

Seems that the "original" theme doesn't highlight self in Python, see https://ethanschoonover.com/solarized/#php-vim.

With that I'll close this as wontfix. Feel free to style it in your own styles.less file, like in the ☝️ above example.