]> git.mdlowis.com Git - projs/tide.git/commitdiff
functioning comment highlighting for C, ruby, and shell
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 9 Jun 2017 16:25:05 +0000 (12:25 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 9 Jun 2017 16:25:05 +0000 (12:25 -0400)
TODO.md
lib/colors.c
lib/view.c

diff --git a/TODO.md b/TODO.md
index f014f895319e4d81ce9fac6b86756a605cb1e67b..bd4443fcde01b20da1991b879fce89c8930d2322 100644 (file)
--- 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
index 072847b77927c8d63e46da9226085e0c4cade5cc..5f77de03b594999d0df77960abc161600b438f8e 100644 (file)
@@ -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;
     }
index 1e9d17de32ca4a63616a81f6ef0d1bdc9e044cd4..ee1e91d973d9fee5199cf03194ccaccee9fc32c3 100644 (file)
@@ -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++;
         }
     }