Emacs代码根据现有代码自动设置缩进选项卡模式 [英] Emacs code to automatically set indent-tabs-mode according to existing code

查看:263
本文介绍了Emacs代码根据现有代码自动设置缩进选项卡模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有准备好的Emacs代码/包根据被访问的文件自动设置缩进选项卡模式?也就是说,如果当前访问的文件使用制表符进行缩进,则indent-tabs-mode应该设置为本地缓冲区为true。相应地,如果使用空格,则缩进选项卡模式应设置为false。这样做的目的是自动检测和使用现有项目的标签模式(不需要特定于Emacs的文件变量注释),以保持与现有代码的选项卡样式保持一致。



此检测的更高级版本可能适应于单个文件可能具有混合选项卡和空格的事实。在这种情况下,明智的启发式可能是在缩进时使用上一行的标签模式,而不是对整个文件的全局选项卡模式进行决定。

解决方案

您还可能对dtrt-indent感兴趣,除了确定是否使用选项卡之外,还可以使用空格来检测偏移量。



http://savannah.nongnu.org/projects/dtrt-indent/


Is there ready Emacs code/package to automatically set indent-tabs-mode according to the file being visited? That is, if the currently visited file uses tabs for indentation, indent-tabs-mode should be set buffer-locally to true. Correspondingly if spaces are used, indent-tabs-mode should be set to false. The purpose of this is to automatically detect and use the tab mode of an existing project (without needing Emacs-specific file variable annotations), to stay consistent with the tab style of existing code.

An even more advanced version of this detection might accomodate for the fact that a single file might have mixed tabs and spaces. In this case a sensible heuristic could be to use the tab mode on the previous line when indenting, instead of deciding upon a tab mode global to the entire file.

解决方案

You might also be interested in dtrt-indent, which detects the offset when spaces are used for indentation in addition to determining if tabs are used.

http://savannah.nongnu.org/projects/dtrt-indent/

这篇关于Emacs代码根据现有代码自动设置缩进选项卡模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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