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

故事扮演 提交于 2019-12-24 06:01:31

问题


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.


回答1:


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 -*-



回答2:


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))


来源:https://stackoverflow.com/questions/7519867/how-do-i-get-emacs-to-treat-a-file-with-the-wrong-extension-correctly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!