qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs clang.c qe.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs clang.c qe.c
Date: Tue, 29 Apr 2014 22:29:56 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/04/29 22:29:56

Modified files:
        .              : clang.c qe.c 

Log message:
        improve c-mode
        
        * colorize *.mm files as Objective-C
        * fix forward/backward-block on special cases:
          colorize end of line in comments and preprocessor lines

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.166&r2=1.167

Patches:
Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- clang.c     18 Apr 2014 21:04:40 -0000      1.58
+++ clang.c     29 Apr 2014 22:29:56 -0000      1.59
@@ -106,7 +106,7 @@
     "c|h|C|H|"          /* C language */
     "y|l|lex|"          /* yacc, lex */
     "cc|hh|cpp|hpp|cxx|hxx|CPP|CC|c++|"   /* C++ */
-    "m|"                /* Objective-C */
+    "m|mm|"             /* Objective-C */
     "e|qe|cs|idl|st|"
     "jav|java|js|json|" /* Java, Javascript, JSon */
     "ec|ecp|"           /* Informix embedded C */
@@ -169,7 +169,7 @@
                      unsigned int *str, int n, int mode_flags)
 {
     int i = 0, start, i1, i2, indent;
-    int c, state, style, style1, type_decl, klen, delim;
+    int c, state, style, style0, style1, type_decl, klen, delim;
     char kbuf[32];
 
     for (indent = 0; qe_isspace(str[indent]); indent++)
@@ -183,12 +183,12 @@
         goto the_end;
 
     c = 0;      /* turn off stupid egcs-2.91.66 warning */
-    style = C_STYLE_DEFAULT;
+    style0 = style = C_STYLE_DEFAULT;
 
     if (state) {
         /* if already in a state, go directly in the code parsing it */
         if (state & IN_C_PREPROCESS)
-            style = C_STYLE_PREPROCESS;
+            style0 = style = C_STYLE_PREPROCESS;
         if (state & IN_C_COMMENT)
             goto parse_comment;
         if (state & IN_C_COMMENT1)
@@ -213,11 +213,13 @@
                 /* normal comment */
                 i++;
             parse_comment:
+                style = C_STYLE_COMMENT;
                 state |= IN_C_COMMENT;
                 for (; i < n; i++) {
                     if (str[i] == '*' && str[i + 1] == '/') {
                         i += 2;
                         state &= ~IN_C_COMMENT;
+                        style = style0;
                         break;
                     }
                 }
@@ -227,6 +229,7 @@
             if (str[i] == '/') {
                 /* line comment */
             parse_comment1:
+                style = C_STYLE_COMMENT;
                 state |= IN_C_COMMENT1;
                 i = n;
                 SET_COLOR(str, start, i, C_STYLE_COMMENT);
@@ -241,6 +244,7 @@
                 /* parse regex */
                 state = IN_C_REGEX;
             parse_regex:
+                style = C_STYLE_REGEX;
                 while (i < n) {
                     c = str[i++];
                     if (c == '\\') {
@@ -262,6 +266,7 @@
                                 i++;
                             }
                             state = 0;
+                            style = style0;
                             break;
                         }
                     }
@@ -273,7 +278,7 @@
         case '#':       /* preprocessor */
             if (mode_flags & (CLANG_C | CLANG_CPP | CLANG_OBJC)) {
                 state = IN_C_PREPROCESS;
-                style = C_STYLE_PREPROCESS;
+                style = style0 = C_STYLE_PREPROCESS;
             }
             if (mode_flags & CLANG_PHP) {
                 goto parse_comment1;
@@ -323,6 +328,7 @@
             style1 = C_STYLE_STRING;
             delim = '\"';
         string:
+            style = style1;
             while (i < n) {
                 c = str[i++];
                 if (c == '\\') {
@@ -332,6 +338,7 @@
                 } else
                 if (c == delim) {
                     state &= ~(IN_C_STRING | IN_C_STRING_Q | IN_C_STRING_BQ);
+                    style = style0;
                     break;
                 }
             }
@@ -434,6 +441,12 @@
         SET_COLOR1(str, start, style);
     }
  the_end:
+    if (state & (IN_C_COMMENT | IN_C_COMMENT1 | IN_C_PREPROCESS | 
+                 IN_C_STRING | IN_C_STRING_Q | IN_C_STRING_BQ)) {
+        /* set style on eol char */
+        SET_COLOR1(str, n, style);
+    }
+
     /* strip state if not overflowing from a comment */
     if (!(state & IN_C_COMMENT) && n > 0 && ((str[n - 1] & CHAR_MASK) != '\\'))
         state &= ~(IN_C_COMMENT1 | IN_C_PREPROCESS);
@@ -965,7 +978,7 @@
         s->mode_name = "CPP";
         s->mode_flags = CLANG_CPP;
     } else
-    if (match_extension(s->b->filename, "m")) {
+    if (match_extension(s->b->filename, "m|mm")) {
         s->mode_name = "ObjC";
         s->mode_flags = CLANG_OBJC;
     } else

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.166
retrieving revision 1.167
diff -u -b -r1.166 -r1.167
--- qe.c        15 Apr 2014 07:58:49 -0000      1.166
+++ qe.c        29 Apr 2014 22:29:56 -0000      1.167
@@ -3278,7 +3278,7 @@
         s->colorize_max_valid_offset = INT_MAX;
     }
 
-    /* realloc line buffer if needed */
+    /* realloc state array if needed */
     if ((line_num + 2) > s->colorize_nb_lines) {
         s->colorize_nb_lines = line_num + 2 + COLORIZED_LINE_PREALLOC_SIZE;
         if (!qe_realloc(&s->colorize_states,
@@ -3301,9 +3301,12 @@
         cctx.state_only = 1;
 
         for (l = s->colorize_nb_valid_lines; l <= line_num; l++) {
-            len = eb_get_line(s->b, buf, buf_size, &offset);
+            len = eb_get_line(s->b, buf, buf_size - 1, &offset);
+            /* skip byte order mark if present */
             bom = (len > 0 && buf[0] == 0xFEFF);
             s->colorize_func(&cctx, buf + bom, len - bom, s->mode_flags);
+            /* buf[len] has char '\0' but may hold style, force buf ending */
+            buf[len + 1] = 0;
             s->colorize_states[l] = cctx.colorize_state;
         }
     }
@@ -3311,9 +3314,10 @@
     /* compute line color */
     cctx.colorize_state = s->colorize_states[line_num];
     cctx.state_only = 0;
-    len = eb_get_line(s->b, buf, buf_size, offsetp);
+    len = eb_get_line(s->b, buf, buf_size - 1, offsetp);
     bom = (len > 0 && buf[0] == 0xFEFF);
     s->colorize_func(&cctx, buf + bom, len - bom, s->mode_flags);
+    buf[len + 1] = 0;
 
     /* XXX: if state is same as previous, minimize invalid region? */
     s->colorize_states[line_num + 1] = cctx.colorize_state;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]