qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs clang.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs clang.c
Date: Wed, 19 Apr 2017 04:14:31 -0400 (EDT)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        17/04/19 04:14:31

Modified files:
        .              : clang.c 

Log message:
        clang: detect objective-C header files

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.126&r2=1.127

Patches:
Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -b -r1.126 -r1.127
--- clang.c     17 Apr 2017 09:16:24 -0000      1.126
+++ clang.c     19 Apr 2017 08:14:31 -0000      1.127
@@ -1374,18 +1374,36 @@
     "id|BOOL|SEL|Class|Object|"
 };
 
-static int objc_mode_probe(ModeDef *mode, ModeProbeData *p)
+static int objc_mode_probe(ModeDef *mode, ModeProbeData *mp)
 {
-    if (match_extension(p->filename, mode->extensions)) {
+    const char *p = cs8(mp->buf);
+
+    if (match_extension(mp->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)) {
+         * if file is empty, starts with a comment or a #import
+         */
+        if (*p == '/' || *p == '\0'
+        ||  strstart(p, "#import", NULL)) {
             return 81;
         } else {
             return 80;
         }
     }
+    if (match_extension(mp->filename, "h")) {
+        /* favor Objective C over C/C++ for .h extension
+         * if file has #import or @keyword at the beginning of a line
+         */
+        const char *q;
+        for (q = p;; q++) {
+            if ((*q == '@' && qe_isalpha(q[1]))
+            ||  (*q == '#' && strstart(p, "#import", NULL))) {
+                return 85;
+            }
+            q = strchr(q, '\n');
+            if (q == NULL)
+                break;
+        }
+    }
     return 1;
 }
 



reply via email to

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