qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs extra-modes.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs extra-modes.c
Date: Tue, 13 May 2014 08:49:17 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/05/13 08:49:17

Modified files:
        .              : extra-modes.c 

Log message:
        added sharp-mode for txt files with # end of line comments

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/extra-modes.c?cvsroot=qemacs&r1=1.17&r2=1.18

Patches:
Index: extra-modes.c
===================================================================
RCS file: /sources/qemacs/qemacs/extra-modes.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- extra-modes.c       24 Apr 2014 22:06:11 -0000      1.17
+++ extra-modes.c       13 May 2014 08:49:17 -0000      1.18
@@ -937,6 +937,70 @@
     return 0;
 }
 
+/*---------------- sharp file coloring ----------------*/
+
+/* Very simple colorizer: # introduces comments, that's it! */
+
+enum {
+    SHARP_STYLE_TEXT =       QE_STYLE_DEFAULT,
+    SHARP_STYLE_COMMENT =    QE_STYLE_COMMENT,
+};
+
+static void sharp_colorize_line(QEColorizeContext *cp,
+                               unsigned int *str, int n, int mode_flags)
+{
+    int i = 0, start, c;
+
+    while (i < n) {
+        start = i;
+        c = str[i++];
+        switch (c) {
+        case '#':
+            i = n;
+            SET_COLOR(str, start, i, SHARP_STYLE_COMMENT);
+            continue;
+        default:
+            break;
+        }
+    }
+}
+
+static int sharp_mode_probe(ModeDef *mode, ModeProbeData *pd)
+{
+    const char *p = (const char *)pd->buf;
+
+    if (match_extension(pd->filename, mode->extensions)) {
+        while (qe_isspace(*p))
+            p++;
+        if (*p == '#')
+            return 60;
+    }
+
+    return 1;
+}
+
+/* specific script commands */
+static CmdDef sharp_commands[] = {
+    CMD_DEF_END,
+};
+
+static ModeDef sharp_mode;
+
+static int sharp_init(void)
+{
+    /* sharp txt mode is almost like the text mode, so we copy and patch it */
+    memcpy(&sharp_mode, &text_mode, sizeof(ModeDef));
+    sharp_mode.name = "sharp";
+    sharp_mode.extensions = "txt";
+    sharp_mode.mode_probe = sharp_mode_probe;
+    sharp_mode.colorize_func = sharp_colorize_line;
+
+    qe_register_mode(&sharp_mode);
+    qe_register_cmd_table(sharp_commands, &sharp_mode);
+
+    return 0;
+}
+
 /*---------------- PostScript colors ----------------*/
 
 enum {
@@ -2836,6 +2900,7 @@
     vim_init();
     pascal_init();
     ini_init();
+    sharp_init();
     ps_init();
     sql_init();
     lua_init();



reply via email to

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