Sublime Forum

First_line_match: # -*- mode: shell-script -*-

#1

When a shell script named ‘example.inc’ contains the following first line:

# -- mode: shell-script --

the “Bash” syntax highlighting is not applied (actually, no syntax highlighting at all).

when ‘example.inc’ is renamed into ‘example’ (without extension), the correct (Bash) syntax is applied.
when ‘example.inc’ is renamed into ‘example.xyz’ (unknown extension), again no syntax highlighting.

Is this expected?
If yes, how can I (permanently) configure that the file ‘example.inc’ (but not all other *.inc files) must use Bash syntax?

0 Likes

#2

I could not reproduce this with a brand-new ST 3170 portable.

I open example.xyz whose content is as below.

# -*- mode: shell-script -*-

And it’s auto set to Bash.

0 Likes

#3

Well, with ‘example.xyz’ it seems to work indeed (I must have made a mistake).
But it’s not with ‘example.inc’ (checked on Linux and MacOS with ST 3170)

0 Likes

#4

I could reproduce this but it’s auto set to HTML on my machine. Either way, it’s wrong in this case.

Have filed a fix here but may be not accepted.
A workaround would be use a more specific ext like .inc.sh.

0 Likes

#5

Thanks for your patch. I tend to use .inc extension when including (at least) shell scripts and Makefiles, don’t know if this habit is particularly widespread ?

Your workaround would work indeed, but it’s not always easy to rename files in legacy code…

Anyway, your patch seems to indicate that the filename extension (.inc here) has priority over the shebang, right? If yes, could it be an option to reverse the priorities, and give the shebang (first line) a higher priority ?

0 Likes

#6

Yes. The file extension should explicitly tell how the file is treated as. Shebang indicates how the file should be “executed” and saying shebang usually means something started with #! in the first line.

No. But you could force ST to open all .inc files in Bash syntax.

Doing that, you seemingly add a .inc extension to the Bash syntax just like what HTML syntax does now (which generally is wrong). If you have other language using .inc extension, you would run into the same dilemma.

0 Likes