How can I specify the shell variant for a file in that file's Emacs local variables, when the file is not a standalone program?
Emacs allows me to specify that a shell include file should be opened in sh
mode, by setting a local variable in the editor hints:
# Local variables:
# coding: utf-8
# mode: sh
# End:
# vim: fileencoding=utf-8 filetype=bash :
I can specify to Vim that the file's shell variant is specifically Bash, and it obeys the editor hint to present specific Bash syntax highlighting. But Emacs has sh
mode which covers all shell variants.
Emacs will properly interpret such a file if it has a shebang line (e.g. #! /bin/bash
). But some files are not stand-alone programs, so I do not want those to have a shebang line.
Emacs sh
mode treats those files as Posix shell syntax, which they are not. sh
mode has the concept of “variant” of shell syntax; but I'm unable to find out how to specify, in the file's editor hints, which variant to use for the file.
How can I set the editor hints in the file to tell Emacs that its syntax is Bash?
Update 2014-04-24: I have reported Emacs bug#17333 for this missing behaviour.
sh-shell
as a file-local variable. Yay! Until then, my answer below really does work without adding an explicit shebang line (notwithstanding bignose's initial impression to the contrary).NEWS
file states that “In sh-mode you can now usesh-shell
as a file-local variable to specify the type of shell in use (bash
,csh
, etc).”