How to programatically fetch color codes from a syntax theme?


Dear all,

I’m in need of a script to fetch all colors (and their uses) from the current syntax theme. Any pointers as to how I go about doing that?



You could create a non-displaying element with each of the standard classes that grammars and syntax themes use, then use getComputedStyle() and grab the color.


Sorry for being slow, but I’ve only used Atom for editing. Where am I supposed to run this?


What are you trying to do with it? You can run it from anywhere, technically, but a package would be the most reasonable place for something that messes with the DOM.


It would probably be better if you explain what you’re trying to do rather than ask for help with how you’ve tried to do it. Why do you need to fetch all colors and their uses from the current syntax theme?


Sorry, I should have been more clear.

@DamnedScholar’s answer was very helpful, even if I failed to explain what my use case was.

I know it is horrible internet question-behavior, but I hadn’t tried anything, as I really had no idea where to start. Now I do, and my best bet is probably to make a small package that does it for me.

I need to retrieve various colors from the current syntax theme to create custom (based on the syntax theme) themes for inline plots in Juno (the Atom based Julia IDE).


You shouldn’t need to do anything super-special to do this. All themes should define the values that are enumerated in the ui-variables list which you can find in the styleguide package. You can see the names of the styles by opening the Command Palette and selecting Styleguide: Show.

By including @import "ui-variables"; at the top of your package’s stylesheet and then using the variable names you see in the Styleguide, you can be assured that your package will blend into any properly-constructed Atom theme.


And that’s why the use case is important, since @leedohm’s answer is exactly what you’re looking for. I gave the answer to the literal question you asked, but if you’re translating style variables from a theme to another package, you don’t have to use a script to fetch colors at all.


Additionally, there is information on everything I mentioned in the Atom Flight Manual here: