Syntax color coding in IDE

Ok first, I fully realize that this question is addressed in other posts, including in the FAQ section. HOWEVER, the answers are several years old and my version of the IDE does not seem to function as described. Please don't hurt me.

I'm trying to figure out where the settings are for the color coding of syntax in the IDE. I found this post which refers to this instructional document, which says:

If you tried the new sketch, you probably noticed that nothing from our library was recognized by the environment and highlighted in color. Unfortunately, the Arduino software can't automatically figure out what you've define in your library (though it would be a nice feature to have), so you have to give it a little help. To do this, create a file called keywords.txt in the Morse directory.

The document was last updated this year, but this is not how my IDE behaves. My functions ALL get orange highlighting without a keywords.txt file.

This post refers to a theme.txt file that defines this syntax color coding, but I've searched my IDE folder, and indeed my entire system drive, and no such file exists.

This helpful reply sets out what the various colors mean (functions are orange, variables are green, aqua or teal, and struct are light greenish), but that isn't what I'm getting at all. My variables are black, my types are teal, flow control statements (if, else, return, etc.) are green.

One of the reasons I ask this is that struct names, typedefs of structs, and struct data members, and struct variables are black...unless you access a member variable as in aStructVariable.aMember = 0... then it turns orange, which is confusing.

Many of the previous answers to this question seem to be "ignore the colors" which is unhelpful and really a non-answer. The colors ARE helpful to me as a first line of defense against typos and whatnot. It's just that they could be more helpful if I had a definitive, up-to-date, and correct set of definitions. And ideally, the ability to alter the settings.

Any information would be highly appreciated.

BTW I'm using IDE 2.0.0.

The first thing to do is to upgrade to version 2.0.4

Done, thank you.
Same behavior, same lack of theme.txt file, same confusion, same question.
What's next?

Hi @cinerobert. As you probably guessed already, the information you found was all written for Arduino IDE 1.x. Arduino IDE 2.x has a completely different keyword highlighting system and doesn't support custom keyword definitions via the keywords.txt file as Arduino IDE 1.x did.

Arduino IDE 2.x uses a high quality C++ syntax highlighting system (the same one as is built-in to the VS Code editor). This system automatically processes your sketch code and highlights it according to the C++ language structure. So it does a pretty good job of understanding and highlighting the code in general, but it doesn't have any mechanism for defining custom keywords to be highlighted in some special way.

Although the custom keyword system of Arduino IDE 1.x might seem like a useful feature at a glance, in practice I'm not sure it was in the end.

One problem is that the library authors are very inconsistent in defining keywords. Some library authors defined keywords comprehensively and correctly. Other library authors defined some keywords, but forgot to keep the keywords.txt file updated as new API elements were added to the library. Some library authors made an attempt to define the keywords, but didn't format the keywords.txt file correctly, so the IDE didn't recognize them. Some library authors didn't bother with keywords at all.

Another problem was that Arduino IDE 1.x's handling of these keywords is very crude. All keywords of all installed libraries were highlighted, regardless of whether the library was used in the sketch or if the specific occurrence of the keyword was actually a refence to the library code.

So between these two things, once you had a decent collection of libraries installed you would find the highlighting of your code was very patchy, with missing highlighting in some places and unexpected highlighting in other places.

I think the whole manual keywords definition system was created at a time when the IDE was not sophisticated enough to understand the code at all, meaning that automated syntax highlighting was not possible.

1 Like

Thank you @ptillisch. I appreciate the info.

Would the VS Code documentation be a good place to look for the current settings? I'm a little unclear on how it treats structs and a couple of other things.

I would start by looking around in the repository of the syntax highlighting system:

1 Like

Awesome, thank you!!!

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.