4coder»Forums
David
2 posts
Semidynamic custom keywords
Edited by David on Reason: Initial post
Hi everyone!
My name is David and I just got 4coder yesterday and I'm loving it so far.
For me this is the first time that I'm using an editor that is not Visual Studio (with Visual Assist), so I'm still a bit shaky when programming.
One feature that I'm missing quite a bit is that my own classes, structs and typedefs are highlighted (like primitive data types).
After reading this: link I got the idea to write a small script that would scan a project for classes, structs and typedefs and then spit out a header file with the
1
{ make_stafl( "u8", CPP_TOKEN_KEY_TYPE ) },
lines.

So far so good, but now that I have my "custom_keywords.h" file I am not sure what exactly to do with it.
Do I have to get it to the 4Coder folder and compile it with the "buildsuper.bat" or is there a way to keep the file local to the project?

-David
Allen Webster
476 posts / 6 projects
Heyo
Semidynamic custom keywords
Edited by Allen Webster on
Hi David!

If you've already followed the instructions in the link you posted, you have your own customization layer separated out from the 4coder default custom layer code. In order to use your new keywords you're going to need to implement your own version of the file_settings hook found in 4coder_default_hooks.cpp. Obviously your life would be easier if I supported an API like:

1
2
3
4
Keyword_Table table = join_keyword_tables(cpp_keyword_table, my_keyword_table);
Parse_Context ctx = register_keyword_table(table);
set_extension_ctx("cpp", ctx);
set_extension_ctx("h", ctx);


However I just don't have anything close to that convenient setup, so you're going to have to manually put all those pieces together.

1. When you generate your list of keywords from the parse, you'll need to manually copy the keywords from the default C++ (or whatever language) table and join them together into a single language file in your project.
2. You will need to implement a copy of the file settings hook that goes to your own language data when it detects the extensions you care about.
3. You will need to change 4coder to using your file start hook instead of the default file settings hook.

BUT! There's some good news. If you're only trying to make this work with C++ there's a little hack setup to avoid all that nonsense. Instead what you can do is inject your special keywords with just a single define.

In the table of C++ keywords I have the following bit of code:

1
2
3
4
#if defined(EXTRA_KEYWORDS)
#include EXTRA_KEYWORDS
#undef EXTRA_KEYWORDS
#endif


So if you generate a list that matches this format (and has nothing before or after it in the file):

1
2
3
PSAT("u8", CPP_TOKEN_KEY_TYPE),
PSAT("u16", CPP_TOKEN_KEY_TYPE),
PSAT("u32", CPP_TOKEN_KEY_TYPE),


Then you can define EXTRA_KEYWORDS to the name of that file before you include the default include and it will inject the contents of that file right into the C++ table. Then you don't have to do any joining work and the default hook will pick up your modifications automatically without you changing the hook.

Hope that is enough to get you there!
David
2 posts
Semidynamic custom keywords
Hey thanks for the quick reply.

I actually got it to work, although it is a little clunky.

If anyone wants to try it out, here is a link to the script: pastebin.

Disclaimer: I suck at python.

The script is written in python(3) and you would place it in the directory, where your code files are. When you run it, make sure to pass it the filepath to where you want your custom_keys.h file to be (+the filename). Note that this script overrides the custom keys file if it already exists, so use with caution. I have call this script from my projects build.bat, so after a compile 4Coder has the current project's types loaded.

If anyone has any suggestions, please tell me.

-David