diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9c8b867 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "termios.h": "c" + } +} \ No newline at end of file diff --git a/editor b/editor index 5be2e09..dc4b773 100755 Binary files a/editor and b/editor differ diff --git a/editor.c b/editor.c index 1b1511e..7cd6b4f 100644 --- a/editor.c +++ b/editor.c @@ -44,7 +44,9 @@ enum editorHighlight { HL_COMMENT, HL_STRING, HL_NUMBER, - HL_MATCH + HL_MATCH, + HL_KEYWORD1, + HL_KEYWORD2 }; /*** data ***/ @@ -54,6 +56,7 @@ struct editorSyntax { char **filematch; int flags; char *singleline_comment_start; // single comment line pattern for this language + char **keywords; }; typedef struct editorrow { @@ -85,12 +88,20 @@ struct editorConfig { /*** filetypes ***/ char *C_HL_extensions[] = { ".c", ".h", ".cpp", NULL }; +char *C_HL_keywords[] = { + "switch", "if", "while", "for", "break", "continue", "return", "else", + "struct", "union", "typedef", "static", "enum", "class", "case", + "int|", "long|", "double|", "float|", "char|", "unsigned|", "signed|", + "void|", "define", "include", NULL +}; + struct editorSyntax HLDB[] = { { "c", C_HL_extensions, HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS, - "//" + "//", + C_HL_keywords }, }; @@ -253,6 +264,8 @@ void editorUpdateSyntax(editorrow *row) { if (E.syntax == NULL) return; + char **keywords = E.syntax->keywords; + char *scs = E.syntax->singleline_comment_start; int scs_len = scs ? strlen(scs) : 0; @@ -306,6 +319,25 @@ void editorUpdateSyntax(editorrow *row) { } } + if (prev_sep) { + int j; + for (j = 0; keywords[j]; j++) { + int klen = strlen(keywords[j]); + int kw2 = keywords[j][klen - 1] == '|'; + if (kw2) klen--; + if (!strncmp(&row->render[i], keywords[j], klen) && + is_separator(row->render[i + klen])) { + memset(&row->hl[i], kw2 ? HL_KEYWORD2 : HL_KEYWORD1, klen); + i += klen; + break; + } + } + if (keywords[j] != NULL) { + prev_sep = 0; + continue; + } + } + prev_sep = is_separator(c); i++; } @@ -316,10 +348,14 @@ int editorSyntaxToColor(int hl) { case HL_NUMBER: return 32; case HL_MATCH: // search query match - return 31; + return 91; case HL_STRING: return 33; case HL_COMMENT: + return 92; + case HL_KEYWORD1: + return 31; + case HL_KEYWORD2: return 34; default: return 37;