[Midnight Commander] #4252: MCEdit: incorrect syntax detection

1 view
Skip to first unread message

Ticket System

unread,
May 29, 2021, 2:31:19 PM5/29/21
to andrew....@gmail.com, mc-...@googlegroups.com
#4252: MCEdit: incorrect syntax detection
--------------------------------+--------------------------------
Reporter: andrew_b | Owner:
Type: defect | Status: new
Priority: major | Milestone: Future Releases
Component: mcedit | Version: master
Keywords: | Blocked By:
Blocking: | Branch state: no branch
Votes for changeset: |
--------------------------------+--------------------------------
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);
}}}

--
Ticket URL: <http://www.midnight-commander.org/ticket/4252>
Midnight Commander <https://midnight-commander.org>
Midnight Development Center

Ticket System

unread,
May 29, 2021, 3:04:19 PM5/29/21
to andrew....@gmail.com, mc-...@googlegroups.com, Terr...@gmail.com
#4252: MCEdit: incorrect syntax detection
--------------------------+---------------------------------------

Reporter: andrew_b | Owner:
Type: defect | Status: new
Priority: major | Milestone: Future Releases
Component: mcedit | Version: master
Resolution: | Keywords:

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
--------------------------+---------------------------------------
Changes (by TerraNova):

* cc: TerraTech@… (added)


--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:1>

Ticket System

unread,
May 29, 2021, 3:17:10 PM5/29/21
to andrew....@gmail.com, mc-...@googlegroups.com, Terr...@gmail.com
#4252: MCEdit: incorrect syntax detection
--------------------------+---------------------------------------

Reporter: andrew_b | Owner:
Type: defect | Status: new
Priority: major | Milestone: Future Releases
Component: mcedit | Version: master
Resolution: | Keywords:

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
--------------------------+---------------------------------------

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>

Ticket System

unread,
May 30, 2021, 3:29:26 AM5/30/21
to andrew....@gmail.com, mc-...@googlegroups.com, Terr...@gmail.com
#4252: MCEdit: incorrect syntax detection
--------------------------+---------------------------------------

Reporter: andrew_b | Owner:
Type: defect | Status: new
Priority: major | Milestone: Future Releases
Component: mcedit | Version: master
Resolution: | Keywords:

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
--------------------------+---------------------------------------

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>

Ticket System

unread,
May 30, 2021, 3:33:38 AM5/30/21
to andrew....@gmail.com, mc-...@googlegroups.com, Terr...@gmail.com
#4252: MCEdit: incorrect syntax detection
--------------------------+---------------------------------------

Reporter: andrew_b | Owner:
Type: defect | Status: new
Priority: major | Milestone: Future Releases
Component: mcedit | Version: master
Resolution: | Keywords:

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
--------------------------+---------------------------------------

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>

Ticket System

unread,
May 30, 2021, 5:52:05 AM5/30/21
to andrew....@gmail.com, mc-...@googlegroups.com, Terr...@gmail.com
#4252: MCEdit: incorrect syntax detection
--------------------------+---------------------------------------

Reporter: andrew_b | Owner:
Type: defect | Status: new
Priority: major | Milestone: Future Releases
Component: mcedit | Version: master
Resolution: | Keywords:

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
--------------------------+---------------------------------------

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>

Ticket System

unread,
May 30, 2021, 6:45:04 AM5/30/21
to andrew....@gmail.com, mc-...@googlegroups.com, Terr...@gmail.com
#4252: MCEdit: incorrect syntax detection
--------------------------+---------------------------------------
Reporter: andrew_b | Owner:
Type: defect | Status: closed

Priority: major | Milestone: Future Releases
Component: mcedit | Version: master
Resolution: wontfix | Keywords:

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
--------------------------+---------------------------------------
Changes (by andrew_b):

* status: new => closed
* resolution: => wontfix


Comment:

ticket:4246#comment:9

--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:6>

Ticket System

unread,
Sep 5, 2021, 7:13:02 AM9/5/21
to andrew....@gmail.com, mc-...@googlegroups.com, Terr...@gmail.com
#4252: MCEdit: incorrect syntax detection
--------------------------+------------------------------
Reporter: andrew_b | Owner:
Type: defect | Status: closed
Priority: major | Milestone:
Component: mcedit | Version: master
Resolution: wontfix | Keywords:

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
--------------------------+------------------------------
Changes (by zaytsev):

* milestone: Future Releases =>


--
Ticket URL: <http://www.midnight-commander.org/ticket/4252#comment:7>

Reply all
Reply to author
Forward
0 new messages