使用标签代替Emacs红宝石模式中的空格缩进 [英] Indent with tab instead of spaces in Emacs ruby-mode
问题描述
我一直在尝试配置Emacs,以便在缩进Ruby代码时插入tab而不是一系列空格。
到目前为止,我已经尝试将var ruby-indent-tabs-mode
设置为 t
,以便根据文档,它将在不为零的情况下将选项卡插入红宝石模式。但是到目前为止,没有骰子。
我也尝试通过轻松自定义
进行自定义,其中插入以下内容进入我的 init.el
:
(custom-set-variables
;; custom-set-variables是由Custom添加的
;;如果你手工编辑,你可能会搞砸,所以要小心
;;你的init文件应该只包含一个这样的例子
;;如果有不止一个,他们将无法正常工作
'(ruby-indent-tabs-mode t))
(custom-set-faces
;; Custom-set-faces由Custom添加
;;如果你手工编辑,你可以把它弄乱,所以要小心
;;你的init文件应该包含
;;如果有不止一个,他们将无法正常工作
)
在通过 Ch v 检查变量后,它会将变量设置为 t
,但按< kbd> TAB 不断插入空格。
我甚至尝试编辑使用 .el
文件进行红宝石模式,并重新编译它不起作用。
帮助将不胜感激。
-----编辑-----
以下是通过 Ch m 报告的次要模式:
启用次要模式:缩略语自动完成自动组合
自动压缩自动加密文件名阴影字体锁
全局自动 - 完整的全球字体锁定红宝石行号菜单栏
显示Smartparens显示Smartparens全球Smartparens
Smartparens全球瞬态标记
init.el
文件目前有:
(cask-initialize)
(需要托盘)
(add-to-list'load-path〜/ elisp)
(加载php-mode)
(add-to-list'auto-mode-alist
'(\\.php [34]?\\\\ | \\.phtml\\'。php-mode))
(global-set-k ey(kbdCx< up>)'windmove-up)
(global-set-key(kbdCx< down>)'windmove-down)
(global-set- key(kbdCx< right>)'windmove-right)
(global-set-key(kbdCx< left>)'windmove-left)
require'package)
(add-to-list'package-archives
'(marmalade)。
http://marmalade-repo.org/packages/))
(package-initialize)
(global-set-key(kbdCx> )
(global-set-key(kbdCx<)'mc / mark-previous-like-this)
(global-set-键(kbdCc C-<)'mc / mark-all-like-this)
(全局设置键(kbdCSc CSc)'mc / edit-lines)
(需要smartparens-config)
(需要smartparens-ruby)
(需要smartparens-erb)
(smartparens-global-mode)
-smartparens-global-mode t)
(sp-with-modes'(rhtml-mode)
(sp-local-pair<%=%>)
(sp-local-pair<% - %>))
(require'auto-complete-config)
(add-to-list'ac-dictionary -directories
〜/ .emacs.d / .cask / 24.3.50.1 / elpa / auto-complete-20130724.1750 / dict)
(ac-config-default)
(setq ac -ignore-case nil)
(add-to-list'ac-modes'enh-ruby-mode)
(add-to-list'ac-modes'web-mode)
(custom-set-variables
;; Custom自定义变量被添加。
;;如果你手工编辑,你可以把它弄乱,所以要小心。
;;您的init文件应该只包含一个这样的实例。
;;如果有不止一个,就不行。
'(indent-tabs-mode t)
'(ruby-indent-tabs-mode t))
(custom-set-faces
;; custom-set-faces
;;如果你手动编辑它,你可以把它弄乱,所以要小心
;;你的init文件应该只包含一个这样的实例
;;
(setq-default indent-tabs-mode t)
(setq enh-ruby-indent- tab-mode t)
(smart-tabs-insinuate'ruby)
(smart-tabs-advice ruby-indent-line ruby-indent-level)
(setq ruby -indent-tabs-mode t)
遵循 init.el
(在您已经拥有的自定义项之下):
(setq-default indent-tabs-mode t)
从 indent-tabs-mode
:
如果这是非零,缩进可以插入选项卡。 p>
我不使用 ruby-mode
,所以我不知道 indent-tabs-mode
和 ruby-indent-tabs-mode
。将 indent-tabs-mode
设置为 t
(并将您所做的自定义项删除红宝石缩进的选项卡模式
)。但是,当您将上述代码段添加到配置中时,Emacs的默认行为将是插入缩进的选项卡。
编辑
可以看出这里, enh-ruby-mode
定义了一个可定制的变量,名为 enh-ruby-indent-tabs-mode
,默认值为零
。 稍后的价值的变量用于覆盖 indent-tabs-mode
的值,这就是为什么设置 indent-tabs-mode
t
对使用 enh-ruby-mode
的缓冲区没有影响。
所以除非你启用了 ruby-mode
和 enh-ruby-mode
可能修改 indent-tabs-mode
变量,添加
(setq enh-ruby-indent-tabs-mode t)
到你的 init.el
应该解决你的问题。
另一个编辑(工作解决方案)
(点数:这个答案让我走上正轨) / p>
使用
-
Emacs 24.3.1
-
ruby-mode
version 1.2 (内置) -
code> enh-ruby-mode 版本 20140406.252 (通过 Mx
...)
我能够通过将以下内容添加到否则完全为空 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)
此解决方案适用于GUI和控制台版本的Emacs。它可能会与您的其他自定义功能整合,但您将 需要从 c \\ c>自定义设置变量部分和您上面发布的 init.el
还要注意,如果您遇到Emacs插入的情况一个空格而不是一个标签,您可以随时删除它,并强制插入一个选项卡引用它通过 Cq TAB 。
包装
原来有一个 bug 在 enh-ruby-mode
中,导致从第二级开始块的缩进失败当 enh-ruby-indent-tabs-mode
设置为 t
。 enh-ruby-mode
的作者/维护者没有修复它的计划,但是错误报告包含一个补丁,可以解决这个问题。
I've been trying to configure Emacs so that it insert a 'tab' instead of a series of 'spaces' when indenting Ruby code.
So far, I've tried setting the var ruby-indent-tabs-mode
to t
so that, as per the documentation, it would "insert tabs in ruby mode if this is non-nil.". But so far, no dice.
I've also tried customising it via Easy customisation
, which inserted the following into my init.el
:
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ruby-indent-tabs-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
And after inspecting the variable via C-h v, it reports the variable is set to t
, but pressing TAB keeps on inserting spaces.
I even tried editing the .el
file for ruby-mode and re-compiling it to no effect.
Help would be appreciated.
----- EDIT -----
Here's the minor modes reported active via C-h m:
Enabled minor modes: Abbrev Auto-Complete Auto-Composition
Auto-Compression Auto-Encryption File-Name-Shadow Font-Lock
Global-Auto-Complete Global-Font-Lock Inf-Ruby Line-Number Menu-Bar
Show-Smartparens Show-Smartparens-Global Smartparens
Smartparens-Global Transient-Mark
The init.el
file currently has:
(require 'cask "/Users/snowingheart/.cask/cask.el")
(cask-initialize)
(require 'pallet)
(add-to-list 'load-path "~/elisp")
(load "php-mode")
(add-to-list 'auto-mode-alist
'("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode))
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)
(require 'package)
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/"))
(package-initialize)
(global-set-key (kbd "C-x >") 'mc/mark-next-like-this)
(global-set-key (kbd "C-x <") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(require 'smartparens-config)
(require 'smartparens-ruby)
(require 'smartparens-erb)
(smartparens-global-mode)
(show-smartparens-global-mode t)
(sp-with-modes '(rhtml-mode)
(sp-local-pair "<%=" "%>")
(sp-local-pair "<%-" "%>"))
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories
"~/.emacs.d/.cask/24.3.50.1/elpa/auto-complete-20130724.1750/dict")
(ac-config-default)
(setq ac-ignore-case nil)
(add-to-list 'ac-modes 'enh-ruby-mode)
(add-to-list 'ac-modes 'web-mode)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(indent-tabs-mode t)
'(ruby-indent-tabs-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(setq-default indent-tabs-mode t)
(setq enh-ruby-indent-tabs-mode t)
(smart-tabs-insinuate 'ruby)
(smart-tabs-advice ruby-indent-line ruby-indent-level)
(setq ruby-indent-tabs-mode t)
Try adding the following to your init.el
(below the customizations you already have):
(setq-default indent-tabs-mode t)
From the documentation for indent-tabs-mode
:
Indentation can insert tabs if this is non-nil.
I don't use ruby-mode
so I don't know about possible interactions between indent-tabs-mode
and ruby-indent-tabs-mode
. It might just be enough to set indent-tabs-mode
to t
(and erase the customizations you made to ruby-indent-tabs-mode
). But when you add the snippet above to your configuration, the default behavior for Emacs will be to insert tabs for indentation.
EDIT
As can be seen here, enh-ruby-mode
defines a customizable variable called enh-ruby-indent-tabs-mode
with a default value of nil
. Later on the value of this variable is used to override the value of indent-tabs-mode
, which is why setting indent-tabs-mode
to t
has no effect on buffers with enh-ruby-mode
enabled.
So unless you enable any other modes besides ruby-mode
and enh-ruby-mode
that might be modifying the indent-tabs-mode
variable, adding
(setq enh-ruby-indent-tabs-mode t)
to your init.el
should fix your problem.
Another EDIT (working solution)
(Credits: This answer put me on the right track.)
Using
Emacs 24.3.1
ruby-mode
version 1.2 (built-in)enh-ruby-mode
version 20140406.252 (installed via M-xpackage-install
...)
I was able to make it work by adding the following to an otherwise completely empty 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)
This solution works for both the GUI and the console version of Emacs. It will probably integrate fine with your other customizations but you will need to remove the custom-set-variables
section and everything below it from the version of your init.el
you posted above.
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 via C-q TAB.
Wrapping up
Turns out there is a bug in enh-ruby-mode
which causes indentation to fail for blocks starting from the second level when enh-ruby-indent-tabs-mode
is set to t
. The author/maintainer of enh-ruby-mode
has no plans of fixing it, but the bug report includes a patch that supposedly fixes the issue.
这篇关于使用标签代替Emacs红宝石模式中的空格缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!