summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-01 19:30:55 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-01 19:30:55 -0500
commit01bfdf98e4475e13e7b4bb8b8fbd382fa836986e (patch)
treedcf687f1bc64e726b1a3675312ec0f98dd373c19 /buffer.c
parentb376a87775d10dc7a693c0e1ecbe59e867e4634a (diff)
switched syntax highlighting to use a number for the state (will be useful later)
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/buffer.c b/buffer.c
index fa16c20..a672bdf 100644
--- a/buffer.c
+++ b/buffer.c
@@ -2006,9 +2006,14 @@ void buffer_render(TextBuffer *buffer, Rect r) {
Language language = buffer_language(buffer);
// dynamic array of character types, to be filled by syntax_highlight
SyntaxCharType *char_types = NULL;
- for (u32 line_idx = 0; line_idx < start_line; ++line_idx) {
- Line *line = &lines[line_idx];
- syntax_highlight(&syntax_state, language, line->str, line->len, NULL);
+ bool syntax_highlighting = language && settings->syntax_highlighting;
+ if (syntax_highlighting) {
+ for (u32 line_idx = 0; line_idx < start_line; ++line_idx) {
+ Line *line = &lines[line_idx];
+ syntax_highlight(&syntax_state, language, line->str, line->len, NULL);
+ }
+ } else {
+ gl_color_rgba(colors[COLOR_TEXT]);
}
for (u32 line_idx = start_line; line_idx < nlines; ++line_idx) {
@@ -2016,12 +2021,14 @@ void buffer_render(TextBuffer *buffer, Rect r) {
if (arr_len(char_types) < line->len) {
arr_set_len(char_types, line->len);
}
- syntax_highlight(&syntax_state, language, line->str, line->len, char_types);
+ if (language)
+ syntax_highlight(&syntax_state, language, line->str, line->len, char_types);
for (u32 i = 0; i < line->len; ++i) {
char32_t c = line->str[i];
- SyntaxCharType type = char_types[i];
-
- gl_color_rgba(colors[syntax_char_type_to_color(type)]);
+ if (syntax_highlighting) {
+ SyntaxCharType type = char_types[i];
+ gl_color_rgba(colors[syntax_char_type_to_color(type)]);
+ }
switch (c) {
case '\n': assert(0); break;
case '\r': break; // for CRLF line endings