qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs bufed.c extra-modes.c lisp.c orgmode.c q...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs bufed.c extra-modes.c lisp.c orgmode.c q...
Date: Fri, 30 May 2014 17:18:15 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/05/30 17:18:15

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

Log message:
        improve syntax colorizing modes consistency
        
        * create separate modes for all syntax colorizers
        * add colorizing_flags to mode structure for code sharing
        * pass ModeDef struct pointer to colorizing function
        * remove obsolete window fields

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/bufed.c?cvsroot=qemacs&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/qemacs/extra-modes.c?cvsroot=qemacs&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/qemacs/lisp.c?cvsroot=qemacs&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/qemacs/orgmode.c?cvsroot=qemacs&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.177&r2=1.178
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.72&r2=1.73
http://cvs.savannah.gnu.org/viewcvs/qemacs/htmlsrc.c?cvsroot=qemacs&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/qemacs/makemode.c?cvsroot=qemacs&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/qemacs/perl.c?cvsroot=qemacs&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/qemacs/script.c?cvsroot=qemacs&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.48&r2=1.49
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/qemacs/markdown.c?cvsroot=qemacs&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.178&r2=1.179
http://cvs.savannah.gnu.org/viewcvs/qemacs/xml.c?cvsroot=qemacs&r1=1.22&r2=1.23

Patches:
Index: bufed.c
===================================================================
RCS file: /sources/qemacs/qemacs/bufed.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- bufed.c     29 May 2014 18:29:14 -0000      1.32
+++ bufed.c     30 May 2014 17:18:12 -0000      1.33
@@ -99,17 +99,7 @@
             if (b1->default_mode) {
                 mode_name = b1->default_mode->name;
             } else {
-                EditState *e;
-
                 mode_name = "none";
-                for (e = qs->first_window; e != NULL; e = e->next_window) {
-                    if (e->b == b1) {
-                        if (e->mode_name) {
-                            mode_name = e->mode_name;
-                            break;
-                        }
-                    }
-                }
             }
 
             eb_printf(b, " %10d %c %-8s %-8s %s",

Index: extra-modes.c
===================================================================
RCS file: /sources/qemacs/qemacs/extra-modes.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- extra-modes.c       29 May 2014 18:29:15 -0000      1.25
+++ extra-modes.c       30 May 2014 17:18:13 -0000      1.26
@@ -81,7 +81,7 @@
 };
 
 static void asm_colorize_line(QEColorizeContext *cp,
-                              unsigned int *str, int n, int mode_flags)
+                              unsigned int *str, int n, ModeDef *syn)
 {
     char keyword[MAX_KEYWORD_SIZE];
     int i = 0, start = 0, c, w, len, wn = 0; /* word number on line */
@@ -228,7 +228,7 @@
 };
 
 static void basic_colorize_line(QEColorizeContext *cp,
-                                unsigned int *str, int n, int mode_flags)
+                                unsigned int *str, int n, ModeDef *syn)
 {
     char keyword[MAX_KEYWORD_SIZE];
     int i = 0, start, c, style, len;
@@ -279,11 +279,11 @@
                 }
             }
             keyword[len] = '\0';
-            if (strfind(basic_keywords, keyword)) {
+            if (syn && syn->keywords && strfind(syn->keywords, keyword)) {
                 SET_COLOR(str, start, i, BASIC_STYLE_KEYWORD);
                 continue;
             }
-            if (strfind(basic_types, keyword)) {
+            if (syn && syn->types && strfind(syn->types, keyword)) {
                 SET_COLOR(str, start, i, BASIC_STYLE_TYPE);
                 continue;
             }
@@ -296,6 +296,8 @@
 static ModeDef basic_mode = {
     .name = "Basic",
     .extensions = "bas|frm|mst|vb|vbs",
+    .keywords = basic_keywords,
+    .types = basic_types,
     .colorize_func = basic_colorize_line,
 };
 
@@ -388,7 +390,7 @@
 }
 
 static void vim_colorize_line(QEColorizeContext *cp,
-                              unsigned int *str, int n, int mode_flags)
+                              unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, j, start, c, state, comm, level, style;
 
@@ -593,7 +595,7 @@
 };
 
 static void pascal_colorize_line(QEColorizeContext *cp,
-                                 unsigned int *str, int n, int mode_flags)
+                                 unsigned int *str, int n, ModeDef *syn)
 {
     char keyword[MAX_KEYWORD_SIZE];
     int i = 0, start = i, c, k, style, len;
@@ -701,11 +703,11 @@
                     keyword[len++] = qe_tolower(str[i]);
             }
             keyword[len] = '\0';
-            if (strfind(pascal_keywords, keyword)) {
+            if (syn && syn->keywords && strfind(syn->keywords, keyword)) {
                 SET_COLOR(str, start, i, PASCAL_STYLE_KEYWORD);
                 continue;
             }
-            if (strfind(pascal_types, keyword)) {
+            if (syn && syn->types && strfind(syn->types, keyword)) {
                 SET_COLOR(str, start, i, PASCAL_STYLE_TYPE);
                 continue;
             }
@@ -725,6 +727,8 @@
 static ModeDef pascal_mode = {
     .name = "Pascal",
     .extensions = "pas",
+    .keywords = pascal_keywords,
+    .types = pascal_types,
     .colorize_func = pascal_colorize_line,
 };
 
@@ -748,7 +752,7 @@
 };
 
 static void ini_colorize_line(QEColorizeContext *cp,
-                              unsigned int *str, int n, int mode_flags)
+                              unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start, c, bol = 1;
 
@@ -873,7 +877,7 @@
 };
 
 static void sharp_colorize_line(QEColorizeContext *cp,
-                               unsigned int *str, int n, int mode_flags)
+                               unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start, c;
 
@@ -937,7 +941,7 @@
 #define wrap 0
 
 static void ps_colorize_line(QEColorizeContext *cp,
-                             unsigned int *str, int n, int mode_flags)
+                             unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start = i, c;
     int colstate = cp->colorize_state;
@@ -1056,7 +1060,7 @@
 };
 
 static void sql_colorize_line(QEColorizeContext *cp,
-                              unsigned int *str, int n, int mode_flags)
+                              unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start = i, c, style;
     int state = cp->colorize_state;
@@ -1182,8 +1186,8 @@
     }
 }
 
-void lua_colorize_line(QEColorizeContext *cp,
-                       unsigned int *str, int n, int mode_flags)
+static void lua_colorize_line(QEColorizeContext *cp,
+                              unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start = i, c, sep = 0, level = 0, level1, klen, style;
     int state = cp->colorize_state;
@@ -1302,7 +1306,7 @@
     cp->colorize_state = state;
 }
 
-static ModeDef lua_mode = {
+ModeDef lua_mode = {
     .name = "Lua",
     .extensions = "lua",
     .colorize_func = lua_colorize_line,
@@ -1447,7 +1451,7 @@
 }
 
 static void julia_colorize_line(QEColorizeContext *cp,
-                                unsigned int *str, int n, int mode_flags)
+                                unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start = i, c, sep = 0, klen;
     int state = cp->colorize_state;
@@ -1610,8 +1614,8 @@
     return qe_findchar("!#$%&+./<=>address@hidden|-~:", c);
 }
 
-void haskell_colorize_line(QEColorizeContext *cp,
-                           unsigned int *str, int n, int mode_flags)
+static void haskell_colorize_line(QEColorizeContext *cp,
+                                  unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start = i, c, sep = 0, level = 0, klen;
     int state = cp->colorize_state;
@@ -1775,7 +1779,7 @@
     cp->colorize_state = state;
 }
 
-static ModeDef haskell_mode = {
+ModeDef haskell_mode = {
     .name = "Haskell",
     .extensions = "hs|haskell",
     .colorize_func = haskell_colorize_line,
@@ -1816,8 +1820,8 @@
     PYTHON_STYLE_FUNCTION = QE_STYLE_FUNCTION,
 };
 
-void python_colorize_line(QEColorizeContext *cp,
-                          unsigned int *str, int n, int mode_flags)
+static void python_colorize_line(QEColorizeContext *cp,
+                                 unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start = i, c, sep = 0, klen;
     int state = cp->colorize_state;
@@ -1993,7 +1997,7 @@
     cp->colorize_state = state;
 }
 
-static ModeDef python_mode = {
+ModeDef python_mode = {
     .name = "Python",
     .extensions = "py|pyt",
     .colorize_func = python_colorize_line,
@@ -2073,8 +2077,8 @@
     return j - i;
 }
 
-void ruby_colorize_line(QEColorizeContext *cp,
-                        unsigned int *str, int n, int mode_flags)
+static void ruby_colorize_line(QEColorizeContext *cp,
+                               unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, j, start = i, c, indent, sig, style;
     static int sep, sep0, level;        /* XXX: ugly patch */
@@ -2471,7 +2475,7 @@
     return 1;
 }
 
-static ModeDef ruby_mode = {
+ModeDef ruby_mode = {
     .name = "Ruby",
     .extensions = "rb|gemspec",
     .mode_probe = ruby_mode_probe,
@@ -2523,7 +2527,7 @@
 };
 
 static void ocaml_colorize_line(QEColorizeContext *cp,
-                                 unsigned int *str, int n, int mode_flags)
+                                 unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start = i, c, k, style;
     int colstate = cp->colorize_state;

Index: lisp.c
===================================================================
RCS file: /sources/qemacs/qemacs/lisp.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- lisp.c      29 May 2014 18:29:15 -0000      1.16
+++ lisp.c      30 May 2014 17:18:13 -0000      1.17
@@ -22,6 +22,7 @@
 
 /* TODO: lisp-indent = 2 */
 
+#define LISP_LANG_LISP    1
 #define LISP_LANG_ELISP   2
 #define LISP_LANG_SCHEME  4
 #define LISP_LANG_RACKET  8
@@ -118,10 +119,13 @@
 }
 
 static void lisp_colorize_line(QEColorizeContext *cp,
-                               unsigned int *str, int n, int mode_flags)
+                               unsigned int *str, int n, ModeDef *syn)
 {
     int colstate = cp->colorize_state;
     int i = 0, start = i, len, level, style, has_expr;
+    int mode_flags = syn ? syn->colorize_flags : 0;
+    const char *keywords = syn && syn->keywords ? syn->keywords : 
lisp_keywords;
+    const char *types = syn && syn->types ? syn->types : lisp_types;
     char kbuf[32];
 
     level = colstate & IN_LISP_LEVEL;
@@ -311,11 +315,11 @@
                     SET_COLOR(str, start, i, LISP_STYLE_NUMBER);
                     continue;
                 }
-                if (strfind(lisp_keywords, kbuf)) {
+                if (strfind(keywords, kbuf)) {
                     SET_COLOR(str, start, i, LISP_STYLE_KEYWORD);
                     continue;
                 }
-                if (strfind(lisp_types, kbuf)) {
+                if (strfind(types, kbuf)) {
                     SET_COLOR(str, start, i, LISP_STYLE_TYPE);
                     continue;
                 }
@@ -338,7 +342,7 @@
     cp->colorize_state = colstate;
 }
 
-static int lisp_mode_probe(ModeDef *mode, ModeProbeData *mp)
+static int elisp_mode_probe(ModeDef *mode, ModeProbeData *mp)
 {
     /* check file name or extension */
     if (match_extension(mp->filename, mode->extensions)
@@ -348,36 +352,49 @@
     return 1;
 }
 
-static int lisp_mode_init(EditState *s)
-{
-    /* select lisp flavor */
-    if (match_extension(s->b->filename, "el")
-    ||  strstart(get_basename(s->b->filename), ".emacs", NULL)) {
-        s->mode_name = "ELisp";
-        s->mode_flags = LISP_LANG_ELISP;
-    } else
-    if (match_extension(s->b->filename, "scm|ss")) {
-        s->mode_name = "Scheme";
-        s->mode_flags = LISP_LANG_SCHEME;
-    } else
-    if (match_extension(s->b->filename, "rkt|rktd")) {
-        s->mode_name = "Racket";
-        s->mode_flags = LISP_LANG_RACKET;
-    }
-    return 0;
-}
-
 ModeDef lisp_mode = {
     .name = "Lisp",
-    .extensions = "ll|li|lh|lo|lm|lisp|el|scm|ss|rkt|rktd",
-    .mode_probe = lisp_mode_probe,
-    .mode_init = lisp_mode_init,
+    .extensions = "ll|li|lh|lo|lm|lisp",
+    .keywords = lisp_keywords,
+    .types = lisp_types,
+    .colorize_func = lisp_colorize_line,
+    .colorize_flags = LISP_LANG_LISP,
+};
+
+ModeDef elisp_mode = {
+    .name = "ELisp",
+    .extensions = "el",
+    .keywords = lisp_keywords,
+    .types = lisp_types,
+    .mode_probe = elisp_mode_probe,
+    .colorize_func = lisp_colorize_line,
+    .colorize_flags = LISP_LANG_ELISP,
+};
+
+ModeDef scheme_mode = {
+    .name = "Scheme",
+    .extensions = "scm|ss",
+    .keywords = lisp_keywords,
+    .types = lisp_types,
+    .colorize_func = lisp_colorize_line,
+    .colorize_flags = LISP_LANG_SCHEME,
+};
+
+ModeDef racket_mode = {
+    .name = "Racket",
+    .extensions = "rkt|rktd",
+    .keywords = lisp_keywords,
+    .types = lisp_types,
     .colorize_func = lisp_colorize_line,
+    .colorize_flags = LISP_LANG_RACKET,
 };
 
 static int lisp_init(void)
 {
     qe_register_mode(&lisp_mode, MODEF_SYNTAX);
+    qe_register_mode(&elisp_mode, MODEF_SYNTAX);
+    qe_register_mode(&scheme_mode, MODEF_SYNTAX);
+    qe_register_mode(&racket_mode, MODEF_SYNTAX);
 
     return 0;
 }

Index: orgmode.c
===================================================================
RCS file: /sources/qemacs/qemacs/orgmode.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- orgmode.c   29 May 2014 18:29:16 -0000      1.22
+++ orgmode.c   30 May 2014 17:18:13 -0000      1.23
@@ -100,7 +100,7 @@
 }
 
 static void org_colorize_line(QEColorizeContext *cp,
-                              unsigned int *str, int n, int mode_flags)
+                              unsigned int *str, int n, ModeDef *syn)
 {
     int colstate = cp->colorize_state;
     int i = 0, j = 0, kw, base_style = 0, has_space;
@@ -114,7 +114,7 @@
             if (colstate & IN_ORG_LISP) {
                 colstate &= ~(IN_ORG_LISP | IN_ORG_BLOCK);
                 cp->colorize_state = colstate;
-                lisp_mode.colorize_func(cp, str, n, 0);
+                lisp_mode.colorize_func(cp, str, n, &lisp_mode);
                 colstate = cp->colorize_state;
                 colstate |= IN_ORG_LISP | IN_ORG_BLOCK;
             }

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.177
retrieving revision 1.178
diff -u -b -r1.177 -r1.178
--- qe.h        29 May 2014 10:26:14 -0000      1.177
+++ qe.h        30 May 2014 17:18:13 -0000      1.178
@@ -756,7 +756,7 @@
  * styles. 'buf' is guaranted to have one more '\0' char after its len.
  */
 typedef void (*ColorizeFunc)(QEColorizeContext *cp,
-                             unsigned int *buf, int n, int mode_flags);
+                             unsigned int *buf, int n, ModeDef *syn);
 
 /* buffer.c */
 
@@ -1117,11 +1117,9 @@
                                   (list mode only) */
     /* low level colorization function */
     GetColorizedLineFunc get_colorized_line;
+    ColorizeFunc colorize_func; /* colorization function */
 
-    /* colorization function */
-    ColorizeFunc colorize_func;
-    /* default text style */
-    int default_style;
+    int default_style;  /* default text style */
 
     /* after this limit, the fields are not saved into the buffer */
     int end_of_saved_data;
@@ -1139,8 +1137,6 @@
     /* 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
@@ -1211,8 +1207,10 @@
 
 struct ModeDef {
     const char *name;
+    const char *mode_name;
     const char *extensions;
-    //const char *mode_line;
+    const char *keywords;
+    const char *types;
 
     int flags;
 #define MODEF_NOCMD      0x8000 /* do not register xxx-mode command 
automatically */
@@ -1238,6 +1236,8 @@
     int (*text_backward_offset)(EditState *, int);
 
     ColorizeFunc colorize_func;
+    int colorize_flags;
+    int auto_indent;
 
     /* common functions are defined here */
     /* TODO: Should have single move function with move type and argument */
@@ -1251,8 +1251,6 @@
     void (*write_char)(EditState *, int);
     void (*mouse_goto)(EditState *, int x, int y);
 
-    int auto_indent;
-
     EditBufferDataType *data_type; /* native buffer data type (NULL = raw) */
     void (*get_mode_line)(EditState *s, buf_t *out);
     void (*indent_func)(EditState *s, int offset);
@@ -1964,75 +1962,20 @@
 
 void do_dired(EditState *s);
 
-/* clang.c */
-
-/* C mode flavors */
-enum {
-    CLANG_GENERIC,
-    CLANG_C,
-    CLANG_CPP,
-    CLANG_OBJC,
-    CLANG_CSHARP,
-    CLANG_CSS,
-    CLANG_JS,
-    CLANG_AS,
-    CLANG_JAVA,
-    CLANG_PHP,
-    CLANG_GO,
-    CLANG_D,
-    CLANG_LIMBO,
-    CLANG_CYCLONE,
-    CLANG_CH,
-    CLANG_SQUIRREL,
-    CLANG_ICI,
-    CLANG_JSX,
-    CLANG_HAXE,
-    CLANG_DART,
-    CLANG_PIKE,
-    CLANG_FLAVOR = 0x1F,
-};
-
-/* C mode options */
-#define CLANG_CC          0x0100  /* all C language features */
-#define CLANG_LEX         0x0200
-#define CLANG_YACC        0x0400
-#define CLANG_REGEX       0x0800
-
-void c_colorize_line(QEColorizeContext *cp,
-                     unsigned int *str, int n, int mode_flags);
-
-static inline void js_colorize_line(QEColorizeContext *cp,
-                                    unsigned int *str, int n, int mode_flags)
-{
-    c_colorize_line(cp, str, n, mode_flags | CLANG_JS | CLANG_REGEX);
-}
-
-static inline void php_colorize_line(QEColorizeContext *cp,
-                                     unsigned int *str, int n, int mode_flags)
-{
-    c_colorize_line(cp, str, n, mode_flags | CLANG_PHP | CLANG_REGEX);
-}
-
-static inline void csharp_colorize_line(QEColorizeContext *cp,
-                                        unsigned int *str, int n, int 
mode_flags)
-{
-    c_colorize_line(cp, str, n, mode_flags | CLANG_CSHARP);
-}
-
-static inline void css_colorize_line(QEColorizeContext *cp,
-                                     unsigned int *str, int n, int mode_flags)
-{
-    c_colorize_line(cp, str, n, mode_flags | CLANG_CSS);
-}
-
-/* xml.c */
+/* syntax colorizers */
 
+extern ModeDef c_mode;
+extern ModeDef cpp_mode;
+extern ModeDef js_mode;
+extern ModeDef php_mode;
+extern ModeDef csharp_mode;
+extern ModeDef css_mode;
 extern ModeDef xml_mode;
-
-/* htmlsrc.c */
-
-void htmlsrc_colorize_line(QEColorizeContext *cp,
-                           unsigned int *str, int n, int mode_flags);
+extern ModeDef htmlsrc_mode;
+extern ModeDef lua_mode;
+extern ModeDef haskell_mode;
+extern ModeDef python_mode;
+extern ModeDef ruby_mode;
 
 /* html.c */
 
@@ -2041,17 +1984,6 @@
 int gxml_mode_init(EditState *s,
                    int is_html, const char *default_stylesheet);
 
-/* extra-modes.c */
-
-void lua_colorize_line(QEColorizeContext *cp,
-                       unsigned int *str, int n, int mode_flags);
-void haskell_colorize_line(QEColorizeContext *cp,
-                           unsigned int *str, int n, int mode_flags);
-void python_colorize_line(QEColorizeContext *cp,
-                          unsigned int *str, int n, int mode_flags);
-void ruby_colorize_line(QEColorizeContext *cp,
-                        unsigned int *str, int n, int mode_flags);
-
 /* image.c */
 
 void fill_border(EditState *s, int x, int y, int w, int h, int color);

Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -b -r1.72 -r1.73
--- clang.c     29 May 2014 18:29:15 -0000      1.72
+++ clang.c     30 May 2014 17:18:13 -0000      1.73
@@ -21,6 +21,43 @@
 
 #include "qe.h"
 
+/* C mode flavors */
+enum {
+    CLANG_C,
+    CLANG_CPP,
+    CLANG_OBJC,
+    CLANG_CSHARP,
+    CLANG_CSS,
+    CLANG_JS,
+    CLANG_AS,
+    CLANG_JAVA,
+    CLANG_PHP,
+    CLANG_GO,
+    CLANG_D,
+    CLANG_LIMBO,
+    CLANG_CYCLONE,
+    CLANG_CH,
+    CLANG_SQUIRREL,
+    CLANG_ICI,
+    CLANG_JSX,
+    CLANG_HAXE,
+    CLANG_DART,
+    CLANG_PIKE,
+    CLANG_IDL,
+    CLANG_CALC,
+    CLANG_ENSCRIPT,
+    CLANG_QSCRIPT,
+    CLANG_FLAVOR = 0x1F,
+};
+
+/* C mode options */
+#define CLANG_LEX         0x0200
+#define CLANG_YACC        0x0400
+#define CLANG_REGEX       0x0800
+#define CLANG_WLITERALS   0x1000
+#define CLANG_PREPROC     0x2000
+#define CLANG_CC          0x3100  /* all C language features */
+
 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|"
@@ -321,61 +358,56 @@
     "variant|void|"
 };
 
-struct QEModeFlavor {
-    const char *keywords;
-    const char *types;
-} const c_mode_flavors[] = {
-    { NULL,              NULL },           /* CLANG_GENERIC */
-    { c_keywords,        c_types },        /* CLANG_C */
-    { cpp_keywords,      cpp_types },      /* CLANG_CPP */
-    { objc_keywords,     objc_types },     /* CLANG_OBJC */
-    { csharp_keywords,   csharp_types },   /* CLANG_CSHARP */
-    { css_keywords,      css_types },      /* CLANG_CSS */
-    { js_keywords,       js_types },       /* CLANG_JS */
-    { as_keywords,       as_types },       /* CLANG_AS */
-    { java_keywords,     java_types },     /* CLANG_JAVA */
-    { php_keywords,      php_types },      /* CLANG_PHP */
-    { go_keywords,       go_types },       /* CLANG_GO */
-    { d_keywords,        d_types },        /* CLANG_D */
-    { limbo_keywords,    limbo_types },    /* CLANG_LIMBO */
-    { cyclone_keywords,  cyclone_types },  /* CLANG_CYCLONE */
-    { ch_keywords,       ch_types },       /* CLANG_CH */
-    { squirrel_keywords, squirrel_types }, /* CLANG_SQUIRREL */
-    { ici_keywords,      ici_types },      /* CLANG_ICI */
-    { jsx_keywords,      jsx_types },      /* CLANG_JSX */
-    { haxe_keywords,     haxe_types },     /* CLANG_HAXE */
-    { dart_keywords,     dart_types },     /* CLANG_DART */
-    { pike_keywords,     pike_types },     /* CLANG_PIKE */
+static const char idl_keywords[] = {
+    "abstract|attribute|case|component|const|consumes|context|custom|"
+    "default|emits|enum|eventtype|exception|factory|false|FALSE|finder|"
+    "fixed|getraises|home|import|in|inout|interface|local|module|multiple|"
+    "native|oneway|out|primarykey|private|provides|public|publishes|raises|"
+    "readonly|sequence|setraises|struct|supports|switch|TRUE|true|"
+    "truncatable|typedef|typeid|typeprefix|union|uses|ValueBase|valuetype|"
+};
+
+static const char idl_types[] = {
+    
"unsigned|short|long|float|double|char|wchar|string|wstring|octet|any|void|"
+    "boolean|Boolean|object|Object|"
+};
+
+static const char calc_keywords[] = {
+    "if|else|for|while|do|continue|break|goto|return|local|global|static|"
+    "switch|case|default|quit|exit|define|read|show|help|write|mat|obj|"
+    "print|cd|undefine|abort|"
+};
+
+static const char calc_types[] = {
+    "|"
+};
+
+static const char enscript_keywords[] = {
+    "if|else|return|state|extends|BEGIN|END|forever|continue|do|"
+    "not|and|or|orelse|switch|case|default|true|false|"
+};
+
+static const char enscript_types[] = {
+    "|"
+};
+
+static const char qs_keywords[] = {
+    "break|case|class|continue|def|default|del|delete|do|else|for|"
+    "function|if|module|new|return|self|string|struct|switch|this|"
+    "typeof|while|"
+};
+
+static const char qs_types[] = {
+    "char|int|var|void|Array|Char|Function|Number|Object|String|"
 };
 
-static const char c_mode_extensions[] = {
+static const char c_extensions[] = {
     "c|h|i|C|H|I|"      /* C language */
-    "y|yacc|l|lex|"     /* yacc, lex */
-    "cc|hh|cpp|hpp|cxx|hxx|CPP|CC|c++|"   /* C++ */
-    "m|mm|"             /* Objective-C, Limbo */
-    "cs|"               /* C Sharp */
-    "css|"              /* Cascaded Style Sheet, CSS */
-    "js|json|"          /* Javascript, JSon */
-    "as|"               /* Actionscript */
-    "jav|java|"         /* Java */
-    "jsx|"              /* JSX (extended Javascript) */
-    "hx|"               /* Haxe (extended Javascript) */
-    "dart|"             /* Dart (extended Javascript) */
-    "pike|"             /* Pike */
-    "go|"               /* Go language */
-    "d|di|"             /* D language */
-    "cyc|cyl|cys|"      /* Cyclone language */
-    "ch|"               /* Ch interpreter */
-    "nut|"              /* Squirrel language */
-    "ici|"              /* ICI language (C interpreter) */
-    "st|"               /* GNU Enscript syntax files */
-    "qe|qs|"            /* QEmacs / QScript */
-    "idl|"              /* IDL language */
+    /* Other C flavors */
     "e|"                /* EEL */
-    "ec|ecp|"           /* Informix embedded C */
+    "ecp|"              /* Informix embedded C */
     "pgc|"              /* Postgres embedded C */
     "pcc|"              /* Oracle C++ */
-    "cal|"              /* GNU Calc */
 };
 
 /* grab a C identifier from a uint buf, stripping color.
@@ -434,20 +466,20 @@
     IN_C_COMMENT_D_SHIFT = 8,
 };
 
-void c_colorize_line(QEColorizeContext *cp,
-                     unsigned int *str, int n, int mode_flags)
+static void c_colorize_line(QEColorizeContext *cp,
+                            unsigned int *str, int n, ModeDef *syn)
 {
     const char *keywords = NULL;
     const char *types = NULL;
     int i = 0, start, i1, i2, indent, level;
     int c, state, style, style0, style1, type_decl, klen, delim, flavor;
+    int mode_flags;
     char kbuf[32];
 
+    mode_flags = syn ? syn->colorize_flags : 0;
     flavor = (mode_flags & CLANG_FLAVOR);
-    if (flavor < countof(c_mode_flavors)) {
-        keywords = c_mode_flavors[flavor].keywords;
-        types = c_mode_flavors[flavor].types;
-    }
+    keywords = syn ? syn->keywords : NULL;
+    types = syn ? syn->types : NULL;
 
     for (indent = 0; qe_isspace(str[indent]); indent++)
         continue;
@@ -587,7 +619,7 @@
             }
             break;
         case '#':       /* preprocessor */
-            if ((mode_flags & CLANG_CC) || flavor == CLANG_CSHARP) {
+            if (mode_flags & CLANG_PREPROC) {
                 state = IN_C_PREPROCESS;
                 style = style0 = C_STYLE_PREPROCESS;
             }
@@ -619,7 +651,7 @@
             }
             break;
         case 'L':       /* wide character and string literals */
-            if (mode_flags & CLANG_CC) {
+            if (mode_flags & CLANG_WLITERALS) {
                 if (str[i] == '\'') {
                     i++;
                     goto parse_string_q;
@@ -1308,6 +1340,24 @@
     }
 }
 
+/* C mode specific commands */
+static CmdDef c_commands[] = {
+    CMD2( KEY_CTRL('i'), KEY_NONE,
+          "c-indent-command", do_c_indent, ES, "*")
+            /* should map to KEY_META + KEY_CTRL_LEFT ? */
+    CMD3( KEY_META('['), KEY_NONE,
+          "c-backward-conditional", do_c_forward_conditional, ESi, -1, "*v")
+    CMD3( KEY_META(']'), KEY_NONE,
+          "c-forward-conditional", do_c_forward_conditional, ESi, 1, "*v")
+    CMD2( KEY_META('i'), KEY_NONE,
+          "c-list-conditionals", do_c_list_conditionals, ES, "")
+    CMD2( '{', '}',
+          "c-electric-key", do_c_electric, ESi, "*ki")
+    CMD2( KEY_RET, KEY_NONE,
+          "c-newline", do_c_return, ES, "*v")
+    CMD_DEF_END,
+};
+
 static int c_mode_probe(ModeDef *mode, ModeProbeData *p)
 {
     /* trust the file extension */
@@ -1323,175 +1373,340 @@
         return 50;
 
     if (p->buf[0] == '#') {
-        if (p->buf[1] == '!'
-        &&  memstr(p->buf, p->line_len, "bin/calc")) {
-            /* GNU Calc script */
-            return 80;
-        }
-        /* same for file starting with '#include' */
-        if (strstart(cs8(p->buf), "#include", NULL))
-            return 50;
-
-        /* same for file starting with '#pragma' as in #pragma once */
-        if (strstart(cs8(p->buf), "#pragma", NULL))
+        /* same for file starting with `#include` or `#pragma`*/
+        if (strstart(cs8(p->buf), "#include", NULL)
+        ||  strstart(cs8(p->buf), "#pragma", NULL)) {
             return 50;
     }
+    }
 
     return 1;
 }
 
-static int c_mode_init(EditState *s)
-{
-    const char *base = get_basename(s->b->filename);
+ModeDef c_mode = {
+    .name = "C",
+    .extensions = c_extensions,
+    .mode_probe = c_mode_probe,
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_C | CLANG_CC,
+    .keywords = c_keywords,
+    .types = c_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
 
-    /* Select C like flavor */
-    if (match_extension(base, "c|h|i|C|H|I")) {
-        s->mode_flags = CLANG_C | CLANG_CC;
-    } else
-    if (match_extension(base, "y|yacc")) {
-        s->mode_name = "Yacc";
-        s->mode_flags = CLANG_C | CLANG_CC | CLANG_YACC;
-    } else
-    if (match_extension(base, "l|lex")) {
-        s->mode_name = "Lex";
-        s->mode_flags = CLANG_C | CLANG_CC | CLANG_LEX;
-    } else
-    if (match_extension(base, "cc|hh|cpp|hpp|cxx|hxx|CPP|CC|c++")) {
-        s->mode_name = "CPP";
-        s->mode_flags = CLANG_CPP | CLANG_CC;
-    } else
-    if (match_extension(base, "cs")) {
-        s->mode_name = "C#";
-        s->mode_flags = CLANG_CSHARP;
-    } else
-    if (match_extension(base, "m|mm")) {
-        int offset = 0;
-        if (eb_nextc(s->b, offset, &offset) == '/') {
-            // XXX: should also check for #import
-            s->mode_name = "ObjC";
-            s->mode_flags = CLANG_OBJC | CLANG_CC;
+ModeDef yacc_mode = {
+    .name = "Yacc",
+    .extensions = "y|yacc",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_C | CLANG_CC | CLANG_YACC,
+    .keywords = c_keywords,
+    .types = c_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef lex_mode = {
+    .name = "Lex",
+    .extensions = "l|lex",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_C | CLANG_CC | CLANG_LEX,
+    .keywords = c_keywords,
+    .types = c_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef cpp_mode = {
+    .name = "C++",
+    .mode_name = "cpp",
+    .extensions = "cc|hh|cpp|hpp|cxx|hxx|CPP|CC|c++",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_CPP | CLANG_CC,
+    .keywords = cpp_keywords,
+    .types = cpp_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+static int objc_mode_probe(ModeDef *mode, ModeProbeData *p)
+{
+    if (match_extension(p->filename, mode->extensions)) {
+        /* favor Objective C over Limbo for .m extension
+         * if file is empty, starts with a comment or a #import */
+        if (p->buf[0] == '/' || p->buf[0] == '\0'
+        ||  strstart(cs8(p->buf), "#import", NULL)) {
+            return 81;
         } else {
-            s->mode_name = "Limbo";
-            s->mode_flags = CLANG_LIMBO;
+            return 80;
         }
-    } else
-    if (match_extension(base, "jav|java")) {
-        s->mode_name = "Java";
-        s->mode_flags = CLANG_JAVA;
-    } else
-    if (match_extension(base, "css")) {
-        s->mode_name = "CSS";
-        s->mode_flags = CLANG_CSS;
-    } else
-    if (match_extension(base, "js|json")) {
-        s->mode_name = "Javascript";
-        s->mode_flags = CLANG_JS | CLANG_REGEX;
-    } else
-    if (match_extension(base, "as")) {
-        s->mode_name = "Actionscript";
-        s->mode_flags = CLANG_AS | CLANG_REGEX;
-    } else
-    if (match_extension(base, "jsx")) {
-        s->mode_name = "JSX";
-        s->mode_flags = CLANG_JSX | CLANG_REGEX;
-    } else
-    if (match_extension(base, "hx")) {
-        s->mode_name = "Haxe";
-        s->mode_flags = CLANG_HAXE | CLANG_REGEX;
-    } else
-    if (match_extension(base, "dart")) {
-        s->mode_name = "Dart";
-        s->mode_flags = CLANG_DART;
-    } else
-    if (match_extension(base, "pike")) {
-        s->mode_name = "Pike";
-        s->mode_flags = CLANG_PIKE;
-    } else
-    if (match_extension(base, "go")) {
-        s->mode_name = "Go";
-        s->mode_flags = CLANG_GO;
-    } else
-    if (match_extension(base, "d|di")) {
-        s->mode_name = "D";
-        s->mode_flags = CLANG_D;
-    } else
-    if (match_extension(base, "cyc|cyl|cys")) {
-        s->mode_name = "Cyclone";
-        s->mode_flags = CLANG_CYCLONE | CLANG_CC;
-    } else
-    if (match_extension(base, "chf")) {
-        s->mode_name = "Ch";
-        s->mode_flags = CLANG_CH | CLANG_CC;
-    } else
-    if (match_extension(base, "nut")) {
-        s->mode_name = "Squirrel";
-        s->mode_flags = CLANG_SQUIRREL;
-    } else
-    if (match_extension(base, "ici")) {
-        s->mode_name = "ICI";
-        s->mode_flags = CLANG_ICI;
-    } else
-    if (match_extension(base, "st")) {
-        s->mode_name = "Enscript";
-        s->mode_flags = CLANG_C | CLANG_CC | CLANG_REGEX;
-    } else
-    if (match_extension(base, "qe|qs")
-    ||  !strcmp(base, ".qerc")
-    ||  strstr(s->b->filename, "/.qe/config")) {
-        s->mode_name = "QScript";
-        s->mode_flags = CLANG_CC | CLANG_REGEX;
-    } else
-    if (match_extension(base, "idl")) {
-        s->mode_name = "IDL";
-        s->mode_flags = CLANG_CC | CLANG_REGEX;
-    } else
-    if (match_extension(base, "e")) {
-        s->mode_name = "EEL";
-        s->mode_flags = CLANG_C | CLANG_CC;
-    } else
-    if (match_extension(base, "ec|ecp")) {
-        s->mode_name = "Informix";
-        s->mode_flags = CLANG_C | CLANG_CC;
-    } else
-    if (match_extension(base, "pgc")) {
-        s->mode_name = "Postgres";
-        s->mode_flags = CLANG_C | CLANG_CC;
-    } else
-    if (match_extension(base, "pcc")) {
-        s->mode_name = "Oracle";
-        s->mode_flags = CLANG_CPP | CLANG_CC;
-    } else
-    if (match_extension(base, "cal")) {
-        s->mode_name = "Calc";
-        s->mode_flags = CLANG_CC;
     }
-    return 0;
+    return 1;
 }
 
-/* C mode specific commands */
-static CmdDef c_commands[] = {
-    CMD2( KEY_CTRL('i'), KEY_NONE,
-          "c-indent-command", do_c_indent, ES, "*")
-            /* should map to KEY_META + KEY_CTRL_LEFT ? */
-    CMD3( KEY_META('['), KEY_NONE,
-          "c-backward-conditional", do_c_forward_conditional, ESi, -1, "*v")
-    CMD3( KEY_META(']'), KEY_NONE,
-          "c-forward-conditional", do_c_forward_conditional, ESi, 1, "*v")
-    CMD2( KEY_META('i'), KEY_NONE,
-          "c-list-conditionals", do_c_list_conditionals, ES, "")
-    CMD2( '{', '}',
-          "c-electric-key", do_c_electric, ESi, "*ki")
-    CMD2( KEY_RET, KEY_NONE,
-          "c-newline", do_c_return, ES, "*v")
-    CMD_DEF_END,
+ModeDef objc_mode = {
+    .name = "ObjC", /* Objective C */
+    .extensions = "m|mm",
+    .mode_probe = objc_mode_probe,
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_OBJC | CLANG_CC,
+    .keywords = objc_keywords,
+    .types = objc_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
 };
 
-static ModeDef c_mode = {
-    .name = "C",
-    .extensions = c_mode_extensions,
-    .mode_probe = c_mode_probe,
-    .mode_init = c_mode_init,
+ModeDef csharp_mode = {
+    .name = "C#",   /* C Sharp */
+    .mode_name = "csharp",
+    .extensions = "cs",
     .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_CSHARP | CLANG_PREPROC,
+    .keywords = csharp_keywords,
+    .types = csharp_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef css_mode = {
+    .name = "CSS",
+    .extensions = "css",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_CSS,
+    .keywords = css_keywords,
+    .types = css_types,
+    .indent_func = c_indent_line,
+};
+
+ModeDef js_mode = {
+    .name = "Javascript",
+    .extensions = "js|json",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_JS | CLANG_REGEX,
+    .keywords = js_keywords,
+    .types = js_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef as_mode = {
+    .name = "Actionscript",
+    .extensions = "as",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_AS | CLANG_REGEX,
+    .keywords = as_keywords,
+    .types = as_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef java_mode = {
+    .name = "Java",
+    .extensions = "jav|java",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_JAVA,
+    .keywords = java_keywords,
+    .types = java_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef php_mode = {
+    .name = "PHP",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_PHP | CLANG_REGEX,
+    .keywords = php_keywords,
+    .types = php_types,
+};
+
+ModeDef go_mode = {
+    .name = "Go",
+    .extensions = "go",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_GO,
+    .keywords = go_keywords,
+    .types = go_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef d_mode = {
+    .name = "D",
+    .extensions = "d|di",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_D,
+    .keywords = d_keywords,
+    .types = d_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef limbo_mode = {
+    .name = "Limbo",
+    .extensions = "m",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_LIMBO,
+    .keywords = limbo_keywords,
+    .types = limbo_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef cyclone_mode = {
+    .name = "Cyclone",
+    .extensions = "cyc|cyl|cys",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_CYCLONE | CLANG_CC,
+    .keywords = cyclone_keywords,
+    .types = cyclone_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef ch_mode = {
+    .name = "Ch",
+    .extensions = "chf",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_CH | CLANG_CC,
+    .keywords = ch_keywords,
+    .types = ch_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef squirrel_mode = {
+    .name = "Squirrel",
+    .extensions = "nut",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_SQUIRREL,
+    .keywords = squirrel_keywords,
+    .types = squirrel_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef ici_mode = {
+    .name = "ICI",
+    .extensions = "ici",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_ICI,
+    .keywords = ici_keywords,
+    .types = ici_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef jsx_mode = {
+    .name = "JSX",
+    .extensions = "jsx",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_JSX | CLANG_REGEX,
+    .keywords = jsx_keywords,
+    .types = jsx_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef haxe_mode = {
+    .name = "Haxe",
+    .extensions = "hx",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_HAXE | CLANG_REGEX,
+    .keywords = haxe_keywords,
+    .types = haxe_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef dart_mode = {
+    .name = "Dart",
+    .extensions = "dart",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_DART,
+    .keywords = dart_keywords,
+    .types = dart_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef pike_mode = {
+    .name = "Pike",
+    .extensions = "pike",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_PIKE,
+    .keywords = pike_keywords,
+    .types = pike_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+static ModeDef idl_mode = {
+    .name = "IDL",
+    .extensions = "idl",
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_IDL | CLANG_PREPROC | CLANG_WLITERALS | 
CLANG_REGEX,
+    .keywords = idl_keywords,
+    .types = idl_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+static int calc_mode_probe(ModeDef *mode, ModeProbeData *p)
+{
+    if (match_extension(p->filename, mode->extensions))
+        return 80;
+    
+    if (p->buf[0] == '#' && p->buf[1] == '!'
+    &&  memstr(p->buf, p->line_len, "/calc")) {
+        /* GNU Calc script */
+        return 80;
+    }
+    return 1;
+}
+
+ModeDef calc_mode = {
+    .name = "calc", /* GNU Calc */
+    .extensions = "cal|calc",
+    .mode_probe = calc_mode_probe,
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_CALC | CLANG_CC,
+    .keywords = calc_keywords,
+    .types = calc_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+ModeDef enscript_mode = {
+    .name = "Enscript", /* GNU Enscript */
+    .extensions = "st", /* syntax files */
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_ENSCRIPT | CLANG_REGEX,
+    .keywords = enscript_keywords,
+    .types = enscript_types,
+    .indent_func = c_indent_line,
+    .auto_indent = 1,
+};
+
+static int qs_mode_probe(ModeDef *mode, ModeProbeData *p)
+{
+    if (match_extension(p->filename, mode->extensions))
+        return 80;
+    
+    if (!strcmp(p->filename, ".qerc")
+    ||  strstr(p->real_filename, "/.qe/config"))
+        return 80;
+
+    return 1;
+}
+
+ModeDef qscript_mode = {
+    .name = "QScript",
+    .extensions = "qe|qs",
+    .mode_probe = qs_mode_probe,
+    .colorize_func = c_colorize_line,
+    .colorize_flags = CLANG_QSCRIPT | CLANG_REGEX,
+    .keywords = qs_keywords,
+    .types = qs_types,
     .indent_func = c_indent_line,
     .auto_indent = 1,
 };
@@ -1505,6 +1720,34 @@
     for (p = ";:#&|"; *p; p++) {
         qe_register_binding(*p, "c-electric-key", &c_mode);
     }
+
+    qe_register_mode(&idl_mode, MODEF_SYNTAX);
+    qe_register_mode(&yacc_mode, MODEF_SYNTAX);
+    qe_register_mode(&lex_mode, MODEF_SYNTAX);
+    qe_register_mode(&cpp_mode, MODEF_SYNTAX);
+    qe_register_mode(&objc_mode, MODEF_SYNTAX);
+    qe_register_mode(&csharp_mode, MODEF_SYNTAX);
+    qe_register_mode(&css_mode, MODEF_SYNTAX);
+    qe_register_mode(&js_mode, MODEF_SYNTAX);
+    qe_register_mode(&as_mode, MODEF_SYNTAX);
+    qe_register_mode(&java_mode, MODEF_SYNTAX);
+    qe_register_mode(&php_mode, MODEF_SYNTAX);
+    qe_register_mode(&go_mode, MODEF_SYNTAX);
+    qe_register_mode(&d_mode, MODEF_SYNTAX);
+    qe_register_mode(&limbo_mode, MODEF_SYNTAX);
+    qe_register_mode(&cyclone_mode, MODEF_SYNTAX);
+    qe_register_mode(&ch_mode, MODEF_SYNTAX);
+    qe_register_mode(&squirrel_mode, MODEF_SYNTAX);
+    qe_register_mode(&ici_mode, MODEF_SYNTAX);
+    qe_register_mode(&jsx_mode, MODEF_SYNTAX);
+    qe_register_mode(&haxe_mode, MODEF_SYNTAX);
+    qe_register_mode(&dart_mode, MODEF_SYNTAX);
+    qe_register_mode(&pike_mode, MODEF_SYNTAX);
+    qe_register_mode(&idl_mode, MODEF_SYNTAX);
+    qe_register_mode(&calc_mode, MODEF_SYNTAX);
+    qe_register_mode(&enscript_mode, MODEF_SYNTAX);
+    qe_register_mode(&qscript_mode, MODEF_SYNTAX);
+
     return 0;
 }
 

Index: htmlsrc.c
===================================================================
RCS file: /sources/qemacs/qemacs/htmlsrc.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- htmlsrc.c   29 May 2014 18:29:14 -0000      1.20
+++ htmlsrc.c   30 May 2014 17:18:14 -0000      1.21
@@ -96,8 +96,8 @@
     }
 }
 
-void htmlsrc_colorize_line(QEColorizeContext *cp,
-                           unsigned int *str, int n, int mode_flags)
+static void htmlsrc_colorize_line(QEColorizeContext *cp,
+                                  unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start = i, c, len;
     int state = cp->colorize_state;
@@ -121,7 +121,7 @@
             c = str[i];     /* save char to set '\0' delimiter */
             str[i] = '\0';
             cp->colorize_state = state & ~(IN_HTML_PHP_TAG | 
IN_HTML_PHP_STRING);
-            php_colorize_line(cp, str + start, i - start, 0);
+            php_mode.colorize_func(cp, str + start, i - start, &php_mode);
             state = cp->colorize_state |
                     (state & (IN_HTML_PHP_TAG | IN_HTML_PHP_STRING));
             str[i] = c;
@@ -146,7 +146,7 @@
             c = str[i];     /* save char to set '\0' delimiter */
             str[i] = '\0';
             cp->colorize_state = state & ~(IN_HTML_ASP_TAG | 
IN_HTML_ASP_STRING);
-            csharp_colorize_line(cp, str + start, i - start, 0);
+            csharp_mode.colorize_func(cp, str + start, i - start, 
&csharp_mode);
             state = cp->colorize_state |
                     (state & (IN_HTML_ASP_TAG | IN_HTML_ASP_STRING));
             str[i] = c;
@@ -174,7 +174,7 @@
             str[i] = '\0';
             state &= ~IN_HTML_SCRIPT;
             cp->colorize_state = state;
-            js_colorize_line(cp, str + start, i - start, 0);
+            js_mode.colorize_func(cp, str + start, i - start, &js_mode);
             state = cp->colorize_state;
             state |= IN_HTML_SCRIPT;
             str[i] = c;
@@ -194,7 +194,7 @@
             str[i] = '\0';
             state &= ~IN_HTML_STYLE;
             cp->colorize_state = state;
-            css_colorize_line(cp, str + start, i - start, 0);
+            css_mode.colorize_func(cp, str + start, i - start, &css_mode);
             state = cp->colorize_state;
             state |= IN_HTML_STYLE;
             str[i] = c;
@@ -415,7 +415,7 @@
     CMD_DEF_END,
 };
 
-static ModeDef htmlsrc_mode = {
+ModeDef htmlsrc_mode = {
     .name = "html-src",
     .extensions = "html|htm|asp|aspx|shtml|hta|htp|phtml|php",
     .mode_probe = htmlsrc_mode_probe,

Index: makemode.c
===================================================================
RCS file: /sources/qemacs/qemacs/makemode.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- makemode.c  29 May 2014 18:29:14 -0000      1.20
+++ makemode.c  30 May 2014 17:18:14 -0000      1.21
@@ -55,7 +55,7 @@
 };
 
 static void makefile_colorize_line(QEColorizeContext *cp,
-                                   unsigned int *str, int n, int mode_flags)
+                                   unsigned int *str, int n, ModeDef *syn)
 {
     char buf[32];
     int i = 0, j = i, level;

Index: perl.c
===================================================================
RCS file: /sources/qemacs/qemacs/perl.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- perl.c      29 May 2014 18:29:14 -0000      1.20
+++ perl.c      30 May 2014 17:18:14 -0000      1.21
@@ -105,7 +105,7 @@
 }
 
 static void perl_colorize_line(QEColorizeContext *cp,
-                               unsigned int *str, int n, int mode_flags)
+                               unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, c, c1, c2, j = i, s1, s2, delim = 0;
     int colstate = cp->colorize_state;

Index: script.c
===================================================================
RCS file: /sources/qemacs/qemacs/script.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- script.c    29 May 2014 18:29:16 -0000      1.15
+++ script.c    30 May 2014 17:18:14 -0000      1.16
@@ -43,7 +43,7 @@
 }
 
 static void script_colorize_line(QEColorizeContext *cp,
-                                 unsigned int *str, int n, int mode_flags)
+                                 unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, j, c, start, style;
 

Index: dired.c
===================================================================
RCS file: /sources/qemacs/qemacs/dired.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- dired.c     29 May 2014 10:26:15 -0000      1.48
+++ dired.c     30 May 2014 17:18:14 -0000      1.49
@@ -1015,7 +1015,7 @@
 }
 
 static void dired_colorize_line(QEColorizeContext *cp,
-                                unsigned int *str, int n, int mode_flags)
+                                unsigned int *str, int n, ModeDef *syn)
 {
     const unsigned int *p;
     int i = 0, start = i, style;

Index: latex-mode.c
===================================================================
RCS file: /sources/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- latex-mode.c        29 May 2014 18:29:15 -0000      1.49
+++ latex-mode.c        30 May 2014 17:18:15 -0000      1.50
@@ -34,7 +34,7 @@
  * than one line (eg, multi-line functions and strings)
  */
 static void latex_colorize_line(QEColorizeContext *cp,
-                                unsigned int *str, int n, int mode_flags)
+                                unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start, c;
     int state = cp->colorize_state;

Index: markdown.c
===================================================================
RCS file: /sources/qemacs/qemacs/markdown.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- markdown.c  29 May 2014 18:29:15 -0000      1.15
+++ markdown.c  30 May 2014 17:18:15 -0000      1.16
@@ -90,7 +90,7 @@
 }
 
 static void mkd_colorize_line(QEColorizeContext *cp,
-                              unsigned int *str, int n, int mode_flags)
+                              unsigned int *str, int n, ModeDef *syn)
 {
     int colstate = cp->colorize_state;
     int level, indent, i = 0, j, start = i, base_style = 0;
@@ -105,7 +105,7 @@
         /* block level HTML markup */
         colstate &= ~IN_MKD_HTML_BLOCK;
         cp->colorize_state = colstate;
-        htmlsrc_colorize_line(cp, str, n, 0);
+        htmlsrc_mode.colorize_func(cp, str, n, &htmlsrc_mode);
         colstate = cp->colorize_state;
         colstate |= IN_MKD_HTML_BLOCK;
         if ((str[i] & CHAR_MASK) == '<' && (str[i + 1] & CHAR_MASK) == '/')
@@ -129,19 +129,19 @@
 
             switch (lang) {
             case IN_MKD_C:
-                c_colorize_line(cp, str, n, CLANG_C);
+                c_mode.colorize_func(cp, str, n, &c_mode);
                 break;
             case IN_MKD_PYTHON:
-                python_colorize_line(cp, str, n, 0);
+                python_mode.colorize_func(cp, str, n, &python_mode);
                 break;
             case IN_MKD_RUBY:
-                ruby_colorize_line(cp, str, n, 0);
+                ruby_mode.colorize_func(cp, str, n, &ruby_mode);
                 break;
             case IN_MKD_HASKELL:
-                haskell_colorize_line(cp, str, n, 0);
+                haskell_mode.colorize_func(cp, str, n, &haskell_mode);
                 break;
             case IN_MKD_LUA:
-                lua_colorize_line(cp, str, n, 0);
+                lua_mode.colorize_func(cp, str, n, &lua_mode);
                 break;
             default:
                 SET_COLOR(str, i, n, MKD_STYLE_CODE);
@@ -810,7 +810,7 @@
 
 ModeDef mkd_mode = {
     .name = "markdown",
-    .extensions = "mkd|md",
+    .extensions = "mkd|md|markdown",
     .mode_init = mkd_mode_init,
     .colorize_func = mkd_colorize_line,
 };

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -b -r1.178 -r1.179
--- qe.c        29 May 2014 18:29:15 -0000      1.178
+++ qe.c        30 May 2014 17:18:15 -0000      1.179
@@ -95,6 +95,9 @@
 
     m->flags |= flags;
 
+    if (!m->mode_name)
+        m->mode_name = m->name;
+
     /* register mode in mode list (at end) */
     for (p = &qs->first_mode;; p = &(*p)->next) {
         if (*p == m)
@@ -149,12 +152,12 @@
         CmdDef *def;
 
         /* lower case convert for C mode, Perl... */
-        qe_strtolower(buf, sizeof(buf) - 10, m->name);
+        qe_strtolower(buf, sizeof(buf) - 10, m->mode_name);
         pstrcat(buf, sizeof(buf), "-mode");
         size = strlen(buf) + 1;
         /* constant immediate string parameter */
         size += snprintf(buf + size, sizeof(buf) - size,
-                         "S{%s}", m->name) + 1;
+                         "S{%s}", m->mode_name) + 1;
         def = qe_mallocz_array(CmdDef, 2);
         def->name = qe_malloc_dup(buf, size);
         def->key = def->alt_key = KEY_NONE;
@@ -172,7 +175,7 @@
     ModeDef *m;
 
     for (m = qs->first_mode; m != NULL; m = m->next) {
-        complete_test(cp, m->name);
+        complete_test(cp, m->mode_name);
     }
 }
 
@@ -182,7 +185,7 @@
     ModeDef *m;
 
     for (m = qs->first_mode; m != NULL; m = m->next) {
-        if (strequal(m->name, name))
+        if (strequal(m->mode_name, name))
             break;
     }
     return m;
@@ -1846,8 +1849,6 @@
                 m = &text_mode;
         }
         s->mode = m;
-        s->mode_name = m->name;
-        s->mode_flags = 0;
 
         /* init mode */
         generic_mode_init(s, saved_data);
@@ -2231,7 +2232,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 ? s->mode->name : "raw");
     if (!s->insert)
         buf_printf(out, " Ovwrt");
     if (s->interactive)
@@ -3355,7 +3356,7 @@
             if (bom) {
                 SET_COLOR1(buf, 0, QE_STYLE_PREPROCESS);
             }
-            s->colorize_func(&cctx, buf + bom, len - bom, s->mode_flags);
+            s->colorize_func(&cctx, buf + bom, len - bom, s->mode);
             /* buf[len] has char '\0' but may hold style, force buf ending */
             buf[len + 1] = 0;
             s->colorize_states[line] = cctx.colorize_state;
@@ -3370,7 +3371,7 @@
     if (bom) {
         SET_COLOR1(buf, 0, QE_STYLE_PREPROCESS);
     }
-    s->colorize_func(&cctx, buf + bom, len - bom, s->mode_flags);
+    s->colorize_func(&cctx, buf + bom, len - bom, s->mode);
     buf[len + 1] = 0;
 
     /* XXX: if state is same as previous, minimize invalid region? */

Index: xml.c
===================================================================
RCS file: /sources/qemacs/qemacs/xml.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- xml.c       29 May 2014 18:29:15 -0000      1.22
+++ xml.c       30 May 2014 17:18:15 -0000      1.23
@@ -52,7 +52,7 @@
 }
 
 static void xml_colorize_line(QEColorizeContext *cp,
-                              unsigned int *str, int n, int mode_flags)
+                              unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start = i, c;
     int state = cp->colorize_state;
@@ -140,7 +140,7 @@
                     str[i] = '\0';
                     state &= ~IN_XML_SCRIPT;
                     cp->colorize_state = state;
-                    js_colorize_line(cp, str + start, i - start, 0);
+                    js_mode.colorize_func(cp, str + start, i - start, 
&js_mode);
                     state = cp->colorize_state;
                     state |= IN_XML_SCRIPT;
                     str[i] = c;
@@ -162,7 +162,7 @@
                     str[i] = '\0';
                     state &= ~IN_XML_STYLE;
                     cp->colorize_state = state;
-                    css_colorize_line(cp, str + start, i - start, 0);
+                    css_mode.colorize_func(cp, str + start, i - start, 
&css_mode);
                     state = cp->colorize_state;
                     state |= IN_XML_STYLE;
                     str[i] = c;



reply via email to

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