如何使emacs正确处理扩展名错误的文件? [英] how do I get emacs to treat a file with the wrong extension correctly?

查看:79
本文介绍了如何使emacs正确处理扩展名错误的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此(让我们不必担心为什么)我有一个名为 dotemacs .emacs 文件和一个 .bashrc 文件称为 dotbashrc .

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.

当我加载 dotemacs 时,没有语法高亮(除其他外).如果我执行 M-x lisp-mode ,那么一切都很好.

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

在不更改文件名的情况下,如何使emacs自动识别 dotemacs 是Lisp文件并进入 lisp模式?对于bash脚本和扩展名错误(或没有扩展名)的任何其他类型的文件也是如此.

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.

推荐答案

您可以将其放在dotemacs文件的顶部:

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

; -*- mode: lisp -*-

在加载文件时使它启动elisp模式.

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

对于shell脚本,放置#!/bin/bash(对于您使用的任何shell)都足以打开正确的模式.或者将其放在文件顶部:

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

这篇关于如何使emacs正确处理扩展名错误的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆