Keywords to a specific sketch

I have a rather large sketch which contains a bunch of macros and to keep overview (the macros are also for that) i wanted to light them, up in different colors. I first did that by adding them to a keywords.txt of a library that i anyway always include, but now i have just made a folder in the libraries folder with an empty header file and a keywords.txt file.

But what i would really want is them to be specific to a sketch. As far as i can tell all keywords are added to any library that is in the (sub) folder of the libraries folder(s)

Does anybody know of a way to do this ?

Hi @Deva_Rishi. Arduino IDE doesn't have support for defining keywords on a per-sketch basis.

I think the only way to accomplish that would be by adding the desired functionality to the Arduino IDE application. For Arduino IDE 1.x, you could investigate whether it is possible to accomplish using its "Tools" framework:

That approach would probably be superior to the alternative of modifying the source code of the Arduino IDE application and building the modified version yourself from source.


For Arduino IDE 2.x, you could instead investigate whether it is possible to accomplish through its equivalent VS Code extension framework. There are thousands of free open source VS Code extensions, so if you look around you might find that one already exists. This is a good place to look:

If you find something you want to give a try and would like instructions for installing it, just let us know and we'll provide assistance with that (it is a bit more complex to install an extension for Arduino IDE than it is when using VS Code).

If there isn't an existing extension, you might also be able to accomplish it via a custom extension. This information would likely be relevant to that endeavor:

It is a shame that you cannot have a keywords.txt file in the sketch directory that has precedence those in folders in the libraries folder

Totally with you on that one. The way it was organized in IDE 1.x results in many artifacts and lights up certain sections of code that make no sense at all.

That might be a bit beyond the scope of what i would want to do (with my time), but

Well i am not really using IDE 2.x as yet (due to a bug that has been reported already but not fixed as yet) But maybe it is something that could be added as an extra feature regardless, or if someone else would be interested in investigating more on the subject.

So i guess in short, the answer is "No unfortunately not !"

What bug would that be ?

Completely understandable.

It is interesting to think about possible ways to accomplish this, but unlikely it would be worth the effort that would be required for someone not already familiar with the "Tools" framework to actually do it.

The decision was made to not implement any support for custom keywords in Arduino IDE 2.x; not even the library and platform keywords system established in Arduino IDE 1.x. So the feature definitely won't be added by the Arduino company.

However, the VS Code extension framework is quite powerful and flexible so there is a good chance the community could add the capability without needing to touch the Arduino IDE codebase. And due to the popularity of VS Code, there is already an extension for pretty much any general (as opposed to Arduino-specific) feature you could possibly imagine.

The network ports for ESP8266 don't show up only the ESP32 ports do.

Well that is an avenue worth pursuing at some point in the future.

Thanks for the details

Actually that is quite unfortunate. On what was that decision based ? On the possibility to use the VS Code extension framework within the IDE ?

As end users there is always this complication where i may want certain features or am using certain features, but the people that make decisions have a different opinion on the way to move forward. This of course also happens with 3rd party core development.
In this case, it makes sense to not go on with the older system, though i admit that may also deter users from switching to the newer version IDE. In my case it might. IDE 1.8.19 works pretty well for what i want to do, and say the bug mentioned in #7 does eventually get fixed, i would still have to make a choice between having stuff light up in colors at times in a confusing way, or not having any keywords light up at all.

In the end i guess it is also what one wants to devote resources (time) to.

Essentially, yes. Arduino IDE 2.x uses the same syntax highlighting system as is used for C++ in VS Code:

So Arduino is able to leverage an existing high quality solution instead of having to dedicate finite resources to creating and maintaining something.

Keep in mind that Arduino IDE 2.x is a complete rewrite of the application, in a different language, not sharing even a single line of code with 1.x. So this wasn't a matter of deciding to remove an existing implementation, but rather a decision not to implement the feature again from scratch.

Arduino IDE does have syntax highlighting. It is only the ability for special highlighting to be applied to arbitrary keywords that is missing.

I understand that completely.

So eh what are the advantages again of the Arduino IDE :smiley: Why shouldn't we all just switch to VScode (or platfomio for that matter) altogether ?

Nou ja anyway, i am grateful you take the time to explain all this to me (us) and not completely unhappy with the workaround i have for a system which is a tad goofy to begin with (keywords of libraries did i haven't included lighting up .. ) I spend an hour trying to get the LITERAL1 to show up in blue, until i found a thread stating that only 1 TAB should be in between, which is aesthetically to the eye of any Libra of course.

VS Code by itself is only a very feature rich text editor. It is not an integrated development environment like Arduino IDE. You can turn it into an integrated development environment for a given language by installing extensions. So if you want to talk about VS Code as a true alternative to Arduino IDE you must talk about VS Code + a specific set of extensions.

Microsoft did create an "Arduino" VS Code extension. However, they have retired it. There are some 3rd party extensions that also allow VS Code to be used as an IDE for developing Arduino sketch projects. These are maintained as hobby projects.

As for the "PlatformIO IDE" VS Code extension, it is certainly a good option. However, it doesn't fully implement the Arduino sketch specification, so this doesn't provide a true Arduino sketch IDE. That isn't necessarily a bad thing, but it mention it because it means "Arduino IDE vs PlatformIO" isn't an "apples to apples" comparison.

Use of any of the VS Code-based options would result in a much steeper learning curve than Arduino IDE.

I don't have experience using the alternatives, but I'm doubtful whether any of them are going to provide keywords.txt support or discover the "network" protocol port of your ESP8266 board. So the better question might be "why would you switch"?

This idea that the keywords.txt file should be aesthetic is a common pitfall. The thing you must keep in mind is this is a delimiter-separated data file formatted this way in order to be readable by a machine. The tab character is the field delimiter, not something used to make the content pretty for humans.

I had never even looked into it.
CodeBlocks/WxWidgets is an IDE, but again it doesn't have the out of the box functionality.

I think there was an Arduino extension but unmaintained (or hardly), I did look into that, because CodeBlocks is great as an IDE, but i didn't actually managed to get it going properly. IDE 1.x is not bad and i guess i am just used to working with it. Still trying to understand part of it.

Anyway as before, i cant really use IDE 2.x for now, so i can't really judge or comment on it.

I can't comment on the utility of VS Code as an Arduino sketch development IDE because I don't have any meaningful experience using it with those extensions. However, it is very much worth a look as a general purpose text editor or an IDE for PC applications in various programming languages. I use VS Code constantly for those purposes and it is excellent.

The software developer community is in agreement on this subject as VS Code has been the world's most popular development editor/IDE for the last eight years. If you avoid using "M$" products, there is a fully open source distribution maintained by 3rd parties named VSCodium.

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