我一直在尝试配置Emacs,以便它插入一个'标签'而不是一系列的空间'缩进Ruby代码时。
到目前为止,我已尝试将var ruby-indent-tabs-mode
设置为t
,以便根据文档,如果不是,则会在ruby模式下插入标签零。&#34 ;.但到目前为止,没有骰子。
我还尝试通过Easy customisation
进行自定义,并将以下内容插入我的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.
)
通过 Ch v 检查变量后,它报告变量设置为t
,但按 TAB 继续插入空格。
我甚至尝试为ruby-mode编辑.el
文件并重新编译它无效。
帮助将不胜感激。
-----编辑-----
这里通过 C-h m 报告的次要模式是活跃的:
启用次要模式:缩写自动完成自动组合
自动压缩自动加密文件名称阴影字体锁定
全局自动完成Global-Font-Lock Inf-Ruby线号菜单栏
Show-Smartparens Show-Smartparens-Global Smartparens
Smartparens-Global Transient-Mark
init.el
文件目前有:
(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)
答案 0 :(得分:2)
尝试将以下内容添加到init.el
(在您已有的自定义项下方):
(setq-default indent-tabs-mode t)
来自indent-tabs-mode
的文档:
缩进可以插入标签,如果这是非零的。
我不使用ruby-mode
因此我不知道indent-tabs-mode
和ruby-indent-tabs-mode
之间可能的互动。将indent-tabs-mode
设置为t
(并删除您对ruby-indent-tabs-mode
所做的自定义)可能就足够了。但是当您将上面的代码段添加到配置中时,Emacs的默认行为是插入缩进标签。
可以看到here,enh-ruby-mode
定义了一个名为enh-ruby-indent-tabs-mode
的可自定义变量,其默认值为nil
。 Later on此变量的值用于覆盖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
应该解决您的问题。
(致谢:This answer让我走上正轨。)
使用
Emacs 24.3.1
ruby-mode
版 1.2 (内置)
enh-ruby-mode
版 20140406.252 (通过 M-x package-install
安装...)
我能够通过将以下内容添加到完全空的 init.el
文件中来实现:
(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和控制台版本。它可能与您的其他自定义功能很好地集成,但将需要从您在上面发布的custom-set-variables
版本中删除init.el
部分及其下方的所有部分。
另请注意,如果您遇到Emacs插入空格而不是标签的情况,您可以随时将其删除,并强制quoting it通过 Cq <插入标签KBD> TAB
当enh-ruby-mode
设置为{{1}时,enh-ruby-indent-tabs-mode
中的bug导致块从第二级开始缩进失败}}。 t
的作者/维护者没有修复它的计划,但是错误报告包含一个可以修复问题的补丁。