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);
}}}
--
Ticket URL: <http://www.midnight-commander.org/ticket/4252>
Midnight Commander <https://midnight-commander.org>
Midnight Development Center
* cc: TerraTech@… (added)
--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:1>
Comment (by ossi):
you can't make it AND, because that would defeat the idea that scripts
without a file extension are detected solely by their shebang.
if openrc scripts have no extension "by definition", then their file name
pattern must not match anything - either via a special value which makes
it explicit, or by an arbitrary "impossible" file name, say n0eXt3ns10n
(yeah, that looks stupid).
--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:2>
Comment (by andrew_b):
Replying to [comment:2 ossi]:
> you can't make it AND, because that would defeat the idea that scripts
without a file extension are detected solely by their shebang.
This is an argument.
> if openrc scripts have no extension "by definition", then their file
name pattern must not match anything - either via a special value which
makes it explicit, or by an arbitrary "impossible" file name, say
n0eXt3ns10n (yeah, that looks stupid).
What about creating of a random file name, like
{{{
dd if=/dev/urandom bs=64 count=1 2>/dev/null | md5sum | cut -d' ' -f 1
}}}
--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:3>
Comment (by andrew_b):
Replying to [comment:3 andrew_b]:
> What about creating of a random file name
Or use `^$` pattern as it was in the first version of patch
(ticket:4246#comment:1).
--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:4>
Comment (by ossi):
the random pattern would be just as cryptic, even if a bit less stupid-
looking.
yeah, the empty pattern does seem like a good idea - after all, the actual
file name can't be empty by definition.
--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:5>
* status: new => closed
* resolution: => wontfix
Comment:
ticket:4246#comment:9
--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:6>
* milestone: Future Releases =>
--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:7>