-
Notifications
You must be signed in to change notification settings - Fork 34
Modules
Modules are used to add new features to the editor without messing with the core code base. Modules must be in the source code when being compiled, but in the future may be able to add after the initial install.
Syntax highlighting was the first module. It was adapted from the existing kilo syntax highlighting by separating it out of the core editor and into an easily augment-able system where users can add their own language highlighting easily.
The syntax highlighting code base is located in modules/syntax/
.
The main structure for highlighting is the editor_syntax struct in modules/syntax/editor_syntax.h
.
struct editor_syntax {
char **filematch;
char **keywords;
char singleline_comment_start[2];
char multiline_comment_start[3];
char multiline_comment_end[3];
int flags;
};
filematch
is a pointer to a char array containing the file extensions for a specific language e.g. {".c", ".cpp", ".h", NULL};
for C/C++ files.
keywords
is a pointer to a char array containing keywords for a language. Currently there are only two available colour options for keywords but more will be added soon.
The next three items in the struct are for commenting.
And flags
is for string and number highlighting.
To add syntax highlighting for a new language please create a folder in the modules/syntax/
directory with the name of the language and in their place a header file of the same name e.g. modules/syntax/mylang/mylang.h
.
All language header files need to #include "../editor_syntax.h"
so they can use the structure to contain all of the individual highlighting parts (keywords, extensions etc.).
The two available colours are chosen either by "keyword"
or "keyword|"
. The trailing |
is recognized when the buffer is being parsed and then the word is given a different colour. In future more colours will be added by adding more trailing symbols.
For reference on how to construct a syntax highlighting module see the C/C++ implementation
Then just #include "mylang/mylang.h"
in the syntax.h
file and add the name of your language struct to the highlight_db
array.
To change the colour of the highlighting, look at the editor_syntax_to_colour
function in bric.c
.
Git integration is planned for the future.