Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ style CLI.

Kilo was written by Salvatore Sanfilippo aka antirez and is released
under the BSD 2 clause license.

# TODO

* Testing and stability to reach "usable" level.
* Improve internals to be more understandable.

### Maybe

* Send alternate screen sequences if TERM=xterm: "\033[?1049h" and "\033[?1049l"
10 changes: 0 additions & 10 deletions TODO

This file was deleted.

42 changes: 4 additions & 38 deletions kilo.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,50 +152,16 @@ void editorSetStatusMessage(const char *fmt, ...);
* a trailing '|' character is added at the end, they are highlighted in
* a different color, so that you can have two different sets of keywords.
*
* Finally add a stanza in the HLDB global variable with two two arrays
* of strings, and a set of flags in order to enable highlighting of
* comments and numbers.
* Finally add the new syntax to the list of syntaxs in the HLBD struct
* found in `./languages/languages.c`, and a set of flags in order
* to enable highlighting of comments and numbers.
*
* The characters for single and multi line comments must be exactly two
* and must be provided as well (see the C language example).
*
* There is no support to highlight patterns currently. */

/* C / C++ */
char *C_HL_extensions[] = {".c",".h",".cpp",".hpp",".cc",NULL};
char *C_HL_keywords[] = {
/* C Keywords */
"auto","break","case","continue","default","do","else","enum",
"extern","for","goto","if","register","return","sizeof","static",
"struct","switch","typedef","union","volatile","while","NULL",

/* C++ Keywords */
"alignas","alignof","and","and_eq","asm","bitand","bitor","class",
"compl","constexpr","const_cast","deltype","delete","dynamic_cast",
"explicit","export","false","friend","inline","mutable","namespace",
"new","noexcept","not","not_eq","nullptr","operator","or","or_eq",
"private","protected","public","reinterpret_cast","static_assert",
"static_cast","template","this","thread_local","throw","true","try",
"typeid","typename","virtual","xor","xor_eq",

/* C types */
"int|","long|","double|","float|","char|","unsigned|","signed|",
"void|","short|","auto|","const|","bool|",NULL
};

/* Here we define an array of syntax highlights by extensions, keywords,
* comments delimiters and flags. */
struct editorSyntax HLDB[] = {
{
/* C / C++ */
C_HL_extensions,
C_HL_keywords,
"//","/*","*/",
HL_HIGHLIGHT_STRINGS | HL_HIGHLIGHT_NUMBERS
}
};

#define HLDB_ENTRIES (sizeof(HLDB)/sizeof(HLDB[0]))
#include "languages/languages.c"

/* ======================= Low level terminal handling ====================== */

Expand Down
24 changes: 24 additions & 0 deletions languages/c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
char *C_HL_extensions[];
char *C_HL_keywords[];
const struct editorSyntax syntax_c = {
C_HL_extensions,
C_HL_keywords,
"//","/*","*/",
HL_HIGHLIGHT_STRINGS | HL_HIGHLIGHT_NUMBERS
};

char *C_HL_extensions[] = {".c",".h",NULL};
char *C_HL_keywords[] = {
/* Preprocessor Keywords */
"#define", "#include", "#pragma", "#undef",
"#if", "#ifdef", "#ifndef", "#else", "#elif", "#endif", "#error",

/* C Keywords */
"auto","break","case","continue","default","do","else","enum",
"extern","for","goto","if","register","return","sizeof","static",
"struct","switch","typedef","union","volatile","while","NULL",

/* C types */
"int|","long|","double|","float|","char|","unsigned|","signed|",
"void|","short|","auto|","const|","bool|",NULL
};
34 changes: 34 additions & 0 deletions languages/cpp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

char *CPP_HL_extensions[];
char *CPP_HL_keywords[];
const struct editorSyntax syntax_cpp = {
CPP_HL_extensions,
CPP_HL_keywords,
"//","/*","*/",
HL_HIGHLIGHT_STRINGS | HL_HIGHLIGHT_NUMBERS
};

char *CPP_HL_extensions[] = {".cpp",".hpp",".cc",NULL};
char *CPP_HL_keywords[] = {
/* Preprocessor Keywords */
"#define", "#include", "#pragma", "#undef",
"#if", "#ifdef", "#ifndef", "#else", "#elif", "#endif", "#error",

/* C Keywords */
"auto","break","case","continue","default","do","else","enum",
"extern","for","goto","if","register","return","sizeof","static",
"struct","switch","typedef","union","volatile","while","NULL",

/* C++ Keywords */
"alignas","alignof","and","and_eq","asm","bitand","bitor","class",
"compl","constexpr","const_cast","deltype","delete","dynamic_cast",
"explicit","export","false","friend","inline","mutable","namespace",
"new","noexcept","not","not_eq","nullptr","operator","or","or_eq",
"private","protected","public","reinterpret_cast","static_assert",
"static_cast","template","this","thread_local","throw","true","try",
"typeid","typename","virtual","xor","xor_eq",

/* C types */
"int|","long|","double|","float|","char|","unsigned|","signed|",
"void|","short|","auto|","const|","bool|",NULL
};
17 changes: 17 additions & 0 deletions languages/languages.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Separating out the syntaxes like this should make it much easier to add more later,
* and makes this portion of the code much easier to read, taking almost a hundred
* lines of code out of the main program logic, bringing it a little closer to the
* goal of being "less than 1000 SLOC"
*/

#include "c.h"
#include "cpp.h"

struct editorSyntax HLDB[] = {

syntax_c,
syntax_cpp

};
#define HLDB_ENTRIES (sizeof(HLDB)/sizeof(HLDB[0]))