Emacs:只为一个文件设置制表符缩进 [英] Emacs: Set tab indent for just one file on the fly
问题描述
我在一个开源项目上工作,创建者将其标签缩进设置为2个空格。
我想只是启动它的一个文件,我的工作,而不是其他类型的文件。必须有一些类似于 M-x set-tab-indent
的东西。这是一个以 .js
结尾的JavaScript文件。
我知道我可以使用:
(setq-default tab-width int)
在我的 .emacs
文件内,但我只是调用一个 Mx 命令
设置它,并在我的这个文件的工作期间忘记它。我尝试了 Mx apropos
和Google,但找不到具体的命令。
谢谢。
在项目目录中创建一个文件.dir-locals.el,并填写如下: p>
((nil。((tab-width。2))))
pre>
这将自动设置tab-width,您不必修改实际的文件(这可能是版本控制的。)
请参阅手册有关格式的更多信息。我相信这需要Emacs 23。
I work on an open source project where the creator sets his tab-indents to 2 spaces.
I'd like to just enable it on the fly for the one file I work on and not other files of the same type. There must be something like M-x
set-tab-indent
. It is a JavaScript file ending in.js
.I know I can use:
(setq-default tab-width int)
inside my
.emacs
file, but I rather just call an M-xcommand
to set it and forget it during my duration of working on this file. I tried M-xapropos
and Google but couldn't find the specific command.Thanks.
解决方案Create a file ".dir-locals.el" in the project's directory and fill it like this:
((nil . ((tab-width . 2))))
This will take care of setting tab-width automatically and you don't have to modify the actual file (which is likely version-controlled.)
See the manual for more information about the format. I believe this requires Emacs 23.
这篇关于Emacs:只为一个文件设置制表符缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!