Bug 440446 - Files named "makefile.cpp", "makefile.c", etc. are highlighted as Makefile by default
Summary: Files named "makefile.cpp", "makefile.c", etc. are highlighted as Makefile by...
Status: REPORTED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (other bugs)
Version First Reported In: 5.84.0
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-31 13:42 UTC by Igor Kushnir
Modified: 2023-12-19 18:27 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Kushnir 2021-07-31 13:42:13 UTC
SUMMARY
In data/syntax/makefile.xml the language tag's priority attribute's value is 11 since https://commits.kde.org/syntax-highlighting/f5c28a08c23c4d8b0ca76dcc3e9127142cdbfe86. This is a very high priority, which trumps the extensions of C++ (priority=9), C (priority=5) and many other languages.

/usr/share/mime/globs2 assigns separate priorities to different patterns belonging to the same MIME type. For example:
50:text/x-makefile:makefile
50:text/x-makefile:gnumakefile
50:text/x-makefile:*.mak
10:text/x-makefile:makefile.*

This makes it easy to assign lower priorities to unusual patterns like "makefile.*". "10" is the lowest priority in my system globs2 file. Although the commit that introduced the high priority into makefile.xml did so for the sake of this very pattern in order to assign the Makefile syntax to a file named "Makefile.inc". Note also the related revision history comment close to the top of makefile.xml:
<!-- small priority to allow for example Makefile.cpp to be detected as cpp file -->
This comment must have been missed by the author and the reviewer of the commit that re-increased the priority.

The easiest fix is to set the priority in makefile.xml to a sufficiently low value. But doing so would reintroduce the "Makefile.inc" issue fixed by the aforementioned commit. The easy fix would also lower the priority of unambiguous literal Makefile patterns, such as "GNUmakefile", "Makefile", "makefile", as well as the "*.mk" pattern, which might cause certain makefiles to be highlighted as some other language.

STEPS TO REPRODUCE
1. Create a file named "Makefile.cpp" or rename an existing C++ file to "Makefile.cpp".
2. Open the file "Makefile.cpp" in Kate.

OBSERVED RESULT
The opened file is highlighted as "Makefile".

EXPECTED RESULT
The opened file is highlighted as "C++".

SOFTWARE/OS VERSIONS
Manjaro GNU/Linux, Xfce
KDE Frameworks Version: 5.84.0
Qt Version: 5.15.2+kde
Comment 1 Christoph Cullmann 2022-10-02 16:52:29 UTC
Perhaps we could just have a more restricted makefile.* wildcard, there are not that many real life suffixes in use like .in and .am and .inc.

Patches welcome.
Comment 2 Igor Kushnir 2022-10-26 05:43:01 UTC
(In reply to Christoph Cullmann from comment #1)
> Perhaps we could just have a more restricted makefile.* wildcard, there are
> not that many real life suffixes in use like .in and .am and .inc.
> 
> Patches welcome.
Searched "Makefile" on GitHub and immediately found lots of makefile extensions in use: https://github.com/LIVE-EMPIRE/LITZLERTOTO/blob/e6a17324850b7b85233e6f20fcaba4af8a99a493/Engine/Source/ThirdParty/libPNG/libPNG-1.5.2/scripts/README.txt. Can some Makefile extensions (i.e. C and C++ header/source extensions) be excluded somehow instead?
Comment 3 Christoph Cullmann 2023-12-19 18:27:09 UTC
(In reply to Igor Kushnir from comment #2)
> (In reply to Christoph Cullmann from comment #1)
> > Perhaps we could just have a more restricted makefile.* wildcard, there are
> > not that many real life suffixes in use like .in and .am and .inc.
> > 
> > Patches welcome.
> Searched "Makefile" on GitHub and immediately found lots of makefile
> extensions in use:
> https://github.com/LIVE-EMPIRE/LITZLERTOTO/blob/
> e6a17324850b7b85233e6f20fcaba4af8a99a493/Engine/Source/ThirdParty/libPNG/
> libPNG-1.5.2/scripts/README.txt. Can some Makefile extensions (i.e. C and
> C++ header/source extensions) be excluded somehow instead?

That is not feasible with the current wildcard syntax.