尝试将以下内容添加到您的init.el
(在您已有的自定义项下方):
(setq-default indent-tabs-mode t)
从文档中indent-tabs-mode
:
如果不为零,缩进可以插入制表符。
我不使用ruby-mode
所以我不知道之间可能存在的相互作用indent-tabs-mode
and ruby-indent-tabs-mode
。设置可能就足够了indent-tabs-mode
to t
(并删除您所做的自定义ruby-indent-tabs-mode
)。但是,当您将上面的代码片段添加到配置中时,Emacs 的默认行为将是插入制表符以进行缩进。
EDIT
可以看出here https://github.com/zenspider/enhanced-ruby-mode/blob/master/enh-ruby-mode.el#L76, enh-ruby-mode https://github.com/zenspider/enhanced-ruby-mode定义了一个名为的可定制变量enh-ruby-indent-tabs-mode
默认值为nil
. Later on https://github.com/zenspider/enhanced-ruby-mode/blob/master/enh-ruby-mode.el#L472该变量的值用于覆盖indent-tabs-mode
,这就是为什么设置indent-tabs-mode
to t
对缓冲区没有影响enh-ruby-mode
已启用。
所以除非你启用除此之外的任何其他模式ruby-mode
and enh-ruby-mode
这可能会修改indent-tabs-mode
变量,添加
(setq enh-ruby-indent-tabs-mode t)
to your init.el
应该可以解决你的问题。
另一个编辑(工作解决方案)
(学分:这个答案 https://stackoverflow.com/a/21788651/1199226让我走上正轨。)
Using
我可以通过将以下内容添加到否则完全是空的 init.el
file:
(package-initialize)
(setq-default tab-width 2)
(setq enh-ruby-indent-tabs-mode t)
(defvaralias 'enh-ruby-indent-level 'tab-width)
(defvaralias 'enh-ruby-hanging-indent-level 'tab-width)
该解决方案适用于 Emacs 的 GUI 和控制台版本。它可能会与您的其他自定义设置很好地集成,但您will需要删除custom-set-variables
部分及其下面的所有内容来自您的版本init.el
你在上面发帖了。
Note also that if you do come across a situation in which Emacs inserts a space instead of a tab you can always delete it and force insertion of a tab by quoting it https://www.gnu.org/software/emacs/manual/html_node/emacs/Inserting-Text.html via C-q TAB.
包起来
原来有一个bug https://github.com/zenspider/enhanced-ruby-mode/issues/42 in enh-ruby-mode
这会导致缩进失败从第二层开始的块 when enh-ruby-indent-tabs-mode
被设定为t
。作者/维护者enh-ruby-mode
没有修复它的计划,但错误报告中包含一个据称可以修复该问题的补丁。