qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs bufed.c clang.c extra-modes.c htmlsrc.c ...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs bufed.c clang.c extra-modes.c htmlsrc.c ...
Date: Mon, 24 Mar 2014 10:58:11 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/03/24 10:58:11

Modified files:
        .              : bufed.c clang.c extra-modes.c htmlsrc.c 
                         latex-mode.c lisp.c makemode.c markdown.c 
                         orgmode.c perl.c qe.c qe.h script.c xml.c 

Log message:
        improve c-mode, add mode_flags to handle language mode flavors
        
        * add mode_flags and mode_name in EditState
        * pass mode_flags to ColorizeFuncs
        * define several CLANG mode flavors for C, C++, Javascript, Java, etc.
        * add flavor specific keyword lists for c-mode
        * add regex support in c-mode for Javascript flavor

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/bufed.c?cvsroot=qemacs&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.51&r2=1.52
http://cvs.savannah.gnu.org/viewcvs/qemacs/extra-modes.c?cvsroot=qemacs&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/qemacs/htmlsrc.c?cvsroot=qemacs&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/qemacs/lisp.c?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/makemode.c?cvsroot=qemacs&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/qemacs/markdown.c?cvsroot=qemacs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/qemacs/orgmode.c?cvsroot=qemacs&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/qemacs/perl.c?cvsroot=qemacs&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.161&r2=1.162
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.157&r2=1.158
http://cvs.savannah.gnu.org/viewcvs/qemacs/script.c?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/xml.c?cvsroot=qemacs&r1=1.15&r2=1.16

Patches:
Index: bufed.c
===================================================================
RCS file: /sources/qemacs/qemacs/bufed.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- bufed.c     11 Mar 2014 19:36:00 -0000      1.27
+++ bufed.c     24 Mar 2014 10:58:09 -0000      1.28
@@ -103,8 +103,8 @@
                 mode_name = "none";
                 for (e = qs->first_window; e != NULL; e = e->next_window) {
                     if (e->b == b1) {
-                        if (e->mode) {
-                            mode_name = e->mode->name;
+                        if (e->mode_name) {
+                            mode_name = e->mode_name;
                             break;
                         }
                     }

Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- clang.c     23 Mar 2014 01:11:34 -0000      1.51
+++ clang.c     24 Mar 2014 10:58:09 -0000      1.52
@@ -21,41 +21,51 @@
 
 #include "qe.h"
 
-#if 0
-static const char cc_keywords[] =
+static const char cc_keywords[] = {
     "asm|catch|class|delete|friend|inline|new|operator|"
-    "private|protected|public|template|try|this|virtual|throw|";
+    "private|protected|public|template|try|this|virtual|throw|"
+};
 
-static const char java_keywords[] =
-    "abstract|boolean|byte|catch|class|extends|false|final|"
-    "finally|function|implements|import|in|instanceof|"
-    "interface|native|new|null|package|private|protected|"
-    "public|super|synchronized|this|throw|throws|transient|"
-    "true|try|var|with|";
-#endif
+static const char js_keywords[] = {
+    "break|continue|delete|else|for|function|if|in|new|return|"
+    "this|typeof|var|void|while|with|case|catch|class|const|"
+    "debugger|default|do|enum|export|extends|finally|import|super|"
+    "switch|throw|try|undefined|null|true|false|"
+};
 
-static const char *c_mode_keywords =
+static const char java_keywords[] = {
+    "abstract|boolean|break|byte|case|catch|class|const|continue|"
+    "default|do|alse|extends|false|final|finally|for|function|"
+    "if|implements|import|in|instanceof|interface|native|new|null|"
+    "package|private|protected|public|return|"
+    "static|super|switch|synchronized|"
+    "this|throw|throws|transient|true|try|var|while|with|"
+};
+
+static const char c_keywords[] = {
     "auto|break|case|const|continue|default|do|else|enum|extern|for|goto|"
     "if|inline|register|restrict|return|sizeof|static|struct|switch|"
-    "typedef|union|volatile|while|";
+    "typedef|union|volatile|while|"
+};
 
 /* NOTE: 'var' is added for javascript */
-static const char *c_mode_types =
+static const char c_mode_types[] = {
     "char|double|float|int|long|unsigned|short|signed|void|var|"
-    "_Bool|_Complex|_Imaginary|";
+    "_Bool|_Complex|_Imaginary|"
+};
 
-static const char c_mode_extensions[] =
+static const char c_mode_extensions[] = {
     "c|h|C|H|"          /* C language */
     "y|l|lex|"          /* yacc, lex */
     "cc|hh|cpp|hpp|cxx|hxx|CPP|CC|c++|"   /* C++ */
     "m|"                /* Objective-C */
-    "e|qe|cs|idl|"
+    "e|qe|cs|idl|st|"
     "jav|java|js|json|" /* Java, Javascript, JSon */
     "ec|ecp|"           /* Informix embedded C */
     "pgc|"              /* Postgres embedded C */
     "pcc|"              /* Oracle C++ */
     "cal"               /* GNU Calc */
-    ;
+};
 
 /* grab a C identifier from a uchar buf, stripping color.
  * return char count.
@@ -86,19 +96,23 @@
     C_STRING     = 4,   /* double quoted string spanning multiple lines */
     C_STRING_Q   = 8,   /* single quoted string spanning multiple lines */
     C_PREPROCESS = 16,  /* preprocessor directive with \ at EOL */
+    C_REGEX      = 32,  /* regex with \ at EOL */
 };
 
-void c_colorize_line(unsigned int *buf, int len,
+void c_colorize_line(unsigned int *str, int n, int mode_flags,
                      int *colorize_state_ptr, __unused__ int state_only)
 {
-    int c, state, style, style1, type_decl, klen, delim;
+    int i = 0, j = i, indent, c, state, style, style1, type_decl, klen, delim;
     unsigned int *p, *p_start, *p_end, *p1, *p2;
     char kbuf[32];
 
+    for (indent = 0; qe_isspace(str[indent]); indent++)
+        continue;
+
     state = *colorize_state_ptr;
-    p = buf;
+    p = str;
     p_start = p;
-    p_end = p + len;
+    p_end = p + n;
     type_decl = 0;
 
     if (p >= p_end)
@@ -119,6 +133,8 @@
             goto parse_string;
         if (state & C_STRING_Q)
             goto parse_string_q;
+        if (state & C_REGEX)
+            goto parse_regex;
     }
 
     while (p < p_end) {
@@ -152,6 +168,44 @@
                 set_color(p_start, p, QE_STYLE_COMMENT);
                 goto the_end;
             }
+            i = p - str - 1;
+            if ((mode_flags & CLANG_REGEX)
+            &&  (i == indent
+            ||   (str[i + 1] != ' ' && str[i + 1] != '='
+            &&    !qe_isalnum(str[i - 1] & CHAR_MASK)
+            &&    str[i - 1] != ')'))) {
+                /* XXX: should use mode context to tell regex from divide */
+                /* parse regex */
+                j = i + 1;
+                state = C_REGEX;
+            parse_regex:
+                while (j < n) {
+                    /* XXX: should ignore / inside char classes */
+                    c = str[j++];
+                    if (c == '\\') {
+                        if (j < n) {
+                            j += 1;
+                        }
+                    } else
+                    if (c == '#' && str[j] == '{') {
+                        /* should parse full syntax */
+                        while (j < n && str[j++] != '}')
+                            continue;
+                    } else
+                    if (c == '/') {
+                        while (qe_findchar("ensuimox", str[j])) {
+                            j++;
+                        }
+                        state = 0;
+                        break;
+                    }
+                }
+#define QE_STYLE_REGEX  QE_STYLE_STRING_Q
+                SET_COLOR(str, i, j, QE_STYLE_REGEX);
+                i = j;
+                p = str + i;
+                continue;
+            }
             break;
         case '#':       /* preprocessor */
             state = C_PREPROCESS;
@@ -231,7 +285,11 @@
                 } while (qe_isalnum_(c));
                 kbuf[klen] = '\0';
 
-                if (strfind(c_mode_keywords, kbuf)) {
+                if (((mode_flags & (CLANG_C|CLANG_CPP|CLANG_OBJC)) && 
strfind(c_keywords, kbuf))
+                ||  ((mode_flags & CLANG_CPP) && strfind(cc_keywords, kbuf))
+                ||  ((mode_flags & CLANG_JS) && strfind(js_keywords, kbuf))
+                ||  ((mode_flags & CLANG_JAVA) && strfind(java_keywords, kbuf))
+                   ) {
                     set_color(p_start, p, QE_STYLE_KEYWORD);
                     continue;
                 }
@@ -254,18 +312,18 @@
                     continue;
                 }
 
-                if (*p == '(') {
+                if (*p == '(' || (p[0] == ' ' && p[1] == '(')) {
                     /* function call */
                     /* XXX: different styles for call and definition */
                     set_color(p_start, p, QE_STYLE_FUNCTION);
                     continue;
                 }
                 /* assume typedef if starting at first column */
-                if (p_start == buf)
+                if (p_start == str)
                     type_decl = 1;
 
                 if (type_decl) {
-                    if (p_start == buf) {
+                    if (p_start == str) {
                         /* assume type if first column */
                         set_color(p_start, p, QE_STYLE_TYPE);
                     } else {
@@ -280,7 +338,7 @@
     }
  the_end:
     /* strip state if not overflowing from a comment */
-    if (!(state & C_COMMENT) && p > buf && ((p[-1] & CHAR_MASK) != '\\'))
+    if (!(state & C_COMMENT) && p > str && ((p[-1] & CHAR_MASK) != '\\'))
         state &= ~(C_COMMENT1 | C_PREPROCESS);
     *colorize_state_ptr = state;
 }
@@ -793,6 +851,45 @@
     return 1;
 }
 
+static int c_mode_init(EditState *s, ModeSavedData *saved_data)
+{
+    text_mode.mode_init(s, saved_data);
+
+    /* Select C like flavor */
+    if (match_extension(s->b->filename, "c|h|C|H")) {
+        s->mode_flags = CLANG_C;
+    } else
+    if (match_extension(s->b->filename, "cc|hh|cpp|hpp|cxx|hxx|CPP|CC|c++")) {
+        s->mode_name = "CPP";
+        s->mode_flags = CLANG_CPP;
+    } else
+    if (match_extension(s->b->filename, "m")) {
+        s->mode_name = "ObjC";
+        s->mode_flags = CLANG_OBJC;
+    } else
+    if (match_extension(s->b->filename, "js|json")) {
+        s->mode_name = "Javascript";
+        s->mode_flags = CLANG_JS | CLANG_REGEX;
+    } else
+    if (match_extension(s->b->filename, "st")) {
+        s->mode_name = "Syntax";
+        s->mode_flags = CLANG_C | CLANG_REGEX;
+    } else
+    if (match_extension(s->b->filename, "jav|java")) {
+        s->mode_name = "Java";
+        s->mode_flags = CLANG_JAVA;
+    } else
+    if (match_extension(s->b->filename, "l|lex")) {
+        s->mode_name = "Lex";
+        s->mode_flags = CLANG_C | CLANG_LEX;
+    } else
+    if (match_extension(s->b->filename, "y")) {
+        s->mode_name = "Yacc";
+        s->mode_flags = CLANG_C | CLANG_YACC;
+    }
+    return 0;
+}
+
 /* C mode specific commands */
 static CmdDef c_commands[] = {
     CMD2( KEY_CTRL('i'), KEY_NONE,
@@ -822,6 +919,7 @@
     c_mode.name = "C";
     c_mode.extensions = c_mode_extensions;
     c_mode.mode_probe = c_mode_probe;
+    c_mode.mode_init = c_mode_init;
     c_mode.colorize_func = c_colorize_line;
     c_mode.indent_func = c_indent_line;
 

Index: extra-modes.c
===================================================================
RCS file: /sources/qemacs/qemacs/extra-modes.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- extra-modes.c       16 Mar 2014 00:34:29 -0000      1.9
+++ extra-modes.c       24 Mar 2014 10:58:09 -0000      1.10
@@ -79,8 +79,8 @@
     ASM_IDENTIFIER =  QE_STYLE_VARIABLE,
 };
 
-static void asm_colorize_line(unsigned int *str, int n, int *statep,
-                              __unused__ int state_only)
+static void asm_colorize_line(unsigned int *str, int n, int mode_flags,
+                              int *statep, __unused__ int state_only)
 {
     int i = 0, j, w;
     int wn = 0; /* word number on line */
@@ -246,8 +246,8 @@
     BASIC_IDENTIFIER =  QE_STYLE_VARIABLE,
 };
 
-static void basic_colorize_line(unsigned int *str, int n, int *statep,
-                                __unused__ int state_only)
+static void basic_colorize_line(unsigned int *str, int n, int mode_flags,
+                                int *statep, __unused__ int state_only)
 {
     int i = 0, j;
 
@@ -367,8 +367,8 @@
     PAS_FUNCTION =    QE_STYLE_FUNCTION,
 };
 
-static void pascal_colorize_line(unsigned int *str, int n, int *statep,
-                                 __unused__ int state_only)
+static void pascal_colorize_line(unsigned int *str, int n, int mode_flags,
+                                 int *statep, __unused__ int state_only)
 {
     int i = 0, j = i, k;
     int colstate =  *statep;
@@ -545,8 +545,8 @@
     INI_PREPROCESS =  QE_STYLE_PREPROCESS,
 };
 
-static void ini_colorize_line(unsigned int *str, int n, int *statep,
-                              __unused__ int state_only)
+static void ini_colorize_line(unsigned int *str, int n, int mode_flags,
+                              int *statep, __unused__ int state_only)
 {
     int i = 0, j;
     int bol = 1;
@@ -694,8 +694,8 @@
 #define ispssep(c)      (qe_findchar(" \t\r\n,()<>[]{}/", c))
 #define wrap 0
 
-static void ps_colorize_line(unsigned int *str, int n, int *statep,
-                             __unused__ int state_only)
+static void ps_colorize_line(unsigned int *str, int n, int mode_flags,
+                             int *statep, __unused__ int state_only)
 {
     int i = 0, j;
     int colstate = *statep;
@@ -783,6 +783,9 @@
     if (match_extension(p->filename, mode->extensions))
         return 80;
 
+    if (*p->buf == '%' && qe_stristr((const char *)p->buf, "script"))
+        return 40;
+
     return 1;
 }
 
@@ -819,8 +822,8 @@
     SQL_PREPROCESS =   QE_STYLE_PREPROCESS,
 };
 
-static void sql_colorize_line(unsigned int *str, int n, int *statep,
-                              __unused__ int state_only)
+static void sql_colorize_line(unsigned int *str, int n, int mode_flags,
+                              int *statep, __unused__ int state_only)
 {
     int i = 0, j = i;
     int state = *statep;
@@ -963,8 +966,8 @@
     }
 }
 
-void lua_colorize_line(unsigned int *str, int n, int *statep,
-                       __unused__ int state_only)
+void lua_colorize_line(unsigned int *str, int n, int mode_flags,
+                       int *statep, __unused__ int state_only)
 {
     int i = 0, j = i, c, sep = 0, level = 0, level1, klen, style;
     int state = *statep;
@@ -1152,8 +1155,8 @@
     return qe_findchar("!#$%&+./<=>address@hidden|-~:", c);
 }
 
-void haskell_colorize_line(unsigned int *str, int n, int *statep,
-                           __unused__ int state_only)
+void haskell_colorize_line(unsigned int *str, int n, int mode_flags,
+                           int *statep, __unused__ int state_only)
 {
     int i = 0, j = i, c, sep = 0, level = 0, klen;
     int state = *statep;
@@ -1386,8 +1389,8 @@
     PYTHON_FUNCTION =     QE_STYLE_FUNCTION,
 };
 
-void python_colorize_line(unsigned int *str, int n, int *statep,
-                           __unused__ int state_only)
+void python_colorize_line(unsigned int *str, int n, int mode_flags,
+                          int *statep, __unused__ int state_only)
 {
     int i = 0, j = i, c, sep = 0, klen;
     int state = *statep;
@@ -1672,8 +1675,8 @@
     return j - i;
 }
 
-void ruby_colorize_line(unsigned int *str, int n, int *statep,
-                        __unused__ int state_only)
+void ruby_colorize_line(unsigned int *str, int n, int mode_flags,
+                        int *statep, __unused__ int state_only)
 {
     int i = 0, j = i, c, indent, sig;
     static int sep, sep0, level;        /* XXX: ugly patch */

Index: htmlsrc.c
===================================================================
RCS file: /sources/qemacs/qemacs/htmlsrc.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- htmlsrc.c   6 Mar 2014 20:36:50 -0000       1.10
+++ htmlsrc.c   24 Mar 2014 10:58:10 -0000      1.11
@@ -66,7 +66,7 @@
     HTML_SCRIPT    = 0x80,      /* <SCRIPT> [...] </SCRIPT> */
 };
 
-void htmlsrc_colorize_line(unsigned int *buf, int len,
+void htmlsrc_colorize_line(unsigned int *buf, int len, int mode_flags,
                            int *colorize_state_ptr, int state_only)
 {
     int c, state, js_state, l;
@@ -107,7 +107,8 @@
             c = *p;     /* save char to set '\0' delimiter */
             *p = '\0';
             /* XXX: should have javascript specific colorize_func */
-            c_colorize_line(p_start, p - p_start, &js_state, state_only);
+            c_colorize_line(p_start, p - p_start, CLANG_JS | CLANG_REGEX,
+                            &js_state, state_only);
             *p = c;
             state = js_state | HTML_SCRIPT;
             if (p < p_end) {

Index: latex-mode.c
===================================================================
RCS file: /sources/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- latex-mode.c        18 Mar 2014 08:20:05 -0000      1.43
+++ latex-mode.c        24 Mar 2014 10:58:10 -0000      1.44
@@ -26,6 +26,7 @@
  * than one line (eg, multi-line functions and strings)
  */
 static void latex_colorize_line(unsigned int *buf, __unused__ int len,
+                                __unused__ int mode_flags,
                                 int *colorize_state_ptr,
                                 __unused__ int state_only)
 {

Index: lisp.c
===================================================================
RCS file: /sources/qemacs/qemacs/lisp.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- lisp.c      10 Mar 2014 22:11:24 -0000      1.7
+++ lisp.c      24 Mar 2014 10:58:10 -0000      1.8
@@ -31,8 +31,8 @@
 #define LISP_COMMENT    QE_STYLE_COMMENT
 #define LISP_STRING     QE_STYLE_STRING
 
-static void lisp_colorize_line(unsigned int *str, int n, int *statep,
-                               __unused__ int state_only)
+static void lisp_colorize_line(unsigned int *str, int n, int mode_flags,
+                               int *statep, __unused__ int state_only)
 {
     int colstate = *statep;
     int i = 0, j = 0;

Index: makemode.c
===================================================================
RCS file: /sources/qemacs/qemacs/makemode.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- makemode.c  13 Mar 2014 07:59:31 -0000      1.13
+++ makemode.c  24 Mar 2014 10:58:10 -0000      1.14
@@ -30,8 +30,8 @@
 #define MAKEFILE_VARIABLE       QE_STYLE_VARIABLE
 #define MAKEFILE_MACRO          QE_STYLE_TYPE
 
-static void makefile_colorize_line(unsigned int *str, int n, int *statep,
-                                   int state_only)
+static void makefile_colorize_line(unsigned int *str, int n, int mode_flags,
+                                   int *statep, int state_only)
 {
     int i, j, level;
 

Index: markdown.c
===================================================================
RCS file: /sources/qemacs/qemacs/markdown.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- markdown.c  21 Mar 2014 20:49:30 -0000      1.8
+++ markdown.c  24 Mar 2014 10:58:10 -0000      1.9
@@ -102,8 +102,8 @@
     return 0;
 }
 
-static void mkd_colorize_line(unsigned int *str, int n, int *statep,
-                              __unused__ int state_only)
+static void mkd_colorize_line(unsigned int *str, int n, int mode_flags,
+                              int *statep, __unused__ int state_only)
 {
     int colstate = *statep;
     int level, indent, i = 0, j = 0, base_style = 0;
@@ -117,7 +117,7 @@
     ||  (str[i] == '<' && str[i + 1] != '/')) {
         /* block level HTML markup */
         colstate &= ~IN_HTML_BLOCK;
-        htmlsrc_colorize_line(str, n, &colstate, state_only);
+        htmlsrc_colorize_line(str, n, 0, &colstate, state_only);
         colstate |= IN_HTML_BLOCK;
         if ((str[i] & CHAR_MASK) == '<' && (str[i + 1] & CHAR_MASK) == '/')
             colstate = 0;
@@ -137,19 +137,19 @@
             colstate &= ~(IN_BLOCK | IN_LANG);
             switch (lang) {
             case IN_C:
-                c_colorize_line(str, n, &colstate, state_only);
+                c_colorize_line(str, n, CLANG_C, &colstate, state_only);
                 break;
             case IN_PYTHON:
-                python_colorize_line(str, n, &colstate, state_only);
+                python_colorize_line(str, n, 0, &colstate, state_only);
                 break;
             case IN_RUBY:
-                ruby_colorize_line(str, n, &colstate, state_only);
+                ruby_colorize_line(str, n, 0, &colstate, state_only);
                 break;
             case IN_HASKELL:
-                haskell_colorize_line(str, n, &colstate, state_only);
+                haskell_colorize_line(str, n, 0, &colstate, state_only);
                 break;
             case IN_LUA:
-                lua_colorize_line(str, n, &colstate, state_only);
+                lua_colorize_line(str, n, 0, &colstate, state_only);
                 break;
             default:
                 SET_COLOR(str, i, n, QE_STYLE_MKD_CODE);

Index: orgmode.c
===================================================================
RCS file: /sources/qemacs/qemacs/orgmode.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- orgmode.c   21 Mar 2014 20:49:30 -0000      1.16
+++ orgmode.c   24 Mar 2014 10:58:10 -0000      1.17
@@ -84,8 +84,8 @@
     return 0;
 }
 
-static void org_colorize_line(unsigned int *str, int n, int *statep,
-                              __unused__ int state_only)
+static void org_colorize_line(unsigned int *str, int n, int mode_flags,
+                              int *statep, __unused__ int state_only)
 {
     int colstate = *statep;
     int i = 0, j = 0, kw, base_style = 0, has_space;
@@ -98,7 +98,7 @@
         } else {
             if (colstate & IN_LISP) {
                 colstate &= ~(IN_LISP | IN_BLOCK);
-                lisp_mode.colorize_func(str, n, &colstate, state_only);
+                lisp_mode.colorize_func(str, n, 0, &colstate, state_only);
                 colstate |= IN_LISP | IN_BLOCK;
             }
             *statep = colstate;

Index: perl.c
===================================================================
RCS file: /sources/qemacs/qemacs/perl.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- perl.c      10 Mar 2014 22:11:24 -0000      1.14
+++ perl.c      24 Mar 2014 10:58:10 -0000      1.15
@@ -100,8 +100,8 @@
     return j;
 }
 
-static void perl_colorize_line(unsigned int *str, int n, int *statep,
-                               __unused__ int state_only)
+static void perl_colorize_line(unsigned int *str, int n, int mode_flags,
+                               int *statep, __unused__ int state_only)
 {
     int i = 0, c, c1, c2, j = i, s1, s2, delim = 0;
     int colstate = *statep;

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.161
retrieving revision 1.162
diff -u -b -r1.161 -r1.162
--- qe.c        21 Mar 2014 20:49:30 -0000      1.161
+++ qe.c        24 Mar 2014 10:58:10 -0000      1.162
@@ -1805,6 +1805,8 @@
                 m = &text_mode;
         }
         s->mode = m;
+        s->mode_name = m->name;
+        s->mode_flags = 0;
 
         /* init mode */
         m->mode_init(s, saved_data);
@@ -2183,7 +2185,7 @@
 
     buf_printf(out, "%c%c:%c%c  %-20s  (%s",
                c1, state, s->b->flags & BF_READONLY ? '%' : mod,
-               mod, s->b->name, s->mode->name);
+               mod, s->b->name, s->mode_name);
     if (!s->insert)
         buf_printf(out, " Ovwrt");
     if (s->interactive)
@@ -3293,7 +3295,8 @@
         for (l = s->colorize_nb_valid_lines; l <= line_num; l++) {
             len = eb_get_line(s->b, buf, buf_size, &offset);
             bom = (len > 0 && buf[0] == 0xFEFF);
-            s->colorize_func(buf + bom, len - bom, &colorize_state, 1);
+            s->colorize_func(buf + bom, len - bom, s->mode_flags,
+                             &colorize_state, 1);
             s->colorize_states[l] = colorize_state;
         }
     }
@@ -3302,7 +3305,7 @@
     colorize_state = s->colorize_states[line_num];
     len = eb_get_line(s->b, buf, buf_size, offsetp);
     bom = (len > 0 && buf[0] == 0xFEFF);
-    s->colorize_func(buf + bom, len - bom, &colorize_state, 0);
+    s->colorize_func(buf + bom, len - bom, s->mode_flags, &colorize_state, 0);
 
     /* XXX: if state is same as previous, minimize invalid region? */
     s->colorize_states[line_num + 1] = colorize_state;

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.157
retrieving revision 1.158
diff -u -b -r1.157 -r1.158
--- qe.h        24 Mar 2014 09:38:15 -0000      1.157
+++ qe.h        24 Mar 2014 10:58:10 -0000      1.158
@@ -1045,7 +1045,7 @@
 /* colorize a line: this function modifies buf to set the char
  * styles. 'buf' is guaranted to have one more '\0' char after its len.
  */
-typedef void (*ColorizeFunc)(unsigned int *buf, int len,
+typedef void (*ColorizeFunc)(unsigned int *buf, int len, int mode_flags,
                              int *colorize_state_ptr, int state_only);
 
 /* contains all the information necessary to uniquely identify a line,
@@ -1114,6 +1114,8 @@
     /* maximum valid offset, INT_MAX if not modified. Needed to invalide
        'colorize_states' */
     int colorize_max_valid_offset;
+    int mode_flags;            /* local mode flags for flavors */
+    const char *mode_name;     /* name for mode flavor */
 
     int busy; /* true if editing cannot be done if the window
                  (e.g. the parser HTML is parsing the buffer to
@@ -1932,7 +1934,16 @@
 
 /* c_mode.c */
 
-void c_colorize_line(unsigned int *buf, int len,
+#define CLANG_C      0x01
+#define CLANG_CPP    0x02
+#define CLANG_OBJC   0x04
+#define CLANG_JS     0x08
+#define CLANG_JAVA   0x10
+#define CLANG_LEX    0x20
+#define CLANG_YACC   0x40
+#define CLANG_REGEX  0x80
+
+void c_colorize_line(unsigned int *buf, int len, int mode_flags,
                      int *colorize_state_ptr, int state_only);
 
 /* xml.c */
@@ -1941,7 +1952,7 @@
 
 /* htmlsrc.c */
 
-void htmlsrc_colorize_line(unsigned int *buf, int len,
+void htmlsrc_colorize_line(unsigned int *buf, int len, int mode_flags,
                            int *colorize_state_ptr, int state_only);
 
 /* html.c */
@@ -1954,13 +1965,13 @@
 
 /* extra-modes.c */
 
-void lua_colorize_line(unsigned int *buf, int len,
+void lua_colorize_line(unsigned int *buf, int len, int mode_flags,
                        int *colorize_state_ptr, int state_only);
-void haskell_colorize_line(unsigned int *buf, int len,
+void haskell_colorize_line(unsigned int *buf, int len, int mode_flags,
                            int *colorize_state_ptr, int state_only);
-void python_colorize_line(unsigned int *buf, int len,
+void python_colorize_line(unsigned int *buf, int len, int mode_flags,
                           int *colorize_state_ptr, int state_only);
-void ruby_colorize_line(unsigned int *buf, int len,
+void ruby_colorize_line(unsigned int *buf, int len, int mode_flags,
                         int *colorize_state_ptr, int state_only);
 
 /* image.c */

Index: script.c
===================================================================
RCS file: /sources/qemacs/qemacs/script.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- script.c    10 Mar 2014 22:11:24 -0000      1.6
+++ script.c    24 Mar 2014 10:58:10 -0000      1.7
@@ -42,8 +42,8 @@
     return j;
 }
 
-static void script_colorize_line(unsigned int *str, int n, int *statep,
-                                 __unused__ int state_only)
+static void script_colorize_line(unsigned int *str, int n, int mode_flags,
+                                 int *statep, __unused__ int state_only)
 {
     int i = 0, j, style;
 

Index: xml.c
===================================================================
RCS file: /sources/qemacs/qemacs/xml.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- xml.c       10 Feb 2014 03:24:35 -0000      1.15
+++ xml.c       24 Mar 2014 10:58:10 -0000      1.16
@@ -30,7 +30,7 @@
     XML_SCRIPT = 0x80, /* special mode for inside a script, ored with c mode */
 };
 
-static void xml_colorize_line(unsigned int *buf, int len,
+static void xml_colorize_line(unsigned int *buf, int len, int mode_flags,
                               int *colorize_state_ptr, int state_only)
 {
     int c, state;
@@ -112,7 +112,8 @@
                         if (*p == '\0') {
                             state &= ~XML_SCRIPT;
                             /* XXX: should have javascript specific 
colorize_func */
-                            c_colorize_line(p_start, p - p_start, &state, 
state_only);
+                            c_colorize_line(p_start, p - p_start,
+                                CLANG_C | CLANG_REGEX, &state, state_only);
                             state |= XML_SCRIPT;
                             break;
                         } else
@@ -125,7 +126,8 @@
                             c = *p;
                             *p = '\0';
                             /* XXX: should have javascript specific 
colorize_func */
-                            c_colorize_line(p_start, p - p_start, &state, 
state_only);
+                            c_colorize_line(p_start, p - p_start,
+                                CLANG_C | CLANG_REGEX, &state, state_only);
                             *p = c;
                             state |= XML_SCRIPT;
                             set_color(p, p1, QE_STYLE_TAG);



reply via email to

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