Sublime Forum

Creating a custom color scheme?

#1

I have been googling this exact question for the past 2 and a half hours. The only things I have found so far, are questions and videos on installing themes and color schemes, people having issues with installing them, and stuff like that.

I want to code my own color scheme. And for simplicity, I’d prefer if I could open an existing scheme file, and just edit it, and save over it. I tried opening the ones I had in my Sublime directory, but they just wouldn’t open. From what I’ve seen in the videos, the scheme files are xml files, but it’s not the case for me.

I never coded in xml, and I don’t know any of the sublime source code commands and keywords.

I’d like to add, I’m trying to do this for custom syntax (for which I have support in Sublime). And I found “tmtheme editor” by Monokai, but it doesn’t seem to support custom functions or rules.

0 Likes

HTML code Monokai color scheme - can I make <!--#include tags look different to plain comments?
#2

looks this, it may help you: Option to modify theme contrast

1 Like

#3

Unfortunately it is difficult to know what your issue is from your description. Maybe if you explained what steps you are following, someone could explain what you are doing wrong. Maybe you are trying to edit a packed color scheme (a color scheme in a sublime-package zip file)?

Maybe something like this could help as the plugin actually unpacks the color scheme for you: SchemeEditor. But you do have to install the editor via Python’s pip, install the plugin manually, and configure it to work. Maybe that is a little overwhelming.

You could try: https://packagecontrol.io/packages/ColorSchemeEditor. Maybe it unpacks the color scheme? I’ve never tried it, but maybe it does those things.

I’d like to add, I’m trying to do this for custom syntax (for which I have support in Sublime). And I found “tmtheme editor” by Monokai, but it doesn’t seem to support custom functions or rules.

I can’t begin to guess what you mean by this. Highlighting things that are not currently highlighted may be as simple as creating a new color entry in your color scheme and configuring it with the correct scope. Sometimes it is much more complicated and it requires you modify your syntax file to scope what you want to highlight differently and then maybe adjust your color scheme.

1 Like

#4

I think you may also find some value in Package Resource Viewer as this will let you look at the contents of a package and then create an overriding variation on it. That way, you could tinker with the color scheme of your choice and selectively tweak various colors to suit your needs.

2 Likes

#5

I realize now that I didn’t use the correct words when describing what the Monokai theme editor doesn’t seem to support.

Currently, I have 3 ways of editing a theme. So that’s not an issue anymore. What I’m currently having trouble with, is defining custom scopes for the syntax, so that the theme recognizes certain words and colors them accordingly.

btw, I managed to open the tmtheme files, I just had to install the “PackageResourceViewer” package.

Let’s say a program has an API, and that API has some commands, which are not a “string”, “keyword” (public, private, etc.), or any of those things, so they don’t get colored, unlike something like “dog”, which is a string, and would be recognized by the “string” scope in the tmtheme file.

This is what I described when talking about the editor not having support for “custom functions or rules”.

In Monokai’s editor, you can create a new scope, and the following window will appear.

Basically what I tried doing there, is in “Scope” writing the exact API’s command that I saw on-screen (for example, HouseObject), however it did nothing and the instances of that command didn’t change to the color I specified.

All the other scopes are something like “string” and don’t actually say something like " " " " (anything within quotation marks), and doesn’t specify a list of acceptable words. This makes me think that I have to create a whole list of definitions for the syntax somehow, and then reference those definitions in the scopes I create. Just like a string is a definition for things in quotation marks.

0 Likes

#6

@Remi, yes that is a good solution. If the problem is indeed a packed color scheme, then an unpacking with Package Resource Viewer will make it viewable, and then you can continue following whatever YouTube guide you were watching.

For help on any other questions you may need to ask very specific questions with examples to help us understand what issues you are having.

0 Likes

#7

You are headed into the land of syntax definition. That is the source of the scopes used for selector strings that the color schemes operate on. I have had experience writing my own from scratch, however less experience with extending a syntax scheme. There are several recent posts about using Thom Smith’s YAML macros for creating a syntax extension to an already existing scheme and you may want to review those and see if they are relevant to your issue.

Do realize however, that all the syntax scope engine has to work with is parsing the text that is presented to it. So I am a little concerted about your comment:

You DO have to have some way of identifying the text you are seeking to alter the presentation of. I am hoping you simply meant that you’re looking for a function name that’s part of a particular library or something like that. However if you are truly looking for something kind of strange, the regular expression for finding this text may be complicated.

If you are using a well known set of commands, or particular API, you may be able to search for a syntax where someone has already extended it to support the library bits you desire.

1 Like

#8

I had another thought while waiting for a design packet review to print. I’m kind of feeling around in the dark here because I don’t know exactly what you’re working on, but it IS possible that the syntax engine is scoping some structure however it’s doing so in a way that the color scheme is not picking up. It could be due to whomever wrote the syntax definition, or whomever wrote the color scheme. Anyhow, if you put the point onto the object you’re trying to find, you can find out how it is already scoped by hitting C-M-S-p (I think this is the default keybind but you can check in Tools >> Developer >> Show Scope Name). There are also some plugins like ScopeAlways and others that will find ways to display the scope at the point. Anyhow, if your syntax definition is setting the scope in some definitive way for the object you are trying to highlight then you actually have it easier. You just need to write a selector (a string of scope-like text with partial matching and subtractions) for the field and then you can edit your color scheme to track that.

1 Like

#9

Yes, I am just looking for function names that are part of a particular library.

The thing is, I did find syntax which has expanded the library I need. Hence me originally saying “(for which I have support in Sublime)”.

Just read your second reply, and when I use “Show Scope Name” it just says “source.cs” for all the elements that are not affected by the color scheme. btw, I am using the default Monokai one currently.

It seems that whoever coded the extended syntax, covered some of the elements of the API, but not all. The ones that are affected with the color scheme, have definitions called “Untitled:11” and “Untitled:14”.

0 Likes

#10

Yep, if what you want to highlight isn’t scoped, it’s not a color scheme issue, but a syntax issue. The color scheme highlights scopes. So if a bit of text does not have the scope needed, you have to delve into modifying syntax files, and in some cases the color scheme if you’ve added a scope that isn’t covered, or presents itself in a weird way that needs additional rules in the color scheme.

1 Like

#11

How would I go about editing the syntax files? And how hard would adding definitions be, for someone who never coded in xml and such?

0 Likes

#12

Well, it’s not exactly a lighthearted romp across fields of gold, but it’s not too bad either. It’s mainly figuring out the regular expression for your desired text (and if you’re just highlighting new keywords, it might be pretty straightforward.)

Again I would refer you to the posts where someone is taking an established syntax definition and extending it to cover certain elements the original author did not. This is the announcement for the YAML macros by Thom Smith wherein he has written some tool that let you add features to a syntax definition without having to edit the original (though you will almost certainly need to understand the original.)

4 Likes

#13

Unfortunately that is not an easy question, though I’ve modified sytax files in the old plist format, and a little in the new YAML format, I am far from an expert.

I would check out the documentation resources: https://www.sublimetext.com/support.

There are also plugins that help with these tasks such as https://packagecontrol.io/packages/PackageDev.

There are also a number of people on this forum that have really gotten familiar with syntax files that could probably be of more use answering this question than me.

1 Like