Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
added ability for 2nd keyword in syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
MorganPeterson committed Jan 13, 2022
1 parent 66691df commit bf53bc9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
25 changes: 13 additions & 12 deletions src/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ typedef enum {
} buffer_flags_t;

enum {
HL_NORMAL = 1,
HL_SYMBOL,
HL_COMMENT,
HL_MLCOMMENT,
HL_KEYWORD,
HL_SINGLE_QUOTE,
HL_DOUBLE_QUOTE,
HL_NUMBER,
HL_MATCH,
HL_MODELINE,
HL_BACKGROUND,
HL_FOREGROUND,
HL_NORMAL = 1,
HL_SYMBOL,
HL_COMMENT,
HL_MLCOMMENT,
HL_KEYWORD,
HL_KEYWORD2,
HL_SINGLE_QUOTE,
HL_DOUBLE_QUOTE,
HL_NUMBER,
HL_MATCH,
HL_MODELINE,
HL_BACKGROUND,
HL_FOREGROUND,
};

typedef enum {
Expand Down
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,3 @@ fatal(char *msg) {
fprintf(stderr, msg, "editor");
exit(1);
}

10 changes: 6 additions & 4 deletions src/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ char *C_HL_keywords[] = {
"struct", "union", "typedef", "static", "enum", "class", "case", "NULL",
"int|", "int32_t|", "int8_t|", "int64_t|", "long|", "double|", "float|",
"char|", "unsigned|", "signed|", "void|", "#include|", "#define|", "auto",
"const", "short|", "defualt", "register", "sizeof|", "volatile|", "goto|",
"const", "short|", "default", "register", "sizeof|", "volatile|", "goto|",
"do", "extern", NULL };

char *JS_HL_keywords[] = {
Expand Down Expand Up @@ -87,7 +87,7 @@ static char_t symbols[] = "{}[]()";
static int32_t
is_separator(int c)
{
return isspace(c) || c == '\0' || strchr(",.()+-/*=~%<>[];", c) != NULL;
return isspace(c) || c == '\0' || strchr(",.()+-/*=~%<>[];:{}", c) != NULL;
}

int32_t
Expand Down Expand Up @@ -127,7 +127,7 @@ parse_text(buffer_t *b, int32_t p)
if (now == NULL)
return state;

if (state == HL_KEYWORD && is_separator(*now)) {
if ((state == HL_KEYWORD || state == HL_KEYWORD2) && is_separator(*now)) {
next_state = state = HL_NORMAL;
}

Expand Down Expand Up @@ -210,7 +210,9 @@ parse_text(buffer_t *b, int32_t p)
if (kw2)
klen--;
if (!strncmp((char*)now, kyw[j], klen) && is_separator(*(now + klen))) {
return (next_state = HL_KEYWORD);
if (kw2)
return (next_state = HL_KEYWORD);
return (next_state = HL_KEYWORD2);
}
}
}
Expand Down
25 changes: 13 additions & 12 deletions src/themes.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ enum {

color_t colors[] = {
{"white", 255, "#EEEEEEE"},
{"offwhite", 252, "#d0d0d0"},
{"offwhite", 252, "#d0d0d0"},
{"darkred", 124, "#AF0000"},
{"green", 28, "#008700"},
{"green", 28, "#008700"},
{"olive", 64, "#5F8700"},
{"brightblue", 31, "#0087AF"},
{"darkgrey", 102, "#878787"},
Expand All @@ -43,15 +43,16 @@ color_t colors[] = {
void
init_colors(void)
{
init_pair(HL_BACKGROUND, colors[BRIGHTBLUE].eightbit, colors[WHITE].eightbit);
init_pair(HL_NORMAL, colors[BLACK].eightbit, colors[WHITE].eightbit);
init_pair(HL_SYMBOL, colors[DARKBLUE].eightbit, colors[WHITE].eightbit);
init_pair(HL_NUMBER, colors[ORANGE].eightbit, colors[WHITE].eightbit);
init_pair(HL_DOUBLE_QUOTE, colors[OLIVE].eightbit, colors[WHITE].eightbit);
init_pair(HL_SINGLE_QUOTE, colors[GREEN].eightbit, colors[WHITE].eightbit);
init_pair(HL_COMMENT, colors[DARKGREY].eightbit, colors[WHITE].eightbit);
init_pair(HL_MLCOMMENT, colors[DARKGREY].eightbit, colors[WHITE].eightbit);
init_pair(HL_MODELINE, colors[NAVY].eightbit, colors[OFFWHITE].eightbit);
init_pair(HL_KEYWORD, colors[PINK].eightbit, colors[WHITE].eightbit);
init_pair(HL_BACKGROUND, colors[BRIGHTBLUE].eightbit, colors[WHITE].eightbit);
init_pair(HL_NORMAL, colors[BLACK].eightbit, colors[WHITE].eightbit);
init_pair(HL_SYMBOL, colors[DARKBLUE].eightbit, colors[WHITE].eightbit);
init_pair(HL_NUMBER, colors[ORANGE].eightbit, colors[WHITE].eightbit);
init_pair(HL_DOUBLE_QUOTE, colors[OLIVE].eightbit, colors[WHITE].eightbit);
init_pair(HL_SINGLE_QUOTE, colors[GREEN].eightbit, colors[WHITE].eightbit);
init_pair(HL_COMMENT, colors[DARKGREY].eightbit, colors[WHITE].eightbit);
init_pair(HL_MLCOMMENT, colors[DARKGREY].eightbit, colors[WHITE].eightbit);
init_pair(HL_MODELINE, colors[NAVY].eightbit, colors[OFFWHITE].eightbit);
init_pair(HL_KEYWORD, colors[PINK].eightbit, colors[WHITE].eightbit);
init_pair(HL_KEYWORD2, colors[DARKRED].eightbit, colors[WHITE].eightbit);
}

0 comments on commit bf53bc9

Please sign in to comment.