Subject: bug#13815: Wrong mode for files with awkward shebang lines

From: Andrew Pennebaker <[email-masked]>
Date: Mon, 25 Feb 2013 16:56:03 -0500

Some of my Scala code opens as Shell script major mode in Emacs, a problem
caused by several factors:

In order to enable dot-slashing for Scala scripts, programmers sometimes
start their code as follows:

#!/bin/sh
exec scala "$0" "$@"
!#

object Hello {
def main(args: Array[String]) {
println("Hello World!")
}
}

This is an awkward shebang line; due to the nature of shebangs, it must be
split across three lines of code, starting with #!/bin/sh.

This creates problems for Emacs, as Emacs uses `file` to detect which major
mode should be used, and `file` returns 'text/x-shellscript' when a file
begins #!/bin/sh, regardless of the file extension or programming language
content the file actually contains.

This could be solved a variety of ways, but I think the simplest is to
prioritize file extension over mimetype when a file extension is available.
We can't trust mimetypes for code that contains these awkward shebangs.

-- 
Cheers,

Andrew Pennebaker
www.yellosoft.us