So I know that I can put at the first or second line of a file a line such as:

# -*- mode: conf -*-

to tell Emacs what major mode I want the file to be opened with.

But if that mode isn't installed I wish Emacs to fallback to a different mode. For example I wish to use the apache-mode, but if it doesn't exist I wish to fallback to conf-mode.

Is this possible, and if so how?

1 Answer 1


Found it:

# -*- mode: conf; mode: apache -*-

It seems that the last valid mode wins, so I need to put the my wanted mode last, and the fallback mode(s) before it.

  • 1
    Interesting. I suspect that will activate all the named modes (those that are available at least), one after the other. This should do no harm, but might be a bit time consuming. It's a handy trick, though. Commented Aug 23, 2018 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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