2

I have a file called zshrc (not .zshrc). Emacs does not recognize that it must use sh-modeautomatically. I want to put some sort of hint for emacs to pick up and syntax highlight my file accordingly.

how do I achieve that?

  • 4
    Possible duplicate of UNIX config files, load conf-unix-mode – Kaushal Modi Aug 24 '16 at 3:16
  • 1
    You can use the example above and use auto-mode-alist to set "zshrc\\'" to sh-mode. – Kaushal Modi Aug 24 '16 at 3:17
  • @KaushalModi no, it's not a duplicate — the other post is about setting a mode in all files in a directory. – jch Sep 11 '16 at 14:42
  • @jch I that that it does not matter. The core question is how to set "foo" files in "bar" mode. In the former case, you needed to put the dir in the regexp, in this latter case, you need to put the filename. – Kaushal Modi Sep 11 '16 at 14:46
8

You can use a file-local variable to specify the mode.

You can either put them at the top of the file, like so:

# -*- mode: sh -*-

or at the bottom of the file, like so:

# Local Variables:
# mode: sh
# End:
  • I have tried this method using // -*- mode: php -*- in a PHP file with a non-standard extension but it doesn't seem to work. Have I got the syntax wrong? // is a valid PHP comment prefix – vfclists Jun 26 '17 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.