Skip to content

Commit

Permalink
Highlight keywords
Browse files Browse the repository at this point in the history
Signed-off-by: Delwin Perera <perera@mm.tu-darmstadt.de>
  • Loading branch information
perdel committed Nov 8, 2024
1 parent 1a60132 commit 00e844e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions kilo.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ void editorUpdateSyntax(erow *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;

Expand Down Expand Up @@ -291,6 +293,26 @@ void editorUpdateSyntax(erow *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++;
}
Expand Down

0 comments on commit 00e844e

Please sign in to comment.