John Lawrence Aspden
John Lawrence Aspden

Reputation: 17470

how do I get emacs to treat a file with the wrong extension correctly?

So (let us not concern ourselves with why) I have a .emacs file which is called dotemacs, and a .bashrc file which is called dotbashrc.

When I load up dotemacs, I get no syntax highlighing (amongst other things). If I do M-x lisp-mode then all is well.

Without changing the name of the file, how do I get emacs to recognise automatically that dotemacs is a lisp file and go into lisp-mode? Similarly for bash scripts, and indeed any other type of file with the wrong (or no) extension.

Upvotes: 2

Views: 1046

Answers (2)

meeiw
meeiw

Reputation: 41

I like the answer above, but here is another way you could do it :)

Add the following line to your .emacs

(add-to-list 'auto-mode-alist '(".emacs" . lisp-mode))

Upvotes: 4

Burton Samograd
Burton Samograd

Reputation: 3638

You can put this at the top of the dotemacs file:

; -*- mode: lisp -*-

causing it to start elisp-mode when you load the file.

For shell scripts, putting a #!/bin/bash (for whichever shell you are using) is enough to turn on the correct mode. Or otherwise put this at the top of the file:

# -*- mode: sh -*-

Upvotes: 6

Related Questions