From 00e844e85925756f8fdc5c33f3b837765e66bbe7 Mon Sep 17 00:00:00 2001 From: Delwin Perera Date: Fri, 8 Nov 2024 23:00:48 +0100 Subject: [PATCH] Highlight keywords Signed-off-by: Delwin Perera --- kilo.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/kilo.c b/kilo.c index a0393a2..e0cf1a7 100644 --- a/kilo.c +++ b/kilo.c @@ -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; @@ -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++; }