id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking	branch_state	votes
4252	MCEdit: incorrect syntax detection	andrew_b		"From ticket:4246#comment:6

There are two conditions are used to detect syntax highlighting type:
* a file name matched to the specified regular expression;
* a first line of file matched to the specified regular expression (for example, a shebang in shell scripts).

Current implementation is an OR logic: if one of those conditions is met, the rule is considered found (see src/editor/syntax.c).

{{{
   1327             q = mc_search (args[1], DEFAULT_CHARSET, editor_file, MC_SEARCH_T_REGEX);
   1328             /* does filename match arg 1 ? */
   1329             if (!q && args[3] != NULL)
   1330             {
   1331                 /* does first line match arg 3 ? */
   1332                 q = mc_search (args[3], DEFAULT_CHARSET, first_line, MC_SEARCH_T_REGEX);
   1333             }
   1334             if (q)
   1335             {
   1336                 int line_error;
   1337                 char *syntax_type;
   1338 
   1339               found_type:
   1340                 syntax_type = args[2];
}}}

It is suggested to use AND logic: both regexps must be matched (if the first line regexp is present, of course) to detect the syntax highlighting type:

{{{
#!diff
diff --git a/src/editor/syntax.c b/src/editor/syntax.c
index e271641a1..6c7ede76a 100644
--- a/src/editor/syntax.c
+++ b/src/editor/syntax.c
@@ -1326,7 +1326,7 @@ edit_read_syntax_file (WEdit * edit, GPtrArray * pnames, const char *syntax_file
 
             q = mc_search (args[1], DEFAULT_CHARSET, editor_file, MC_SEARCH_T_REGEX);
             /* does filename match arg 1 ? */
-            if (!q && args[3] != NULL)
+            if (q && args[3] != NULL)
             {
                 /* does first line match arg 3 ? */
                 q = mc_search (args[3], DEFAULT_CHARSET, first_line, MC_SEARCH_T_REGEX);
}}}
"	defect	closed	major		mcedit	master	wontfix		TerraTech@…			no branch	
