From: Michael D. Lowis Date: Fri, 9 Jun 2017 16:25:05 +0000 (-0400) Subject: functioning comment highlighting for C, ruby, and shell X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=3291f5016537585274ac70c83904899e5bd35aea;p=projs%2Ftide.git functioning comment highlighting for C, ruby, and shell --- diff --git a/TODO.md b/TODO.md index f014f89..bd4443f 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,11 @@ Up Next: +* highlight strings and characters +* highlight classes of identifiers +* higlight current line in gutter +* ^A shortcut should set implicit mark + * move by words is inconsistent. Example: var infoId = 'readerinfo'+reader.id; * Add a way to CD using a builtin (buffers will track original dir) @@ -11,7 +16,6 @@ Up Next: The Future: -* Syntax highlighting * Case insensitive search * Ctrl+Up,Down requires two undos to revert. * Ctrl+Up,Down with non line selection should track column diff --git a/lib/colors.c b/lib/colors.c index 072847b..5f77de0 100644 --- a/lib/colors.c +++ b/lib/colors.c @@ -76,7 +76,7 @@ SyntaxSpan* colors_scan(SyntaxDef* syntax, Buf* buf) { else if (matches(buf, &off, syntax->comments.multi_beg)) for (; off < end && !matches(buf, &off, syntax->comments.multi_end); off++); if (start != off) - spans = mkspan(start, ++off, CLR_Comment, spans); + spans = mkspan(start, --off, CLR_Comment, spans); if (!firstspan && spans) firstspan = spans; } diff --git a/lib/view.c b/lib/view.c index 1e9d17d..ee1e91d 100644 --- a/lib/view.c +++ b/lib/view.c @@ -107,18 +107,20 @@ void view_update(View* view, size_t* csrx, size_t* csry) { SyntaxSpan* curr = view->spans; for (size_t r = 0; curr && r < view->nrows; r++) { Row* row = view->rows[r]; - for (; curr && curr->end < row->off; curr = curr->next); - if (curr) { - size_t off = row->off, col = 0; - while (col < row->len) { - if (curr->beg <= off && off < curr->end && !(row->cols[col].attr & 0xFF00)) { - uint32_t attr = row->cols[col].attr; - row->cols[col].attr = (row->cols[col].attr & 0xFF00) | curr->color; - } - off++, col++; - while (col < row->len && row->cols[col].rune == '\0') - col++; + size_t off = row->off, col = 0; + while (col < row->len) { + /* skip irrelevant highlight regions */ + for (; curr && curr->end < off; curr = curr->next); + if (!curr) { r = -1; break; } // Break both loops if we're done + + /* check if we're in the current region */ + if (curr->beg <= off && off <= curr->end && !(row->cols[col].attr & 0xFF00)) { + uint32_t attr = row->cols[col].attr; + row->cols[col].attr = (row->cols[col].attr & 0xFF00) | curr->color; } + off++, col++; + while (col < row->len && row->cols[col].rune == '\0') + col++; } }