Replacing header patterns with signature patterns in #2819 was a mistake, since both are quite different from each other, and both have their uses. In fact, this caused a serious regression: for such files as shell scripts without *.sh extension but with #!/bin/sh inside (and other similar common use cases that have no filename matches and thus were relying on header matches), filetype detection does not work at all anymore.
Since both header and signature patterns are useful, reintroduce support for header patterns while keeping support for signature patterns as well, and make both work nicely together.
Also, unlike in the old implementation (before signatures were introduced), ensure that filename matches take precedence over header matches, i.e. if there is at least one filename match found, all header matches are ignored. This makes the behavior more deterministic and prevents previously observed issues like https://github.com/zyedidia/micro/issues/2894 and https://github.com/zyedidia/micro/issues/3054: wrongly detected filetypes caused by some overly general header patterns.
Precisely, the new behavior is:
if there is at least one filename match, use filename matches only
if there are no filename matches, use header matches
in both cases, try to use signatures to find the best match among
multiple filename or header matches
Changed signature patterns back to header patterns in almost all syntax files, except C++ and Objective-C (for which signature was actually introduced).
Also done a bit of refactoring and bugfixing of the code in UpdateRules() (see commit messages for the details).
Replacing
header
patterns withsignature
patterns in #2819 was a mistake, since both are quite different from each other, and both have their uses. In fact, this caused a serious regression: for such files as shell scripts without*.sh
extension but with#!/bin/sh
inside (and other similar common use cases that have nofilename
matches and thus were relying onheader
matches), filetype detection does not work at all anymore.Since both header and signature patterns are useful, reintroduce support for header patterns while keeping support for signature patterns as well, and make both work nicely together.
Also, unlike in the old implementation (before signatures were introduced), ensure that
filename
matches take precedence overheader
matches, i.e. if there is at least one filename match found, all header matches are ignored. This makes the behavior more deterministic and prevents previously observed issues like https://github.com/zyedidia/micro/issues/2894 and https://github.com/zyedidia/micro/issues/3054: wrongly detected filetypes caused by some overly general header patterns.Precisely, the new behavior is:
Changed
signature
patterns back toheader
patterns in almost all syntax files, except C++ and Objective-C (for whichsignature
was actually introduced).Also done a bit of refactoring and bugfixing of the code in
UpdateRules()
(see commit messages for the details).Fixes #3201