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.
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 -*-
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))
精彩评论